CMS 3D CMS Logo

L1TOMDSHelper.cc
Go to the documentation of this file.
2 
5 
6 using namespace std;
7 
8 //_____________________________________________________________________
9 L1TOMDSHelper::L1TOMDSHelper() { m_omdsReader = nullptr; }
10 
11 //_____________________________________________________________________
12 L1TOMDSHelper::~L1TOMDSHelper() { delete m_omdsReader; }
13 
14 //_____________________________________________________________________
15 bool L1TOMDSHelper::connect(string iOracleDB, string iPathCondDB, int &error) {
16  // Handeling inputs
17  m_oracleDB = iOracleDB;
18  m_pathCondDB = iPathCondDB;
19  error = NO_ERROR;
20 
21  // Initializing variables
22  bool SessionOpen = false;
23  bool out = false;
24 
25  m_omdsReader = new l1t::OMDSReader();
26  m_omdsReader->connect(m_oracleDB, m_pathCondDB);
27 
28  // Testing session
29  if (!m_omdsReader->dbSession().connectionString().empty()) {
30  SessionOpen = true;
31  }
32 
33  // Defining output and error message if needed
34  if (SessionOpen) {
35  out = true;
36  } else {
37  error = WARNING_DB_CONN_FAILED;
38  }
39 
40  return out;
41 }
42 
43 //_____________________________________________________________________
44 map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMTriggerXsecFits(string iTable, int &error) {
45  map<string, WbMTriggerXSecFit> out;
46  const l1t::OMDSReader::QueryResults qresults;
47  error = NO_ERROR;
48 
49  // Parameters
50  string qSchema = "CMS_WBM";
51 
52  // Fields to retrive in the query
53  vector<string> qStrings;
54  qStrings.push_back("BIT");
55  qStrings.push_back("NAME");
56  qStrings.push_back("PM1"); //Inverse
57  qStrings.push_back("P0"); //Constant
58  qStrings.push_back("P1"); //Linear
59  qStrings.push_back("P2"); //Quadratic
60 
61  l1t::OMDSReader::QueryResults paramResults = m_omdsReader->basicQuery(qStrings, qSchema, iTable, "", qresults);
62 
63  if (paramResults.queryFailed()) {
64  error = WARNING_DB_QUERY_FAILED;
65  } else {
66  for (int i = 0; i < paramResults.numberRows(); ++i) {
67  WbMTriggerXSecFit tFit;
68  tFit.fitFunction = "[0]/x+[1]+[2]*x+[3]*x*x"; // Fitting function hardcoded for now
69 
70  string tBitName;
71 
72  paramResults.fillVariableFromRow("BIT", i, tFit.bitNumber);
73  paramResults.fillVariableFromRow("NAME", i, tBitName);
74  paramResults.fillVariableFromRow("PM1", i, tFit.pm1);
75  paramResults.fillVariableFromRow("P0", i, tFit.p0);
76  paramResults.fillVariableFromRow("P1", i, tFit.p1);
77  paramResults.fillVariableFromRow("P2", i, tFit.p2);
78 
79  tFit.bitName = tBitName;
80 
81  out[tBitName] = tFit;
82  }
83  }
84 
85  return out;
86 }
87 
88 //_____________________________________________________________________
89 map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMAlgoXsecFits(int &error) {
90  return getWbMTriggerXsecFits("LEVEL1_ALGO_CROSS_SECTION", error);
91 }
92 
93 //_____________________________________________________________________
94 map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMTechXsecFits(int &error) {
95  return getWbMTriggerXsecFits("LEVEL1_TECH_CROSS_SECTION", error);
96 }
97 
98 //_____________________________________________________________________
99 int L1TOMDSHelper::getNumberCollidingBunches(int lhcFillNumber, int &error) {
100  int nCollidingBunches = 0;
101  error = NO_ERROR;
102 
103  // Parameters
104  string rtlSchema = "CMS_RUNTIME_LOGGER";
105  string table = "FILL_INITLUMIPERBUNCH";
106  string atribute1 = "LHCFILL";
107 
108  // Fields to retrive in the query
109  vector<std::string> qStrings;
110  qStrings.push_back("BUNCH");
111  qStrings.push_back("BEAM1CONFIG");
112  qStrings.push_back("BEAM2CONFIG");
113 
115  m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
116 
117  // Check query successful
118  if (qResults.queryFailed()) {
119  error = WARNING_DB_QUERY_FAILED;
120  } else {
121  if (qResults.numberRows() != 3564) {
122  error = WARNING_DB_INCORRECT_NBUNCHES;
123  } else {
124  // Now we count the number of bunches with both beam 1 and 2 configured
125  for (int i = 0; i < qResults.numberRows(); ++i) {
126  int bunch;
127  bool beam1config, beam2config;
128  qResults.fillVariableFromRow("BUNCH", i, bunch);
129  qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
130  qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
131 
132  if (beam1config && beam2config) {
133  nCollidingBunches++;
134  }
135  }
136  }
137  }
138 
139  return nCollidingBunches;
140 }
141 
142 //_____________________________________________________________________
144  BeamConfiguration bConfig;
145  error = NO_ERROR;
146 
147  // Fields to retrive in the query
148  string rtlSchema = "CMS_RUNTIME_LOGGER";
149  string table = "FILL_INITLUMIPERBUNCH";
150  string atribute1 = "LHCFILL";
151 
152  // Setting the strings we want to recover from OMDS
153  vector<std::string> qStrings;
154  qStrings.push_back("BUNCH");
155  qStrings.push_back("BEAM1CONFIG");
156  qStrings.push_back("BEAM2CONFIG");
157 
159  m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
160 
161  if (qResults.queryFailed()) {
162  error = WARNING_DB_QUERY_FAILED;
163  } else {
164  if (qResults.numberRows() != 3564) {
165  error = WARNING_DB_INCORRECT_NBUNCHES;
166  } else {
167  bConfig.m_valid = true;
168 
169  int nCollidingBunches = 0;
170 
171  for (int i = 0; i < qResults.numberRows(); ++i) {
172  int bunch;
173  bool beam1config, beam2config;
174  qResults.fillVariableFromRow("BUNCH", i, bunch);
175  qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
176  qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
177 
178  if (beam1config) {
179  bConfig.beam1.push_back(true);
180  } else {
181  bConfig.beam1.push_back(false);
182  }
183 
184  if (beam2config) {
185  bConfig.beam2.push_back(true);
186  } else {
187  bConfig.beam2.push_back(false);
188  }
189 
190  if (beam1config && beam2config) {
191  nCollidingBunches++;
192  }
193  }
194 
195  bConfig.nCollidingBunches = nCollidingBunches;
196  }
197  }
198 
199  return bConfig;
200 }
201 
202 //_____________________________________________________________________
203 vector<bool> L1TOMDSHelper::getBunchStructure(int lhcFillNumber, int &error) {
204  vector<bool> BunchStructure;
205  error = NO_ERROR;
206 
207  // Fields to retrive in the query
208  string rtlSchema = "CMS_RUNTIME_LOGGER";
209  string table = "FILL_INITLUMIPERBUNCH";
210  string atribute1 = "LHCFILL";
211 
212  // Setting the strings we want to recover from OMDS
213  vector<std::string> qStrings;
214  qStrings.push_back("BUNCH");
215  qStrings.push_back("BEAM1CONFIG");
216  qStrings.push_back("BEAM2CONFIG");
217 
219  m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
220 
221  if (qResults.queryFailed()) {
222  error = WARNING_DB_QUERY_FAILED;
223  } else {
224  if (qResults.numberRows() != 3564) {
225  error = WARNING_DB_INCORRECT_NBUNCHES;
226  } else {
227  for (int i = 0; i < qResults.numberRows(); ++i) {
228  int bunch;
229  bool beam1config, beam2config;
230  qResults.fillVariableFromRow("BUNCH", i, bunch);
231  qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
232  qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
233 
234  if (beam1config && beam2config) {
235  BunchStructure.push_back(true);
236  } else {
237  BunchStructure.push_back(false);
238  }
239  }
240  }
241  }
242 
243  return BunchStructure;
244 }
245 
246 //_____________________________________________________________________
247 vector<float> L1TOMDSHelper::getInitBunchLumi(int lhcFillNumber, int &error) {
248  vector<float> InitBunchLumi;
249  error = NO_ERROR;
250 
251  // Fields to retrive in the query
252  string rtlSchema = "CMS_RUNTIME_LOGGER";
253  string table = "FILL_INITLUMIPERBUNCH";
254  string atribute1 = "LHCFILL";
255 
256  // Setting the strings we want to recover from OMDS
257  vector<std::string> qStrings;
258  qStrings.push_back("BUNCH");
259  qStrings.push_back("INITBUNCHLUMI");
260 
262  m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
263 
264  if (qResults.queryFailed()) {
265  error = WARNING_DB_QUERY_FAILED;
266  } else {
267  if (qResults.numberRows() != 3564) {
268  error = WARNING_DB_INCORRECT_NBUNCHES;
269  } else {
270  for (int i = 0; i < qResults.numberRows(); ++i) {
271  int bunch;
272  float initbunchlumi;
273  qResults.fillVariableFromRow("BUNCH", i, bunch);
274  qResults.fillVariableFromRow("INITBUNCHLUMI", i, initbunchlumi);
275 
276  InitBunchLumi.push_back(initbunchlumi);
277  }
278  }
279  }
280 
281  return InitBunchLumi;
282 }
283 
284 //_____________________________________________________________________
285 vector<double> L1TOMDSHelper::getRelativeBunchLumi(int lhcFillNumber, int &error) {
286  vector<double> RelativeBunchLumi;
287  error = NO_ERROR;
288 
289  // Fields to retrive in the query
290  string rtlSchema = "CMS_RUNTIME_LOGGER";
291  string table = "FILL_INITLUMIPERBUNCH";
292  string atribute1 = "LHCFILL";
293 
294  // Setting the strings we want to recover from OMDS
295  vector<std::string> qStrings;
296  qStrings.push_back("BUNCH");
297  qStrings.push_back("INITBUNCHLUMI");
298 
300  m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
301 
302  if (qResults.queryFailed()) {
303  error = WARNING_DB_QUERY_FAILED;
304  } else {
305  if (qResults.numberRows() != 3564) {
306  error = WARNING_DB_INCORRECT_NBUNCHES;
307  } else {
308  //-> Get the inicial bunch luminosity add calculate the total luminosity of the fill
309  double InitTotalLumi = 0;
310  vector<float> InitBunchLumi;
311 
312  for (int i = 0; i < qResults.numberRows(); ++i) {
313  int bunch;
314  float initbunchlumi;
315  qResults.fillVariableFromRow("BUNCH", i, bunch);
316  qResults.fillVariableFromRow("INITBUNCHLUMI", i, initbunchlumi);
317 
318  InitTotalLumi += initbunchlumi;
319  InitBunchLumi.push_back(initbunchlumi);
320  }
321 
322  //-> We calculate the relative luminosity for each bunch
323  for (unsigned int i = 0; i < InitBunchLumi.size(); i++) {
324  RelativeBunchLumi.push_back(InitBunchLumi[i] / InitTotalLumi);
325  }
326  }
327  }
328 
329  return RelativeBunchLumi;
330 }
331 
332 //_____________________________________________________________________
333 string L1TOMDSHelper::enumToStringError(int iObject) {
334  string out;
335 
336  switch (iObject) {
337  case NO_ERROR:
338  out = "NO_ERROR";
339  break;
340  case WARNING_DB_CONN_FAILED:
341  out = "WARNING_DB_CONN_FAILED";
342  break;
343  case WARNING_DB_QUERY_FAILED:
344  out = "WARNING_DB_QUERY_FAILED";
345  break;
346  case WARNING_DB_INCORRECT_NBUNCHES:
347  out = "WARNING_DB_INCORRECT_NBUNCHES";
348  break;
349  default:
350  out = "UNKNOWN";
351  break;
352  };
353 
354  return out;
355 }
l1t::OMDSReader::QueryResults
Definition: OMDSReader.h:49
BeamConfiguration::m_valid
bool m_valid
Definition: L1TOMDSHelper.h:36
Handle.h
mps_fire.i
i
Definition: mps_fire.py:355
L1TOMDSHelper::L1TOMDSHelper
L1TOMDSHelper()
Definition: L1TOMDSHelper.cc:9
L1TOMDSHelper::getNumberCollidingBunches
int getNumberCollidingBunches(int lhcFillNumber, int &error)
Definition: L1TOMDSHelper.cc:99
l1t::OMDSReader
Definition: OMDSReader.h:42
WbMTriggerXSecFit::bitNumber
float bitNumber
Definition: L1TOMDSHelper.h:46
L1TOMDSHelper::getWbMAlgoXsecFits
std::map< std::string, WbMTriggerXSecFit > getWbMAlgoXsecFits(int &error)
Definition: L1TOMDSHelper.cc:89
WbMTriggerXSecFit::p0
float p0
Definition: L1TOMDSHelper.h:47
WbMTriggerXSecFit::p2
float p2
Definition: L1TOMDSHelper.h:47
relativeConstraints.error
error
Definition: relativeConstraints.py:53
l1t::OMDSReader::QueryResults::fillVariableFromRow
bool fillVariableFromRow(const std::string &columnName, int rowNumber, T &outputVariable) const
Definition: OMDSReader.h:279
Run.h
WbMTriggerXSecFit::fitFunction
TString fitFunction
Definition: L1TOMDSHelper.h:45
L1TOMDSHelper::getBunchStructure
std::vector< bool > getBunchStructure(int lhcFillNumber, int &error)
Definition: L1TOMDSHelper.cc:203
L1TOMDSHelper::getWbMTriggerXsecFits
std::map< std::string, WbMTriggerXSecFit > getWbMTriggerXsecFits(std::string iTable, int &error)
Definition: L1TOMDSHelper.cc:44
L1TOMDSHelper::enumToStringError
std::string enumToStringError(int)
Definition: L1TOMDSHelper.cc:333
L1TOMDSHelper::getBeamConfiguration
BeamConfiguration getBeamConfiguration(int lhcFillNumber, int &error)
Definition: L1TOMDSHelper.cc:143
WbMTriggerXSecFit::p1
float p1
Definition: L1TOMDSHelper.h:47
l1t::OMDSReader::QueryResults::numberRows
int numberRows() const
Definition: OMDSReader.h:60
BeamConfiguration::nCollidingBunches
int nCollidingBunches
Definition: L1TOMDSHelper.h:37
L1TOMDSHelper::getRelativeBunchLumi
std::vector< double > getRelativeBunchLumi(int lhcFillNumber, int &error)
Definition: L1TOMDSHelper.cc:285
L1TOMDSHelper::getInitBunchLumi
std::vector< float > getInitBunchLumi(int lhcFillNumber, int &error)
Definition: L1TOMDSHelper.cc:247
WbMTriggerXSecFit::bitName
TString bitName
Definition: L1TOMDSHelper.h:44
BeamConfiguration
Definition: L1TOMDSHelper.h:19
std
Definition: JetResolutionObject.h:76
L1TOMDSHelper::getWbMTechXsecFits
std::map< std::string, WbMTriggerXSecFit > getWbMTechXsecFits(int &error)
Definition: L1TOMDSHelper.cc:94
L1TOMDSHelper::connect
bool connect(std::string iOracleDB, std::string iPathCondDB, int &error)
Definition: L1TOMDSHelper.cc:15
L1TOMDSHelper::~L1TOMDSHelper
~L1TOMDSHelper()
Definition: L1TOMDSHelper.cc:12
WbMTriggerXSecFit::pm1
float pm1
Definition: L1TOMDSHelper.h:47
l1t::OMDSReader::QueryResults::queryFailed
bool queryFailed() const
Definition: OMDSReader.h:59
WbMTriggerXSecFit
Definition: L1TOMDSHelper.h:43
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
BeamConfiguration::beam2
std::vector< bool > beam2
Definition: L1TOMDSHelper.h:39
TableParser.table
table
Definition: TableParser.py:111
L1TOMDSHelper.h
BeamConfiguration::beam1
std::vector< bool > beam1
Definition: L1TOMDSHelper.h:38