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