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 
12 //#include "CondCore/DBCommon/interface/DbSession.h"
13 //#include "CondCore/DBCommon/interface/DbScopedTransaction.h"
14 
15 //#include "CondCore/MetaDataService/interface/MetaData.h"
16 
18 
19 // L1T includes
22 
24 
25 #include <string>
26 #include <map>
27 
28 namespace l1t
29 {
30 
31 /* This class is used to write L1 Trigger configuration data to Pool DB.
32  * It also has a function for reading L1TriggerKey directly from Pool.
33  *
34  * In order to use this class to write payloads, user has to make sure to register datatypes that she or he is
35  * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
36  * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
37  * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
38  */
39 
41 {
42  public:
43  DataWriter();
44  ~DataWriter();
45 
46  // Payload and IOV writing functions.
47 
48  // Get payload from EventSetup and write to DB with no IOV
49  // recordType = "record@type", return value is payload token
51  const std::string& recordType ) ;
52 
53  // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
54  // for given ESRecord. PoolDBOutputService knows the corresponding IOV tag.
55  // Return value is true if IOV was updated; false if IOV was already
56  // up to date.
57  bool updateIOV( const std::string& esRecordName,
59  edm::RunNumber_t sinceRun,
60  bool logTransactions = false ) ;
61 
62  // Write L1TriggerKeyList payload and set IOV. Takes ownership of pointer.
63  void writeKeyList( L1TriggerKeyList* keyList,
64  edm::RunNumber_t sinceRun = 0,
65  bool logTransactions = false ) ;
66 
67  // Read object directly from Pool, not from EventSetup.
68  template< class T >
69  void readObject( const std::string& payloadToken,
70  T& outputObject ) ;
71 
74 
75  std::string lastPayloadToken( const std::string& recordName ) ;
76 
78 
79  protected:
80 };
81 
82 template< class T >
83 void DataWriter::readObject( const std::string& payloadToken,
84  T& outputObject )
85 {
87  if( !poolDb.isAvailable() )
88  {
89  throw cond::Exception( "DataWriter: PoolDBOutputService not available."
90  ) ;
91  }
92 
94  session.transaction().start(true);
95 
96  // Get object from CondDB
97  boost::shared_ptr<T> ref = session.fetchPayload<T>(payloadToken) ;
98  outputObject = *ref ;
99  session.transaction().commit ();
100 }
101 
102 } // ns
103 
104 #endif
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:163
void start(bool readOnly=true)
Definition: Session.cc:22
cond::persistency::Session session() const
Transaction & transaction()
Definition: Session.cc:71
std::string lastPayloadToken(const std::string &recordName)
Definition: DataWriter.cc:179
std::string payloadToken(const std::string &recordName, edm::RunNumber_t runNumber)
Definition: DataWriter.cc:151
bool isAvailable() const
Definition: Service.h:46
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
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:194
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:83
unsigned int RunNumber_t
Definition: EventRange.h:32
long double T
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:89
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")