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_ = iPSet.getUntrackedParameter<bool>("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
47  dbe = 0;
49 
50  std::string sName;
51 
52  // create persistent objects
53 
54  sName = fName + "Run";
55  produces<MEtoEDM<TH1F>, edm::InRun>(sName);
56  produces<MEtoEDM<TH1S>, edm::InRun>(sName);
57  produces<MEtoEDM<TH1D>, edm::InRun>(sName);
58  produces<MEtoEDM<TH2F>, edm::InRun>(sName);
59  produces<MEtoEDM<TH2S>, edm::InRun>(sName);
60  produces<MEtoEDM<TH2D>, edm::InRun>(sName);
61  produces<MEtoEDM<TH3F>, edm::InRun>(sName);
62  produces<MEtoEDM<TProfile>, edm::InRun>(sName);
63  produces<MEtoEDM<TProfile2D>, edm::InRun>(sName);
64  produces<MEtoEDM<double>, edm::InRun>(sName);
65  produces<MEtoEDM<long long>, edm::InRun>(sName);
66  produces<MEtoEDM<TString>, edm::InRun>(sName);
67 
68  sName = fName + "Lumi";
69  produces<MEtoEDM<TH1F>, edm::InLumi>(sName);
70  produces<MEtoEDM<TH1S>, edm::InLumi>(sName);
71  produces<MEtoEDM<TH1D>, edm::InLumi>(sName);
72  produces<MEtoEDM<TH2F>, edm::InLumi>(sName);
73  produces<MEtoEDM<TH2S>, edm::InLumi>(sName);
74  produces<MEtoEDM<TH2D>, edm::InLumi>(sName);
75  produces<MEtoEDM<TH3F>, edm::InLumi>(sName);
76  produces<MEtoEDM<TProfile>, edm::InLumi>(sName);
77  produces<MEtoEDM<TProfile2D>, edm::InLumi>(sName);
78  produces<MEtoEDM<double>, edm::InLumi>(sName);
79  produces<MEtoEDM<long long>, edm::InLumi>(sName);
80  produces<MEtoEDM<TString>, edm::InLumi>(sName);
81 
82  iCount.clear();
83 
84  assert(sizeof(int64_t) == sizeof(long long));
85 
86 }
87 
89 {
90 }
91 
92 void
94 {
95 }
96 
97 void
99 {
100  std::string MsgLoggerCat = "MEtoEDMConverter_endJob";
101 
102  if (verbosity > 0) {
103 
104  // keep track just of package names
105  std::map<std::string,int> packages;
106 
107  // count various objects we have
108  unsigned nTH1F = 0;
109  unsigned nTH1S = 0;
110  unsigned nTH1D = 0;
111  unsigned nTH2F = 0;
112  unsigned nTH2S = 0;
113  unsigned nTH2D = 0;
114  unsigned nTH3F = 0;
115  unsigned nTProfile = 0;
116  unsigned nTProfile2D = 0;
117  unsigned nDouble = 0;
118  unsigned nInt64 = 0;
119  unsigned nString = 0;
120 
121  if (verbosity > 1) std::cout << std::endl << "Summary :" << std::endl;
122 
123  // get contents out of DQM
124  std::vector<MonitorElement *>::iterator mmi, mme;
125  std::vector<MonitorElement *> items(dbe->getAllContents(""));
126 
127  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
128 
129  // keep track of leading directory (i.e. package)
130  StringList dir = StringOps::split((*mmi)->getPathname(),"/");
131  ++packages[dir[0]];
132 
133  // check type
134  if (verbosity > 1) std::cout << "MEobject:" << std::endl;
135  MonitorElement *me = *mmi;
136  TObject *tobj = me->getRootObject();
137  switch (me->kind())
138  {
140  ++nInt64;
141  if (verbosity > 1)
142  std::cout << " scalar: " << tobj->GetName() << ": Int64\n";
143  break;
144 
146  ++nDouble;
147  if (verbosity > 1)
148  std::cout << " scalar: " << tobj->GetName() << ": Double\n";
149  break;
150 
152  ++nString;
153  if (verbosity > 1)
154  std::cout << " scalar: " << tobj->GetName() << ": String\n";
155  break;
156 
158  ++nTH1F;
159  if (verbosity > 1)
160  std::cout << " normal: " << tobj->GetName() << ": TH1F\n";
161  break;
162 
164  ++nTH1S;
165  if (verbosity > 1)
166  std::cout << " normal: " << tobj->GetName() << ": TH1S\n";
167  break;
168 
170  ++nTH1D;
171  if (verbosity > 1)
172  std::cout << " normal: " << tobj->GetName() << ": TH1D\n";
173  break;
174 
176  ++nTH2F;
177  if (verbosity > 1)
178  std::cout << " normal: " << tobj->GetName() << ": TH2F\n";
179  break;
180 
182  ++nTH2S;
183  if (verbosity > 1)
184  std::cout << " normal: " << tobj->GetName() << ": TH2S\n";
185  break;
186 
188  ++nTH2D;
189  if (verbosity > 1)
190  std::cout << " normal: " << tobj->GetName() << ": TH2D\n";
191  break;
192 
194  ++nTH3F;
195  if (verbosity > 1)
196  std::cout << " normal: " << tobj->GetName() << ": TH3F\n";
197  break;
198 
200  ++nTProfile;
201  if (verbosity > 1)
202  std::cout << " normal: " << tobj->GetName() << ": TProfile\n";
203  break;
204 
206  ++nTProfile2D;
207  if (verbosity > 1)
208  std::cout << " normal: " << tobj->GetName() << ": TProfile2D\n";
209  break;
210 
211  default:
212  edm::LogError(MsgLoggerCat)
213  << "ERROR: The DQM object '" << me->getFullname()
214  << "' is neither a ROOT object nor a recognised "
215  << "simple object.\n";
216  continue;
217  }
218  } // end loop through monitor elements
219 
220  // list unique packages
221  std::cout << "Packages accessing DQM:" << std::endl;
222  std::map<std::string,int>::iterator pkgIter;
223  for (pkgIter = packages.begin(); pkgIter != packages.end(); ++pkgIter)
224  std::cout << " " << pkgIter->first << ": " << pkgIter->second
225  << std::endl;
226 
227  std::cout << "We have " << nTH1F << " TH1F objects" << std::endl;
228  std::cout << "We have " << nTH1S << " TH1S objects" << std::endl;
229  std::cout << "We have " << nTH1D << " TH1D objects" << std::endl;
230  std::cout << "We have " << nTH2F << " TH2F objects" << std::endl;
231  std::cout << "We have " << nTH2S << " TH2S objects" << std::endl;
232  std::cout << "We have " << nTH2D << " TH2D objects" << std::endl;
233  std::cout << "We have " << nTH3F << " TH3F objects" << std::endl;
234  std::cout << "We have " << nTProfile << " TProfile objects" << std::endl;
235  std::cout << "We have " << nTProfile2D << " TProfile2D objects" << std::endl;
236  std::cout << "We have " << nDouble << " Double objects" << std::endl;
237  std::cout << "We have " << nInt64 << " Int64 objects" << std::endl;
238  std::cout << "We have " << nString << " String objects" << std::endl;
239 
240  if (verbosity > 1) std::cout << std::endl;
241 
242  }
243 
244  if (verbosity >= 0)
245  edm::LogInfo(MsgLoggerCat)
246  << "Terminating having processed " << iCount.size() << " runs.";
247 
248 }
249 
250 void
252 {
253  std::string MsgLoggerCat = "MEtoEDMConverter_beginRun";
254 
255  // No need to do any reset in the MultiThread DQM, since we will
256  // index each and every MonitorElement by Run and Lumi.
257 
258  if (enableMultiThread_)
259  return;
260 
261  int nrun = iRun.run();
262 
263  // keep track of number of runs processed
264  ++iCount[nrun];
265 
266  if (verbosity > 0) { // keep track of number of runs processed
267  edm::LogInfo(MsgLoggerCat)
268  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
269  } else if (verbosity == 0) {
270  if (nrun%frequency == 0 || iCount.size() == 1) {
271  edm::LogInfo(MsgLoggerCat)
272  << "Processing run " << nrun << " (" << iCount.size() << " runs total)";
273  }
274  }
275 
276  // clear contents of monitor elements
277  std::vector<MonitorElement *>::iterator mmi, mme;
278  std::vector<MonitorElement *> items(dbe->getAllContents(path));
279 
280  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
281 
282  MonitorElement *me = *mmi;
283 
284  switch (me->kind())
285  {
287  break;
288 
290  break;
291 
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 
328  me->Reset();
329  break;
330 
331  default:
332  edm::LogError(MsgLoggerCat)
333  << "ERROR: The DQM object '" << me->getFullname()
334  << "' is neither a ROOT object nor a recognised "
335  << "simple object.\n";
336  continue;
337  }
338 
339  } // end loop through monitor elements
340 }
341 void
343 {
344 }
345 
346 void
348 {
349  dbe->scaleElements();
350  putData(iRun, false, iRun.run(), 0);
351 }
352 
353 void
355 {
356  putData(iLumi, true, iLumi.run(), iLumi.id().luminosityBlock());
357 }
358 
359 template <class T>
360 void
362  bool iLumiOnly,
363  uint32_t run,
364  uint32_t lumi)
365 {
366  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
367 
368  if (verbosity > 0)
369  edm::LogInfo (MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
370 
371  // extract ME information into vectors
372  std::vector<MonitorElement *>::iterator mmi, mme;
373  std::vector<MonitorElement *> items(dbe->getAllContents(path,
374  enableMultiThread_ ? run : 0,
375  enableMultiThread_ ? lumi : 0));
376 
377  unsigned int n1F=0;
378  unsigned int n1S=0;
379  unsigned int n1D=0;
380  unsigned int n2F=0;
381  unsigned int n2S=0;
382  unsigned int n2D=0;
383  unsigned int n3F=0;
384  unsigned int nProf=0;
385  unsigned int nProf2=0;
386  unsigned int nDouble=0;
387  unsigned int nInt64=0;
388  unsigned int nString=0;
389 
390  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
391 
392  MonitorElement *me = *mmi;
393 
394  // store only flagged ME at endLumi transition, and Run-based
395  // histo at endRun transition
396  if (iLumiOnly && !me->getLumiFlag()) continue;
397  if (!iLumiOnly && me->getLumiFlag()) continue;
398 
399  switch (me->kind())
400  {
402  ++nInt64;
403  break;
404 
406  ++nDouble;
407  break;
408 
410  ++nString;
411  break;
412 
414  ++n1F;
415  break;
416 
418  ++n1S;
419  break;
420 
422  ++n1D;
423  break;
424 
426  ++n2F;
427  break;
428 
430  ++n2S;
431  break;
432 
434  ++n2D;
435  break;
436 
438  ++n3F;
439  break;
440 
442  ++nProf;
443  break;
444 
446  ++nProf2;
447  break;
448 
449  default:
450  edm::LogError(MsgLoggerCat)
451  << "ERROR: The DQM object '" << me->getFullname()
452  << "' is neither a ROOT object nor a recognised "
453  << "simple object.\n";
454  continue;
455  }
456  }
457 
458  std::auto_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
459  std::auto_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
460  std::auto_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
461  std::auto_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
462  std::auto_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
463  std::auto_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
464  std::auto_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
465  std::auto_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
466  std::auto_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
467  std::auto_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
468  std::auto_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
469  std::auto_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
470 
471  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
472 
473  MonitorElement *me = *mmi;
474 
475  // store only flagged ME at endLumi transition, and Run-based
476  // histo at endRun transition
477  if (iLumiOnly && !me->getLumiFlag()) continue;
478  if (!iLumiOnly && me->getLumiFlag()) continue;
479 
480  // get monitor elements
481  switch (me->kind())
482  {
484  pOutInt->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getIntValue());
485  break;
486 
488  pOutDouble->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getFloatValue());
489  break;
490 
492  pOutString->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getStringValue());
493  break;
494 
496  pOut1->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1F());
497  break;
498 
500  pOut1s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1S());
501  break;
502 
504  pOut1d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1D());
505  break;
506 
508  pOut2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2F());
509  break;
510 
512  pOut2s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2S());
513  break;
514 
516  pOut2d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2D());
517  break;
518 
520  pOut3->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH3F());
521  break;
522 
524  pOutProf->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile());
525  break;
526 
528  pOutProf2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile2D());
529  break;
530 
531  default:
532  edm::LogError(MsgLoggerCat)
533  << "ERROR: The DQM object '" << me->getFullname()
534  << "' is neither a ROOT object nor a recognised "
535  << "simple object.\n";
536  continue;
537  }
538 
539  if (!iLumiOnly) {
540  // remove ME after copy to EDM is done.
541  if (deleteAfterCopy)
542  dbe->removeElement(me->getPathname(),me->getName());
543  }
544 
545  } // end loop through monitor elements
546 
547  std::string sName;
548 
549  if (iLumiOnly) {
550  sName = fName + "Lumi";
551  } else {
552  sName = fName + "Run";
553  }
554 
555  // produce objects to put in events
556  iPutTo.put(pOutInt,sName);
557  iPutTo.put(pOutDouble,sName);
558  iPutTo.put(pOutString,sName);
559  iPutTo.put(pOut1,sName);
560  iPutTo.put(pOut1s,sName);
561  iPutTo.put(pOut1d,sName);
562  iPutTo.put(pOut2,sName);
563  iPutTo.put(pOut2s,sName);
564  iPutTo.put(pOut2d,sName);
565  iPutTo.put(pOut3,sName);
566  iPutTo.put(pOutProf,sName);
567  iPutTo.put(pOutProf2,sName);
568 
569 }
570 
571 void
573 {
574 
575 }
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:42
TProfile2D * getTProfile2D(void) const
tuple lumi
Definition: fjr2json.py:35
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:243
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:121
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:41