CMS 3D CMS Logo

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"
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  enableMultiThread_ = false;
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  std::string sName;
49 
50  // create persistent objects
51 
52  sName = fName + "Run";
53  produces<MEtoEDM<TH1F>, edm::Transition::EndRun>(sName);
54  produces<MEtoEDM<TH1S>, edm::Transition::EndRun>(sName);
55  produces<MEtoEDM<TH1D>, edm::Transition::EndRun>(sName);
56  produces<MEtoEDM<TH2F>, edm::Transition::EndRun>(sName);
57  produces<MEtoEDM<TH2S>, edm::Transition::EndRun>(sName);
58  produces<MEtoEDM<TH2D>, edm::Transition::EndRun>(sName);
59  produces<MEtoEDM<TH3F>, edm::Transition::EndRun>(sName);
60  produces<MEtoEDM<TProfile>, edm::Transition::EndRun>(sName);
61  produces<MEtoEDM<TProfile2D>, edm::Transition::EndRun>(sName);
62  produces<MEtoEDM<double>, edm::Transition::EndRun>(sName);
63  produces<MEtoEDM<long long>, edm::Transition::EndRun>(sName);
64  produces<MEtoEDM<TString>, edm::Transition::EndRun>(sName);
65 
66  sName = fName + "Lumi";
67  produces<MEtoEDM<TH1F>, edm::Transition::EndLuminosityBlock>(sName);
68  produces<MEtoEDM<TH1S>, edm::Transition::EndLuminosityBlock>(sName);
69  produces<MEtoEDM<TH1D>, edm::Transition::EndLuminosityBlock>(sName);
70  produces<MEtoEDM<TH2F>, edm::Transition::EndLuminosityBlock>(sName);
71  produces<MEtoEDM<TH2S>, edm::Transition::EndLuminosityBlock>(sName);
72  produces<MEtoEDM<TH2D>, edm::Transition::EndLuminosityBlock>(sName);
73  produces<MEtoEDM<TH3F>, edm::Transition::EndLuminosityBlock>(sName);
74  produces<MEtoEDM<TProfile>, edm::Transition::EndLuminosityBlock>(sName);
75  produces<MEtoEDM<TProfile2D>, edm::Transition::EndLuminosityBlock>(sName);
76  produces<MEtoEDM<double>, edm::Transition::EndLuminosityBlock>(sName);
77  produces<MEtoEDM<long long>, edm::Transition::EndLuminosityBlock>(sName);
78  produces<MEtoEDM<TString>, edm::Transition::EndLuminosityBlock>(sName);
79 
80  consumesMany<DQMToken, edm::InLumi>();
81  consumesMany<DQMToken, edm::InRun>();
82  usesResource("DQMStore");
83 
84  static_assert(sizeof(int64_t) == sizeof(long long),"type int64_t is not the same length as long long");
85 
86 }
87 
89 
90 void
92 {
93  // 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 void
103 
104 void
105 MEtoEDMConverter::endRun(edm::Run const& iRun, const edm::EventSetup& iSetup) {}
106 
107 void
109 {
110  DQMStore * store = edm::Service<DQMStore>().operator->();
111  store->meBookerGetter([&](DQMStore::IBooker &b, DQMStore::IGetter &g) {
112  store->scaleElements();
113  putData(g, iRun, false, iRun.run(), 0);
114  });
115 }
116 
117 void
119 {
120  DQMStore * store = edm::Service<DQMStore>().operator->();
121  store->meBookerGetter([&](DQMStore::IBooker &b, DQMStore::IGetter &g) {
122  putData(g, iLumi, true, iLumi.run(), iLumi.id().luminosityBlock());
123  });
124 }
125 
126 template <class T>
127 void
129  T& iPutTo,
130  bool iLumiOnly,
131  uint32_t run,
132  uint32_t lumi)
133 {
134  std::string MsgLoggerCat = "MEtoEDMConverter_putData";
135 
136  if (verbosity > 0)
137  edm::LogInfo (MsgLoggerCat) << "\nStoring MEtoEDM dataformat histograms.";
138 
139  // extract ME information into vectors
140  std::vector<MonitorElement *>::iterator mmi, mme;
141  std::vector<MonitorElement *> items(iGetter.getAllContents(path,
142  enableMultiThread_ ? run : 0,
143  enableMultiThread_ ? lumi : 0));
144 
145 
146  unsigned int n1F=0;
147  unsigned int n1S=0;
148  unsigned int n1D=0;
149  unsigned int n2F=0;
150  unsigned int n2S=0;
151  unsigned int n2D=0;
152  unsigned int n3F=0;
153  unsigned int nProf=0;
154  unsigned int nProf2=0;
155  unsigned int nDouble=0;
156  unsigned int nInt64=0;
157  unsigned int nString=0;
158 
159  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
160  MonitorElement *me = *mmi;
161 
162  // store only flagged ME at endLumi transition, and Run-based
163  // histo at endRun transition
164  if (iLumiOnly && !me->getLumiFlag()) continue;
165  if (!iLumiOnly && me->getLumiFlag()) continue;
166 
167  switch (me->kind())
168  {
170  ++nInt64;
171  break;
172 
174  ++nDouble;
175  break;
176 
178  ++nString;
179  break;
180 
182  ++n1F;
183  break;
184 
186  ++n1S;
187  break;
188 
190  ++n1D;
191  break;
192 
194  ++n2F;
195  break;
196 
198  ++n2S;
199  break;
200 
202  ++n2D;
203  break;
204 
206  ++n3F;
207  break;
208 
210  ++nProf;
211  break;
212 
214  ++nProf2;
215  break;
216 
217  default:
218  edm::LogError(MsgLoggerCat)
219  << "ERROR: The DQM object '" << me->getFullname()
220  << "' is neither a ROOT object nor a recognised "
221  << "simple object.\n";
222  continue;
223  }
224  }
225 
226  std::unique_ptr<MEtoEDM<long long> > pOutInt(new MEtoEDM<long long>(nInt64));
227  std::unique_ptr<MEtoEDM<double> > pOutDouble(new MEtoEDM<double>(nDouble));
228  std::unique_ptr<MEtoEDM<TString> > pOutString(new MEtoEDM<TString>(nString));
229  std::unique_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
230  std::unique_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
231  std::unique_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
232  std::unique_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
233  std::unique_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
234  std::unique_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
235  std::unique_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
236  std::unique_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
237  std::unique_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
238 
239  for (mmi = items.begin (), mme = items.end (); mmi != mme; ++mmi) {
240 
241  MonitorElement *me = *mmi;
242 
243  // store only flagged ME at endLumi transition, and Run-based
244  // histo at endRun transition
245  if (iLumiOnly && !me->getLumiFlag()) continue;
246  if (!iLumiOnly && me->getLumiFlag()) continue;
247 
248  // get monitor elements
249  switch (me->kind())
250  {
252  pOutInt->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getIntValue());
253  break;
254 
256  pOutDouble->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getFloatValue());
257  break;
258 
260  pOutString->putMEtoEdmObject(me->getFullname(),me->getTags(),me->getStringValue());
261  break;
262 
264  pOut1->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1F());
265  break;
266 
268  pOut1s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1S());
269  break;
270 
272  pOut1d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH1D());
273  break;
274 
276  pOut2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2F());
277  break;
278 
280  pOut2s->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2S());
281  break;
282 
284  pOut2d->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH2D());
285  break;
286 
288  pOut3->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTH3F());
289  break;
290 
292  pOutProf->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile());
293  break;
294 
296  pOutProf2->putMEtoEdmObject(me->getFullname(),me->getTags(),*me->getTProfile2D());
297  break;
298 
299  default:
300  edm::LogError(MsgLoggerCat)
301  << "ERROR: The DQM object '" << me->getFullname()
302  << "' is neither a ROOT object nor a recognised "
303  << "simple object.\n";
304  continue;
305  }
306 
307  if (!iLumiOnly) {
308  // remove ME after copy to EDM is done.
309  if (deleteAfterCopy) {
310  iGetter.removeElement(me->getPathname(), me->getName());
311  }
312  }
313  } // end loop through monitor elements
314 
315  std::string sName;
316 
317  if (iLumiOnly) {
318  sName = fName + "Lumi";
319  } else {
320  sName = fName + "Run";
321  }
322 
323  // produce objects to put in events
324  iPutTo.put(std::move(pOutInt),sName);
325  iPutTo.put(std::move(pOutDouble),sName);
326  iPutTo.put(std::move(pOutString),sName);
327  iPutTo.put(std::move(pOut1),sName);
328  iPutTo.put(std::move(pOut1s),sName);
329  iPutTo.put(std::move(pOut1d),sName);
330  iPutTo.put(std::move(pOut2),sName);
331  iPutTo.put(std::move(pOut2s),sName);
332  iPutTo.put(std::move(pOut2d),sName);
333  iPutTo.put(std::move(pOut3),sName);
334  iPutTo.put(std::move(pOutProf),sName);
335  iPutTo.put(std::move(pOutProf2),sName);
336 
337 }
338 
339 void
341 {
342 
343 }
LuminosityBlockID id() const
TProfile * getTProfile() const
T getUntrackedParameter(std::string const &, T const &) const
int64_t getIntValue() const
std::vector< MonitorElement * > getAllContents(std::string const &path, uint32_t runNumber=0, uint32_t lumi=0)
Definition: DQMStore.cc:295
RunNumber_t run() const
Definition: RunBase.h:40
TProfile2D * getTProfile2D() const
const std::string & getPathname() const
get pathname of parent folder
TH1F * getTH1F() const
TH2S * getTH2S() const
double getFloatValue() const
const std::string & getName() const
get name of ME
~MEtoEDMConverter() override
void endRunProduce(edm::Run &, const edm::EventSetup &) override
Definition: DQMStore.h:29
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
void beginJob() override
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
TH2D * getTH2D() const
RunNumber_t run() const
void endRun(edm::Run const &, const edm::EventSetup &) override
TH2F * getTH2F() const
const std::string & getStringValue() const
const std::string getFullname() const
get full name of ME including Pathname
TH3F * getTH3F() const
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
void endJob() override
DQMNet::TagList getTags() const
TH1D * getTH1D() const
TH1S * getTH1S() const
bool getLumiFlag() const
true if ME is meant to be stored for each luminosity section
MEtoEDMConverter(const edm::ParameterSet &)
void beginRun(edm::Run const &, const edm::EventSetup &) override
void putData(DQMStore::IGetter &g, T &iPutTo, bool iLumiOnly, uint32_t run, uint32_t lumi)
long double T
void removeElement(Args &&...args)
Definition: DQMStore.h:199
Kind kind() const
Get the type of the monitor element.
def move(src, dest)
Definition: eostools.py:511
void endLuminosityBlockProduce(edm::LuminosityBlock &, const edm::EventSetup &) override
Definition: Run.h:44