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