CMS 3D CMS Logo

LHERunInfoProduct.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iterator>
3 #include <iostream>
4 #include <iomanip>
5 #include <sstream>
6 #include <string>
7 #include <cmath>
8 #include <map>
9 #include <set>
10 
12 
15 
17  if (mode != other.mode)
18  return false;
19 
20  switch (mode) {
21  case kFooter:
22  case kDone:
23  return true;
24 
25  case kHeader:
26  return header == other.header;
27 
28  case kBody:
29  return header == other.header && iter == other.iter;
30 
31  case kInit:
32  return line == other.line;
33  }
34 
35  return false;
36 }
37 
39  tmp.clear();
40 
41  do {
42  switch (mode) {
43  case kHeader:
44  if (header == runInfo->headers_end()) {
45  if (line++ == 1)
46  tmp = "</header>\n";
47  else {
48  mode = kInit;
49  tmp = "<init>\n";
50  line = 0;
51  }
52  break;
53  } else if (!line) {
54  line++;
55  tmp = "<header>\n";
56  break;
57  } else {
58  mode = kBody;
59  const std::string &tag = header->tag();
60  tmp = tag.empty() ? "<!--" : (tag == "<>") ? "" : ("<" + tag + ">");
61  iter = header->begin();
62  continue;
63  }
64 
65  case kBody:
66  if (iter == header->end()) {
67  mode = kHeader;
68  const std::string &tag = header->tag();
69  tmp += tag.empty() ? "-->" : (tag == "<>") ? "" : ("</" + tag + ">");
70  tmp += "\n";
71  header++;
72  } else {
73  tmp += *iter++;
74  if (iter == header->end() &&
75  (tmp.empty() || (tmp[tmp.length() - 1] != '\r' && tmp[tmp.length() - 1] != '\n')))
76  continue;
77  }
78  break;
79 
80  case kInit: {
81  const lhef::HEPRUP &heprup = runInfo->heprup();
82  if (!line++) {
83  std::ostringstream ss;
84  ss << std::setprecision(7) << std::scientific << std::uppercase << " " << heprup.IDBMUP.first << " "
85  << heprup.IDBMUP.second << " " << heprup.EBMUP.first << " " << heprup.EBMUP.second << " "
86  << heprup.PDFGUP.first << " " << heprup.PDFGUP.second << " " << heprup.PDFSUP.first << " "
87  << heprup.PDFSUP.second << " " << heprup.IDWTUP << " " << heprup.NPRUP << std::endl;
88  tmp = ss.str();
89  break;
90  }
91  if (line >= (unsigned int)heprup.NPRUP + runInfo->comments_size() + 2) {
92  tmp = "</init>\n";
93  mode = kFooter;
94  break;
95  } else if (line >= (unsigned int)heprup.NPRUP + 2) {
96  tmp = *(runInfo->comments_begin() + (line - (unsigned int)heprup.NPRUP - 2));
97  break;
98  }
99 
100  std::ostringstream ss;
101  ss << std::setprecision(7) << std::scientific << std::uppercase << "\t" << heprup.XSECUP[line - 2] << "\t"
102  << heprup.XERRUP[line - 2] << "\t" << heprup.XMAXUP[line - 2] << "\t" << heprup.LPRUP[line - 2] << std::endl;
103  tmp = ss.str();
104  } break;
105 
106  case kFooter:
107  mode = kDone;
108 
109  default:
110  /* ... */;
111  }
112  } while (false);
113 }
114 
117 
118  result.runInfo = this;
119  result.header = headers_begin();
121  result.line = 0;
122  result.tmp = "<LesHouchesEvents version=\"1.0\">\n";
123 
124  return result;
125 }
126 
129 
130  result.runInfo = this;
132  result.line = 0;
133  result.tmp = "<init>\n";
134 
135  return result;
136 }
137 
139  static const std::string theEnd("</LesHouchesEvents>\n");
140 
141  return theEnd;
142 }
143 
144 namespace {
145  struct XSec {
146  inline XSec() : xsec(0.0), err(0.0), max(0.0) {}
147 
148  double xsec;
149  double err;
150  double max;
151  };
152 
153  struct HeaderLess {
154  bool operator()(const LHERunInfoProduct::Header &a, const LHERunInfoProduct::Header &b) const;
155  };
156 } // namespace
157 
158 bool HeaderLess::operator()(const LHERunInfoProduct::Header &a, const LHERunInfoProduct::Header &b) const {
159  if (a == b)
160  return false;
161  if (a.tag() < b.tag())
162  return true;
163  if (a.tag() > b.tag())
164  return false;
165 
168 
169  for (; iter1 != a.end() && iter2 != b.end(); ++iter1, ++iter2) {
170  if (*iter1 < *iter2)
171  return true;
172  else if (*iter1 != *iter2)
173  return false;
174  }
175 
176  return iter2 != b.end();
177 }
178 
179 static std::vector<std::string> checklist{"iseed", "Random", ".log", ".dat", ".lhe"};
180 static std::vector<std::string> tag_comparison_checklist{"", "MGRunCard", "mgruncard"};
181 
182 bool LHERunInfoProduct::find_if_checklist(const std::string x, std::vector<std::string> checklist) {
183  return checklist.end() != std::find_if(checklist.begin(), checklist.end(), [&](const std::string &y) {
184  return x.find(y) != std::string::npos;
185  });
186 }
187 
189  return !(tag.empty() || tag.find("Alpgen") == 0 || tag == "MGGridCard" || tag == "MGRunCard" || tag == "mgruncard" ||
190  tag == "MadSpin" || tag == "madspin");
191 }
192 
194  if (heprup_.IDBMUP != other.heprup_.IDBMUP || heprup_.EBMUP != other.heprup_.EBMUP ||
195  heprup_.PDFGUP != other.heprup_.PDFGUP || heprup_.PDFSUP != other.heprup_.PDFSUP ||
196  heprup_.IDWTUP != other.heprup_.IDWTUP) {
197  return false;
198  }
199 
200  bool compatibleHeaders = (headers_ == other.headers_);
201 
202  // try to merge not equal but compatible headers (i.e. different iseed)
203  while (!compatibleHeaders) {
204  // okay, something is not the same.
205  // Let's try to merge, but don't duplicate identical headers
206  // and test the rest against a whitelist
207 
208  std::set<Header, HeaderLess> headers;
209  std::copy(headers_begin(), headers_end(), std::inserter(headers, headers.begin()));
210 
211  // make a list of headers contained in the second file
212  std::vector<std::vector<std::string> > runcard_v2;
213  std::vector<std::string> runcard_v2_header;
214  for (auto header2 : headers_) {
215  // fill a vector with the relevant header tags that can be not equal but sill compatible
216  if (find_if_checklist(header2.tag(), tag_comparison_checklist)) {
217  runcard_v2.push_back(header2.lines());
218  runcard_v2_header.push_back(header2.tag());
219  }
220  }
221 
222  // loop over the headers of the original file
223  bool failed = false;
224  for (std::vector<LHERunInfoProduct::Header>::const_iterator header = other.headers_begin();
225  header != other.headers_end();
226  ++header) {
227  if (headers.count(*header)) {
228  continue;
229  }
230 
232  bool header_compatible = false;
233  for (unsigned int iter_runcard = 0; iter_runcard < runcard_v2.size(); iter_runcard++) {
234  std::vector<std::string> runcard_v1 = header->lines();
235  runcard_v1.erase(std::remove_if(runcard_v1.begin(),
236  runcard_v1.end(),
237  [&](const std::string &x) { return find_if_checklist(x, checklist); }),
238  runcard_v1.end());
239  runcard_v2[iter_runcard].erase(
240  std::remove_if(runcard_v2[iter_runcard].begin(),
241  runcard_v2[iter_runcard].end(),
242  [&](const std::string &x) { return find_if_checklist(x, checklist); }),
243  runcard_v2[iter_runcard].end());
244 
245  if (std::equal(runcard_v1.begin(), runcard_v1.end(), runcard_v2[iter_runcard].begin())) {
246  header_compatible = true;
247  break;
248  }
249  }
250  if (header_compatible)
251  continue;
252  }
253 
254  if (isTagComparedInMerge(header->tag())) {
255  failed = true;
256  } else {
257  addHeader(*header);
258  headers.insert(*header);
259  }
260  }
261 
262  if (failed) {
263  break;
264  }
265 
266  compatibleHeaders = true;
267  }
268 
269  // still not compatible after fixups
270  if (!compatibleHeaders) {
271  return false;
272  }
273 
274  // it is exactly the same, so merge
275  return true;
276 }
277 
279  heprup_.swap(other.heprup_);
280  headers_.swap(other.headers_);
281  comments_.swap(other.comments_);
282 }
lhef::HEPRUP::XSECUP
std::vector< double > XSECUP
Definition: LesHouches.h:112
DDAxes::y
LHERunInfoProduct::headers_
std::vector< Header > headers_
Definition: LHERunInfoProduct.h:125
LHERunInfoProduct::Header::const_iterator
std::vector< std::string >::const_iterator const_iterator
Definition: LHERunInfoProduct.h:18
LHERunInfoProduct::Header
Definition: LHERunInfoProduct.h:16
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
LHERunInfoProduct::const_iterator::kFooter
Definition: LHERunInfoProduct.h:97
LHERunInfoProduct::const_iterator::header
headers_const_iterator header
Definition: LHERunInfoProduct.h:100
LHERunInfoProduct::const_iterator::kDone
Definition: LHERunInfoProduct.h:97
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
runEdmFileComparison.failed
failed
Definition: runEdmFileComparison.py:225
LHERunInfoProduct::heprup
const lhef::HEPRUP & heprup() const
Definition: LHERunInfoProduct.h:55
LHERunInfoProduct::const_iterator::next
void next()
Definition: LHERunInfoProduct.cc:38
LHERunInfoProduct::const_iterator::operator==
bool operator==(const const_iterator &other) const
Definition: LHERunInfoProduct.cc:16
LHERunInfoProduct::const_iterator::kHeader
Definition: LHERunInfoProduct.h:97
DDAxes::x
LHERunInfoProduct::headers_end
headers_const_iterator headers_end() const
Definition: LHERunInfoProduct.h:59
LHERunInfoProduct::const_iterator::kInit
Definition: LHERunInfoProduct.h:97
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
LHERunInfoProduct::addHeader
void addHeader(const Header &header)
Definition: LHERunInfoProduct.h:52
lhef::HEPRUP::swap
void swap(HEPRUP &other)
Definition: LesHouches.h:61
LHERunInfoProduct::init
const_iterator init() const
Definition: LHERunInfoProduct.cc:127
getRunAppsInfo.headers
headers
Definition: getRunAppsInfo.py:65
lhef::HEPRUP::EBMUP
std::pair< double, double > EBMUP
Definition: LesHouches.h:82
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
LHERunInfoProduct::headers_begin
headers_const_iterator headers_begin() const
Definition: LHERunInfoProduct.h:58
checklist
static std::vector< std::string > checklist
Definition: LHERunInfoProduct.cc:179
LHERunInfoProduct.h
LHERunInfoProduct
Definition: LHERunInfoProduct.h:13
LHERunInfoProduct::end
const_iterator end() const
Definition: LHERunInfoProduct.h:109
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
LHERunInfoProduct::const_iterator::kBody
Definition: LHERunInfoProduct.h:97
lhef::HEPRUP::LPRUP
std::vector< int > LPRUP
Definition: LesHouches.h:128
trackingPlots.other
other
Definition: trackingPlots.py:1465
b
double b
Definition: hdecay.h:118
LHERunInfoProduct::mergeProduct
bool mergeProduct(const LHERunInfoProduct &other)
Definition: LHERunInfoProduct.cc:193
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LHERunInfoProduct::const_iterator::line
unsigned int line
Definition: LHERunInfoProduct.h:103
lhef::HEPRUP::PDFGUP
std::pair< int, int > PDFGUP
Definition: LesHouches.h:88
a
double a
Definition: hdecay.h:119
LHERunInfoProduct::swap
void swap(LHERunInfoProduct &other)
Definition: LHERunInfoProduct.cc:278
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
runTheMatrix.err
err
Definition: runTheMatrix.py:288
lhef::HEPRUP::NPRUP
int NPRUP
Definition: LesHouches.h:107
createfilelist.int
int
Definition: createfilelist.py:10
LHERunInfoProduct::begin
const_iterator begin() const
Definition: LHERunInfoProduct.cc:115
lhef::HEPRUP
Definition: LesHouches.h:22
lhef::HEPRUP::IDWTUP
int IDWTUP
Definition: LesHouches.h:101
LHERunInfoProduct::isTagComparedInMerge
static bool isTagComparedInMerge(const std::string &tag)
Definition: LHERunInfoProduct.cc:188
LesHouches.h
lhef::HEPRUP::XERRUP
std::vector< double > XERRUP
Definition: LesHouches.h:118
LHERunInfoProduct::const_iterator
Definition: LHERunInfoProduct.h:65
LHERunInfoProduct::const_iterator::mode
Mode mode
Definition: LHERunInfoProduct.h:102
lhef::HEPRUP::PDFSUP
std::pair< int, int > PDFSUP
Definition: LesHouches.h:94
LHERunInfoProduct::comments_
std::vector< std::string > comments_
Definition: LHERunInfoProduct.h:126
LHERunInfoProduct::const_iterator::iter
Header::const_iterator iter
Definition: LHERunInfoProduct.h:101
Exception.h
tag_comparison_checklist
static std::vector< std::string > tag_comparison_checklist
Definition: LHERunInfoProduct.cc:180
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
mps_fire.result
result
Definition: mps_fire.py:303
lhef::HEPRUP::XMAXUP
std::vector< double > XMAXUP
Definition: LesHouches.h:123
LHERunInfoProduct::heprup_
lhef::HEPRUP heprup_
Definition: LHERunInfoProduct.h:124
mps_splice.line
line
Definition: mps_splice.py:76
cond::serialization::equal
bool equal(const T &first, const T &second)
Definition: Equal.h:32
LHERunInfoProduct::find_if_checklist
bool find_if_checklist(const std::string x, std::vector< std::string > checklist)
Definition: LHERunInfoProduct.cc:182
lhef::HEPRUP::IDBMUP
std::pair< int, int > IDBMUP
Definition: LesHouches.h:77
LHERunInfoProduct::endOfFile
static const std::string & endOfFile()
Definition: LHERunInfoProduct.cc:138