-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelperFor.h
151 lines (120 loc) · 4.02 KB
/
HelperFor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef HELPERFOR_H
#define HELPERFOR_H
//-----------------------------------------------------------------------------
// Package: PhysicsTools
// Sub-Package: TheNtupleMaker
// Description: Base class for helpers
// Created: Aug, 2010 Harrison B. Prosper
// 01 May, 2011 HBP add param
//$Revision: 1.6 $
//-----------------------------------------------------------------------------
#include <sstream>
#include <memory>
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "PhysicsTools/TheNtupleMaker/interface/HLTConfigProvider.h"
#include "PhysicsTools/TheNtupleMaker/interface/Configuration.h"
//-----------------------------------------------------------------------------
/// Base class for helpers.
template <typename X>
class HelperFor
{
public:
HelperFor() : blockname(Configuration::instance().getBlockname()),
buffername(Configuration::instance().getBuffername()),
labelname(Configuration::instance().getLabelname()),
parameters(Configuration::instance().getParameters()),
config(Configuration::instance().getConfig()),
hltconfig(Configuration::instance().getHLTconfig()),
event(0), // pointer to current event
eventsetup(0), // pointer to current event setup
object(0), // pointer to current helped object
oindex(0), // index of current helped object (dumb pointer)
index(0), // index of current helper object (dumb pointer)
count(1) // number of instances returned by helper
{}
virtual ~HelperFor() {}
///
void cacheEvent(const edm::Event& e, const edm::EventSetup& s)
{
event = &e;
eventsetup = &s;
hltconfig = Configuration::instance().getHLTconfig();
}
///
void cacheObject(const X& o, int n=0)
{
object = &o;
oindex = n;
count = 1;
}
/// return number of items per cached object
int size() const { return count; }
/// set index of item to be retrieved.
void set(int n) { index = n; }
// ---------------- can be overridden
/// do some event-level analysis, if needed.
virtual void analyzeEvent() {}
/// do some object-level analysis, if needed.
virtual void analyzeObject() {}
/// do some post event-level analysis, if needed.
virtual void flushEvent() {}
// ---------------- available to user
std::string blockname;
std::string buffername;
std::string labelname;
std::map<std::string, std::string> parameters;
template <typename T>
T parameter(std::string key)
{
if ( parameters.find(key) != parameters.end() )
{
T a;
std::istringstream iss(parameters[key]);
iss >> a;
return a;
}
return (T)0;
}
std::string parameter(std::string key)
{
if ( parameters.find(key) != parameters.end() )
return parameters[key];
else
return "";
}
// template <>
// std::string parameter<std::string>(std::string key)
// {
// if ( parameters.find(key) != parameters.end() )
// return parameters[key];
// else
// return "";
// }
// std::istringstream& parameter(std::string key)
// {
// std::string value("");
// if ( parameters.find(key) != parameters.end() ) value = parameters[key];
// std::auto_ptr<std::istringstream> iss(new std::istringstream(value));
// return *(iss->get());
// }
/// Pointer to ParameterSet initialized from config file.
const edm::ParameterSet* config;
///
const HLTConfigProvider* hltconfig;
/// Parameter set local to buffer
//const edm::ParameterSet localconfig;
/// Pointer to event.
const edm::Event* event;
/// Pointer to event.
const edm::EventSetup* eventsetup;
/// Pointer to current (helped) object
const X* object;
/// Index of current (helped) object (with count starting at zero).
int oindex;
/// Index of current helper object, which could differ from oindex..
int index;
///
int count;
};
#endif