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 
12 #include <cassert>
13 
15 #include "classlib/utils/StringList.h"
16 #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 
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
49  dbe = 0;
51 
52  std::string sName;
53 
54  // create persistent objects
55 
56  sName = fName + "Run";
57  produces<MEtoEDM<TH1F>, edm::InRun>(sName);
58  produces<MEtoEDM<TH1S>, edm::InRun>(sName);
59  produces<MEtoEDM<TH1D>, edm::InRun>(sName);
60  produces<MEtoEDM<TH2F>, edm::InRun>(sName);
61  produces<MEtoEDM<TH2S>, edm::InRun>(sName);
62  produces<MEtoEDM<TH2D>, edm::InRun>(sName);
63  produces<MEtoEDM<TH3F>, edm::InRun>(sName);
64  produces<MEtoEDM<TProfile>, edm::InRun>(sName);
65  produces<MEtoEDM<TProfile2D>, edm::InRun>(sName);
66  produces<MEtoEDM<double>, edm::InRun>(sName);
67  produces<MEtoEDM<long long>, edm::InRun>(sName);
68  produces<MEtoEDM<TString>, edm::InRun>(sName);
69 
70  sName = fName + "Lumi";
71  produces<MEtoEDM<TH1F>, edm::InLumi>(sName);
72  produces<MEtoEDM<TH1S>, edm::InLumi>(sName);
73  produces<MEtoEDM<TH1D>, edm::InLumi>(sName);
74  produces<MEtoEDM<TH2F>, edm::InLumi>(sName);
75  produces<MEtoEDM<TH2S>, edm::InLumi>(sName);
76  produces<MEtoEDM<TH2D>, edm::InLumi>(sName);
77  produces<MEtoEDM<TH3F>, edm::InLumi>(sName);
78  produces<MEtoEDM<TProfile>, edm::InLumi>(sName);
79  produces<MEtoEDM<TProfile2D>, edm::InLumi>(sName);
80  produces<MEtoEDM<double>, edm::InLumi>(sName);
81  produces<MEtoEDM<long long>, edm::InLumi>(sName);
82  produces<MEtoEDM<TString>, edm::InLumi>(sName);
83 
84  iCount.clear();
85 
86  assert(sizeof(int64_t) == sizeof(long long));
87 
88 }
89 
91 {
92 }
93 
94 void
96 {
97 }
98 
99 void
101 {
102  std::string MsgLoggerCat = "MEtoEDMConverter_endJob";
103 
104  if (verbosity > 0) {
105 
106  // keep track just of package names
107  std::map<std::string,int> packages;
108 
109  // count various objects we have
110  unsigned nTH1F = 0;
111  unsigned nTH1S = 0;
112  unsigned nTH1D = 0;
113  unsigned nTH2F = 0;
114  unsigned nTH2S = 0;
115  unsigned nTH2D = 0;
116  unsigned nTH3F = 0;
117  unsigned nTProfile = 0;
118  unsigned nTProfile2D = 0;
119  unsigned nDouble = 0;
120  unsigned nInt64 = 0;
121  unsigned nString = 0;
122 
123  if (verbosity > 1) std::cout << std::endl << "Summary :" << std::endl;
124 
125  // get contents out of DQM
126  std::vector<MonitorElement *>::iterator mmi, mme;
127  std::vector<MonitorElement *> items(dbe->getAllContents(""));
128 
129  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
130 
131  // keep track of leading directory (i.e. package)
132  StringList dir = StringOps::split((*mmi)->getPathname(),"/");
133  ++packages[dir[0]];
134 
135  // check type
136  if (verbosity > 1) std::cout << "MEobject:" << std::endl;
137  MonitorElement *me = *mmi;
138  TObject *tobj = me->getRootObject();
139  switch (me->kind())
140  {
142  ++nInt64;
143  if (verbosity > 1)
144  std::cout << " scalar: " << tobj->GetName() << ": Int64\n";
145  break;
146 
148  ++nDouble;
149  if (verbosity > 1)
150  std::cout << " scalar: " << tobj->GetName() << ": Double\n";
151  break;
152 
154  ++nString;
155  if (verbosity > 1)
156  std::cout << " scalar: " << tobj->GetName() << ": String\n";
157  break;
158 
160  ++nTH1F;
161  if (verbosity > 1)
162  std::cout << " normal: " << tobj->GetName() << ": TH1F\n";
163  break;
164 
166  ++nTH1S;
167  if (verbosity > 1)
168  std::cout << " normal: " << tobj->GetName() << ": TH1S\n";
169  break;
170 
172  ++nTH1D;
173  if (verbosity > 1)
174  std::cout << " normal: " << tobj->GetName() << ": TH1D\n";
175  break;
176 
178  ++nTH2F;
179  if (verbosity > 1)
180  std::cout << " normal: " << tobj->GetName() << ": TH2F\n";
181  break;
182 
184  ++nTH2S;
185  if (verbosity > 1)
186  std::cout << " normal: " << tobj->GetName() << ": TH2S\n";
187  break;
188 
190  ++nTH2D;
191  if (verbosity > 1)
192  std::cout << " normal: " << tobj->GetName() << ": TH2D\n";
193  break;
194 
196  ++nTH3F;
197  if (verbosity > 1)
198  std::cout << " normal: " << tobj->GetName() << ": TH3F\n";
199  break;
200 
202  ++nTProfile;
203  if (verbosity > 1)
204  std::cout << " normal: " << tobj->GetName() << ": TProfile\n";
205  break;
206 
208  ++nTProfile2D;
209  if (verbosity > 1)
210  std::cout << " normal: " << tobj->GetName() << ": TProfile2D\n";
211  break;
212 
213  default:
214  edm::LogError(MsgLoggerCat)
215  << "ERROR: The DQM object '" << me->getFullname()
216  << "' is neither a ROOT object nor a recognised "
217  << "simple object.\n";
218  continue;
219  }
220  } // end loop through monitor elements
221 
222  // list unique packages
223  std::cout << "Packages accessing DQM:" << std::endl;
224  std::map<std::string,int>::iterator pkgIter;
225  for (pkgIter = packages.begin(); pkgIter != packages.end(); ++pkgIter)
226  std::cout << " " << pkgIter->first << ": " << pkgIter->second
227  << std::endl;
228 
229  std::cout << "We have " << nTH1F << " TH1F objects" << std::endl;
230  std::cout << "We have " << nTH1S << " TH1S objects" << std::endl;
231  std::cout << "We have " << nTH1D << " TH1D objects" << std::endl;
232  std::cout << "We have " << nTH2F << " TH2F objects" << std::endl;
233  std::cout << "We have " << nTH2S << " TH2S objects" << std::endl;
234  std::cout << "We have " << nTH2D << " TH2D objects" << std::endl;
235  std::cout << "We have " << nTH3F << " TH3F objects" << std::endl;
236  std::cout << "We have " << nTProfile << " TProfile objects" << std::endl;
237  std::cout << "We have " << nTProfile2D << " TProfile2D objects" << std::endl;
238  std::cout << "We have " << nDouble << " Double objects" << std::endl;
239  std::cout << "We have " << nInt64 << " Int64 objects" << std::endl;
240  std::cout << "We have " << nString << " String objects" << std::endl;
241 
242  if (verbosity > 1) std::cout << std::endl;
243 
244  }
245 
246  if (verbosity >= 0)
247  edm::LogInfo(MsgLoggerCat)
248  << "Terminating having processed " << iCount.size() << " runs.";
249 
250 }
251 
252 void
254 {
255  std::string MsgLoggerCat = "MEtoEDMConverter_beginRun";
256 
257  int nrun = iRun.run();
258 
259  // keep track of number of runs processed
260  ++iCount[nrun];
261 
262  if (verbosity > 0) { // keep track of number of runs processed
263  edm::LogInfo(MsgLoggerCat)
264  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
265  } else if (verbosity == 0) {
266  if (nrun%frequency == 0 || iCount.size() == 1) {
267  edm::LogInfo(MsgLoggerCat)
268  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
269  }
270  }
271 
272  // clear contents of monitor elements
273  std::vector<MonitorElement *>::iterator mmi, mme;
274  std::vector<MonitorElement *> items(dbe->getAllContents(path));
275 
276  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
277 
278  MonitorElement *me = *mmi;
279 
280  switch (me->kind())
281  {
283  break;
284 
286  break;
287 
289  break;
290 
292  me->Reset();
293  break;
294 
296  me->Reset();
297  break;
298 
300  me->Reset();
301  break;
302 
304  me->Reset();
305  break;
306 
308  me->Reset();
309  break;
310 
312  me->Reset();
313  break;
314 
316  me->Reset();
317  break;
318 
320  me->Reset();
321  break;
322 
324  me->Reset();
325  break;
326 
327  default:
328  edm::LogError(MsgLoggerCat)
329  << "ERROR: The DQM object '" << me->getFullname()
330  << "' is neither a ROOT object nor a recognised "
331  << "simple object.\n";
332  continue;
333  }
334 
335  } // end loop through monitor elements
336 }
337 void
339 {
340 }
341 
342 void
344 {
345  dbe->scaleElements();
346  putData(iRun, false);
347 }
348 
349 void
351 {
352  putData(iLumi, true);
353 }
354 
355 template <class T>
356 void
357 MEtoEDMConverter::putData(T& iPutTo, bool iLumiOnly)
358 {
359  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
360 
361  if (verbosity > 0)
362  edm::LogInfo (MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
363 
364  // extract ME information into vectors
365  std::vector<MonitorElement *>::iterator mmi, mme;
366  std::vector<MonitorElement *> items(dbe->getAllContents(path));
367 
368  unsigned int n1F=0;
369  unsigned int n1S=0;
370  unsigned int n1D=0;
371  unsigned int n2F=0;
372  unsigned int n2S=0;
373  unsigned int n2D=0;
374  unsigned int n3F=0;
375  unsigned int nProf=0;
376  unsigned int nProf2=0;
377  unsigned int nDouble=0;
378  unsigned int nInt64=0;
379  unsigned int nString=0;
380 
381  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
382 
383  MonitorElement *me = *mmi;
384 
385  // store only flagged ME at endLumi transition, and Run-based
386  // histo at endRun transition
387  if (iLumiOnly && !me->getLumiFlag()) continue;
388  if (!iLumiOnly && me->getLumiFlag()) continue;
389 
390  switch (me->kind())
391  {
393  ++nInt64;
394  break;
395 
397  ++nDouble;
398  break;
399 
401  ++nString;
402  break;
403 
405  ++n1F;
406  break;
407 
409  ++n1S;
410  break;
411 
413  ++n1D;
414  break;
415 
417  ++n2F;
418  break;
419 
421  ++n2S;
422  break;
423 
425  ++n2D;
426  break;
427 
429  ++n3F;
430  break;
431 
433  ++nProf;
434  break;
435 
437  ++nProf2;
438  break;
439 
440  default:
441  edm::LogError(MsgLoggerCat)
442  << "ERROR: The DQM object '" << me->getFullname()
443  << "' is neither a ROOT object nor a recognised "
444  << "simple object.\n";
445  continue;
446  }
447  }
448 
449  std::auto_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
450  std::auto_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
451  std::auto_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
452  std::auto_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
453  std::auto_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
454  std::auto_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
455  std::auto_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
456  std::auto_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
457  std::auto_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
458  std::auto_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
459  std::auto_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
460  std::auto_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
461 
462  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
463 
464  MonitorElement *me = *mmi;
465 
466  // store only flagged ME at endLumi transition, and Run-based
467  // histo at endRun transition
468  if (iLumiOnly && !me->getLumiFlag()) continue;
469  if (!iLumiOnly && me->getLumiFlag()) continue;
470 
471  // get monitor elements
472  switch (me->kind())
473  {
475  pOutInt->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getIntValue());
476  break;
477 
479  pOutDouble->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getFloatValue());
480  break;
481 
483  pOutString->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getStringValue());
484  break;
485 
487  pOut1->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1F());
488  break;
489 
491  pOut1s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1S());
492  break;
493 
495  pOut1d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1D());
496  break;
497 
499  pOut2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2F());
500  break;
501 
503  pOut2s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2S());
504  break;
505 
507  pOut2d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2D());
508  break;
509 
511  pOut3->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH3F());
512  break;
513 
515  pOutProf->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile());
516  break;
517 
519  pOutProf2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile2D());
520  break;
521 
522  default:
523  edm::LogError(MsgLoggerCat)
524  << "ERROR: The DQM object '" << me->getFullname()
525  << "' is neither a ROOT object nor a recognised "
526  << "simple object.\n";
527  continue;
528  }
529 
530  if (!iLumiOnly) {
531  // remove ME after copy to EDM is done.
532  if (deleteAfterCopy)
533  dbe->removeElement(me->getPathname(),me->getName());
534  }
535 
536  } // end loop through monitor elements
537 
538  std::string sName;
539 
540  if (iLumiOnly) {
541  sName = fName + "Lumi";
542  } else {
543  sName = fName + "Run";
544  }
545 
546  // produce objects to put in events
547  iPutTo.put(pOutInt,sName);
548  iPutTo.put(pOutDouble,sName);
549  iPutTo.put(pOutString,sName);
550  iPutTo.put(pOut1,sName);
551  iPutTo.put(pOut1s,sName);
552  iPutTo.put(pOut1d,sName);
553  iPutTo.put(pOut2,sName);
554  iPutTo.put(pOut2s,sName);
555  iPutTo.put(pOut2d,sName);
556  iPutTo.put(pOut3,sName);
557  iPutTo.put(pOutProf,sName);
558  iPutTo.put(pOutProf2,sName);
559 
560 }
561 
562 void
564 {
565 
566 }
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:42
TProfile2D * getTProfile2D(void) const
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
std::vector< MonitorElement * > getAllContents(const std::string &path) const
Definition: DQMStore.cc:1677
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:243
const std::string & getPathname(void) const
get pathname of parent folder
virtual ~MEtoEDMConverter()
DQMNet::TagList getTags(void) const
void removeElement(const std::string &name)
Definition: DQMStore.cc:2577
double getFloatValue(void) 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
void scaleElements(void)
Definition: DQMStore.cc:2803
TObject * getRootObject(void) const
int64_t getIntValue(void) const
TH1F * getTH1F(void) const
void putData(T &iPutTo, bool iLumiOnly)
virtual void endJob() override
if(dp >Float(M_PI)) dp-
TProfile * getTProfile(void) const
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
MEtoEDMConverter(const edm::ParameterSet &)
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:36