Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/L1TriggerKeyListExt.h"
0017 #include "CondFormats/L1TObjects/interface/L1TriggerKeyExt.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   typedef std::unique_ptr<WriterProxy> WriterProxyPtr;
0036 
0037   class DataWriterExt {
0038   public:
0039     DataWriterExt();
0040     DataWriterExt(const std::string&);
0041     ~DataWriterExt();
0042 
0043     // Payload and IOV writing functions.
0044 
0045     // Get payload from EventSetup and write to DB with no IOV
0046     // recordType = "record@type", return value is payload token
0047     std::string writePayload(const edm::EventSetup& setup);
0048     std::string writePayload(const edm::EventSetup& setup, const std::string& recordType);
0049 
0050     // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
0051     // for given ESRecord.  PoolDBOutputService knows the corresponding IOV tag.
0052     // Return value is true if IOV was updated; false if IOV was already
0053     // up to date.
0054     bool updateIOV(const std::string& esRecordName,
0055                    const std::string& payloadToken,
0056                    edm::RunNumber_t sinceRun,
0057                    bool logTransactions = false);
0058 
0059     // Write L1TriggerKeyListExt payload and set IOV.  Takes ownership of pointer.
0060     void writeKeyList(L1TriggerKeyListExt* keyList, edm::RunNumber_t sinceRun = 0, bool logTransactions = false);
0061 
0062     // Read object directly from Pool, not from EventSetup.
0063     template <class T>
0064     void readObject(const std::string& payloadToken, T& outputObject);
0065 
0066     std::string payloadToken(const std::string& recordName, edm::RunNumber_t runNumber);
0067 
0068     std::string lastPayloadToken(const std::string& recordName);
0069 
0070     bool fillLastTriggerKeyList(L1TriggerKeyListExt& output);
0071 
0072     WriterProxy* getWriter() { return writer_.get(); }
0073 
0074   private:
0075     WriterProxyPtr writer_;
0076 
0077   protected:
0078   };
0079 
0080   template <class T>
0081   void DataWriterExt::readObject(const std::string& payloadToken, T& outputObject) {
0082     edm::Service<cond::service::PoolDBOutputService> poolDb;
0083     if (!poolDb.isAvailable()) {
0084       throw cond::Exception("DataWriter: PoolDBOutputService not available.");
0085     }
0086 
0087     poolDb->forceInit();
0088     cond::persistency::Session session = poolDb->session();
0089     session.transaction().start(true);
0090 
0091     // Get object from CondDB
0092     std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken);
0093     outputObject = *ref;
0094     session.transaction().commit();
0095   }
0096 
0097 }  // namespace l1t
0098 
0099 #endif