CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/CondTools/L1Trigger/interface/DataWriter.h

Go to the documentation of this file.
00001 #ifndef CondTools_L1Trigger_DataWriter_h
00002 #define CondTools_L1Trigger_DataWriter_h
00003 
00004 // Framework
00005 #include "FWCore/Framework/interface/IOVSyncValue.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/DataKey.h"
00008 
00009 #include "FWCore/ServiceRegistry/interface/Service.h"
00010 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00011 #include "CondCore/DBCommon/interface/DbSession.h"
00012 #include "CondCore/DBCommon/interface/DbScopedTransaction.h"
00013 
00014 #include "CondCore/MetaDataService/interface/MetaData.h"
00015 
00016 #include "DataFormats/Provenance/interface/RunID.h"
00017 
00018 // L1T includes
00019 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
00020 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
00021 
00022 #include "CondTools/L1Trigger/interface/WriterProxy.h"
00023 
00024 #include <string>
00025 #include <map>
00026 
00027 namespace l1t
00028 {
00029 
00030 /* This class is used to write L1 Trigger configuration data to Pool DB.
00031  * It also has a function for reading L1TriggerKey directly from Pool.
00032  *
00033  * In order to use this class to write payloads, user has to make sure to register datatypes that she or he is
00034  * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
00035  * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
00036  * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
00037  */
00038 
00039 class DataWriter
00040 {
00041  public:
00042   DataWriter();
00043   ~DataWriter();
00044 
00045   // Payload and IOV writing functions.  
00046 
00047   // Get payload from EventSetup and write to DB with no IOV
00048   // recordType = "record@type", return value is payload token
00049   std::string writePayload( const edm::EventSetup& setup,
00050                             const std::string& recordType ) ;
00051 
00052   // Use PoolDBOutputService to append IOV with sinceRun to IOV sequence
00053   // for given ESRecord.  PoolDBOutputService knows the corresponding IOV tag.
00054   // Return value is true if IOV was updated; false if IOV was already
00055   // up to date.
00056   bool updateIOV( const std::string& esRecordName,
00057                   const std::string& payloadToken,
00058                   edm::RunNumber_t sinceRun,
00059                   bool logTransactions = false ) ;
00060 
00061   // Write L1TriggerKeyList payload and set IOV.  Takes ownership of pointer.
00062   void writeKeyList( L1TriggerKeyList* keyList,
00063                      edm::RunNumber_t sinceRun = 0,
00064                      bool logTransactions = false ) ;
00065 
00066   // Read object directly from Pool, not from EventSetup.
00067   template< class T >
00068   void readObject( const std::string& payloadToken,
00069                    T& outputObject ) ;
00070 
00071   std::string payloadToken( const std::string& recordName,
00072                             edm::RunNumber_t runNumber ) ;
00073 
00074   std::string lastPayloadToken( const std::string& recordName ) ;
00075 
00076   bool fillLastTriggerKeyList( L1TriggerKeyList& output ) ;
00077 
00078  protected:
00079 };
00080 
00081 template< class T >
00082 void DataWriter::readObject( const std::string& payloadToken,
00083                              T& outputObject )
00084 {
00085   edm::Service<cond::service::PoolDBOutputService> poolDb;
00086   if( !poolDb.isAvailable() )
00087     {
00088       throw cond::Exception( "DataWriter: PoolDBOutputService not available."
00089                              ) ;
00090     }
00091   
00092   cond::DbSession session = poolDb->session();
00093   cond::DbScopedTransaction tr(session);
00094   tr.start(true);
00095  
00096   // Get object from POOL
00097   boost::shared_ptr<T> ref = session.getTypedObject<T>(payloadToken) ;
00098   outputObject = *ref ;
00099   tr.commit ();
00100 }
00101 
00102 } // ns
00103 
00104 #endif