Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:12

0001 #ifndef CondTools_L1Trigger_DataWriter_h
0002 #define CondTools_L1Trigger_DataWriter_h
0003 
0004 // Framework
0005 #include "FWCore/Framework/interface/IOVSyncValue.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/DataKey.h"
0008 
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0011 #include "CondCore/CondDB/interface/Session.h"
0012 
0013 #include "DataFormats/Provenance/interface/RunID.h"
0014 
0015 // L1T includes
0016 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
0017 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
0018 
0019 #include "CondTools/L1Trigger/interface/WriterProxy.h"
0020 
0021 #include <string>
0022 #include <map>
0023 
0024 namespace l1t {
0025 
0026   /* This class is used to write L1 Trigger configuration data to Pool DB.
0027  * It also has a function for reading L1TriggerKey directly from Pool.
0028  *
0029  * In order to use this class to write payloads, user has to make sure to register datatypes that she or he is
0030  * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
0031  * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
0032  * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
0033  */
0034 
0035   class DataWriter {
0036   public:
0037     DataWriter();
0038     ~DataWriter();
0039 
0040     // Payload and IOV writing functions.
0041 
0042     // Get payload from EventSetup and write to DB with no IOV
0043     // recordType = "record@type", return value is payload token
0044     std::string writePayload(const edm::EventSetup& setup, const std::string& recordType);
0045 
0046     // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
0047     // for given ESRecord.  PoolDBOutputService knows the corresponding IOV tag.
0048     // Return value is true if IOV was updated; false if IOV was already
0049     // up to date.
0050     bool updateIOV(const std::string& esRecordName,
0051                    const std::string& payloadToken,
0052                    edm::RunNumber_t sinceRun,
0053                    bool logTransactions = false);
0054 
0055     // Write L1TriggerKeyList payload and set IOV.  Takes ownership of pointer.
0056     void writeKeyList(L1TriggerKeyList* keyList, edm::RunNumber_t sinceRun = 0, bool logTransactions = false);
0057 
0058     // Read object directly from Pool, not from EventSetup.
0059     template <class T>
0060     void readObject(const std::string& payloadToken, T& outputObject);
0061 
0062     std::string payloadToken(const std::string& recordName, edm::RunNumber_t runNumber);
0063 
0064     std::string lastPayloadToken(const std::string& recordName);
0065 
0066     bool fillLastTriggerKeyList(L1TriggerKeyList& output);
0067 
0068   protected:
0069   };
0070 
0071   template <class T>
0072   void DataWriter::readObject(const std::string& payloadToken, T& outputObject) {
0073     edm::Service<cond::service::PoolDBOutputService> poolDb;
0074     if (!poolDb.isAvailable()) {
0075       throw cond::Exception("DataWriter: PoolDBOutputService not available.");
0076     }
0077 
0078     cond::persistency::Session session = poolDb->session();
0079     session.transaction().start(true);
0080 
0081     // Get object from CondDB
0082     std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken);
0083     outputObject = *ref;
0084     session.transaction().commit();
0085   }
0086 
0087 }  // namespace l1t
0088 
0089 #endif