CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MEtoEDMConverter.cc
Go to the documentation of this file.
1 
2 
10 #include <cassert>
11 
13 #include "classlib/utils/StringList.h"
14 #include "classlib/utils/StringOps.h"
17 
18 using namespace lat;
19 
21  std::string MsgLoggerCat = "MEtoEDMConverter_MEtoEDMConverter";
22 
23  // get information from parameter set
24  fName = iPSet.getUntrackedParameter<std::string>("Name", "MEtoEDMConverter");
25  verbosity = iPSet.getUntrackedParameter<int>("Verbosity", 0);
26  frequency = iPSet.getUntrackedParameter<int>("Frequency", 50);
27  path = iPSet.getUntrackedParameter<std::string>("MEPathToSave");
28  // use value of first digit to determine default output level (inclusive)
29  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
30  verbosity %= 10;
31 
32  // print out Parameter Set information being used
33  if (verbosity >= 0) {
34  edm::LogInfo(MsgLoggerCat) << "\n===============================\n"
35  << "Initialized as EDProducer with parameter values:\n"
36  << " Name = " << fName << "\n"
37  << " Verbosity = " << verbosity << "\n"
38  << " Frequency = " << frequency << "\n"
39  << " Path = " << path << "\n"
40  << "===============================\n";
41  }
42 
43  std::string sName;
44 
45  // create persistent objects
46 
47  sName = fName + "Run";
48  produces<MEtoEDM<TH1F>, edm::Transition::EndRun>(sName);
49  produces<MEtoEDM<TH1S>, edm::Transition::EndRun>(sName);
50  produces<MEtoEDM<TH1D>, edm::Transition::EndRun>(sName);
51  produces<MEtoEDM<TH1I>, edm::Transition::EndRun>(sName);
52  produces<MEtoEDM<TH2F>, edm::Transition::EndRun>(sName);
53  produces<MEtoEDM<TH2S>, edm::Transition::EndRun>(sName);
54  produces<MEtoEDM<TH2D>, edm::Transition::EndRun>(sName);
55  produces<MEtoEDM<TH2I>, edm::Transition::EndRun>(sName);
56  produces<MEtoEDM<TH3F>, edm::Transition::EndRun>(sName);
57  produces<MEtoEDM<TProfile>, edm::Transition::EndRun>(sName);
58  produces<MEtoEDM<TProfile2D>, edm::Transition::EndRun>(sName);
59  produces<MEtoEDM<double>, edm::Transition::EndRun>(sName);
60  produces<MEtoEDM<long long>, edm::Transition::EndRun>(sName);
61  produces<MEtoEDM<TString>, edm::Transition::EndRun>(sName);
62 
63  sName = fName + "Lumi";
64  produces<MEtoEDM<TH1F>, edm::Transition::EndLuminosityBlock>(sName);
65  produces<MEtoEDM<TH1S>, edm::Transition::EndLuminosityBlock>(sName);
66  produces<MEtoEDM<TH1D>, edm::Transition::EndLuminosityBlock>(sName);
67  produces<MEtoEDM<TH1I>, edm::Transition::EndLuminosityBlock>(sName);
68  produces<MEtoEDM<TH2F>, edm::Transition::EndLuminosityBlock>(sName);
69  produces<MEtoEDM<TH2S>, edm::Transition::EndLuminosityBlock>(sName);
70  produces<MEtoEDM<TH2D>, edm::Transition::EndLuminosityBlock>(sName);
71  produces<MEtoEDM<TH2I>, edm::Transition::EndLuminosityBlock>(sName);
72  produces<MEtoEDM<TH3F>, edm::Transition::EndLuminosityBlock>(sName);
73  produces<MEtoEDM<TProfile>, edm::Transition::EndLuminosityBlock>(sName);
74  produces<MEtoEDM<TProfile2D>, edm::Transition::EndLuminosityBlock>(sName);
75  produces<MEtoEDM<double>, edm::Transition::EndLuminosityBlock>(sName);
76  produces<MEtoEDM<long long>, edm::Transition::EndLuminosityBlock>(sName);
77  produces<MEtoEDM<TString>, edm::Transition::EndLuminosityBlock>(sName);
78 
79  consumesMany<DQMToken, edm::InLumi>();
80  consumesMany<DQMToken, edm::InRun>();
81  usesResource("DQMStore");
82 
83  static_assert(sizeof(int64_t) == sizeof(long long), "type int64_t is not the same length as long long");
84 }
85 
87 
89 
90 std::shared_ptr<meedm::Void> MEtoEDMConverter::globalBeginRun(edm::Run const& iRun,
91  const edm::EventSetup& iSetup) const {
92  return std::shared_ptr<meedm::Void>();
93 }
94 
95 void MEtoEDMConverter::globalEndRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {}
96 
99  store->meBookerGetter([&](DQMStore::IBooker& b, DQMStore::IGetter& g) { putData(g, iRun, false, iRun.run(), 0); });
100 }
101 
103  edm::EventSetup const&) const {
104  return std::shared_ptr<meedm::Void>();
105 }
106 
110  putData(g, iLumi, true, iLumi.run(), iLumi.id().luminosityBlock());
111  });
112 }
113 
114 template <class T>
115 void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi) {
116  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
117 
118  if (verbosity > 0)
119  edm::LogInfo(MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
120 
121  // extract ME information into vectors
122  std::vector<MonitorElement*>::iterator mmi, mme;
123  std::vector<MonitorElement*> items(iGetter.getAllContents(path, run, lumi));
124 
125  unsigned int n1F = 0;
126  unsigned int n1S = 0;
127  unsigned int n1D = 0;
128  unsigned int n1I = 0;
129  unsigned int n2F = 0;
130  unsigned int n2S = 0;
131  unsigned int n2D = 0;
132  unsigned int n2I = 0;
133  unsigned int n3F = 0;
134  unsigned int nProf = 0;
135  unsigned int nProf2 = 0;
136  unsigned int nDouble = 0;
137  unsigned int nInt64 = 0;
138  unsigned int nString = 0;
139 
140  for (mmi = items.begin(), mme = items.end(); mmi != mme; ++mmi) {
141  MonitorElement* me = *mmi;
142 
143  // store only flagged ME at endLumi transition, and Run-based
144  // histo at endRun transition
145  if (iLumiOnly && !me->getLumiFlag())
146  continue;
147  if (!iLumiOnly && me->getLumiFlag())
148  continue;
149 
150  switch (me->kind()) {
152  ++nInt64;
153  break;
154 
156  ++nDouble;
157  break;
158 
160  ++nString;
161  break;
162 
164  ++n1F;
165  break;
166 
168  ++n1S;
169  break;
170 
172  ++n1D;
173  break;
174 
176  ++n1I;
177  break;
178 
180  ++n2F;
181  break;
182 
184  ++n2S;
185  break;
186 
188  ++n2D;
189  break;
190 
192  ++n2I;
193  break;
194 
196  ++n3F;
197  break;
198 
200  ++nProf;
201  break;
202 
204  ++nProf2;
205  break;
206 
207  default:
208  edm::LogError(MsgLoggerCat) << "ERROR: The DQM object '" << me->getFullname()
209  << "' is neither a ROOT object nor a recognised "
210  << "simple object.\n";
211  continue;
212  }
213  }
214 
215  std::unique_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
216  std::unique_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
217  std::unique_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
218  std::unique_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
219  std::unique_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
220  std::unique_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
221  std::unique_ptr<MEtoEDM<TH1I> > pOut1i(new MEtoEDM<TH1I>(n1I));
222  std::unique_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
223  std::unique_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
224  std::unique_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
225  std::unique_ptr<MEtoEDM<TH2I> > pOut2i(new MEtoEDM<TH2I>(n2I));
226  std::unique_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
227  std::unique_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
228  std::unique_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
229 
230  for (mmi = items.begin(), mme = items.end(); mmi != mme; ++mmi) {
231  MonitorElement* me = *mmi;
232 
233  // store only flagged ME at endLumi transition, and Run-based
234  // histo at endRun transition
235  // DQMStore should only hand out matching MEs
236  assert(iLumiOnly == me->getLumiFlag());
237 
238  // get monitor elements
239  switch (me->kind()) {
241  pOutInt->putMEtoEdmObject(me->getFullname(), me->getIntValue());
242  break;
243 
245  pOutDouble->putMEtoEdmObject(me->getFullname(), me->getFloatValue());
246  break;
247 
249  pOutString->putMEtoEdmObject(me->getFullname(), me->getStringValue());
250  break;
251 
253  pOut1->putMEtoEdmObject(me->getFullname(), *me->getTH1F());
254  break;
255 
257  pOut1s->putMEtoEdmObject(me->getFullname(), *me->getTH1S());
258  break;
259 
261  pOut1d->putMEtoEdmObject(me->getFullname(), *me->getTH1D());
262  break;
263 
265  pOut1i->putMEtoEdmObject(me->getFullname(), *me->getTH1I());
266  break;
267 
269  pOut2->putMEtoEdmObject(me->getFullname(), *me->getTH2F());
270  break;
271 
273  pOut2s->putMEtoEdmObject(me->getFullname(), *me->getTH2S());
274  break;
275 
277  pOut2d->putMEtoEdmObject(me->getFullname(), *me->getTH2D());
278  break;
279 
281  pOut2i->putMEtoEdmObject(me->getFullname(), *me->getTH2I());
282  break;
283 
285  pOut3->putMEtoEdmObject(me->getFullname(), *me->getTH3F());
286  break;
287 
289  pOutProf->putMEtoEdmObject(me->getFullname(), *me->getTProfile());
290  break;
291 
293  pOutProf2->putMEtoEdmObject(me->getFullname(), *me->getTProfile2D());
294  break;
295 
296  default:
297  edm::LogError(MsgLoggerCat) << "ERROR: The DQM object '" << me->getFullname()
298  << "' is neither a ROOT object nor a recognised "
299  << "simple object.\n";
300  continue;
301  }
302 
303  } // end loop through monitor elements
304 
305  std::string sName;
306 
307  if (iLumiOnly) {
308  sName = fName + "Lumi";
309  } else {
310  sName = fName + "Run";
311  }
312 
313  // produce objects to put in events
314  iPutTo.put(std::move(pOutInt), sName);
315  iPutTo.put(std::move(pOutDouble), sName);
316  iPutTo.put(std::move(pOutString), sName);
317  iPutTo.put(std::move(pOut1), sName);
318  iPutTo.put(std::move(pOut1s), sName);
319  iPutTo.put(std::move(pOut1d), sName);
320  iPutTo.put(std::move(pOut2), sName);
321  iPutTo.put(std::move(pOut2s), sName);
322  iPutTo.put(std::move(pOut2d), sName);
323  iPutTo.put(std::move(pOut2i), sName);
324  iPutTo.put(std::move(pOut3), sName);
325  iPutTo.put(std::move(pOutProf), sName);
326  iPutTo.put(std::move(pOutProf2), sName);
327 }
328 
LuminosityBlockID id() const
virtual TH2D * getTH2D() const
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
RunNumber_t run() const
Definition: RunBase.h:40
virtual TH1I * getTH1I() const
virtual TH1F * getTH1F() const
virtual int64_t getIntValue() const
Kind kind() const
Get the type of the monitor element.
~MEtoEDMConverter() override
Log< level::Error, false > LogError
void endRunProduce(edm::Run &, const edm::EventSetup &) override
assert(be >=bs)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
virtual TH1S * getTH1S() const
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:609
void beginJob() override
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
std::shared_ptr< meedm::Void > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
def move
Definition: eostools.py:511
std::shared_ptr< meedm::Void > globalBeginRun(edm::Run const &, const edm::EventSetup &) const override
virtual TH2I * getTH2I() const
void meBookerGetter(iFunc f)
Definition: DQMStore.h:709
RunNumber_t run() const
list lumi
Definition: dqmdumpme.py:53
void globalEndRun(edm::Run const &, const edm::EventSetup &) override
virtual TProfile2D * getTProfile2D() const
virtual TH2S * getTH2S() const
Log< level::Info, false > LogInfo
virtual TProfile * getTProfile() const
virtual TH1D * getTH1D() const
double b
Definition: hdecay.h:118
LuminosityBlockNumber_t luminosityBlock() const
bool getLumiFlag() const
true if ME is meant to be stored for each luminosity section
virtual double getFloatValue() const
virtual const std::string & getStringValue() const
std::string getFullname() const
get full name of ME including Pathname
MEtoEDMConverter(const edm::ParameterSet &)
void putData(DQMStore::IGetter &g, T &iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi)
long double T
virtual TH3F * getTH3F() const
void endLuminosityBlockProduce(edm::LuminosityBlock &, const edm::EventSetup &) override
Definition: Run.h:45