CMS 3D CMS Logo

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  fName(""), verbosity(0), frequency(0), deleteAfterCopy(false)
22 {
23  std::string MsgLoggerCat = "MEtoEDMConverter_MEtoEDMConverter";
24 
25  // get information from parameter set
26  fName = iPSet.getUntrackedParameter<std::string>("Name","MEtoEDMConverter");
27  verbosity = iPSet.getUntrackedParameter<int>("Verbosity",0);
28  frequency = iPSet.getUntrackedParameter<int>("Frequency",50);
29  path = iPSet.getUntrackedParameter<std::string>("MEPathToSave");
30  deleteAfterCopy = iPSet.getUntrackedParameter<bool>("deleteAfterCopy",false);
31  enableMultiThread_ = false;
32  // use value of first digit to determine default output level (inclusive)
33  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
34  verbosity %= 10;
35 
36  // print out Parameter Set information being used
37  if (verbosity >= 0) {
38  edm::LogInfo(MsgLoggerCat)
39  << "\n===============================\n"
40  << "Initialized as EDProducer with parameter values:\n"
41  << " Name = " << fName << "\n"
42  << " Verbosity = " << verbosity << "\n"
43  << " Frequency = " << frequency << "\n"
44  << " Path = " << path << "\n"
45  << "===============================\n";
46  }
47 
48  // get dqm info
50 
51  std::string sName;
52 
53  // create persistent objects
54 
55  sName = fName + "Run";
56  produces<MEtoEDM<TH1F>, edm::Transition::EndRun>(sName);
57  produces<MEtoEDM<TH1S>, edm::Transition::EndRun>(sName);
58  produces<MEtoEDM<TH1D>, edm::Transition::EndRun>(sName);
59  produces<MEtoEDM<TH2F>, edm::Transition::EndRun>(sName);
60  produces<MEtoEDM<TH2S>, edm::Transition::EndRun>(sName);
61  produces<MEtoEDM<TH2D>, edm::Transition::EndRun>(sName);
62  produces<MEtoEDM<TH3F>, edm::Transition::EndRun>(sName);
63  produces<MEtoEDM<TProfile>, edm::Transition::EndRun>(sName);
64  produces<MEtoEDM<TProfile2D>, edm::Transition::EndRun>(sName);
65  produces<MEtoEDM<double>, edm::Transition::EndRun>(sName);
66  produces<MEtoEDM<long long>, edm::Transition::EndRun>(sName);
67  produces<MEtoEDM<TString>, edm::Transition::EndRun>(sName);
68 
69  sName = fName + "Lumi";
70  produces<MEtoEDM<TH1F>, edm::Transition::EndLuminosityBlock>(sName);
71  produces<MEtoEDM<TH1S>, edm::Transition::EndLuminosityBlock>(sName);
72  produces<MEtoEDM<TH1D>, edm::Transition::EndLuminosityBlock>(sName);
73  produces<MEtoEDM<TH2F>, edm::Transition::EndLuminosityBlock>(sName);
74  produces<MEtoEDM<TH2S>, edm::Transition::EndLuminosityBlock>(sName);
75  produces<MEtoEDM<TH2D>, edm::Transition::EndLuminosityBlock>(sName);
76  produces<MEtoEDM<TH3F>, edm::Transition::EndLuminosityBlock>(sName);
77  produces<MEtoEDM<TProfile>, edm::Transition::EndLuminosityBlock>(sName);
78  produces<MEtoEDM<TProfile2D>, edm::Transition::EndLuminosityBlock>(sName);
79  produces<MEtoEDM<double>, edm::Transition::EndLuminosityBlock>(sName);
80  produces<MEtoEDM<long long>, edm::Transition::EndLuminosityBlock>(sName);
81  produces<MEtoEDM<TString>, edm::Transition::EndLuminosityBlock>(sName);
82 
83  consumesMany<DQMToken>();
84 
85  static_assert(sizeof(int64_t) == sizeof(long long),"type int64_t is not the same length as long long");
86 
87 }
88 
90 {
91 }
92 
93 void
95 {
96  // Determine if we are running multithreading asking to the DQMStore. Not to be moved in the ctor
97  enableMultiThread_ = dbe->enableMultiThread_;
98 }
99 
100 void
102 {
103  std::string MsgLoggerCat = "MEtoEDMConverter_endJob";
104 
105  if (verbosity > 0) {
106 
107  // keep track just of package names
108  std::map<std::string,int> packages;
109 
110  // count various objects we have
111  unsigned nTH1F = 0;
112  unsigned nTH1S = 0;
113  unsigned nTH1D = 0;
114  unsigned nTH2F = 0;
115  unsigned nTH2S = 0;
116  unsigned nTH2D = 0;
117  unsigned nTH3F = 0;
118  unsigned nTProfile = 0;
119  unsigned nTProfile2D = 0;
120  unsigned nDouble = 0;
121  unsigned nInt64 = 0;
122  unsigned nString = 0;
123 
124  if (verbosity > 1) std::cout << std::endl << "Summary :" << std::endl;
125 
126  // get contents out of DQM
127  std::vector<MonitorElement *>::iterator mmi, mme;
128  std::vector<MonitorElement *> items(dbe->getAllContents(""));
129 
130  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
131 
132  // keep track of leading directory (i.e. package)
133  StringList dir = StringOps::split((*mmi)->getPathname(),"/");
134  ++packages[dir[0]];
135 
136  // check type
137  if (verbosity > 1) std::cout << "MEobject:" << std::endl;
138  MonitorElement *me = *mmi;
139  TObject *tobj = me->getRootObject();
140  switch (me->kind())
141  {
143  ++nInt64;
144  if (verbosity > 1)
145  std::cout << " scalar: " << tobj->GetName() << ": Int64\n";
146  break;
147 
149  ++nDouble;
150  if (verbosity > 1)
151  std::cout << " scalar: " << tobj->GetName() << ": Double\n";
152  break;
153 
155  ++nString;
156  if (verbosity > 1)
157  std::cout << " scalar: " << tobj->GetName() << ": String\n";
158  break;
159 
161  ++nTH1F;
162  if (verbosity > 1)
163  std::cout << " normal: " << tobj->GetName() << ": TH1F\n";
164  break;
165 
167  ++nTH1S;
168  if (verbosity > 1)
169  std::cout << " normal: " << tobj->GetName() << ": TH1S\n";
170  break;
171 
173  ++nTH1D;
174  if (verbosity > 1)
175  std::cout << " normal: " << tobj->GetName() << ": TH1D\n";
176  break;
177 
179  ++nTH2F;
180  if (verbosity > 1)
181  std::cout << " normal: " << tobj->GetName() << ": TH2F\n";
182  break;
183 
185  ++nTH2S;
186  if (verbosity > 1)
187  std::cout << " normal: " << tobj->GetName() << ": TH2S\n";
188  break;
189 
191  ++nTH2D;
192  if (verbosity > 1)
193  std::cout << " normal: " << tobj->GetName() << ": TH2D\n";
194  break;
195 
197  ++nTH3F;
198  if (verbosity > 1)
199  std::cout << " normal: " << tobj->GetName() << ": TH3F\n";
200  break;
201 
203  ++nTProfile;
204  if (verbosity > 1)
205  std::cout << " normal: " << tobj->GetName() << ": TProfile\n";
206  break;
207 
209  ++nTProfile2D;
210  if (verbosity > 1)
211  std::cout << " normal: " << tobj->GetName() << ": TProfile2D\n";
212  break;
213 
214  default:
215  edm::LogError(MsgLoggerCat)
216  << "ERROR: The DQM object '" << me->getFullname()
217  << "' is neither a ROOT object nor a recognised "
218  << "simple object.\n";
219  continue;
220  }
221  } // end loop through monitor elements
222 
223  // list unique packages
224  std::cout << "Packages accessing DQM:" << std::endl;
225  std::map<std::string,int>::iterator pkgIter;
226  for (pkgIter = packages.begin(); pkgIter != packages.end(); ++pkgIter)
227  std::cout << " " << pkgIter->first << ": " << pkgIter->second
228  << std::endl;
229 
230  std::cout << "We have " << nTH1F << " TH1F objects" << std::endl;
231  std::cout << "We have " << nTH1S << " TH1S objects" << std::endl;
232  std::cout << "We have " << nTH1D << " TH1D objects" << std::endl;
233  std::cout << "We have " << nTH2F << " TH2F objects" << std::endl;
234  std::cout << "We have " << nTH2S << " TH2S objects" << std::endl;
235  std::cout << "We have " << nTH2D << " TH2D objects" << std::endl;
236  std::cout << "We have " << nTH3F << " TH3F objects" << std::endl;
237  std::cout << "We have " << nTProfile << " TProfile objects" << std::endl;
238  std::cout << "We have " << nTProfile2D << " TProfile2D objects" << std::endl;
239  std::cout << "We have " << nDouble << " Double objects" << std::endl;
240  std::cout << "We have " << nInt64 << " Int64 objects" << std::endl;
241  std::cout << "We have " << nString << " String objects" << std::endl;
242 
243  if (verbosity > 1) std::cout << std::endl;
244 
245  }
246 
247  if (verbosity >= 0)
248  edm::LogInfo(MsgLoggerCat)
249  << "Terminating having processed " << iCount.size() << " runs.";
250 
251 }
252 
253 void
255 {
256  std::string MsgLoggerCat = "MEtoEDMConverter_beginRun";
257 
258  // No need to do any reset in the MultiThread DQM, since we will
259  // index each and every MonitorElement by Run and Lumi.
260 
261  if (enableMultiThread_)
262  return;
263 
264  int nrun = iRun.run();
265 
266  // keep track of number of runs processed
267  ++iCount[nrun];
268 
269  if (verbosity > 0) { // keep track of number of runs processed
270  edm::LogInfo(MsgLoggerCat)
271  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
272  } else if (verbosity == 0) {
273  if (nrun%frequency == 0 || iCount.size() == 1) {
274  edm::LogInfo(MsgLoggerCat)
275  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
276  }
277  }
278 
279  // clear contents of monitor elements
280  std::vector<MonitorElement *>::iterator mmi, mme;
281  std::vector<MonitorElement *> items(dbe->getAllContents(path));
282 
283  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
284 
285  MonitorElement *me = *mmi;
286 
287  switch (me->kind())
288  {
290  break;
291 
293  break;
294 
296  break;
297 
299  me->Reset();
300  break;
301 
303  me->Reset();
304  break;
305 
307  me->Reset();
308  break;
309 
311  me->Reset();
312  break;
313 
315  me->Reset();
316  break;
317 
319  me->Reset();
320  break;
321 
323  me->Reset();
324  break;
325 
327  me->Reset();
328  break;
329 
331  me->Reset();
332  break;
333 
334  default:
335  edm::LogError(MsgLoggerCat)
336  << "ERROR: The DQM object '" << me->getFullname()
337  << "' is neither a ROOT object nor a recognised "
338  << "simple object.\n";
339  continue;
340  }
341 
342  } // end loop through monitor elements
343 }
344 void
346 {
347 }
348 
349 void
351 {
352  dbe->scaleElements();
353  putData(iRun, false, iRun.run(), 0);
354 }
355 
356 void
358 {
359  putData(iLumi, true, iLumi.run(), iLumi.id().luminosityBlock());
360 }
361 
362 template <class T>
363 void
365  bool iLumiOnly,
366  uint32_t run,
367  uint32_t lumi)
368 {
369  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
370 
371  if (verbosity > 0)
372  edm::LogInfo (MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
373 
374  // extract ME information into vectors
375  std::vector<MonitorElement *>::iterator mmi, mme;
376  std::vector<MonitorElement *> items(dbe->getAllContents(path,
377  enableMultiThread_ ? run : 0,
378  enableMultiThread_ ? lumi : 0));
379 
380  unsigned int n1F=0;
381  unsigned int n1S=0;
382  unsigned int n1D=0;
383  unsigned int n2F=0;
384  unsigned int n2S=0;
385  unsigned int n2D=0;
386  unsigned int n3F=0;
387  unsigned int nProf=0;
388  unsigned int nProf2=0;
389  unsigned int nDouble=0;
390  unsigned int nInt64=0;
391  unsigned int nString=0;
392 
393  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
394 
395  MonitorElement *me = *mmi;
396 
397  // store only flagged ME at endLumi transition, and Run-based
398  // histo at endRun transition
399  if (iLumiOnly && !me->getLumiFlag()) continue;
400  if (!iLumiOnly && me->getLumiFlag()) continue;
401 
402  switch (me->kind())
403  {
405  ++nInt64;
406  break;
407 
409  ++nDouble;
410  break;
411 
413  ++nString;
414  break;
415 
417  ++n1F;
418  break;
419 
421  ++n1S;
422  break;
423 
425  ++n1D;
426  break;
427 
429  ++n2F;
430  break;
431 
433  ++n2S;
434  break;
435 
437  ++n2D;
438  break;
439 
441  ++n3F;
442  break;
443 
445  ++nProf;
446  break;
447 
449  ++nProf2;
450  break;
451 
452  default:
453  edm::LogError(MsgLoggerCat)
454  << "ERROR: The DQM object '" << me->getFullname()
455  << "' is neither a ROOT object nor a recognised "
456  << "simple object.\n";
457  continue;
458  }
459  }
460 
461  std::unique_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
462  std::unique_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
463  std::unique_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
464  std::unique_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
465  std::unique_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
466  std::unique_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
467  std::unique_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
468  std::unique_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
469  std::unique_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
470  std::unique_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
471  std::unique_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
472  std::unique_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
473 
474  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
475 
476  MonitorElement *me = *mmi;
477 
478  // store only flagged ME at endLumi transition, and Run-based
479  // histo at endRun transition
480  if (iLumiOnly && !me->getLumiFlag()) continue;
481  if (!iLumiOnly && me->getLumiFlag()) continue;
482 
483  // get monitor elements
484  switch (me->kind())
485  {
487  pOutInt->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getIntValue());
488  break;
489 
491  pOutDouble->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getFloatValue());
492  break;
493 
495  pOutString->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getStringValue());
496  break;
497 
499  pOut1->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1F());
500  break;
501 
503  pOut1s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1S());
504  break;
505 
507  pOut1d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1D());
508  break;
509 
511  pOut2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2F());
512  break;
513 
515  pOut2s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2S());
516  break;
517 
519  pOut2d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2D());
520  break;
521 
523  pOut3->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH3F());
524  break;
525 
527  pOutProf->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile());
528  break;
529 
531  pOutProf2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile2D());
532  break;
533 
534  default:
535  edm::LogError(MsgLoggerCat)
536  << "ERROR: The DQM object '" << me->getFullname()
537  << "' is neither a ROOT object nor a recognised "
538  << "simple object.\n";
539  continue;
540  }
541 
542  if (!iLumiOnly) {
543  // remove ME after copy to EDM is done.
544  if (deleteAfterCopy)
545  dbe->removeElement(me->getPathname(),me->getName());
546  }
547 
548  } // end loop through monitor elements
549 
550  std::string sName;
551 
552  if (iLumiOnly) {
553  sName = fName + "Lumi";
554  } else {
555  sName = fName + "Run";
556  }
557 
558  // produce objects to put in events
559  iPutTo.put(std::move(pOutInt),sName);
560  iPutTo.put(std::move(pOutDouble),sName);
561  iPutTo.put(std::move(pOutString),sName);
562  iPutTo.put(std::move(pOut1),sName);
563  iPutTo.put(std::move(pOut1s),sName);
564  iPutTo.put(std::move(pOut1d),sName);
565  iPutTo.put(std::move(pOut2),sName);
566  iPutTo.put(std::move(pOut2s),sName);
567  iPutTo.put(std::move(pOut2d),sName);
568  iPutTo.put(std::move(pOut3),sName);
569  iPutTo.put(std::move(pOutProf),sName);
570  iPutTo.put(std::move(pOutProf2),sName);
571 
572 }
573 
574 void
576 {
577 
578 }
LuminosityBlockID id() const
TH2S * getTH2S(void) const
TH1S * getTH1S(void) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
RunNumber_t run() const
Definition: RunBase.h:40
TProfile2D * getTProfile2D(void) const
TH3F * getTH3F(void) const
TH1D * getTH1D(void) const
TH2D * getTH2D(void) const
~MEtoEDMConverter() override
void endRunProduce(edm::Run &, const edm::EventSetup &) override
Definition: DQMStore.h:25
void beginJob() override
std::map< int, int > iCount
void produce(edm::Event &, const edm::EventSetup &) override
bool getLumiFlag(void) const
true if ME is meant to be stored for each luminosity section
int iEvent
Definition: GenABIO.cc:230
const std::string & getPathname(void) const
get pathname of parent folder
DQMNet::TagList getTags(void) const
double getFloatValue(void) const
RunNumber_t run() const
void endRun(edm::Run const &, const edm::EventSetup &) override
Kind kind(void) const
Get the type of the monitor element.
const std::string getFullname(void) const
get full name of ME including Pathname
const std::string & getStringValue(void) const
TObject * getRootObject(void) const
int64_t getIntValue(void) const
TH1F * getTH1F(void) const
LuminosityBlockNumber_t luminosityBlock() const
void endJob() override
if(dp >Float(M_PI)) dp-
TProfile * getTProfile(void) const
dbl *** dir
Definition: mlp_gen.cc:35
MEtoEDMConverter(const edm::ParameterSet &)
void putData(T &iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi)
void beginRun(edm::Run const &, const edm::EventSetup &) override
TH2F * getTH2F(void) const
long double T
void Reset(void)
reset ME (ie. contents, errors, etc)
double split
Definition: MVATrainer.cc:139
def move(src, dest)
Definition: eostools.py:510
void endLuminosityBlockProduce(edm::LuminosityBlock &, const edm::EventSetup &) override
Definition: Run.h:43