CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/L1TriggerConfig/RCTConfigProducers/src/L1RCTOmdsFedVectorProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    L1RCTOmdsFedVectorProducer
00004 // Class:      L1RCTOmdsFedVectorProducer
00005 // 
00013 //
00014 // Original Author:  Jessica Lynn Leonard,32 4-C20,+41227674522,
00015 //         Created:  Fri Sep  9 11:19:20 CEST 2011
00016 // $Id: L1RCTOmdsFedVectorProducer.cc,v 1.2 2011/10/06 14:29:07 jleonard Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include "boost/shared_ptr.hpp"
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/ModuleFactory.h"
00027 #include "FWCore/Framework/interface/ESProducer.h"
00028 
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 
00031 // OMDS stuff
00032 #include "RelationalAccess/ISession.h"
00033 #include "RelationalAccess/ITransaction.h"
00034 #include "RelationalAccess/IRelationalDomain.h"
00035 #include "RelationalAccess/ISchema.h"
00036 #include "RelationalAccess/IQuery.h"
00037 #include "RelationalAccess/ICursor.h"
00038 #include "RelationalAccess/IConnection.h"
00039 #include "CoralBase/AttributeList.h"
00040 #include "CoralBase/Attribute.h"
00041 #include "CoralKernel/Context.h"
00042 
00043 #include "CondCore/DBCommon/interface/DbConnection.h"
00044 #include "CondCore/DBCommon/interface/DbConnectionConfiguration.h"
00045 #include "CondCore/DBCommon/interface/DbTransaction.h"
00046 // end OMDS stuff
00047 
00048 #include "CondFormats/RunInfo/interface/RunInfo.h"
00049 #include "FWCore/Framework/interface/Run.h"
00050 #include "FWCore/Framework/interface/LuminosityBlock.h"
00051 
00052 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00053 
00054 
00055 //
00056 // class declaration
00057 //
00058 
00059 class L1RCTOmdsFedVectorProducer : public edm::ESProducer {
00060 public:
00061   L1RCTOmdsFedVectorProducer(const edm::ParameterSet&);
00062   ~L1RCTOmdsFedVectorProducer();
00063   
00064   typedef boost::shared_ptr<RunInfo> ReturnType;
00065   
00066   ReturnType produce(const RunInfoRcd&);
00067 private:
00068   // ----------member data ---------------------------
00069   std::string connectionString;
00070   std::string authpath;
00071   std::string tableToRead;
00072 
00073 };
00074 
00075 //
00076 // constants, enums and typedefs
00077 //
00078 
00079 //
00080 // static data member definitions
00081 //
00082 
00083 //
00084 // constructors and destructor
00085 //
00086 L1RCTOmdsFedVectorProducer::L1RCTOmdsFedVectorProducer(const edm::ParameterSet& iConfig) : 
00087   connectionString(iConfig.getParameter<std::string>("connectionString")),
00088   authpath(iConfig.getParameter<std::string>("authpath")),
00089   tableToRead(iConfig.getParameter<std::string>("tableToRead"))
00090 {
00091   //the following line is needed to tell the framework what
00092   // data is being produced
00093   setWhatProduced(this,"OmdsFedVector");
00094 
00095   //now do what ever other initialization is needed
00096 }
00097 
00098 
00099 L1RCTOmdsFedVectorProducer::~L1RCTOmdsFedVectorProducer()
00100 {
00101  
00102    // do anything here that needs to be done at desctruction time
00103    // (e.g. close files, deallocate resources etc.)
00104 
00105 }
00106 
00107 
00108 //
00109 // member functions
00110 //
00111 
00112 // ------------ method called to produce the data  ------------
00113 L1RCTOmdsFedVectorProducer::ReturnType
00114 L1RCTOmdsFedVectorProducer::produce(const RunInfoRcd& iRecord)
00115 {
00116   //  std::cout << "ENTERING L1RCTOmdsFedVectorProducer::produce()" << std::endl;
00117 
00118   using namespace edm::es;
00119   boost::shared_ptr<RunInfo> pRunInfo ;
00120 
00121   //  std::cout << "GETTING FED VECTOR FROM OMDS" << std::endl;
00122   
00123   // GETTING ALREADY-EXISTING RUNINFO OUT OF ES TO FIND OUT RUN NUMBER
00124   edm::ESHandle<RunInfo> sum;
00125   iRecord.get(sum);
00126   const RunInfo* summary=sum.product();
00127   int runNumber = summary->m_run; 
00128   
00129   // CREATING NEW RUNINFO WHICH WILL GET NEW FED VECTOR AND BE RETURNED
00130   pRunInfo = boost::shared_ptr<RunInfo>( new RunInfo() ); 
00131   
00132   
00133   // DO THE DATABASE STUFF
00134   
00135   //make connection object
00136   cond::DbConnection         connection;
00137   
00138   //set in configuration object authentication path
00139   connection.configuration().setAuthenticationPath(authpath);
00140   connection.configure();
00141   
00142   //create session object from connection
00143   cond::DbSession session = connection.createSession();
00144   
00145   session.open(connectionString,true);
00146 
00147   session.transaction().start(true); // (true=readOnly)
00148 
00149   coral::ISchema& schema = session.schema("CMS_RUNINFO");
00150 
00151   //condition
00152   coral::AttributeList conditionData;
00153   conditionData.extend<int>( "n_run" );
00154   conditionData[0].data<int>() = runNumber;
00155   
00156   std::string columnToRead_val = "VALUE";
00157   
00158   std::string tableToRead_fed = "RUNSESSION_STRING";
00159   coral::IQuery* queryV = schema.newQuery();
00160   queryV->addToTableList(tableToRead);
00161   queryV->addToTableList(tableToRead_fed);
00162   queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
00163   //queryV->addToOutputList(tableToRead + "." + columnToRead, columnToRead);
00164   //condition
00165   std::string condition = tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead + ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
00166   //std::string condition = tableToRead + ".runnumber=:n_run AND " + tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'";
00167   queryV->setCondition(condition, conditionData);
00168   coral::ICursor& cursorV = queryV->execute();
00169   std::string fed;
00170   if ( cursorV.next() ) {
00171     //cursorV.currentRow().toOutputStream(std::cout) << std::endl;
00172     const coral::AttributeList& row = cursorV.currentRow();
00173     fed = row[columnToRead_val].data<std::string>();
00174   }
00175   else {
00176     fed="null";
00177   }
00178   //std::cout << "string fed emask == " << fed << std::endl;
00179   delete queryV;
00180   
00181   std::replace(fed.begin(), fed.end(), '%', ' ');
00182   std::stringstream stream(fed);
00183   for(;;)
00184     {
00185       std::string word;
00186       if ( !(stream >> word) ){break;}
00187       std::replace(word.begin(), word.end(), '&', ' ');
00188       std::stringstream ss(word);
00189       int fedNumber;
00190       int val;
00191       ss >> fedNumber >> val;
00192       //std::cout << "fed:: " << fed << "--> val:: " << val << std::endl;
00193       //val bit 0 represents the status of the SLINK, but 5 and 7 means the SLINK/TTS is ON but NA or BROKEN (see mail of alex....)
00194       if( (val & 0001) == 1 && (val != 5) && (val != 7) )
00195         pRunInfo->m_fed_in.push_back(fedNumber);
00196     }
00197   //   std::cout << "feds in run:--> ";
00198   //   std::copy(pRunInfo->m_fed_in.begin(), pRunInfo->m_fed_in.end(), std::ostream_iterator<int>(std::cout, ", "));
00199   //   std::cout << std::endl;
00200   /*
00201     for (size_t i =0; i<pRunInfo->m_fed_in.size() ; ++i)
00202     {
00203     std::cout << "fed in run:--> " << pRunInfo->m_fed_in[i] << std::endl;
00204     }
00205   */
00206   
00207   return pRunInfo ;
00208 }
00209 
00210 //define this as a plug-in
00211 DEFINE_FWK_EVENTSETUP_MODULE(L1RCTOmdsFedVectorProducer);