CMS 3D CMS Logo

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