CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DQM/L1TMonitor/src/L1TOMDSHelper.cc

Go to the documentation of this file.
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   // Handeling inputs
00027   m_oracleDB   = iOracleDB;
00028   m_pathCondDB = iPathCondDB;
00029   error        = NO_ERROR;
00030 
00031   // Initializing variables 
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   // Testing session
00042   if(m_omdsReader->dbSession()){
00043     SessionExists = true;
00044     if(m_omdsReader->dbSession()->isOpen()){SessionOpen = true;}
00045   }
00046   
00047   // Testing connection
00048   if(m_omdsReader->dbConnection()){
00049     ConnectionExists = true;
00050     if(m_omdsReader->dbSession()->isOpen()){ConnectionOpen = true;}
00051   }
00052 
00053   // Defining output and error message if needed
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   // Parameters
00070   string qSchema = "CMS_WBM";
00071 
00072   // Fields to retrive in the query
00073   vector<string> qStrings;
00074   qStrings.push_back("BIT");
00075   qStrings.push_back("NAME");
00076   qStrings.push_back("PM1");  //Inverse
00077   qStrings.push_back("P0");   //Constant
00078   qStrings.push_back("P1");   //Linear
00079   qStrings.push_back("P2");   //Quadratic
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"; // Fitting function hardcoded for now
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   // Parameters
00128   string rtlSchema = "CMS_RUNTIME_LOGGER";
00129   string table     = "FILL_INITLUMIPERBUNCH";
00130   string atribute1 = "LHCFILL";
00131 
00132   // Fields to retrive in the query
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   // Check query successful
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       // Now we count the number of bunches with both beam 1 and 2 configured
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   // Fields to retrive in the query
00171   string rtlSchema = "CMS_RUNTIME_LOGGER";
00172   string table     = "FILL_INITLUMIPERBUNCH";
00173   string atribute1 = "LHCFILL";
00174 
00175   // Setting the strings we want to recover from OMDS
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       for(int i=0; i<qResults.numberRows();++i){    
00192         int   bunch;
00193         bool  beam1config,beam2config;
00194         qResults.fillVariableFromRow("BUNCH"      ,i,bunch);
00195         qResults.fillVariableFromRow("BEAM1CONFIG",i,beam1config);
00196         qResults.fillVariableFromRow("BEAM2CONFIG",i,beam2config);
00197 
00198         if(beam1config){bConfig.beam1.push_back(true);}
00199         else           {bConfig.beam1.push_back(false);}
00200 
00201         if(beam2config){bConfig.beam2.push_back(true);}
00202         else           {bConfig.beam2.push_back(false);}
00203 
00204       }
00205     }
00206   }
00207 
00208   return bConfig;
00209 
00210 }
00211 
00212 
00213 //_____________________________________________________________________
00214 vector<bool> L1TOMDSHelper::getBunchStructure(int lhcFillNumber,int &error){
00215 
00216   vector<bool> BunchStructure;
00217   error = NO_ERROR;
00218 
00219   // Fields to retrive in the query
00220   string rtlSchema = "CMS_RUNTIME_LOGGER";
00221   string table     = "FILL_INITLUMIPERBUNCH";
00222   string atribute1 = "LHCFILL";
00223 
00224   // Setting the strings we want to recover from OMDS
00225   vector<std::string> qStrings ;
00226   qStrings.push_back("BUNCH");
00227   qStrings.push_back("BEAM1CONFIG"); 
00228   qStrings.push_back("BEAM2CONFIG");  
00229 
00230   l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00231 
00232   if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00233   else{
00234 
00235     if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00236     else{
00237 
00238       for(int i=0; i<qResults.numberRows();++i){    
00239         int   bunch;
00240         bool  beam1config,beam2config;
00241         qResults.fillVariableFromRow("BUNCH"      ,i,bunch);
00242         qResults.fillVariableFromRow("BEAM1CONFIG",i,beam1config);
00243         qResults.fillVariableFromRow("BEAM2CONFIG",i,beam2config);
00244 
00245         if(beam1config && beam2config){BunchStructure.push_back(true);}
00246         else                          {BunchStructure.push_back(false);}
00247 
00248       }
00249     }
00250   }
00251 
00252   return BunchStructure;
00253 
00254 }
00255 
00256 //_____________________________________________________________________
00257 vector<float> L1TOMDSHelper::getInitBunchLumi(int lhcFillNumber,int &error){
00258 
00259   vector<float> InitBunchLumi;
00260   error = NO_ERROR;
00261 
00262   // Fields to retrive in the query
00263   string rtlSchema = "CMS_RUNTIME_LOGGER";
00264   string table     = "FILL_INITLUMIPERBUNCH";
00265   string atribute1 = "LHCFILL";
00266 
00267   // Setting the strings we want to recover from OMDS
00268   vector<std::string> qStrings ;
00269   qStrings.push_back("BUNCH");
00270   qStrings.push_back("INITBUNCHLUMI");
00271 
00272   l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00273 
00274   if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00275   else{
00276 
00277     if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00278     else{
00279 
00280       for(int i=0; i<qResults.numberRows();++i){    
00281         int   bunch;
00282         float initbunchlumi;
00283         qResults.fillVariableFromRow("BUNCH"        ,i,bunch);
00284         qResults.fillVariableFromRow("INITBUNCHLUMI",i,initbunchlumi);
00285 
00286         InitBunchLumi.push_back(initbunchlumi);
00287       }
00288     }
00289   }
00290 
00291   return InitBunchLumi;
00292 
00293 }
00294 
00295 //_____________________________________________________________________
00296 vector<double> L1TOMDSHelper::getRelativeBunchLumi(int lhcFillNumber,int &error){
00297 
00298   vector<double> RelativeBunchLumi;
00299   error = NO_ERROR;
00300 
00301   // Fields to retrive in the query
00302   string rtlSchema = "CMS_RUNTIME_LOGGER";
00303   string table     = "FILL_INITLUMIPERBUNCH";
00304   string atribute1 = "LHCFILL";
00305 
00306   // Setting the strings we want to recover from OMDS
00307   vector<std::string> qStrings ;
00308   qStrings.push_back("BUNCH");
00309   qStrings.push_back("INITBUNCHLUMI");
00310 
00311   l1t::OMDSReader::QueryResults qResults = m_omdsReader->basicQuery(qStrings,rtlSchema,table,atribute1,m_omdsReader->singleAttribute(lhcFillNumber));
00312 
00313   if(qResults.queryFailed()){error = WARNING_DB_QUERY_FAILED;}
00314   else{
00315 
00316     if(qResults.numberRows() != 3564){error = WARNING_DB_INCORRECT_NBUNCHES;}
00317     else{
00318 
00319       //-> Get the inicial bunch luminosity add calculate the total luminosity of the fill
00320       double        InitTotalLumi = 0;
00321       vector<float> InitBunchLumi;
00322 
00323       for(int i=0; i<qResults.numberRows();++i){    
00324         int   bunch;
00325         float initbunchlumi;
00326         qResults.fillVariableFromRow("BUNCH"        ,i,bunch);
00327         qResults.fillVariableFromRow("INITBUNCHLUMI",i,initbunchlumi);
00328 
00329         InitTotalLumi += initbunchlumi;
00330         InitBunchLumi.push_back(initbunchlumi);
00331       }
00332 
00333       //-> We calculate the relative luminosity for each bunch
00334       for(unsigned int i=0 ; i<InitBunchLumi.size() ; i++){
00335         RelativeBunchLumi.push_back(InitBunchLumi[i]/InitTotalLumi);
00336       }
00337     }
00338   }
00339 
00340   return RelativeBunchLumi;
00341 
00342 }
00343 
00344 //_____________________________________________________________________
00345 string L1TOMDSHelper::enumToStringError(int iObject){
00346 
00347   string out;
00348 
00349   switch(iObject){
00350     case NO_ERROR:                      out = "NO_ERROR";                      break;
00351     case WARNING_DB_CONN_FAILED:        out = "WARNING_DB_CONN_FAILED";        break;
00352     case WARNING_DB_QUERY_FAILED:       out = "WARNING_DB_QUERY_FAILED";       break;
00353     case WARNING_DB_INCORRECT_NBUNCHES: out = "WARNING_DB_INCORRECT_NBUNCHES"; break;
00354     default:                            out = "UNKNOWN";                       break;
00355   };
00356 
00357   return out;
00358 
00359 }