CMS 3D CMS Logo

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 
27 /* This class is used to write L1 Trigger configuration data to Pool DB.
28  * It also has a function for reading L1TriggerKey directly from Pool.
29  *
30  * In order to use this class to write payloads, user has to make sure to register datatypes that she or he is
31  * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
32  * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
33  * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
34  */
35 
37 {
38  public:
39  DataWriterExt();
41 
42  // Payload and IOV writing functions.
43 
44  // Get payload from EventSetup and write to DB with no IOV
45  // recordType = "record@type", return value is payload token
47  const std::string& recordType ) ;
48 
49  // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
50  // for given ESRecord. PoolDBOutputService knows the corresponding IOV tag.
51  // Return value is true if IOV was updated; false if IOV was already
52  // up to date.
53  bool updateIOV( const std::string& esRecordName,
55  edm::RunNumber_t sinceRun,
56  bool logTransactions = false ) ;
57 
58  // Write L1TriggerKeyListExt payload and set IOV. Takes ownership of pointer.
59  void writeKeyList( L1TriggerKeyListExt* keyList,
60  edm::RunNumber_t sinceRun = 0,
61  bool logTransactions = false ) ;
62 
63  // Read object directly from Pool, not from EventSetup.
64  template< class T >
65  void readObject( const std::string& payloadToken,
66  T& outputObject ) ;
67 
70 
71  std::string lastPayloadToken( const std::string& recordName ) ;
72 
74 
75  protected:
76 };
77 
78 template< class T >
80  T& outputObject )
81 {
83  if( !poolDb.isAvailable() )
84  {
85  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
86  ) ;
87  }
88 
89  poolDb->forceInit();
92 
93  // Get object from CondDB
94  std::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken) ;
95  outputObject = *ref ;
97 }
98 
99 } // ns
100 
101 #endif
persistency::Exception Exception
Definition: Exception.h:25
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:79
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
cond::persistency::Session session() const
std::string lastPayloadToken(const std::string &recordName)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
delete x;
Definition: CaloConfig.h:22
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
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:46
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
unsigned int RunNumber_t
long double T
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215