CMS 3D CMS Logo

MEtoEDMConverter.cc
Go to the documentation of this file.
1 
9 // framework & common header files
26 
27 //DQM services
30 
31 #include "classlib/utils/StringList.h"
32 #include "classlib/utils/StringOps.h"
33 
34 // helper files
35 #include <iostream>
36 #include <cstdlib>
37 #include <string>
38 #include <memory>
39 #include <vector>
40 #include <map>
41 #include <cassert>
42 #include <cstdint>
43 
44 #include "TString.h"
45 #include "TH1F.h"
46 #include "TH1S.h"
47 #include "TH1D.h"
48 #include "TH1I.h"
49 #include "TH2F.h"
50 #include "TH2S.h"
51 #include "TH2D.h"
52 #include "TH2I.h"
53 #include "TH3F.h"
54 #include "TProfile.h"
55 #include "TProfile2D.h"
56 #include "TObjString.h"
57 
58 namespace meedm {
59  struct Void {};
60 } // namespace meedm
61 
62 //Using RunCache and LuminosityBlockCache tells the framework the module is able to
63 // allow multiple concurrent Runs and LuminosityBlocks.
64 
65 class MEtoEDMConverter : public edm::one::EDProducer<edm::RunCache<meedm::Void>,
66  edm::LuminosityBlockCache<meedm::Void>,
67  edm::EndLuminosityBlockProducer,
68  edm::EndRunProducer,
69  edm::one::SharedResources> {
70 public:
73 
74  explicit MEtoEDMConverter(const edm::ParameterSet&);
75  ~MEtoEDMConverter() override;
76  void beginJob() override;
77  void produce(edm::Event&, const edm::EventSetup&) override;
78  std::shared_ptr<meedm::Void> globalBeginRun(edm::Run const&, const edm::EventSetup&) const override;
79  void globalEndRun(edm::Run const&, const edm::EventSetup&) override;
80  void endRunProduce(edm::Run&, const edm::EventSetup&) override;
83  std::shared_ptr<meedm::Void> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
84  edm::EventSetup const&) const override;
85 
86  template <class T>
87  void putData(DQMStore::IGetter& g, T& iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi);
88 
89  using TagList = std::vector<uint32_t>;
90 
91 private:
93  int verbosity;
94  int frequency;
96 
97  // private statistics information
98  std::map<int, int> iCount;
101 
102 }; // end class declaration
103 
104 using namespace lat;
105 
107  std::string MsgLoggerCat = "MEtoEDMConverter_MEtoEDMConverter";
108 
109  // get information from parameter set
110  fName = iPSet.getUntrackedParameter<std::string>("Name", "MEtoEDMConverter");
111  verbosity = iPSet.getUntrackedParameter<int>("Verbosity", 0);
112  frequency = iPSet.getUntrackedParameter<int>("Frequency", 50);
113  path = iPSet.getUntrackedParameter<std::string>("MEPathToSave");
114  // use value of first digit to determine default output level (inclusive)
115  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
116  verbosity %= 10;
117 
118  // print out Parameter Set information being used
119  if (verbosity >= 0) {
120  edm::LogInfo(MsgLoggerCat) << "\n===============================\n"
121  << "Initialized as EDProducer with parameter values:\n"
122  << " Name = " << fName << "\n"
123  << " Verbosity = " << verbosity << "\n"
124  << " Frequency = " << frequency << "\n"
125  << " Path = " << path << "\n"
126  << "===============================\n";
127  }
128 
129  std::string sName;
130 
131  // create persistent objects
132 
133  sName = fName + "Run";
134  produces<MEtoEDM<TH1F>, edm::Transition::EndRun>(sName);
135  produces<MEtoEDM<TH1S>, edm::Transition::EndRun>(sName);
136  produces<MEtoEDM<TH1D>, edm::Transition::EndRun>(sName);
137  produces<MEtoEDM<TH1I>, edm::Transition::EndRun>(sName);
138  produces<MEtoEDM<TH2F>, edm::Transition::EndRun>(sName);
139  produces<MEtoEDM<TH2S>, edm::Transition::EndRun>(sName);
140  produces<MEtoEDM<TH2D>, edm::Transition::EndRun>(sName);
141  produces<MEtoEDM<TH2I>, edm::Transition::EndRun>(sName);
142  produces<MEtoEDM<TH3F>, edm::Transition::EndRun>(sName);
143  produces<MEtoEDM<TProfile>, edm::Transition::EndRun>(sName);
144  produces<MEtoEDM<TProfile2D>, edm::Transition::EndRun>(sName);
145  produces<MEtoEDM<double>, edm::Transition::EndRun>(sName);
146  produces<MEtoEDM<long long>, edm::Transition::EndRun>(sName);
147  produces<MEtoEDM<TString>, edm::Transition::EndRun>(sName);
148 
149  sName = fName + "Lumi";
150  produces<MEtoEDM<TH1F>, edm::Transition::EndLuminosityBlock>(sName);
151  produces<MEtoEDM<TH1S>, edm::Transition::EndLuminosityBlock>(sName);
152  produces<MEtoEDM<TH1D>, edm::Transition::EndLuminosityBlock>(sName);
153  produces<MEtoEDM<TH1I>, edm::Transition::EndLuminosityBlock>(sName);
154  produces<MEtoEDM<TH2F>, edm::Transition::EndLuminosityBlock>(sName);
155  produces<MEtoEDM<TH2S>, edm::Transition::EndLuminosityBlock>(sName);
156  produces<MEtoEDM<TH2D>, edm::Transition::EndLuminosityBlock>(sName);
157  produces<MEtoEDM<TH2I>, edm::Transition::EndLuminosityBlock>(sName);
158  produces<MEtoEDM<TH3F>, edm::Transition::EndLuminosityBlock>(sName);
159  produces<MEtoEDM<TProfile>, edm::Transition::EndLuminosityBlock>(sName);
160  produces<MEtoEDM<TProfile2D>, edm::Transition::EndLuminosityBlock>(sName);
161  produces<MEtoEDM<double>, edm::Transition::EndLuminosityBlock>(sName);
162  produces<MEtoEDM<long long>, edm::Transition::EndLuminosityBlock>(sName);
163  produces<MEtoEDM<TString>, edm::Transition::EndLuminosityBlock>(sName);
164 
168  this->lumigetter_(bd);
169  this->rungetter_(bd);
170  });
171  usesResource("DQMStore");
172 
173  static_assert(sizeof(int64_t) == sizeof(long long), "type int64_t is not the same length as long long");
174 }
175 
177 
179 
180 std::shared_ptr<meedm::Void> MEtoEDMConverter::globalBeginRun(edm::Run const& iRun,
181  const edm::EventSetup& iSetup) const {
182  return std::shared_ptr<meedm::Void>();
183 }
184 
185 void MEtoEDMConverter::globalEndRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {}
186 
189  store->meBookerGetter([&](DQMStore::IBooker& b, DQMStore::IGetter& g) { putData(g, iRun, false, iRun.run(), 0); });
190 }
191 
193  edm::EventSetup const&) const {
194  return std::shared_ptr<meedm::Void>();
195 }
196 
200  putData(g, iLumi, true, iLumi.run(), iLumi.id().luminosityBlock());
201  });
202 }
203 
204 template <class T>
205 void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi) {
206  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
207 
208  if (verbosity > 0)
209  edm::LogInfo(MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
210 
211  // extract ME information into vectors
212  std::vector<MonitorElement*>::iterator mmi, mme;
213  std::vector<MonitorElement*> items(iGetter.getAllContents(path, run, lumi));
214 
215  unsigned int n1F = 0;
216  unsigned int n1S = 0;
217  unsigned int n1D = 0;
218  unsigned int n1I = 0;
219  unsigned int n2F = 0;
220  unsigned int n2S = 0;
221  unsigned int n2D = 0;
222  unsigned int n2I = 0;
223  unsigned int n3F = 0;
224  unsigned int nProf = 0;
225  unsigned int nProf2 = 0;
226  unsigned int nDouble = 0;
227  unsigned int nInt64 = 0;
228  unsigned int nString = 0;
229 
230  for (mmi = items.begin(), mme = items.end(); mmi != mme; ++mmi) {
231  MonitorElement* me = *mmi;
232 
233  // store only flagged ME at endLumi transition, and Run-based
234  // histo at endRun transition
235  if (iLumiOnly && !me->getLumiFlag())
236  continue;
237  if (!iLumiOnly && me->getLumiFlag())
238  continue;
239 
240  switch (me->kind()) {
242  ++nInt64;
243  break;
244 
246  ++nDouble;
247  break;
248 
250  ++nString;
251  break;
252 
254  ++n1F;
255  break;
256 
258  ++n1S;
259  break;
260 
262  ++n1D;
263  break;
264 
266  ++n1I;
267  break;
268 
270  ++n2F;
271  break;
272 
274  ++n2S;
275  break;
276 
278  ++n2D;
279  break;
280 
282  ++n2I;
283  break;
284 
286  ++n3F;
287  break;
288 
290  ++nProf;
291  break;
292 
294  ++nProf2;
295  break;
296 
297  default:
298  edm::LogError(MsgLoggerCat) << "ERROR: The DQM object '" << me->getFullname()
299  << "' is neither a ROOT object nor a recognised "
300  << "simple object.\n";
301  continue;
302  }
303  }
304 
305  std::unique_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
306  std::unique_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
307  std::unique_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
308  std::unique_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
309  std::unique_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
310  std::unique_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
311  std::unique_ptr<MEtoEDM<TH1I> > pOut1i(new MEtoEDM<TH1I>(n1I));
312  std::unique_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
313  std::unique_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
314  std::unique_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
315  std::unique_ptr<MEtoEDM<TH2I> > pOut2i(new MEtoEDM<TH2I>(n2I));
316  std::unique_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
317  std::unique_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
318  std::unique_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
319 
320  for (mmi = items.begin(), mme = items.end(); mmi != mme; ++mmi) {
321  MonitorElement* me = *mmi;
322 
323  // store only flagged ME at endLumi transition, and Run-based
324  // histo at endRun transition
325  // DQMStore should only hand out matching MEs
326  assert(iLumiOnly == me->getLumiFlag());
327 
328  // get monitor elements
329  switch (me->kind()) {
331  pOutInt->putMEtoEdmObject(me->getFullname(), me->getIntValue());
332  break;
333 
335  pOutDouble->putMEtoEdmObject(me->getFullname(), me->getFloatValue());
336  break;
337 
339  pOutString->putMEtoEdmObject(me->getFullname(), me->getStringValue());
340  break;
341 
343  pOut1->putMEtoEdmObject(me->getFullname(), *me->getTH1F());
344  break;
345 
347  pOut1s->putMEtoEdmObject(me->getFullname(), *me->getTH1S());
348  break;
349 
351  pOut1d->putMEtoEdmObject(me->getFullname(), *me->getTH1D());
352  break;
353 
355  pOut1i->putMEtoEdmObject(me->getFullname(), *me->getTH1I());
356  break;
357 
359  pOut2->putMEtoEdmObject(me->getFullname(), *me->getTH2F());
360  break;
361 
363  pOut2s->putMEtoEdmObject(me->getFullname(), *me->getTH2S());
364  break;
365 
367  pOut2d->putMEtoEdmObject(me->getFullname(), *me->getTH2D());
368  break;
369 
371  pOut2i->putMEtoEdmObject(me->getFullname(), *me->getTH2I());
372  break;
373 
375  pOut3->putMEtoEdmObject(me->getFullname(), *me->getTH3F());
376  break;
377 
379  pOutProf->putMEtoEdmObject(me->getFullname(), *me->getTProfile());
380  break;
381 
383  pOutProf2->putMEtoEdmObject(me->getFullname(), *me->getTProfile2D());
384  break;
385 
386  default:
387  edm::LogError(MsgLoggerCat) << "ERROR: The DQM object '" << me->getFullname()
388  << "' is neither a ROOT object nor a recognised "
389  << "simple object.\n";
390  continue;
391  }
392 
393  } // end loop through monitor elements
394 
395  std::string sName;
396 
397  if (iLumiOnly) {
398  sName = fName + "Lumi";
399  } else {
400  sName = fName + "Run";
401  }
402 
403  // produce objects to put in events
404  iPutTo.put(std::move(pOutInt), sName);
405  iPutTo.put(std::move(pOutDouble), sName);
406  iPutTo.put(std::move(pOutString), sName);
407  iPutTo.put(std::move(pOut1), sName);
408  iPutTo.put(std::move(pOut1s), sName);
409  iPutTo.put(std::move(pOut1d), sName);
410  iPutTo.put(std::move(pOut2), sName);
411  iPutTo.put(std::move(pOut2s), sName);
412  iPutTo.put(std::move(pOut2d), sName);
413  iPutTo.put(std::move(pOut2i), sName);
414  iPutTo.put(std::move(pOut3), sName);
415  iPutTo.put(std::move(pOutProf), sName);
416  iPutTo.put(std::move(pOutProf2), sName);
417 }
418 
420 
edm::GetterOfProducts< DQMToken > rungetter_
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
Definition: ProducerBase.h:87
LuminosityBlockNumber_t luminosityBlock() const
dqm::legacy::DQMStore DQMStore
edm::GetterOfProducts< DQMToken > lumigetter_
~MEtoEDMConverter() override
Log< level::Error, false > LogError
void endRunProduce(edm::Run &, const edm::EventSetup &) override
assert(be >=bs)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::vector< uint32_t > TagList
void beginJob() override
T getUntrackedParameter(std::string const &, T const &) const
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
std::shared_ptr< meedm::Void > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:641
std::shared_ptr< meedm::Void > globalBeginRun(edm::Run const &, const edm::EventSetup &) const override
void meBookerGetter(iFunc f)
Definition: DQMStore.h:710
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void globalEndRun(edm::Run const &, const edm::EventSetup &) override
const int verbosity
Log< level::Info, false > LogInfo
LuminosityBlockID id() const
std::map< int, int > iCount
double b
Definition: hdecay.h:120
dqm::legacy::MonitorElement MonitorElement
MEtoEDMConverter(const edm::ParameterSet &)
void putData(DQMStore::IGetter &g, T &iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi)
long double T
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
def move(src, dest)
Definition: eostools.py:511
void endLuminosityBlockProduce(edm::LuminosityBlock &, const edm::EventSetup &) override
Definition: Run.h:45