test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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"
15 
16 using namespace lat;
17 
19  fName(""), verbosity(0), frequency(0), deleteAfterCopy(false)
20 {
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  deleteAfterCopy = iPSet.getUntrackedParameter<bool>("deleteAfterCopy",false);
29  enableMultiThread_ = false;
30  // use value of first digit to determine default output level (inclusive)
31  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
32  verbosity %= 10;
33 
34  // print out Parameter Set information being used
35  if (verbosity >= 0) {
36  edm::LogInfo(MsgLoggerCat)
37  << "\n===============================\n"
38  << "Initialized as EDProducer with parameter values:\n"
39  << " Name = " << fName << "\n"
40  << " Verbosity = " << verbosity << "\n"
41  << " Frequency = " << frequency << "\n"
42  << " Path = " << path << "\n"
43  << "===============================\n";
44  }
45 
46  // get dqm info
48 
49  std::string sName;
50 
51  // create persistent objects
52 
53  sName = fName + "Run";
54  produces<MEtoEDM<TH1F>, edm::InRun>(sName);
55  produces<MEtoEDM<TH1S>, edm::InRun>(sName);
56  produces<MEtoEDM<TH1D>, edm::InRun>(sName);
57  produces<MEtoEDM<TH2F>, edm::InRun>(sName);
58  produces<MEtoEDM<TH2S>, edm::InRun>(sName);
59  produces<MEtoEDM<TH2D>, edm::InRun>(sName);
60  produces<MEtoEDM<TH3F>, edm::InRun>(sName);
61  produces<MEtoEDM<TProfile>, edm::InRun>(sName);
62  produces<MEtoEDM<TProfile2D>, edm::InRun>(sName);
63  produces<MEtoEDM<double>, edm::InRun>(sName);
64  produces<MEtoEDM<long long>, edm::InRun>(sName);
65  produces<MEtoEDM<TString>, edm::InRun>(sName);
66 
67  sName = fName + "Lumi";
68  produces<MEtoEDM<TH1F>, edm::InLumi>(sName);
69  produces<MEtoEDM<TH1S>, edm::InLumi>(sName);
70  produces<MEtoEDM<TH1D>, edm::InLumi>(sName);
71  produces<MEtoEDM<TH2F>, edm::InLumi>(sName);
72  produces<MEtoEDM<TH2S>, edm::InLumi>(sName);
73  produces<MEtoEDM<TH2D>, edm::InLumi>(sName);
74  produces<MEtoEDM<TH3F>, edm::InLumi>(sName);
75  produces<MEtoEDM<TProfile>, edm::InLumi>(sName);
76  produces<MEtoEDM<TProfile2D>, edm::InLumi>(sName);
77  produces<MEtoEDM<double>, edm::InLumi>(sName);
78  produces<MEtoEDM<long long>, edm::InLumi>(sName);
79  produces<MEtoEDM<TString>, edm::InLumi>(sName);
80 
81  iCount.clear();
82 
83  assert(sizeof(int64_t) == sizeof(long long));
84 
85 }
86 
88 {
89 }
90 
91 void
93 {
94  // Determine if we are running multithreading asking to the DQMStore. Not to be moved in the ctor
95  enableMultiThread_ = dbe->enableMultiThread_;
96 }
97 
98 void
100 {
101  std::string MsgLoggerCat = "MEtoEDMConverter_endJob";
102 
103  if (verbosity > 0) {
104 
105  // keep track just of package names
106  std::map<std::string,int> packages;
107 
108  // count various objects we have
109  unsigned nTH1F = 0;
110  unsigned nTH1S = 0;
111  unsigned nTH1D = 0;
112  unsigned nTH2F = 0;
113  unsigned nTH2S = 0;
114  unsigned nTH2D = 0;
115  unsigned nTH3F = 0;
116  unsigned nTProfile = 0;
117  unsigned nTProfile2D = 0;
118  unsigned nDouble = 0;
119  unsigned nInt64 = 0;
120  unsigned nString = 0;
121 
122  if (verbosity > 1) std::cout << std::endl << "Summary :" << std::endl;
123 
124  // get contents out of DQM
125  std::vector<MonitorElement *>::iterator mmi, mme;
126  std::vector<MonitorElement *> items(dbe->getAllContents(""));
127 
128  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
129 
130  // keep track of leading directory (i.e. package)
131  StringList dir = StringOps::split((*mmi)->getPathname(),"/");
132  ++packages[dir[0]];
133 
134  // check type
135  if (verbosity > 1) std::cout << "MEobject:" << std::endl;
136  MonitorElement *me = *mmi;
137  TObject *tobj = me->getRootObject();
138  switch (me->kind())
139  {
141  ++nInt64;
142  if (verbosity > 1)
143  std::cout << " scalar: " << tobj->GetName() << ": Int64\n";
144  break;
145 
147  ++nDouble;
148  if (verbosity > 1)
149  std::cout << " scalar: " << tobj->GetName() << ": Double\n";
150  break;
151 
153  ++nString;
154  if (verbosity > 1)
155  std::cout << " scalar: " << tobj->GetName() << ": String\n";
156  break;
157 
159  ++nTH1F;
160  if (verbosity > 1)
161  std::cout << " normal: " << tobj->GetName() << ": TH1F\n";
162  break;
163 
165  ++nTH1S;
166  if (verbosity > 1)
167  std::cout << " normal: " << tobj->GetName() << ": TH1S\n";
168  break;
169 
171  ++nTH1D;
172  if (verbosity > 1)
173  std::cout << " normal: " << tobj->GetName() << ": TH1D\n";
174  break;
175 
177  ++nTH2F;
178  if (verbosity > 1)
179  std::cout << " normal: " << tobj->GetName() << ": TH2F\n";
180  break;
181 
183  ++nTH2S;
184  if (verbosity > 1)
185  std::cout << " normal: " << tobj->GetName() << ": TH2S\n";
186  break;
187 
189  ++nTH2D;
190  if (verbosity > 1)
191  std::cout << " normal: " << tobj->GetName() << ": TH2D\n";
192  break;
193 
195  ++nTH3F;
196  if (verbosity > 1)
197  std::cout << " normal: " << tobj->GetName() << ": TH3F\n";
198  break;
199 
201  ++nTProfile;
202  if (verbosity > 1)
203  std::cout << " normal: " << tobj->GetName() << ": TProfile\n";
204  break;
205 
207  ++nTProfile2D;
208  if (verbosity > 1)
209  std::cout << " normal: " << tobj->GetName() << ": TProfile2D\n";
210  break;
211 
212  default:
213  edm::LogError(MsgLoggerCat)
214  << "ERROR: The DQM object '" << me->getFullname()
215  << "' is neither a ROOT object nor a recognised "
216  << "simple object.\n";
217  continue;
218  }
219  } // end loop through monitor elements
220 
221  // list unique packages
222  std::cout << "Packages accessing DQM:" << std::endl;
223  std::map<std::string,int>::iterator pkgIter;
224  for (pkgIter = packages.begin(); pkgIter != packages.end(); ++pkgIter)
225  std::cout << " " << pkgIter->first << ": " << pkgIter->second
226  << std::endl;
227 
228  std::cout << "We have " << nTH1F << " TH1F objects" << std::endl;
229  std::cout << "We have " << nTH1S << " TH1S objects" << std::endl;
230  std::cout << "We have " << nTH1D << " TH1D objects" << std::endl;
231  std::cout << "We have " << nTH2F << " TH2F objects" << std::endl;
232  std::cout << "We have " << nTH2S << " TH2S objects" << std::endl;
233  std::cout << "We have " << nTH2D << " TH2D objects" << std::endl;
234  std::cout << "We have " << nTH3F << " TH3F objects" << std::endl;
235  std::cout << "We have " << nTProfile << " TProfile objects" << std::endl;
236  std::cout << "We have " << nTProfile2D << " TProfile2D objects" << std::endl;
237  std::cout << "We have " << nDouble << " Double objects" << std::endl;
238  std::cout << "We have " << nInt64 << " Int64 objects" << std::endl;
239  std::cout << "We have " << nString << " String objects" << std::endl;
240 
241  if (verbosity > 1) std::cout << std::endl;
242 
243  }
244 
245  if (verbosity >= 0)
246  edm::LogInfo(MsgLoggerCat)
247  << "Terminating having processed " << iCount.size() << " runs.";
248 
249 }
250 
251 void
253 {
254  std::string MsgLoggerCat = "MEtoEDMConverter_beginRun";
255 
256  // No need to do any reset in the MultiThread DQM, since we will
257  // index each and every MonitorElement by Run and Lumi.
258 
259  if (enableMultiThread_)
260  return;
261 
262  int nrun = iRun.run();
263 
264  // keep track of number of runs processed
265  ++iCount[nrun];
266 
267  if (verbosity > 0) { // keep track of number of runs processed
268  edm::LogInfo(MsgLoggerCat)
269  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
270  } else if (verbosity == 0) {
271  if (nrun%frequency == 0 || iCount.size() == 1) {
272  edm::LogInfo(MsgLoggerCat)
273  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
274  }
275  }
276 
277  // clear contents of monitor elements
278  std::vector<MonitorElement *>::iterator mmi, mme;
279  std::vector<MonitorElement *> items(dbe->getAllContents(path));
280 
281  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
282 
283  MonitorElement *me = *mmi;
284 
285  switch (me->kind())
286  {
288  break;
289 
291  break;
292 
294  break;
295 
297  me->Reset();
298  break;
299 
301  me->Reset();
302  break;
303 
305  me->Reset();
306  break;
307 
309  me->Reset();
310  break;
311 
313  me->Reset();
314  break;
315 
317  me->Reset();
318  break;
319 
321  me->Reset();
322  break;
323 
325  me->Reset();
326  break;
327 
329  me->Reset();
330  break;
331 
332  default:
333  edm::LogError(MsgLoggerCat)
334  << "ERROR: The DQM object '" << me->getFullname()
335  << "' is neither a ROOT object nor a recognised "
336  << "simple object.\n";
337  continue;
338  }
339 
340  } // end loop through monitor elements
341 }
342 void
344 {
345 }
346 
347 void
349 {
350  dbe->scaleElements();
351  putData(iRun, false, iRun.run(), 0);
352 }
353 
354 void
356 {
357  putData(iLumi, true, iLumi.run(), iLumi.id().luminosityBlock());
358 }
359 
360 template <class T>
361 void
363  bool iLumiOnly,
364  uint32_t run,
365  uint32_t lumi)
366 {
367  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
368 
369  if (verbosity > 0)
370  edm::LogInfo (MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
371 
372  // extract ME information into vectors
373  std::vector<MonitorElement *>::iterator mmi, mme;
374  std::vector<MonitorElement *> items(dbe->getAllContents(path,
375  enableMultiThread_ ? run : 0,
376  enableMultiThread_ ? lumi : 0));
377 
378  unsigned int n1F=0;
379  unsigned int n1S=0;
380  unsigned int n1D=0;
381  unsigned int n2F=0;
382  unsigned int n2S=0;
383  unsigned int n2D=0;
384  unsigned int n3F=0;
385  unsigned int nProf=0;
386  unsigned int nProf2=0;
387  unsigned int nDouble=0;
388  unsigned int nInt64=0;
389  unsigned int nString=0;
390 
391  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
392 
393  MonitorElement *me = *mmi;
394 
395  // store only flagged ME at endLumi transition, and Run-based
396  // histo at endRun transition
397  if (iLumiOnly && !me->getLumiFlag()) continue;
398  if (!iLumiOnly && me->getLumiFlag()) continue;
399 
400  switch (me->kind())
401  {
403  ++nInt64;
404  break;
405 
407  ++nDouble;
408  break;
409 
411  ++nString;
412  break;
413 
415  ++n1F;
416  break;
417 
419  ++n1S;
420  break;
421 
423  ++n1D;
424  break;
425 
427  ++n2F;
428  break;
429 
431  ++n2S;
432  break;
433 
435  ++n2D;
436  break;
437 
439  ++n3F;
440  break;
441 
443  ++nProf;
444  break;
445 
447  ++nProf2;
448  break;
449 
450  default:
451  edm::LogError(MsgLoggerCat)
452  << "ERROR: The DQM object '" << me->getFullname()
453  << "' is neither a ROOT object nor a recognised "
454  << "simple object.\n";
455  continue;
456  }
457  }
458 
459  std::auto_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
460  std::auto_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
461  std::auto_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
462  std::auto_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
463  std::auto_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
464  std::auto_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
465  std::auto_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
466  std::auto_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
467  std::auto_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
468  std::auto_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
469  std::auto_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
470  std::auto_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
471 
472  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
473 
474  MonitorElement *me = *mmi;
475 
476  // store only flagged ME at endLumi transition, and Run-based
477  // histo at endRun transition
478  if (iLumiOnly && !me->getLumiFlag()) continue;
479  if (!iLumiOnly && me->getLumiFlag()) continue;
480 
481  // get monitor elements
482  switch (me->kind())
483  {
485  pOutInt->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getIntValue());
486  break;
487 
489  pOutDouble->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getFloatValue());
490  break;
491 
493  pOutString->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getStringValue());
494  break;
495 
497  pOut1->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1F());
498  break;
499 
501  pOut1s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1S());
502  break;
503 
505  pOut1d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1D());
506  break;
507 
509  pOut2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2F());
510  break;
511 
513  pOut2s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2S());
514  break;
515 
517  pOut2d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2D());
518  break;
519 
521  pOut3->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH3F());
522  break;
523 
525  pOutProf->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile());
526  break;
527 
529  pOutProf2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile2D());
530  break;
531 
532  default:
533  edm::LogError(MsgLoggerCat)
534  << "ERROR: The DQM object '" << me->getFullname()
535  << "' is neither a ROOT object nor a recognised "
536  << "simple object.\n";
537  continue;
538  }
539 
540  if (!iLumiOnly) {
541  // remove ME after copy to EDM is done.
542  if (deleteAfterCopy)
543  dbe->removeElement(me->getPathname(),me->getName());
544  }
545 
546  } // end loop through monitor elements
547 
548  std::string sName;
549 
550  if (iLumiOnly) {
551  sName = fName + "Lumi";
552  } else {
553  sName = fName + "Run";
554  }
555 
556  // produce objects to put in events
557  iPutTo.put(pOutInt,sName);
558  iPutTo.put(pOutDouble,sName);
559  iPutTo.put(pOutString,sName);
560  iPutTo.put(pOut1,sName);
561  iPutTo.put(pOut1s,sName);
562  iPutTo.put(pOut1d,sName);
563  iPutTo.put(pOut2,sName);
564  iPutTo.put(pOut2s,sName);
565  iPutTo.put(pOut2d,sName);
566  iPutTo.put(pOut3,sName);
567  iPutTo.put(pOutProf,sName);
568  iPutTo.put(pOutProf2,sName);
569 
570 }
571 
572 void
574 {
575 
576 }
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
tuple lumi
Definition: fjr2json.py:35
assert(m_qm.get())
TH3F * getTH3F(void) const
TH1D * getTH1D(void) const
TH2D * getTH2D(void) const
virtual void endRunProduce(edm::Run &, const edm::EventSetup &) override
virtual void beginJob() override
std::map< int, int > iCount
virtual 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
virtual ~MEtoEDMConverter()
DQMNet::TagList getTags(void) const
double getFloatValue(void) const
RunNumber_t run() const
virtual 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
virtual void endJob() override
if(dp >Float(M_PI)) dp-
TProfile * getTProfile(void) const
tuple cout
Definition: gather_cfg.py:145
dbl *** dir
Definition: mlp_gen.cc:35
volatile std::atomic< bool > shutdown_flag false
MEtoEDMConverter(const edm::ParameterSet &)
void putData(T &iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi)
virtual 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
virtual void endLuminosityBlockProduce(edm::LuminosityBlock &, const edm::EventSetup &) override
Definition: Run.h:43