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