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 
11 #include <cassert>
12 
14 #include "classlib/utils/StringList.h"
15 #include "classlib/utils/StringOps.h"
16 
17 using namespace lat;
18 
20  fName(""), verbosity(0), frequency(0), deleteAfterCopy(false)
21 {
22  std::string MsgLoggerCat = "MEtoEDMConverter_MEtoEDMConverter";
23 
24  // get information from parameter set
25  fName = iPSet.getUntrackedParameter<std::string>("Name","MEtoEDMConverter");
26  verbosity = iPSet.getUntrackedParameter<int>("Verbosity",0);
27  frequency = iPSet.getUntrackedParameter<int>("Frequency",50);
28  path = iPSet.getUntrackedParameter<std::string>("MEPathToSave");
29  deleteAfterCopy = iPSet.getUntrackedParameter<bool>("deleteAfterCopy",false);
30 
31  // use value of first digit to determine default output level (inclusive)
32  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
33  verbosity %= 10;
34 
35  // print out Parameter Set information being used
36  if (verbosity >= 0) {
37  edm::LogInfo(MsgLoggerCat)
38  << "\n===============================\n"
39  << "Initialized as EDProducer with parameter values:\n"
40  << " Name = " << fName << "\n"
41  << " Verbosity = " << verbosity << "\n"
42  << " Frequency = " << frequency << "\n"
43  << " Path = " << path << "\n"
44  << "===============================\n";
45  }
46 
47  // get dqm info
48  dbe = 0;
50 
51  std::string sName;
52 
53  // create persistent objects
54 
55  sName = fName + "Run";
56  produces<MEtoEDM<TH1F>, edm::InRun>(sName);
57  produces<MEtoEDM<TH1S>, edm::InRun>(sName);
58  produces<MEtoEDM<TH1D>, edm::InRun>(sName);
59  produces<MEtoEDM<TH2F>, edm::InRun>(sName);
60  produces<MEtoEDM<TH2S>, edm::InRun>(sName);
61  produces<MEtoEDM<TH2D>, edm::InRun>(sName);
62  produces<MEtoEDM<TH3F>, edm::InRun>(sName);
63  produces<MEtoEDM<TProfile>, edm::InRun>(sName);
64  produces<MEtoEDM<TProfile2D>, edm::InRun>(sName);
65  produces<MEtoEDM<double>, edm::InRun>(sName);
66  produces<MEtoEDM<long long>, edm::InRun>(sName);
67  produces<MEtoEDM<TString>, edm::InRun>(sName);
68 
69  sName = fName + "Lumi";
70  produces<MEtoEDM<TH1F>, edm::InLumi>(sName);
71  produces<MEtoEDM<TH1S>, edm::InLumi>(sName);
72  produces<MEtoEDM<TH1D>, edm::InLumi>(sName);
73  produces<MEtoEDM<TH2F>, edm::InLumi>(sName);
74  produces<MEtoEDM<TH2S>, edm::InLumi>(sName);
75  produces<MEtoEDM<TH2D>, edm::InLumi>(sName);
76  produces<MEtoEDM<TH3F>, edm::InLumi>(sName);
77  produces<MEtoEDM<TProfile>, edm::InLumi>(sName);
78  produces<MEtoEDM<TProfile2D>, edm::InLumi>(sName);
79  produces<MEtoEDM<double>, edm::InLumi>(sName);
80  produces<MEtoEDM<long long>, edm::InLumi>(sName);
81  produces<MEtoEDM<TString>, edm::InLumi>(sName);
82 
83  iCount.clear();
84 
85  assert(sizeof(int64_t) == sizeof(long long));
86 
87 }
88 
90 {
91 }
92 
93 void
95 {
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  int nrun = iRun.run();
257 
258  // keep track of number of runs processed
259  ++iCount[nrun];
260 
261  if (verbosity > 0) { // keep track of number of runs processed
262  edm::LogInfo(MsgLoggerCat)
263  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
264  } else if (verbosity == 0) {
265  if (nrun%frequency == 0 || iCount.size() == 1) {
266  edm::LogInfo(MsgLoggerCat)
267  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
268  }
269  }
270 
271  // clear contents of monitor elements
272  std::vector<MonitorElement *>::iterator mmi, mme;
273  std::vector<MonitorElement *> items(dbe->getAllContents(path));
274 
275  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
276 
277  MonitorElement *me = *mmi;
278 
279  switch (me->kind())
280  {
282  break;
283 
285  break;
286 
288  break;
289 
291  me->Reset();
292  break;
293 
295  me->Reset();
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 
326  default:
327  edm::LogError(MsgLoggerCat)
328  << "ERROR: The DQM object '" << me->getFullname()
329  << "' is neither a ROOT object nor a recognised "
330  << "simple object.\n";
331  continue;
332  }
333 
334  } // end loop through monitor elements
335 }
336 
337 void
339 {
340  putData(iRun, false);
341 }
342 
343 void
345 {
346 }
347 
348 void
350 {
351  putData(iLumi, true);
352 }
353 
354 template <class T>
355 void
356 MEtoEDMConverter::putData(T& iPutTo, bool iLumiOnly)
357 {
358  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
359 
360  if (verbosity > 0)
361  edm::LogInfo (MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
362 
363  // extract ME information into vectors
364  std::vector<MonitorElement *>::iterator mmi, mme;
365  std::vector<MonitorElement *> items(dbe->getAllContents(path));
366 
367  unsigned int n1F=0;
368  unsigned int n1S=0;
369  unsigned int n1D=0;
370  unsigned int n2F=0;
371  unsigned int n2S=0;
372  unsigned int n2D=0;
373  unsigned int n3F=0;
374  unsigned int nProf=0;
375  unsigned int nProf2=0;
376  unsigned int nDouble=0;
377  unsigned int nInt64=0;
378  unsigned int nString=0;
379 
380  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
381 
382  MonitorElement *me = *mmi;
383 
384  // store only flagged ME
385  if (iLumiOnly && !me->getLumiFlag()) continue;
386 
387  switch (me->kind())
388  {
390  ++nInt64;
391  break;
392 
394  ++nDouble;
395  break;
396 
398  ++nString;
399  break;
400 
402  ++n1F;
403  break;
404 
406  ++n1S;
407  break;
408 
410  ++n1D;
411  break;
412 
414  ++n2F;
415  break;
416 
418  ++n2S;
419  break;
420 
422  ++n2D;
423  break;
424 
426  ++n3F;
427  break;
428 
430  ++nProf;
431  break;
432 
434  ++nProf2;
435  break;
436 
437  default:
438  edm::LogError(MsgLoggerCat)
439  << "ERROR: The DQM object '" << me->getFullname()
440  << "' is neither a ROOT object nor a recognised "
441  << "simple object.\n";
442  continue;
443  }
444  }
445 
446  std::auto_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
447  std::auto_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
448  std::auto_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
449  std::auto_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
450  std::auto_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
451  std::auto_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
452  std::auto_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
453  std::auto_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
454  std::auto_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
455  std::auto_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
456  std::auto_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
457  std::auto_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
458 
459  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
460 
461  MonitorElement *me = *mmi;
462 
463  // store only flagged ME
464  if (iLumiOnly && !me->getLumiFlag()) continue;
465 
466  // get monitor elements
467  switch (me->kind())
468  {
470  pOutInt->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getIntValue());
471  break;
472 
474  pOutDouble->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getFloatValue());
475  break;
476 
478  pOutString->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getStringValue());
479  break;
480 
482  pOut1->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1F());
483  break;
484 
486  pOut1s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1S());
487  break;
488 
490  pOut1d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1D());
491  break;
492 
494  pOut2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2F());
495  break;
496 
498  pOut2s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2S());
499  break;
500 
502  pOut2d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2D());
503  break;
504 
506  pOut3->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH3F());
507  break;
508 
510  pOutProf->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile());
511  break;
512 
514  pOutProf2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile2D());
515  break;
516 
517  default:
518  edm::LogError(MsgLoggerCat)
519  << "ERROR: The DQM object '" << me->getFullname()
520  << "' is neither a ROOT object nor a recognised "
521  << "simple object.\n";
522  continue;
523  }
524 
525  if (!iLumiOnly) {
526  // remove ME after copy to EDM is done.
527  if (deleteAfterCopy)
528  dbe->removeElement(me->getPathname(),me->getName());
529  }
530 
531  } // end loop through monitor elements
532 
533  std::string sName;
534 
535  if (iLumiOnly) {
536  sName = fName + "Lumi";
537  } else {
538  sName = fName + "Run";
539  }
540 
541  // produce objects to put in events
542  iPutTo.put(pOutInt,sName);
543  iPutTo.put(pOutDouble,sName);
544  iPutTo.put(pOutString,sName);
545  iPutTo.put(pOut1,sName);
546  iPutTo.put(pOut1s,sName);
547  iPutTo.put(pOut1d,sName);
548  iPutTo.put(pOut2,sName);
549  iPutTo.put(pOut2s,sName);
550  iPutTo.put(pOut2d,sName);
551  iPutTo.put(pOut3,sName);
552  iPutTo.put(pOutProf,sName);
553  iPutTo.put(pOutProf2,sName);
554 
555 }
556 
557 void
559 {
560 
561 }
virtual void produce(edm::Event &, const edm::EventSetup &)
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
virtual void endRun(edm::Run &, const edm::EventSetup &)
TH3F * getTH3F(void) const
TH1D * getTH1D(void) const
TH2D * getTH2D(void) const
std::map< int, int > iCount
std::vector< MonitorElement * > getAllContents(const std::string &path) const
Definition: DQMStore.cc:1672
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:2572
virtual void endLuminosityBlock(edm::LuminosityBlock &, const edm::EventSetup &)
double getFloatValue(void) const
virtual void beginLuminosityBlock(edm::LuminosityBlock &, const edm::EventSetup &)
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
virtual void beginJob()
int64_t getIntValue(void) const
TH1F * getTH1F(void) const
void putData(T &iPutTo, bool iLumiOnly)
virtual void endJob()
TProfile * getTProfile(void) const
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
MEtoEDMConverter(const edm::ParameterSet &)
TH2F * getTH2F(void) const
virtual void beginRun(edm::Run &, const edm::EventSetup &)
long double T
void Reset(void)
reset ME (ie. contents, errors, etc)
double split
Definition: MVATrainer.cc:139
Definition: Run.h:33