PhysicsTools
UtilAlgos
interface
VariableHelper.h
Go to the documentation of this file.
1
#ifndef ConfigurableAnalysis_VariableHelper_H
2
#define ConfigurableAnalysis_VariableHelper_H
3
4
#include "
FWCore/Framework/interface/ConsumesCollector.h
"
5
#include "
FWCore/ServiceRegistry/interface/ActivityRegistry.h
"
6
#include "
PhysicsTools/UtilAlgos/interface/CachingVariable.h
"
7
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
8
#include "
DataFormats/Provenance/interface/ModuleDescription.h
"
9
#include "
FWCore/ServiceRegistry/interface/ModuleCallingContext.h
"
10
11
class
VariableHelper
{
12
public
:
13
VariableHelper
(
const
edm::ParameterSet
& iConfig,
edm::ConsumesCollector
& iC);
14
~VariableHelper
() {
15
for
(
iterator
it =
variables_
.begin(); it !=
variables_
.end(); ++it) {
16
delete
it->second;
17
}
18
}
19
typedef
std::map<std::string, const CachingVariable*>::const_iterator
iterator
;
20
21
const
CachingVariable
*
variable
(
std::string
name
)
const
;
22
23
iterator
begin
() {
return
variables_
.begin(); }
24
iterator
end
() {
return
variables_
.end(); }
25
26
void
setHolder
(
std::string
hn);
27
void
print
()
const
;
28
std::string
printValues
(
const
edm::Event
&
event
)
const
;
29
30
private
:
31
std::map<std::string, const CachingVariable*>
variables_
;
32
};
33
34
class
VariableHelperService
{
35
private
:
36
VariableHelper
*
SetVariableHelperUniqueInstance_
;
37
std::map<std::string, VariableHelper*>
multipleInstance_
;
38
39
bool
printValuesForEachEvent_
;
40
std::string
printValuesForEachEventCategory_
;
41
42
public
:
43
VariableHelperService
(
const
edm::ParameterSet
& iConfig,
edm::ActivityRegistry
&
r
)
44
:
SetVariableHelperUniqueInstance_
(nullptr) {
45
//r.watchPreModule(this, &VariableHelperService::preModule );
46
r
.watchPreModuleEvent(
this
, &
VariableHelperService::preModule
);
47
//r.watchPostProcessEvent(this, &VariableHelperService::postProcess );
48
r
.watchPostEvent(
this
, &
VariableHelperService::postProcess
);
49
printValuesForEachEvent_
= iConfig.
exists
(
"printValuesForEachEventCategory"
);
50
if
(
printValuesForEachEvent_
)
51
printValuesForEachEventCategory_
= iConfig.
getParameter
<
std::string
>(
"printValuesForEachEventCategory"
);
52
}
53
~VariableHelperService
() {
54
for
(std::map<std::string, VariableHelper*>::iterator it =
multipleInstance_
.begin(); it !=
multipleInstance_
.end();
55
++it) {
56
delete
it->second;
57
}
58
}
59
60
VariableHelper
&
init
(
std::string
user
,
const
edm::ParameterSet
& iConfig,
edm::ConsumesCollector
&& iC) {
61
if
(
multipleInstance_
.find(
user
) !=
multipleInstance_
.end()) {
62
std::cerr
<<
user
<<
" VariableHelper user already defined."
<< std::endl;
63
throw
;
64
}
else
65
SetVariableHelperUniqueInstance_
=
new
VariableHelper
(iConfig, iC);
66
multipleInstance_
[
user
] =
SetVariableHelperUniqueInstance_
;
67
SetVariableHelperUniqueInstance_
->
setHolder
(
user
);
68
69
SetVariableHelperUniqueInstance_
->
print
();
70
return
(*
SetVariableHelperUniqueInstance_
);
71
}
72
73
VariableHelper
&
get
() {
74
if
(!
SetVariableHelperUniqueInstance_
) {
75
std::cerr
<<
" none of VariableHelperUniqueInstance_ or SetVariableHelperUniqueInstance_ is valid."
<< std::endl;
76
throw
;
77
}
else
78
return
(*
SetVariableHelperUniqueInstance_
);
79
}
80
81
void
preModule
(
edm::StreamContext
const
&,
edm::ModuleCallingContext
const
& mcc) {
82
const
edm::ModuleDescription
&
desc
= *mcc.
moduleDescription
();
83
//does a set with the module name, except that it does not throw on non-configured modules
84
std::map<std::string, VariableHelper*>::iterator
f
=
multipleInstance_
.find(
desc
.moduleLabel());
85
if
(
f
!=
multipleInstance_
.end()) {
86
SetVariableHelperUniqueInstance_
= (
f
->second);
87
return
;
88
}
89
SetVariableHelperUniqueInstance_
=
nullptr
;
90
}
91
92
void
postProcess
(
edm::StreamContext
const
& sc) {
93
if
(!
printValuesForEachEvent_
)
94
return
;
95
96
/*const edm::Event & event;
97
std::map<std::string, VariableHelper* >::iterator f= multipleInstance_.begin();
98
for (; f!=multipleInstance_.end();++f){
99
// std::cout<<" category is: "<<printValuesForEachEventCategory_+"|"+f->first<<std::endl;
100
// std::cout<<f->first<<"\n" <<f->second->printValues(event);
101
102
edm::LogInfo(printValuesForEachEventCategory_+"|"+f->first)<<f->first<<"\n"
103
<<f->second->printValues(event);
104
}
105
*/
106
}
107
108
VariableHelper
&
set
(
std::string
user
) {
109
std::map<std::string, VariableHelper*>::iterator
f
=
multipleInstance_
.find(
user
);
110
if
(
f
==
multipleInstance_
.end()) {
111
std::cerr
<<
user
<<
" VariableHelper user not defined."
<< std::endl;
112
throw
;
113
}
else
{
114
SetVariableHelperUniqueInstance_
= (
f
->second);
115
return
(*
SetVariableHelperUniqueInstance_
);
116
}
117
}
118
};
119
120
#endif
ModuleCallingContext.h
MessageLogger.h
VariableHelperService::~VariableHelperService
~VariableHelperService()
Definition:
VariableHelper.h:53
f
double f[11][100]
Definition:
MuScleFitUtils.cc:78
VariableHelper::print
void print() const
Definition:
VariableHelper.cc:29
CachingVariable.h
VariableHelper::VariableHelper
VariableHelper(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
Definition:
VariableHelper.cc:9
VariableHelperService::get
VariableHelper & get()
Definition:
VariableHelper.h:73
VariableHelperService::init
VariableHelper & init(std::string user, const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
Definition:
VariableHelper.h:60
VariableHelperService::VariableHelperService
VariableHelperService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &r)
Definition:
VariableHelper.h:43
VariableHelper::printValues
std::string printValues(const edm::Event &event) const
Definition:
VariableHelper.cc:36
CachingVariable
Definition:
CachingVariable.h:40
edm::ModuleCallingContext::moduleDescription
ModuleDescription const * moduleDescription() const
Definition:
ModuleCallingContext.h:50
edm::ModuleDescription
Definition:
ModuleDescription.h:21
VariableHelperService::preModule
void preModule(edm::StreamContext const &, edm::ModuleCallingContext const &mcc)
Definition:
VariableHelper.h:81
ModuleDescription.h
ActivityRegistry.h
VariableHelper::~VariableHelper
~VariableHelper()
Definition:
VariableHelper.h:14
edm::StreamContext
Definition:
StreamContext.h:31
VariableHelper::iterator
std::map< std::string, const CachingVariable * >::const_iterator iterator
Definition:
VariableHelper.h:19
edm::ActivityRegistry
Definition:
ActivityRegistry.h:133
VariableHelper
Definition:
VariableHelper.h:11
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
VariableHelper::variable
const CachingVariable * variable(std::string name) const
Definition:
VariableHelper.cc:49
edm::ParameterSet::exists
bool exists(std::string const ¶meterName) const
checks if a parameter exists
Definition:
ParameterSet.cc:681
VariableHelper::setHolder
void setHolder(std::string hn)
Definition:
VariableHelper.cc:22
edm::ParameterSet
Definition:
ParameterSet.h:47
VariableHelperService::postProcess
void postProcess(edm::StreamContext const &sc)
Definition:
VariableHelper.h:92
VariableHelper::end
iterator end()
Definition:
VariableHelper.h:24
VariableHelperService::printValuesForEachEvent_
bool printValuesForEachEvent_
Definition:
VariableHelper.h:39
VariableHelper::variables_
std::map< std::string, const CachingVariable * > variables_
Definition:
VariableHelper.h:31
VariableHelper::begin
iterator begin()
Definition:
VariableHelper.h:23
VariableHelperService
Definition:
VariableHelper.h:34
EnviromentSettings.user
user
Definition:
EnviromentSettings.py:30
alignCSCRings.r
r
Definition:
alignCSCRings.py:93
VariableHelperService::SetVariableHelperUniqueInstance_
VariableHelper * SetVariableHelperUniqueInstance_
Definition:
VariableHelper.h:36
submitPVResolutionJobs.desc
string desc
Definition:
submitPVResolutionJobs.py:251
VariableHelperService::multipleInstance_
std::map< std::string, VariableHelper * > multipleInstance_
Definition:
VariableHelper.h:37
VariableHelperService::set
VariableHelper & set(std::string user)
Definition:
VariableHelper.h:108
Skims_PA_cff.name
name
Definition:
Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition:
ParameterSet.h:303
ConsumesCollector.h
event
Definition:
event.py:1
edm::Event
Definition:
Event.h:73
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition:
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
VariableHelperService::printValuesForEachEventCategory_
std::string printValuesForEachEventCategory_
Definition:
VariableHelper.h:40
edm::ConsumesCollector
Definition:
ConsumesCollector.h:45
edm::ModuleCallingContext
Definition:
ModuleCallingContext.h:29
Generated for CMSSW Reference Manual by
1.8.16