CMS 3D CMS Logo

EDMtoMEConverter.cc
Go to the documentation of this file.
1 
8 #include <cassert>
9 
11 
14 
15 using namespace lat;
16 
17 template<typename T>
18 void EDMtoMEConverter::Tokens<T>::set(const edm::InputTag& runInputTag, const edm::InputTag& lumiInputTag, edm::ConsumesCollector& iC) {
19  runToken = iC.mayConsume<MEtoEDM<T>, edm::InRun>(runInputTag);
20  lumiToken = iC.mayConsume<MEtoEDM<T>, edm::InLumi>(lumiInputTag);
21 }
22 
23 template<typename T>
25  iRun.getByToken(runToken, handle);
26 }
27 
28 template<typename T>
30  iLumi.getByToken(lumiToken, handle);
31 }
32 
33 namespace {
34  // general
35  template <size_t I, size_t N>
36  struct ForEachHelper {
37  template <typename Tuple, typename Func>
38  static
39  void call(Tuple&& tpl, Func&& func) {
40  func(std::get<I-1>(tpl));
41  ForEachHelper<I+1, N>::call(std::forward<Tuple>(tpl), std::forward<Func>(func));
42  }
43  };
44  // break recursion
45  template <size_t N>
46  struct ForEachHelper<N, N> {
47  template <typename Tuple, typename Func>
48  static
49  void call(Tuple&& tpl, Func&& func) {
50  func(std::get<N-1>(tpl));
51  }
52  };
53 
54  // helper function to provide nice interface
55  template <typename Tuple, typename Func>
56  void for_each(Tuple&& tpl, Func&& func) {
58  ForEachHelper<1, size>::call(std::forward<Tuple>(tpl), std::forward<Func>(func));
59  }
60 
61 
62  template <typename T> struct HistoTraits;
63  template <> struct HistoTraits<TH1F> {
64  static TH1F *get(MonitorElement *me) { return me->getTH1F(); }
65  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
66  return iBooker.book1D(std::forward<Args>(args)...);
67  }
68  };
69  template <> struct HistoTraits<TH1S> {
70  static TH1S *get(MonitorElement *me) { return me->getTH1S(); }
71  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
72  return iBooker.book1S(std::forward<Args>(args)...);
73  }
74  };
75  template <> struct HistoTraits<TH1D> {
76  static TH1D *get(MonitorElement *me) { return me->getTH1D(); }
77  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
78  return iBooker.book1DD(std::forward<Args>(args)...);
79  }
80  };
81  template <> struct HistoTraits<TH2F> {
82  static TH2F *get(MonitorElement *me) { return me->getTH2F(); }
83  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
84  return iBooker.book2D(std::forward<Args>(args)...);
85  }
86  };
87  template <> struct HistoTraits<TH2S> {
88  static TH2S *get(MonitorElement *me) { return me->getTH2S(); }
89  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
90  return iBooker.book2S(std::forward<Args>(args)...);
91  }
92  };
93  template <> struct HistoTraits<TH2D> {
94  static TH2D *get(MonitorElement *me) { return me->getTH2D(); }
95  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
96  return iBooker.book2DD(std::forward<Args>(args)...);
97  }
98  };
99  template <> struct HistoTraits<TH3F> {
100  static TH3F *get(MonitorElement *me) { return me->getTH3F(); }
101  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
102  return iBooker.book3D(std::forward<Args>(args)...);
103  }
104  };
105  template <> struct HistoTraits<TProfile>{
106  static TProfile *get(MonitorElement *me) { return me->getTProfile(); }
107  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
108  return iBooker.bookProfile(std::forward<Args>(args)...);
109  }
110  };
111  template <> struct HistoTraits<TProfile2D> {
112  static TProfile2D *get(MonitorElement *me) { return me->getTProfile2D(); }
113  template <typename ...Args> static MonitorElement *book(DQMStore::IBooker &iBooker, Args&&... args) {
114  return iBooker.bookProfile2D(std::forward<Args>(args)...);
115  }
116  };
117 
118  // Default to histograms and similar, others are specialized
119  template <typename T>
120  struct AddMonitorElement {
121  template <typename MEtoEDMObject_object, typename RunOrLumi>
122  static
123  MonitorElement *call(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, MEtoEDMObject_object *metoedmobject, const std::string& dir, const std::string& name, const RunOrLumi& runOrLumi) {
124  MonitorElement *me = iGetter.get(dir+"/"+metoedmobject->GetName());
125 
126  if(me) {
127  auto histo = HistoTraits<T>::get(me);
128  if(histo && me->getTH1()->CanExtendAllAxes()) {
129  TList list;
130  list.Add(metoedmobject);
131  if (histo->Merge(&list) == -1)
132  std::cout << "ERROR EDMtoMEConverter::getData(): merge failed for '"
133  << metoedmobject->GetName() << "'" << std::endl;
134  return me;
135  }
136  }
137 
138  iBooker.setCurrentFolder(dir);
139  return HistoTraits<T>::book(iBooker, metoedmobject->GetName(), metoedmobject);
140  }
141  };
142 
143  template <>
144  struct AddMonitorElement<double> {
145  template <typename MEtoEDMObject_object, typename RunOrLumi>
146  static
147  MonitorElement *call(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, MEtoEDMObject_object *metoedmobject, const std::string& dir, const std::string& name, const RunOrLumi& runOrLumi) {
148  iBooker.setCurrentFolder(dir);
149  MonitorElement *me = iBooker.bookFloat(name);
150  me->Fill(*metoedmobject);
151  return me;
152  }
153  };
154 
155  // long long and int share some commonalities, which are captured here (we can have only one default template definition)
156  template <typename T>
157  struct AddMonitorElementForIntegers {
158  template <typename MEtoEDMObject_object, typename RunOrLumi>
159  static
160  MonitorElement *call(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, MEtoEDMObject_object *metoedmobject, const std::string& dir, const std::string& name, const RunOrLumi& runOrLumi) {
161  iBooker.setCurrentFolder(dir);
162  iGetter.setCurrentFolder(dir);
163  T ival = getProcessedEvents(iGetter, dir, name, runOrLumi);
164  MonitorElement *me = iBooker.bookInt(name);
165  me->Fill(*metoedmobject + ival);
166  return me;
167  }
168 
169  static
170  T getProcessedEvents(DQMStore::IGetter &iGetter, const std::string& dir, const std::string& name, const edm::Run&) {
171  if(name.find("processedEvents") != std::string::npos) {
172  if(const MonitorElement *me = iGetter.get(dir+"/"+name)) {
173  return me->getIntValue();
174  }
175  }
176  return 0;
177  }
178 
179  static
180  T getProcessedEvents(DQMStore::IGetter &iGetter, const std::string& dir, const std::string& name, const edm::LuminosityBlock&) {
181  return 0;
182  }
183  };
184  template <>
185  struct AddMonitorElement<long long> {
186  template <typename ...Args>
187  static
188  MonitorElement *call(Args&&... args) {
189  return AddMonitorElementForIntegers<long long>::call(std::forward<Args>(args)...);
190  }
191  };
192  template <>
193  struct AddMonitorElement<int> {
194  template <typename ...Args>
195  static
196  MonitorElement *call(Args&&... args) {
197  return AddMonitorElementForIntegers<int>::call(std::forward<Args>(args)...);
198  }
199  };
200 
201 
202  template <>
203  struct AddMonitorElement<TString> {
204  template <typename MEtoEDMObject_object, typename RunOrLumi>
205  static
206  MonitorElement *call(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, MEtoEDMObject_object *metoedmobject, const std::string& dir, const std::string& name, const RunOrLumi& runOrLumi) {
207  iBooker.setCurrentFolder(dir);
208  std::string scont = metoedmobject->Data();
209  return iBooker.bookString(name, scont);
210  }
211  };
212 
213  void maybeSetLumiFlag(MonitorElement *me, const edm::Run&) {
214  }
215  void maybeSetLumiFlag(MonitorElement *me, const edm::LuminosityBlock&) {
216  me->setLumiFlag();
217  }
218 
219 }
220 
222  verbosity(0), frequency(0)
223 {
224  const edm::InputTag& runInputTag = iPSet.getParameter<edm::InputTag>("runInputTag");
225  const edm::InputTag& lumiInputTag = iPSet.getParameter<edm::InputTag>("lumiInputTag");
227 
228  for_each(tokens_, [&](auto& tok) {
229  tok.set(runInputTag, lumiInputTag, iC);
230  });
231 
232  constexpr char MsgLoggerCat[] = "EDMtoMEConverter_EDMtoMEConverter";
233 
234  // get information from parameter set
235  name = iPSet.getUntrackedParameter<std::string>("Name");
236  verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
237  frequency = iPSet.getUntrackedParameter<int>("Frequency");
238 
239  convertOnEndLumi = iPSet.getUntrackedParameter<bool>("convertOnEndLumi",true);
240  convertOnEndRun = iPSet.getUntrackedParameter<bool>("convertOnEndRun",true);
241 
242  // use value of first digit to determine default output level (inclusive)
243  // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
244  verbosity %= 10;
245 
246  // print out Parameter Set information being used
247  if (verbosity >= 0) {
248  edm::LogInfo(MsgLoggerCat)
249  << "\n===============================\n"
250  << "Initialized as EDAnalyzer with parameter values:\n"
251  << " Name = " << name << "\n"
252  << " Verbosity = " << verbosity << "\n"
253  << " Frequency = " << frequency << "\n"
254  << "===============================\n";
255  }
256 
257  assert(sizeof(int64_t) == sizeof(long long));
258  usesResource("DQMStore");
259 
260  dqmLumiToken_ = produces<DQMToken,edm::Transition::EndLuminosityBlock>("endLumi");
261  dqmRunToken_ = produces<DQMToken,edm::Transition::EndRun>("endRun");
262 } // end constructor
263 
265 
267 {
268  if (convertOnEndRun) {
269  DQMStore * store = edm::Service<DQMStore>().operator->();
270  store->meBookerGetter([&](DQMStore::IBooker &b, DQMStore::IGetter &g) {
271  getData(b, g, iRun);
272  });
273  }
274 
275 
276  iRun.put(dqmRunToken_, std::make_unique<DQMToken>());
277 }
278 
280 {
281  if (convertOnEndLumi) {
282  DQMStore * store = edm::Service<DQMStore>().operator->();
283  store->meBookerGetter([&](DQMStore::IBooker &b, DQMStore::IGetter &g) {
284  getData(b, g, iLumi);
285  });
286  }
287 
288  iLumi.put(dqmLumiToken_, std::make_unique<DQMToken>());
289 }
290 
291 
292 template <class T>
293 void
295 {
296  constexpr char MsgLoggerCat[] = "EDMtoMEConverter_getData";
297 
298  if (verbosity >= 0)
299  edm::LogInfo (MsgLoggerCat) << "\nRestoring MonitorElements.";
300 
301  for_each(tokens_, [&](const auto& tok) {
302  using Tokens_T = typename std::decay<decltype(tok)>::type;
303  using METype = typename Tokens_T::type;
304  using MEtoEDM_T = typename Tokens_T::Product;
305  edm::Handle<MEtoEDM_T> metoedm;
306  tok.getData(iGetFrom, metoedm);
307  if(!metoedm.isValid()) {
308  //edm::LogWarning(MsgLoggerCat)
309  // << "MEtoEDM<TH1F> doesn't exist in run";
310  return;
311  }
312 
313  std::vector<typename MEtoEDM_T::MEtoEDMObject> metoedmobject =
314  metoedm->getMEtoEdmObject();
315 
316  for (unsigned int i = 0; i < metoedmobject.size(); ++i) {
317  // get full path of monitor element
318  const std::string& pathname = metoedmobject[i].name;
319  if (verbosity > 0) std::cout << pathname << std::endl;
320 
322 
323  // deconstruct path from fullpath
324  StringList fulldir = StringOps::split(pathname,"/");
325  std::string name = *(fulldir.end() - 1);
326 
327  for (unsigned j = 0; j < fulldir.size() - 1; ++j) {
328  dir += fulldir[j];
329  if (j != fulldir.size() - 2) dir += "/";
330  }
331 
332  // define new monitor element
333  MonitorElement *me = AddMonitorElement<METype>::call(iBooker, iGetter, &metoedmobject[i].object, dir, name, iGetFrom);
334  maybeSetLumiFlag(me, iGetFrom);
335 
336  // attach taglist
337  for(const auto& tag: metoedmobject[i].tags) {
338  iBooker.tag(me, tag);
339  }
340  } // end loop thorugh metoedmobject
341  });
342 }
343 
size
Write out results.
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
MonitorElement * book1S(Args &&...args)
Definition: DQMStore.h:124
T getUntrackedParameter(std::string const &, T const &) const
int64_t getIntValue() const
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
void endLuminosityBlockProduce(edm::LuminosityBlock &, edm::EventSetup const &) override
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:160
bool getByToken(EDGetToken token, Handle< PROD > &result) const
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:307
EDMtoMEConverter(const edm::ParameterSet &)
TH1 * getTH1() const
MonitorElement * bookInt(Args &&...args)
Definition: DQMStore.h:106
MonitorElement * bookString(Args &&...args)
Definition: DQMStore.h:100
Definition: DQMStore.h:28
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
#define constexpr
~EDMtoMEConverter() override
void Fill(long long x)
void endRunProduce(edm::Run &run, edm::EventSetup const &setup) override
std::tuple< Tokens< TH1F >, Tokens< TH1S >, Tokens< TH1D >, Tokens< TH2F >, Tokens< TH2S >, Tokens< TH2D >, Tokens< TH3F >, Tokens< TProfile >, Tokens< TProfile2D >, Tokens< double >, Tokens< int >, Tokens< long long >, Tokens< TString > > tokens_
void setLumiFlag()
this ME is meant to be stored for each luminosity section
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:166
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:287
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void put(std::unique_ptr< PROD > product)
Put a new product.
edm::EDPutTokenT< DQMToken > dqmRunToken_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
void tag(MonitorElement *, unsigned int)
Definition: DQMStore.cc:291
MonitorElement * book2S(Args &&...args)
Definition: DQMStore.h:142
bool isValid() const
Definition: HandleBase.h:74
edm::EDPutTokenT< DQMToken > dqmLumiToken_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
void set(const edm::InputTag &runInputTag, const edm::InputTag &lumiInputTag, edm::ConsumesCollector &iC)
double b
Definition: hdecay.h:120
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:114
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:349
MonitorElement * book2DD(Args &&...args)
Definition: DQMStore.h:148
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:112
dbl *** dir
Definition: mlp_gen.cc:35
void getData(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, T &iGetFrom)
void getData(const edm::Run &iRun, edm::Handle< Product > &handle) const
MonitorElement * book3D(Args &&...args)
Definition: DQMStore.h:154
long double T
MonitorElement * book1DD(Args &&...args)
Definition: DQMStore.h:130
double split
Definition: MVATrainer.cc:139
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:43
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run