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  for(int i=0; i<qResults.numberRows();++i){
192  int bunch;
193  bool beam1config,beam2config;
194  qResults.fillVariableFromRow("BUNCH" ,i,bunch);
195  qResults.fillVariableFromRow("BEAM1CONFIG",i,beam1config);
196  qResults.fillVariableFromRow("BEAM2CONFIG",i,beam2config);
197 
198  if(beam1config){bConfig.beam1.push_back(true);}
199  else {bConfig.beam1.push_back(false);}
200 
201  if(beam2config){bConfig.beam2.push_back(true);}
202  else {bConfig.beam2.push_back(false);}
203 
204  }
205  }
206  }
207 
208  return bConfig;
209 
210 }
211 
212 
213 //_____________________________________________________________________
214 vector<bool> L1TOMDSHelper::getBunchStructure(int lhcFillNumber,int &error){
215 
216  vector<bool> BunchStructure;
217  error = NO_ERROR;
218 
219  // Fields to retrive in the query
220  string rtlSchema = "CMS_RUNTIME_LOGGER";
221  string table = "FILL_INITLUMIPERBUNCH";
222  string atribute1 = "LHCFILL";
223 
224  // Setting the strings we want to recover from OMDS
225  vector<std::string> qStrings ;
226  qStrings.push_back("BUNCH");
227  qStrings.push_back("BEAM1CONFIG");
228  qStrings.push_back("BEAM2CONFIG");
229 
230  l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
231 
232  if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
233  else{
234 
235  if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
236  else{
237 
238  for(int i=0; i<qResults.numberRows();++i){
239  int bunch;
240  bool beam1config,beam2config;
241  qResults.fillVariableFromRow("BUNCH" ,i,bunch);
242  qResults.fillVariableFromRow("BEAM1CONFIG",i,beam1config);
243  qResults.fillVariableFromRow("BEAM2CONFIG",i,beam2config);
244 
245  if(beam1config && beam2config){BunchStructure.push_back(true);}
246  else {BunchStructure.push_back(false);}
247 
248  }
249  }
250  }
251 
252  return BunchStructure;
253 
254 }
255 
256 //_____________________________________________________________________
257 vector<float> L1TOMDSHelper::getInitBunchLumi(int lhcFillNumber,int &error){
258 
259  vector<float> InitBunchLumi;
260  error = NO_ERROR;
261 
262  // Fields to retrive in the query
263  string rtlSchema = "CMS_RUNTIME_LOGGER";
264  string table = "FILL_INITLUMIPERBUNCH";
265  string atribute1 = "LHCFILL";
266 
267  // Setting the strings we want to recover from OMDS
268  vector<std::string> qStrings ;
269  qStrings.push_back("BUNCH");
270  qStrings.push_back("INITBUNCHLUMI");
271 
272  l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
273 
274  if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
275  else{
276 
277  if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
278  else{
279 
280  for(int i=0; i<qResults.numberRows();++i){
281  int bunch;
282  float initbunchlumi;
283  qResults.fillVariableFromRow("BUNCH" ,i,bunch);
284  qResults.fillVariableFromRow("INITBUNCHLUMI",i,initbunchlumi);
285 
286  InitBunchLumi.push_back(initbunchlumi);
287  }
288  }
289  }
290 
291  return InitBunchLumi;
292 
293 }
294 
295 //_____________________________________________________________________
296 vector<double> L1TOMDSHelper::getRelativeBunchLumi(int lhcFillNumber,int &error){
297 
298  vector<double> RelativeBunchLumi;
299  error = NO_ERROR;
300 
301  // Fields to retrive in the query
302  string rtlSchema = "CMS_RUNTIME_LOGGER";
303  string table = "FILL_INITLUMIPERBUNCH";
304  string atribute1 = "LHCFILL";
305 
306  // Setting the strings we want to recover from OMDS
307  vector<std::string> qStrings ;
308  qStrings.push_back("BUNCH");
309  qStrings.push_back("INITBUNCHLUMI");
310 
311  l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
312 
313  if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
314  else{
315 
316  if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
317  else{
318 
319  //-> Get the inicial bunch luminosity add calculate the total luminosity of the fill
320  double InitTotalLumi = 0;
321  vector<float> InitBunchLumi;
322 
323  for(int i=0; i<qResults.numberRows();++i){
324  int bunch;
325  float initbunchlumi;
326  qResults.fillVariableFromRow("BUNCH" ,i,bunch);
327  qResults.fillVariableFromRow("INITBUNCHLUMI",i,initbunchlumi);
328 
329  InitTotalLumi += initbunchlumi;
330  InitBunchLumi.push_back(initbunchlumi);
331  }
332 
333  //-> We calculate the relative luminosity for each bunch
334  for(unsigned int i=0 ; i<InitBunchLumi.size() ; i++){
335  RelativeBunchLumi.push_back(InitBunchLumi[i]/InitTotalLumi);
336  }
337  }
338  }
339 
340  return RelativeBunchLumi;
341 
342 }
343 
344 //_____________________________________________________________________
346 
347  string out;
348 
349  switch(iObject){
350  case NO_ERROR: out = "NO_ERROR"; break;
351  case WARNING_DB_CONN_FAILED: out = "WARNING_DB_CONN_FAILED"; break;
352  case WARNING_DB_QUERY_FAILED: out = "WARNING_DB_QUERY_FAILED"; break;
353  case WARNING_DB_INCORRECT_NBUNCHES: out = "WARNING_DB_INCORRECT_NBUNCHES"; break;
354  default: out = "UNKNOWN"; break;
355  };
356 
357  return out;
358 
359 }
list table
Definition: asciidump.py:386
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
std::map< std::string, WbMTriggerXSecFit > getWbMAlgoXsecFits(int &error)
std::vector< bool > beam2
Definition: L1TOMDSHelper.h:34
std::string enumToStringError(int)
std::vector< bool > beam1
Definition: L1TOMDSHelper.h:33
std::vector< double > getRelativeBunchLumi(int lhcFillNumber, int &error)