test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MEtoEDMFormat.h
Go to the documentation of this file.
1 #ifndef MEtoEDMFormat_h
2 #define MEtoEDMFormat_h
3 
12 #include <TObject.h>
13 #include <TH1F.h>
14 #include <TH1S.h>
15 #include <TH1D.h>
16 #include <TH2F.h>
17 #include <TH2S.h>
18 #include <TH2D.h>
19 #include <TH3F.h>
20 #include <TProfile.h>
21 #include <TProfile2D.h>
22 #include <TObjString.h>
23 #include <TString.h>
24 #include <THashList.h>
25 #include <TList.h>
26 
27 #include <iostream>
28 #include <string>
29 #include <vector>
30 #include <memory>
31 #include <map>
32 #include <stdint.h>
33 
34 #define METOEDMFORMAT_DEBUG 0
35 
36 namespace {
37  //utility function to check the consistency of the axis labels
38  //taken from TH1::CheckBinLabels
39  bool CheckBinLabels(const TAxis* a1, const TAxis * a2)
40  {
41  // check that axis have same labels
42  THashList *l1 = (const_cast<TAxis*>(a1))->GetLabels();
43  THashList *l2 = (const_cast<TAxis*>(a2))->GetLabels();
44 
45  if (!l1 && !l2 )
46  return true;
47  if (!l1 || !l2 ) {
48  return false;
49  }
50  // check now labels sizes are the same
51  if (l1->GetSize() != l2->GetSize() ) {
52  return false;
53  }
54  for (int i = 1; i <= a1->GetNbins(); ++i) {
55  TString label1 = a1->GetBinLabel(i);
56  TString label2 = a2->GetBinLabel(i);
57  if (label1 != label2) {
58  return false;
59  }
60  }
61  return true;
62  }
63 }
64 
65 template <class T>
66 class MEtoEDM
67 {
68  public:
69  MEtoEDM() {}
70  explicit MEtoEDM(size_t reservedSize) {
71  MEtoEdmObject.reserve(reservedSize);
72  }
73  virtual ~MEtoEDM() {}
74 
75  typedef std::vector<uint32_t> TagList;
76 
78  {
82  };
83 
84  typedef std::vector<MEtoEDMObject> MEtoEdmObjectVector;
85 
87  const TagList &tags,
88  const T &object)
89  {
91  MEtoEdmObject.push_back(temp);
92  MEtoEdmObject.back().name = name;
93  MEtoEdmObject.back().tags = tags;
94  MEtoEdmObject.back().object = object;
95  }
96 
98  { return MEtoEdmObject; }
99 
100  bool mergeProduct(const MEtoEDM<T> &newMEtoEDM) {
101  const MEtoEdmObjectVector &newMEtoEDMObject = newMEtoEDM.getMEtoEdmObject();
102  const size_t nObjects = newMEtoEDMObject.size();
103  // NOTE: we remember the present size since we will only add content
104  // from newMEtoEDMObject after this point
105  const size_t nOldObjects = MEtoEdmObject.size();
106 
107  // if the old and new are not the same size, we want to report a problem
108  if (nObjects != nOldObjects) {
109  std::cout << "WARNING MEtoEDM::mergeProducts(): the lists of histograms to be merged have different sizes: new=" << nObjects << ", old=" << nOldObjects << std::endl;
110  }
111 
112  for (unsigned int i = 0; i < nObjects; ++i) {
113  unsigned int j = 0;
114  // see if the name is already in the old container up to the point where
115  // we may have added new entries in the container
116  const std::string& name = newMEtoEDMObject[i].name;
117  if (i < nOldObjects && (MEtoEdmObject[i].name == name)) {
118  j = i;
119  } else {
120  j = 0;
121  while (j < nOldObjects && (MEtoEdmObject[j].name != name) ) ++j;
122  }
123  if (j >= nOldObjects) {
124  // this value is only in the new container, not the old one
125 #if METOEDMFORMAT_DEBUG
126  std::cout << "WARNING MEtoEDM::mergeProducts(): adding new histogram '" << name << "'" << std::endl;
127 #endif
128  MEtoEdmObject.push_back(newMEtoEDMObject[i]);
129  } else if (MEtoEdmObject[j].object.CanExtendAllAxes() && newMEtoEDMObject[i].object.CanExtendAllAxes()) {
130  TList list;
131  list.Add((TObject*)&newMEtoEDMObject[i].object);
132  if (MEtoEdmObject[j].object.Merge(&list) == -1) {
133  std::cout << "ERROR MEtoEDM::mergeProducts(): merge failed for '" << name << "'" << std::endl;
134  }
135  } else {
136  // this value is also in the new container: add the two
137  if (MEtoEdmObject[j].object.GetNbinsX() == newMEtoEDMObject[i].object.GetNbinsX() &&
138  MEtoEdmObject[j].object.GetXaxis()->GetXmin() == newMEtoEDMObject[i].object.GetXaxis()->GetXmin() &&
139  MEtoEdmObject[j].object.GetXaxis()->GetXmax() == newMEtoEDMObject[i].object.GetXaxis()->GetXmax() &&
140  MEtoEdmObject[j].object.GetNbinsY() == newMEtoEDMObject[i].object.GetNbinsY() &&
141  MEtoEdmObject[j].object.GetYaxis()->GetXmin() == newMEtoEDMObject[i].object.GetYaxis()->GetXmin() &&
142  MEtoEdmObject[j].object.GetYaxis()->GetXmax() == newMEtoEDMObject[i].object.GetYaxis()->GetXmax() &&
143  MEtoEdmObject[j].object.GetNbinsZ() == newMEtoEDMObject[i].object.GetNbinsZ() &&
144  MEtoEdmObject[j].object.GetZaxis()->GetXmin() == newMEtoEDMObject[i].object.GetZaxis()->GetXmin() &&
145  MEtoEdmObject[j].object.GetZaxis()->GetXmax() == newMEtoEDMObject[i].object.GetZaxis()->GetXmax() &&
146  CheckBinLabels((TAxis*)MEtoEdmObject[j].object.GetXaxis(),(TAxis*)newMEtoEDMObject[i].object.GetXaxis()) &&
147  CheckBinLabels((TAxis*)MEtoEdmObject[j].object.GetYaxis(),(TAxis*)newMEtoEDMObject[i].object.GetYaxis()) &&
148  CheckBinLabels((TAxis*)MEtoEdmObject[j].object.GetZaxis(),(TAxis*)newMEtoEDMObject[i].object.GetZaxis()) ) {
149  MEtoEdmObject[j].object.Add(&newMEtoEDMObject[i].object);
150  } else {
151  std::cout << "ERROR MEtoEDM::mergeProducts(): found histograms with different axis limits or different labels, '" << name << "' not merged" << std::endl;
152 #if METOEDMFORMAT_DEBUG
153  std::cout << MEtoEdmObject[j].name << " " << newMEtoEDMObject[i].name << std::endl;
154  std::cout << MEtoEdmObject[j].object.GetNbinsX() << " " << newMEtoEDMObject[i].object.GetNbinsX() << std::endl;
155  std::cout << MEtoEdmObject[j].object.GetXaxis()->GetXmin() << " " << newMEtoEDMObject[i].object.GetXaxis()->GetXmin() << std::endl;
156  std::cout << MEtoEdmObject[j].object.GetXaxis()->GetXmax() << " " << newMEtoEDMObject[i].object.GetXaxis()->GetXmax() << std::endl;
157  std::cout << MEtoEdmObject[j].object.GetNbinsY() << " " << newMEtoEDMObject[i].object.GetNbinsY() << std::endl;
158  std::cout << MEtoEdmObject[j].object.GetYaxis()->GetXmin() << " " << newMEtoEDMObject[i].object.GetYaxis()->GetXmin() << std::endl;
159  std::cout << MEtoEdmObject[j].object.GetYaxis()->GetXmax() << " " << newMEtoEDMObject[i].object.GetYaxis()->GetXmax() << std::endl;
160  std::cout << MEtoEdmObject[j].object.GetNbinsZ() << " " << newMEtoEDMObject[i].object.GetNbinsZ() << std::endl;
161  std::cout << MEtoEdmObject[j].object.GetZaxis()->GetXmin() << " " << newMEtoEDMObject[i].object.GetZaxis()->GetXmin() << std::endl;
162  std::cout << MEtoEdmObject[j].object.GetZaxis()->GetXmax() << " " << newMEtoEDMObject[i].object.GetZaxis()->GetXmax() << std::endl;
163 #endif
164  }
165  }
166  }
167  return true;
168  }
169 
170  void swap(MEtoEDM<T>& iOther) {
171  MEtoEdmObject.swap(iOther.MEtoEdmObject);
172  }
173  private:
174 
176 
177 }; // end class declaration
178 
179 template <>
180 inline bool
182 {
183  const MEtoEdmObjectVector &newMEtoEDMObject = newMEtoEDM.getMEtoEdmObject();
184  const size_t nObjects = newMEtoEDMObject.size();
185  // NOTE: we remember the present size since we will only add content
186  // from newMEtoEDMObject after this point
187  const size_t nOldObjects = MEtoEdmObject.size();
188 
189  // if the old and new are not the same size, we want to report a problem
190  if (nObjects != nOldObjects) {
191  std::cout << "WARNING MEtoEDM::mergeProducts(): the lists of histograms to be merged have different sizes: new=" << nObjects << ", old=" << nOldObjects << std::endl;
192  }
193 
194  for (unsigned int i = 0; i < nObjects; ++i) {
195  unsigned int j = 0;
196  // see if the name is already in the old container up to the point where
197  // we may have added new entries in the container
198  const std::string& name = newMEtoEDMObject[i].name;
199  if (i < nOldObjects && (MEtoEdmObject[i].name == name)) {
200  j = i;
201  } else {
202  j = 0;
203  while (j < nOldObjects && (MEtoEdmObject[j].name != name) ) ++j;
204  }
205  if (j >= nOldObjects) {
206  // this value is only in the new container, not the old one
207 #if METOEDMFORMAT_DEBUG
208  std::cout << "WARNING MEtoEDM::mergeProducts(): adding new histogram '" << name << "'" << std::endl;
209 #endif
210  MEtoEdmObject.push_back(newMEtoEDMObject[i]);
211  }
212  }
213  return true;
214 }
215 
216 template <>
217 inline bool
218 MEtoEDM<int>::mergeProduct(const MEtoEDM<int> &newMEtoEDM)
219 {
220  const MEtoEdmObjectVector &newMEtoEDMObject = newMEtoEDM.getMEtoEdmObject();
221  const size_t nObjects = newMEtoEDMObject.size();
222  // NOTE: we remember the present size since we will only add content
223  // from newMEtoEDMObject after this point
224  const size_t nOldObjects = MEtoEdmObject.size();
225 
226  // if the old and new are not the same size, we want to report a problem
227  if (nObjects != nOldObjects) {
228  std::cout << "WARNING MEtoEDM::mergeProducts(): the lists of histograms to be merged have different sizes: new=" << nObjects << ", old=" << nOldObjects << std::endl;
229  }
230 
231  for (unsigned int i = 0; i < nObjects; ++i) {
232  unsigned int j = 0;
233  // see if the name is already in the old container up to the point where
234  // we may have added new entries in the container
235  const std::string& name = newMEtoEDMObject[i].name;
236  if (i < nOldObjects && (MEtoEdmObject[i].name == name)) {
237  j = i;
238  } else {
239  j = 0;
240  while (j < nOldObjects && (MEtoEdmObject[j].name != name) ) ++j;
241  }
242  if (j >= nOldObjects) {
243  // this value is only in the new container, not the old one
244 #if METOEDMFORMAT_DEBUG
245  std::cout << "WARNING MEtoEDM::mergeProducts(): adding new histogram '" << name << "'" << std::endl;
246 #endif
247  MEtoEdmObject.push_back(newMEtoEDMObject[i]);
248  } else {
249  // this value is also in the new container: add the two
250  if ( MEtoEdmObject[j].name.find("EventInfo/processedEvents") != std::string::npos ) {
251  MEtoEdmObject[j].object += (newMEtoEDMObject[i].object);
252  }
253  if ( MEtoEdmObject[j].name.find("EventInfo/iEvent") != std::string::npos ||
254  MEtoEdmObject[j].name.find("EventInfo/iLumiSection") != std::string::npos) {
255  if (MEtoEdmObject[j].object < newMEtoEDMObject[i].object) {
256  MEtoEdmObject[j].object = (newMEtoEDMObject[i].object);
257  }
258  }
259  }
260  }
261  return true;
262 }
263 
264 template <>
265 inline bool
267 {
268  const MEtoEdmObjectVector &newMEtoEDMObject = newMEtoEDM.getMEtoEdmObject();
269  const size_t nObjects = newMEtoEDMObject.size();
270  // NOTE: we remember the present size since we will only add content
271  // from newMEtoEDMObject after this point
272  const size_t nOldObjects = MEtoEdmObject.size();
273 
274  // if the old and new are not the same size, we want to report a problem
275  if (nObjects != nOldObjects) {
276  std::cout << "WARNING MEtoEDM::mergeProducts(): the lists of histograms to be merged have different sizes: new=" << nObjects << ", old=" << nOldObjects << std::endl;
277  }
278 
279  for (unsigned int i = 0; i < nObjects; ++i) {
280  unsigned int j = 0;
281  // see if the name is already in the old container up to the point where
282  // we may have added new entries in the container
283  const std::string& name = newMEtoEDMObject[i].name;
284  if (i < nOldObjects && (MEtoEdmObject[i].name == name)) {
285  j = i;
286  } else {
287  j = 0;
288  while (j < nOldObjects && (MEtoEdmObject[j].name != name) ) ++j;
289  }
290  if (j >= nOldObjects) {
291  // this value is only in the new container, not the old one
292 #if METOEDMFORMAT_DEBUG
293  std::cout << "WARNING MEtoEDM::mergeProducts(): adding new histogram '" << name << "'" << std::endl;
294 #endif
295  MEtoEdmObject.push_back(newMEtoEDMObject[i]);
296  } else {
297  // this value is also in the new container: add the two
298  if ( MEtoEdmObject[j].name.find("EventInfo/processedEvents") != std::string::npos ) {
299  MEtoEdmObject[j].object += (newMEtoEDMObject[i].object);
300  }
301  if ( MEtoEdmObject[j].name.find("EventInfo/iEvent") != std::string::npos ||
302  MEtoEdmObject[j].name.find("EventInfo/iLumiSection") != std::string::npos) {
303  if (MEtoEdmObject[j].object < newMEtoEDMObject[i].object) {
304  MEtoEdmObject[j].object = (newMEtoEDMObject[i].object);
305  }
306  }
307  }
308  }
309  return true;
310 }
311 
312 template <>
313 inline bool
315 {
316  const MEtoEdmObjectVector &newMEtoEDMObject = newMEtoEDM.getMEtoEdmObject();
317  const size_t nObjects = newMEtoEDMObject.size();
318  // NOTE: we remember the present size since we will only add content
319  // from newMEtoEDMObject after this point
320  const size_t nOldObjects = MEtoEdmObject.size();
321 
322  // if the old and new are not the same size, we want to report a problem
323  if (nObjects != nOldObjects) {
324  std::cout << "WARNING MEtoEDM::mergeProducts(): the lists of histograms to be merged have different sizes: new=" << nObjects << ", old=" << nOldObjects << std::endl;
325  }
326 
327  for (unsigned int i = 0; i < nObjects; ++i) {
328  unsigned int j = 0;
329  // see if the name is already in the old container up to the point where
330  // we may have added new entries in the container
331  const std::string& name = newMEtoEDMObject[i].name;
332  if (i < nOldObjects && (MEtoEdmObject[i].name == name)) {
333  j = i;
334  } else {
335  j = 0;
336  while (j < nOldObjects && (MEtoEdmObject[j].name != name) ) ++j;
337  }
338  if (j >= nOldObjects) {
339  // this value is only in the new container, not the old one
340 #if METOEDMFORMAT_DEBUG
341  std::cout << "WARNING MEtoEDM::mergeProducts(): adding new histogram '" << name << "'" << std::endl;
342 #endif
343  MEtoEdmObject.push_back(newMEtoEDMObject[i]);
344  }
345  }
346  return true;
347 }
348 
349 #endif
int i
Definition: DBlmapReader.cc:9
void swap(MEtoEDM< T > &iOther)
virtual ~MEtoEDM()
Definition: MEtoEDMFormat.h:73
MEtoEDM(size_t reservedSize)
Definition: MEtoEDMFormat.h:70
bool mergeProduct(const MEtoEDM< T > &newMEtoEDM)
int j
Definition: DBlmapReader.cc:9
tuple tags
Definition: o2o.py:248
const MEtoEdmObjectVector & getMEtoEdmObject() const
Definition: MEtoEDMFormat.h:97
tuple cout
Definition: gather_cfg.py:145
std::vector< MEtoEDMObject > MEtoEdmObjectVector
Definition: MEtoEDMFormat.h:84
std::vector< uint32_t > TagList
Definition: MEtoEDMFormat.h:75
long double T
void putMEtoEdmObject(const std::string &name, const TagList &tags, const T &object)
Definition: MEtoEDMFormat.h:86
MEtoEdmObjectVector MEtoEdmObject
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