CMS 3D CMS Logo

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