Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:24

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1RCTOmdsFedVectorProducer
0004 // Class:      L1RCTOmdsFedVectorProducer
0005 //
0006 /**\class L1RCTOmdsFedVectorProducer L1RCTOmdsFedVectorProducer.h L1TriggerConfig/L1RCTOmdsFedVectorProducer/src/L1RCTOmdsFedVectorProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Jessica Lynn Leonard,32 4-C20,+41227674522,
0015 //         Created:  Fri Sep  9 11:19:20 CEST 2011
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/ModuleFactory.h"
0024 #include "FWCore/Framework/interface/ESProducer.h"
0025 
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 
0028 // OMDS stuff
0029 #include "RelationalAccess/ISessionProxy.h"
0030 #include "RelationalAccess/ITransaction.h"
0031 #include "RelationalAccess/IRelationalDomain.h"
0032 #include "RelationalAccess/ISchema.h"
0033 #include "RelationalAccess/IQuery.h"
0034 #include "RelationalAccess/ICursor.h"
0035 #include "RelationalAccess/IConnection.h"
0036 #include "CoralBase/AttributeList.h"
0037 #include "CoralBase/Attribute.h"
0038 #include "CoralKernel/Context.h"
0039 
0040 #include "CondCore/CondDB/interface/ConnectionPool.h"
0041 // end OMDS stuff
0042 
0043 #include "CondFormats/RunInfo/interface/RunInfo.h"
0044 #include "FWCore/Framework/interface/Run.h"
0045 #include "FWCore/Framework/interface/LuminosityBlock.h"
0046 
0047 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
0048 
0049 //
0050 // class declaration
0051 //
0052 
0053 class L1RCTOmdsFedVectorProducer : public edm::ESProducer {
0054 public:
0055   L1RCTOmdsFedVectorProducer(const edm::ParameterSet&);
0056   ~L1RCTOmdsFedVectorProducer() override;
0057 
0058   using ReturnType = std::unique_ptr<RunInfo>;
0059 
0060   ReturnType produce(const RunInfoRcd&);
0061 
0062 private:
0063   // ----------member data ---------------------------
0064   std::string connectionString;
0065   std::string authpath;
0066   std::string tableToRead;
0067 
0068   edm::ESGetToken<RunInfo, RunInfoRcd> token_;
0069 };
0070 
0071 //
0072 // constants, enums and typedefs
0073 //
0074 
0075 //
0076 // static data member definitions
0077 //
0078 
0079 //
0080 // constructors and destructor
0081 //
0082 L1RCTOmdsFedVectorProducer::L1RCTOmdsFedVectorProducer(const edm::ParameterSet& iConfig)
0083     : connectionString(iConfig.getParameter<std::string>("connectionString")),
0084       authpath(iConfig.getParameter<std::string>("authpath")),
0085       tableToRead(iConfig.getParameter<std::string>("tableToRead")) {
0086   //the following line is needed to tell the framework what
0087   // data is being produced
0088   token_ = setWhatProduced(this, "OmdsFedVector").consumes();
0089 
0090   //now do what ever other initialization is needed
0091 }
0092 
0093 L1RCTOmdsFedVectorProducer::~L1RCTOmdsFedVectorProducer() {
0094   // do anything here that needs to be done at desctruction time
0095   // (e.g. close files, deallocate resources etc.)
0096 }
0097 
0098 //
0099 // member functions
0100 //
0101 
0102 // ------------ method called to produce the data  ------------
0103 L1RCTOmdsFedVectorProducer::ReturnType L1RCTOmdsFedVectorProducer::produce(const RunInfoRcd& iRecord) {
0104   //  std::cout << "ENTERING L1RCTOmdsFedVectorProducer::produce()" << std::endl;
0105 
0106   //  std::cout << "GETTING FED VECTOR FROM OMDS" << std::endl;
0107 
0108   // GETTING ALREADY-EXISTING RUNINFO OUT OF ES TO FIND OUT RUN NUMBER
0109   const RunInfo* summary = &iRecord.get(token_);
0110   int runNumber = summary->m_run;
0111 
0112   // CREATING NEW RUNINFO WHICH WILL GET NEW FED VECTOR AND BE RETURNED
0113   auto pRunInfo = std::make_unique<RunInfo>();
0114 
0115   // DO THE DATABASE STUFF
0116 
0117   //make connection object
0118   cond::persistency::ConnectionPool connection;
0119 
0120   //set in configuration object authentication path
0121   connection.setAuthenticationPath(authpath);
0122   connection.configure();
0123 
0124   //create session object from connection
0125   cond::persistency::Session session = connection.createSession(connectionString, true);
0126 
0127   session.transaction().start(true);  // (true=readOnly)
0128 
0129   coral::ISchema& schema = session.coralSession().schema("CMS_RUNINFO");
0130 
0131   //condition
0132   coral::AttributeList conditionData;
0133   conditionData.extend<int>("n_run");
0134   conditionData[0].data<int>() = runNumber;
0135 
0136   std::string columnToRead_val = "VALUE";
0137 
0138   std::string tableToRead_fed = "RUNSESSION_STRING";
0139   coral::IQuery* queryV = schema.newQuery();
0140   queryV->addToTableList(tableToRead);
0141   queryV->addToTableList(tableToRead_fed);
0142   queryV->addToOutputList(tableToRead_fed + "." + columnToRead_val, columnToRead_val);
0143   //queryV->addToOutputList(tableToRead + "." + columnToRead, columnToRead);
0144   //condition
0145   std::string condition =
0146       tableToRead + ".RUNNUMBER=:n_run AND " + tableToRead +
0147       ".NAME='CMS.LVL0:FED_ENABLE_MASK' AND RUNSESSION_PARAMETER.ID = RUNSESSION_STRING.RUNSESSION_PARAMETER_ID";
0148   //std::string condition = tableToRead + ".runnumber=:n_run AND " + tableToRead + ".name='CMS.LVL0:FED_ENABLE_MASK'";
0149   queryV->setCondition(condition, conditionData);
0150   coral::ICursor& cursorV = queryV->execute();
0151   std::string fed;
0152   if (cursorV.next()) {
0153     //cursorV.currentRow().toOutputStream(std::cout) << std::endl;
0154     const coral::AttributeList& row = cursorV.currentRow();
0155     fed = row[columnToRead_val].data<std::string>();
0156   } else {
0157     fed = "null";
0158   }
0159   //std::cout << "string fed emask == " << fed << std::endl;
0160   delete queryV;
0161 
0162   std::replace(fed.begin(), fed.end(), '%', ' ');
0163   std::stringstream stream(fed);
0164   for (;;) {
0165     std::string word;
0166     if (!(stream >> word)) {
0167       break;
0168     }
0169     std::replace(word.begin(), word.end(), '&', ' ');
0170     std::stringstream ss(word);
0171     int fedNumber;
0172     int val;
0173     ss >> fedNumber >> val;
0174     //std::cout << "fed:: " << fed << "--> val:: " << val << std::endl;
0175     //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....)
0176     if ((val & 0001) == 1 && (val != 5) && (val != 7))
0177       pRunInfo->m_fed_in.push_back(fedNumber);
0178   }
0179   //   std::cout << "feds in run:--> ";
0180   //   std::copy(pRunInfo->m_fed_in.begin(), pRunInfo->m_fed_in.end(), std::ostream_iterator<int>(std::cout, ", "));
0181   //   std::cout << std::endl;
0182   /*
0183     for (size_t i =0; i<pRunInfo->m_fed_in.size() ; ++i)
0184     {
0185     std::cout << "fed in run:--> " << pRunInfo->m_fed_in[i] << std::endl;
0186     }
0187   */
0188 
0189   return pRunInfo;
0190 }
0191 
0192 //define this as a plug-in
0193 DEFINE_FWK_EVENTSETUP_MODULE(L1RCTOmdsFedVectorProducer);