File indexing completed on 2024-04-06 12:03:13
0001 #ifndef CondTools_L1Trigger_DataWriter_h
0002 #define CondTools_L1Trigger_DataWriter_h
0003
0004
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
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
0027
0028
0029
0030
0031
0032
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
0044
0045
0046
0047 std::string writePayload(const edm::EventSetup& setup);
0048 std::string writePayload(const edm::EventSetup& setup, const std::string& recordType);
0049
0050
0051
0052
0053
0054 bool updateIOV(const std::string& esRecordName,
0055 const std::string& payloadToken,
0056 edm::RunNumber_t sinceRun,
0057 bool logTransactions = false);
0058
0059
0060 void writeKeyList(L1TriggerKeyListExt* keyList, edm::RunNumber_t sinceRun = 0, bool logTransactions = false);
0061
0062
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
0092 std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken);
0093 outputObject = *ref;
0094 session.transaction().commit();
0095 }
0096
0097 }
0098
0099 #endif