CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataWriter.h
Go to the documentation of this file.
1 #ifndef CondTools_L1Trigger_DataWriter_h
2 #define CondTools_L1Trigger_DataWriter_h
3 
4 // Framework
8 
13 
15 
17 
18 // L1T includes
21 
23 
24 #include <string>
25 #include <map>
26 
27 namespace l1t
28 {
29 
30 /* This class is used to write L1 Trigger configuration data to Pool DB.
31  * It also has a function for reading L1TriggerKey directly from Pool.
32  *
33  * In order to use this class to write payloads, user has to make sure to register datatypes that she or he is
34  * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
35  * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
36  * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
37  */
38 
40 {
41  public:
42  DataWriter();
43  ~DataWriter();
44 
45  // Payload and IOV writing functions.
46 
47  // Get payload from EventSetup and write to DB with no IOV
48  // recordType = "record@type", return value is payload token
49  std::string writePayload( const edm::EventSetup& setup,
50  const std::string& recordType ) ;
51 
52  // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
53  // for given ESRecord. PoolDBOutputService knows the corresponding IOV tag.
54  // Return value is true if IOV was updated; false if IOV was already
55  // up to date.
56  bool updateIOV( const std::string& esRecordName,
57  const std::string& payloadToken,
58  edm::RunNumber_t sinceRun,
59  bool logTransactions = false ) ;
60 
61  // Write L1TriggerKeyList payload and set IOV. Takes ownership of pointer.
62  void writeKeyList( L1TriggerKeyList* keyList,
63  edm::RunNumber_t sinceRun = 0,
64  bool logTransactions = false ) ;
65 
66  // Read object directly from Pool, not from EventSetup.
67  template< class T >
68  void readObject( const std::string& payloadToken,
69  T& outputObject ) ;
70 
71  std::string payloadToken( const std::string& recordName,
73 
74  std::string lastPayloadToken( const std::string& recordName ) ;
75 
77 
78  protected:
79 };
80 
81 template< class T >
82 void DataWriter::readObject( const std::string& payloadToken,
83  T& outputObject )
84 {
86  if( !poolDb.isAvailable() )
87  {
88  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
89  ) ;
90  }
91 
92  cond::DbSession session = poolDb->session();
93  cond::DbScopedTransaction tr(session);
94  tr.start(true);
95 
96  // Get object from POOL
97  boost::shared_ptr<T> ref = session.getTypedObject<T>(payloadToken) ;
98  outputObject = *ref ;
99  tr.commit ();
100 }
101 
102 } // ns
103 
104 #endif
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:195
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:153
bool isAvailable() const
Definition: Service.h:47
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:19
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:58
int start(bool readOnly=false)
start transaction
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:210
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:82
unsigned int RunNumber_t
Definition: EventRange.h:32
long double T
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:125
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:91
int commit()
commit transaction. Will disconnect from database if connection timeout==0 or connectted time close t...
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")