00001 #include "DQM/L1TMonitor/interface/L1TOMDSHelper.h"
00002
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006
00007 using namespace std;
00008
00009
00010 L1TOMDSHelper::L1TOMDSHelper(){
00011
00012 m_omdsReader = 0;
00013
00014 }
00015
00016
00017 L1TOMDSHelper::~L1TOMDSHelper(){
00018
00019 delete m_omdsReader;
00020
00021 }
00022
00023
00024 bool L1TOMDSHelper::connect(string iOracleDB,string iPathCondDB,int &error){
00025
00026
00027 m_oracleDB = iOracleDB;
00028 m_pathCondDB = iPathCondDB;
00029 error = NO_ERROR;
00030
00031
00032 bool SessionExists = false;
00033 bool SessionOpen = false;
00034 bool ConnectionExists = false;
00035 bool ConnectionOpen = false;
00036 bool out = false;
00037
00038 m_omdsReader = new l1t::OMDSReader();
00039 m_omdsReader->connect(m_oracleDB,m_pathCondDB);
00040
00041
00042 if(m_omdsReader->dbSession()){
00043 SessionExists = true;
00044 if(m_omdsReader->dbSession()->isOpen()){SessionOpen = true;}
00045 }
00046
00047
00048 if(m_omdsReader->dbConnection()){
00049 ConnectionExists = true;
00050 if(m_omdsReader->dbSession()->isOpen()){ConnectionOpen = true;}
00051 }
00052
00053
00054 if (SessionExists && SessionOpen && ConnectionExists && ConnectionOpen){out = true;}
00055 else if(!SessionExists || !ConnectionExists) {error = WARNING_DB_CONN_FAILED;}
00056
00057 return out;
00058
00059 }
00060
00061
00062
00063 map<string,WbMTriggerXSecFit> L1TOMDSHelper::getWbMTriggerXsecFits(string iTable,int &error){
00064
00065 map<string,WbMTriggerXSecFit> out;
00066 const l1t::OMDSReader::QueryResults qresults;
00067 error = NO_ERROR;
00068
00069
00070 string qSchema = "CMS_WBM";
00071
00072
00073 vector<string> qStrings;
00074 qStrings.push_back("BIT");
00075 qStrings.push_back("NAME");
00076 qStrings.push_back("PM1");
00077 qStrings.push_back("P0");
00078 qStrings.push_back("P1");
00079 qStrings.push_back("P2");
00080
00081 l1t::OMDSReader::QueryResults paramResults = m_omdsReader->basicQuery(qStrings,qSchema,iTable,"",qresults);
00082
00083 if(paramResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00084 else{
00085
00086 for(int i=0; i<paramResults.numberRows();++i){
00087
00088 WbMTriggerXSecFit tFit;
00089 tFit.fitFunction = "[0]/x+[1]+[2]*x+[3]*x*x";
00090
00091 string tBitName;
00092
00093 paramResults.fillVariableFromRow("BIT" ,i,tFit.bitNumber);
00094 paramResults.fillVariableFromRow("NAME",i,tBitName);
00095 paramResults.fillVariableFromRow("PM1" ,i,tFit.pm1);
00096 paramResults.fillVariableFromRow("P0" ,i,tFit.p0);
00097 paramResults.fillVariableFromRow("P1" ,i,tFit.p1);
00098 paramResults.fillVariableFromRow("P2" ,i,tFit.p2);
00099
00100 tFit.bitName = tBitName;
00101
00102 out[tBitName] = tFit;
00103
00104 }
00105 }
00106
00107 return out;
00108
00109 }
00110
00111
00112 map<string,WbMTriggerXSecFit> L1TOMDSHelper::getWbMAlgoXsecFits(int &error){
00113 return getWbMTriggerXsecFits("LEVEL1_ALGO_CROSS_SECTION",error);
00114 }
00115
00116
00117 map<string,WbMTriggerXSecFit> L1TOMDSHelper::getWbMTechXsecFits(int &error){
00118 return getWbMTriggerXsecFits("LEVEL1_TECH_CROSS_SECTION",error);
00119 }
00120
00121
00122 int L1TOMDSHelper::getNumberCollidingBunches(int lhcFillNumber,int &error){
00123
00124 int nCollidingBunches = 0;
00125 error = NO_ERROR;
00126
00127
00128 string rtlSchema = "CMS_RUNTIME_LOGGER";
00129 string table = "FILL_INITLUMIPERBUNCH";
00130 string atribute1 = "LHCFILL";
00131
00132
00133 vector<std::string> qStrings ;
00134 qStrings.push_back("BUNCH");
00135 qStrings.push_back("BEAM1CONFIG");
00136 qStrings.push_back("BEAM2CONFIG");
00137
00138 l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00139
00140
00141 if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00142 else{
00143
00144 if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00145 else{
00146
00147
00148 for(int i=0; i<qResults.numberRows();++i){
00149 int bunch;
00150 bool beam1config,beam2config;
00151 qResults.fillVariableFromRow("BUNCH" ,i,bunch);
00152 qResults.fillVariableFromRow("BEAM1CONFIG" ,i,beam1config);
00153 qResults.fillVariableFromRow("BEAM2CONFIG" ,i,beam2config);
00154
00155 if(beam1config && beam2config){nCollidingBunches++;}
00156 }
00157 }
00158 }
00159
00160 return nCollidingBunches;
00161
00162 }
00163
00164
00165 BeamConfiguration L1TOMDSHelper::getBeamConfiguration(int lhcFillNumber,int &error){
00166
00167 BeamConfiguration bConfig;
00168 error = NO_ERROR;
00169
00170
00171 string rtlSchema = "CMS_RUNTIME_LOGGER";
00172 string table = "FILL_INITLUMIPERBUNCH";
00173 string atribute1 = "LHCFILL";
00174
00175
00176 vector<std::string> qStrings ;
00177 qStrings.push_back("BUNCH");
00178 qStrings.push_back("BEAM1CONFIG");
00179 qStrings.push_back("BEAM2CONFIG");
00180
00181 l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00182
00183 if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00184 else{
00185
00186 if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00187 else{
00188
00189 bConfig.m_valid = true;
00190
00191 int nCollidingBunches = 0;
00192
00193 for(int i=0; i<qResults.numberRows();++i){
00194 int bunch;
00195 bool beam1config,beam2config;
00196 qResults.fillVariableFromRow("BUNCH" ,i,bunch);
00197 qResults.fillVariableFromRow("BEAM1CONFIG",i,beam1config);
00198 qResults.fillVariableFromRow("BEAM2CONFIG",i,beam2config);
00199
00200 if(beam1config){bConfig.beam1.push_back(true);}
00201 else {bConfig.beam1.push_back(false);}
00202
00203 if(beam2config){bConfig.beam2.push_back(true);}
00204 else {bConfig.beam2.push_back(false);}
00205
00206 if(beam1config && beam2config){nCollidingBunches++;}
00207 }
00208
00209 bConfig.nCollidingBunches = nCollidingBunches;
00210
00211 }
00212 }
00213
00214 return bConfig;
00215
00216 }
00217
00218
00219
00220 vector<bool> L1TOMDSHelper::getBunchStructure(int lhcFillNumber,int &error){
00221
00222 vector<bool> BunchStructure;
00223 error = NO_ERROR;
00224
00225
00226 string rtlSchema = "CMS_RUNTIME_LOGGER";
00227 string table = "FILL_INITLUMIPERBUNCH";
00228 string atribute1 = "LHCFILL";
00229
00230
00231 vector<std::string> qStrings ;
00232 qStrings.push_back("BUNCH");
00233 qStrings.push_back("BEAM1CONFIG");
00234 qStrings.push_back("BEAM2CONFIG");
00235
00236 l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00237
00238 if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00239 else{
00240
00241 if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00242 else{
00243
00244 for(int i=0; i<qResults.numberRows();++i){
00245 int bunch;
00246 bool beam1config,beam2config;
00247 qResults.fillVariableFromRow("BUNCH" ,i,bunch);
00248 qResults.fillVariableFromRow("BEAM1CONFIG",i,beam1config);
00249 qResults.fillVariableFromRow("BEAM2CONFIG",i,beam2config);
00250
00251 if(beam1config && beam2config){BunchStructure.push_back(true);}
00252 else {BunchStructure.push_back(false);}
00253
00254 }
00255 }
00256 }
00257
00258 return BunchStructure;
00259
00260 }
00261
00262
00263 vector<float> L1TOMDSHelper::getInitBunchLumi(int lhcFillNumber,int &error){
00264
00265 vector<float> InitBunchLumi;
00266 error = NO_ERROR;
00267
00268
00269 string rtlSchema = "CMS_RUNTIME_LOGGER";
00270 string table = "FILL_INITLUMIPERBUNCH";
00271 string atribute1 = "LHCFILL";
00272
00273
00274 vector<std::string> qStrings ;
00275 qStrings.push_back("BUNCH");
00276 qStrings.push_back("INITBUNCHLUMI");
00277
00278 l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00279
00280 if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00281 else{
00282
00283 if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00284 else{
00285
00286 for(int i=0; i<qResults.numberRows();++i){
00287 int bunch;
00288 float initbunchlumi;
00289 qResults.fillVariableFromRow("BUNCH" ,i,bunch);
00290 qResults.fillVariableFromRow("INITBUNCHLUMI",i,initbunchlumi);
00291
00292 InitBunchLumi.push_back(initbunchlumi);
00293 }
00294 }
00295 }
00296
00297 return InitBunchLumi;
00298
00299 }
00300
00301
00302 vector<double> L1TOMDSHelper::getRelativeBunchLumi(int lhcFillNumber,int &error){
00303
00304 vector<double> RelativeBunchLumi;
00305 error = NO_ERROR;
00306
00307
00308 string rtlSchema = "CMS_RUNTIME_LOGGER";
00309 string table = "FILL_INITLUMIPERBUNCH";
00310 string atribute1 = "LHCFILL";
00311
00312
00313 vector<std::string> qStrings ;
00314 qStrings.push_back("BUNCH");
00315 qStrings.push_back("INITBUNCHLUMI");
00316
00317 l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00318
00319 if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00320 else{
00321
00322 if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00323 else{
00324
00325
00326 double InitTotalLumi = 0;
00327 vector<float> InitBunchLumi;
00328
00329 for(int i=0; i<qResults.numberRows();++i){
00330 int bunch;
00331 float initbunchlumi;
00332 qResults.fillVariableFromRow("BUNCH" ,i,bunch);
00333 qResults.fillVariableFromRow("INITBUNCHLUMI",i,initbunchlumi);
00334
00335 InitTotalLumi += initbunchlumi;
00336 InitBunchLumi.push_back(initbunchlumi);
00337 }
00338
00339
00340 for(unsigned int i=0 ; i<InitBunchLumi.size() ; i++){
00341 RelativeBunchLumi.push_back(InitBunchLumi[i]/InitTotalLumi);
00342 }
00343 }
00344 }
00345
00346 return RelativeBunchLumi;
00347
00348 }
00349
00350
00351 string L1TOMDSHelper::enumToStringError(int iObject){
00352
00353 string out;
00354
00355 switch(iObject){
00356 case NO_ERROR: out = "NO_ERROR"; break;
00357 case WARNING_DB_CONN_FAILED: out = "WARNING_DB_CONN_FAILED"; break;
00358 case WARNING_DB_QUERY_FAILED: out = "WARNING_DB_QUERY_FAILED"; break;
00359 case WARNING_DB_INCORRECT_NBUNCHES: out = "WARNING_DB_INCORRECT_NBUNCHES"; break;
00360 default: out = "UNKNOWN"; break;
00361 };
00362
00363 return out;
00364
00365 }