CMS 3D CMS Logo

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 "CondCore/DBCommon/interface/TypedRef.h"
00010 #include "CondCore/MetaDataService/interface/MetaData.h"
00011 
00012 #include "DataFormats/Provenance/interface/RunID.h"
00013 
00014 // L1T includes
00015 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
00016 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
00017 
00018 #include "CondTools/L1Trigger/interface/DataManager.h"
00019 #include "CondTools/L1Trigger/interface/WriterProxy.h"
00020 
00021 #include <string>
00022 #include <map>
00023 
00024 namespace l1t
00025 {
00026 
00027 /* This class is used to write L1 Trigger configuration data to Pool DB. Later this data can be
00028  * read from pool DB with class l1t::DataReader.
00029  *
00030  * L1TriggerKey is always writen to database by metod writeKey (...). Payload can be writen to database
00031  * in two ways. If user knows data type that she or he is interested to write to database, should use
00032  * templated version of writePayload. If that is not the case, then non-template version of write payload should
00033  * be used. Both of these methods will write payload to database and updates passed L1TriggerKey to reflect this
00034  * new change. This means that L1TriggerKey should be writen to database last, after all payload has been writen.
00035  *
00036  * Non-template version of writePayload was writen in such way that it could take data from EventSetup. Other options
00037  * also can be implemented.
00038  *
00039  * In order to use non-template version of this class, user has to make sure to register datatypes that she or he is
00040  * interested to write to the framework. This should be done with macro REGISTER_L1_WRITER(record, type) found in
00041  * WriterProxy.h file. Also, one should take care to register these data types to CondDB framework with macro
00042  * REGISTER_PLUGIN(record, type) from registration_macros.h found in PluginSystem.
00043  *
00044  * Validity interval of all data is controled via L1TriggerKey.
00045  */
00046 class DataWriter : public DataManager
00047 {
00048     public:
00049         /* Constructors. This system will use pool db that is configured via provided parameters.
00050          * connect - connection string to pool db, e.g. sqlite_file:test.db
00051          * catalog - catalog that should be used for this connection. e.g. file:test.xml
00052          */
00053   //        explicit DataWriter (const std::string & connect, const std::string & catalog)
00054   //            : DataManager (connect, catalog) {};
00055   explicit DataWriter (const std::string& connectString,
00056                        const std::string& authenticationPath )
00057     : DataManager( connectString, authenticationPath ) {};
00058         virtual ~DataWriter () {};
00059 
00060         /* Data writting functions */
00061 
00062         /* Writes payload to DB and assignes it to provided L1TriggerKey. Key is updated
00063          * to reflect changes.
00064          */
00065         template<typename T>
00066         void writePayload (L1TriggerKey & key, T * payload, const std::string & recordName);
00067 
00068         void writePayload (L1TriggerKey & key, const edm::EventSetup & setup,
00069                 const std::string & record, const std::string & type);
00070 
00071         /* Writes given key to DB and starts its IOV from provided run number.
00072          * From here pointer ownership is managed by POOL
00073          */
00074         void writeKey (L1TriggerKey * key,
00075                        const std::string & tag,
00076                        const edm::RunNumber_t sinceRun);
00077 
00078       // Added by wsun 03/2008
00079 
00080       // Get payload from EventSetup and write to DB with no IOV
00081       // recordType = "record@type", return value is payload token
00082       std::string writePayload( const edm::EventSetup& setup,
00083                                 const std::string& recordType ) ;
00084 
00085       // Write L1TriggerKeyList to DB
00086       void writeKeyList( L1TriggerKeyList* keyList,
00087                          const std::string& tag, // tag for IOV sequence
00088                          edm::RunNumber_t sinceRun = 0 ) ;
00089 
00090       // Append IOV with sinceRun to IOV sequence with given tag
00091       void updateIOV( const std::string& tag,
00092                       const std::string& payloadToken,
00093                       const edm::RunNumber_t sinceRun ) ;
00094 
00095     protected:
00096         /* Helper method that maps tag with iovToken */
00097         void addMappings (const std::string tag, const std::string iovToken);
00098         std::string findTokenForTag (const std::string & tag);
00099 
00100         // map to speed up detection if we already have mapping from given tag to token
00101         typedef std::map<std::string, std::string> TagToToken;
00102         TagToToken tagToToken;
00103 };
00104 
00105 /* Part of the implementation: Template functions that can't go to cc failes */
00106 
00107 template<typename T>
00108 void DataWriter::writePayload (L1TriggerKey & key, T * payload, const std::string & recordName)
00109 {
00110 /*     pool->connect (); */
00111   //connection->connect ( session );
00112 /*     pool->startTransaction (false); */
00113   cond::PoolTransaction& pool = connection->poolTransaction() ;
00114     pool.start (false);
00115 
00116     cond::TypedRef<T> ref (pool, payload);
00117     ref.markWrite (recordName);
00118 
00119     std::string typeName = 
00120         edm::eventsetup::heterocontainer::HCTypeTagTemplate<T, edm::eventsetup::DataKey>::className ();
00121 
00122     key.add (recordName, typeName, ref.token ());
00123 
00124     pool.commit ();
00125 /*     pool->disconnect (); */
00126     //connection->disconnect ();
00127 }
00128 
00129 } // ns
00130 
00131 #endif

Generated on Tue Jun 9 17:26:54 2009 for CMSSW by  doxygen 1.5.4