CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataWriterExt.h
Go to the documentation of this file.
1 #ifndef CondTools_L1Trigger_DataWriter_h
2 #define CondTools_L1Trigger_DataWriter_h
3 
4 // Framework
8 
12 
14 
15 // L1T includes
18 
20 
21 #include <string>
22 #include <map>
23 
24 namespace l1t {
25 
26  /* This class is used to write L1 Trigger configuration data to Pool DB.
27  * It also has a function for reading L1TriggerKey directly from Pool.
28  *
29  * In order to use this class to write payloads, user has to make sure to register datatypes that she or he is
30  * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
31  * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
32  * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
33  */
34 
35  typedef std::unique_ptr<WriterProxy> WriterProxyPtr;
36 
37  class DataWriterExt {
38  public:
39  DataWriterExt();
40  DataWriterExt(const std::string&);
42 
43  // Payload and IOV writing functions.
44 
45  // Get payload from EventSetup and write to DB with no IOV
46  // recordType = "record@type", return value is payload token
48  std::string writePayload(const edm::EventSetup& setup, const std::string& recordType);
49 
50  // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
51  // for given ESRecord. PoolDBOutputService knows the corresponding IOV tag.
52  // Return value is true if IOV was updated; false if IOV was already
53  // up to date.
54  bool updateIOV(const std::string& esRecordName,
56  edm::RunNumber_t sinceRun,
57  bool logTransactions = false);
58 
59  // Write L1TriggerKeyListExt payload and set IOV. Takes ownership of pointer.
60  void writeKeyList(L1TriggerKeyListExt* keyList, edm::RunNumber_t sinceRun = 0, bool logTransactions = false);
61 
62  // Read object directly from Pool, not from EventSetup.
63  template <class T>
64  void readObject(const std::string& payloadToken, T& outputObject);
65 
67 
68  std::string lastPayloadToken(const std::string& recordName);
69 
71 
72  WriterProxy* getWriter() { return writer_.get(); }
73 
74  private:
76 
77  protected:
78  };
79 
80  template <class T>
81  void DataWriterExt::readObject(const std::string& payloadToken, T& outputObject) {
83  if (!poolDb.isAvailable()) {
84  throw cond::Exception("DataWriter: PoolDBOutputService not available.");
85  }
86 
87  poolDb->forceInit();
89  session.transaction().start(true);
90 
91  // Get object from CondDB
92  std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken);
93  outputObject = *ref;
94  session.transaction().commit();
95  }
96 
97 } // namespace l1t
98 
99 #endif
persistency::Exception Exception
Definition: Exception.h:25
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:81
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
void start(bool readOnly=true)
Definition: Session.cc:18
cond::persistency::Session session() const
std::string lastPayloadToken(const std::string &recordName)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
tuple recordName
Definition: align_cfg.py:66
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Transaction & transaction()
Definition: Session.cc:52
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
bool isAvailable() const
Definition: Service.h:40
std::unique_ptr< WriterProxy > WriterProxyPtr
Definition: DataWriterExt.h:35
WriterProxyPtr writer_
Definition: DataWriterExt.h:75
std::string writePayload(const edm::EventSetup &setup)
unsigned int RunNumber_t
WriterProxy * getWriter()
Definition: DataWriterExt.h:72
long double T