Go to the documentation of this file.00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002
00003 #include "CondTools/L1Trigger/interface/DataWriter.h"
00004 #include "CondTools/L1Trigger/interface/Exception.h"
00005 #include "CondCore/MetaDataService/interface/MetaData.h"
00006 #include "CondCore/IOVService/interface/IOVService.h"
00007 #include "CondCore/DBCommon/interface/Exception.h"
00008
00009 #include <utility>
00010
00011 namespace l1t
00012 {
00013 DataWriter::DataWriter(){}
00014 DataWriter::~DataWriter(){}
00015
00016
00017
00018 std::string
00019 DataWriter::writePayload( const edm::EventSetup& setup,
00020 const std::string& recordType )
00021 {
00022 WriterFactory* factory = WriterFactory::get();
00023 std::auto_ptr<WriterProxy> writer(factory->create( recordType + "@Writer" )) ;
00024 if( writer.get() == 0 )
00025 {
00026 throw cond::Exception( "DataWriter: could not create WriterProxy with name "
00027 + recordType + "@Writer" ) ;
00028 }
00029
00030 edm::Service<cond::service::PoolDBOutputService> poolDb;
00031 if (!poolDb.isAvailable())
00032 {
00033 throw cond::Exception( "DataWriter: PoolDBOutputService not available."
00034 ) ;
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 std::string payloadToken = writer->save( setup ) ;
00048
00049 edm::LogVerbatim( "L1-O2O" ) << recordType << " PAYLOAD TOKEN "
00050 << payloadToken ;
00051
00052
00053
00054 return payloadToken ;
00055 }
00056
00057 void
00058 DataWriter::writeKeyList( L1TriggerKeyList* keyList,
00059 edm::RunNumber_t sinceRun,
00060 bool logTransactions )
00061 {
00062 edm::Service<cond::service::PoolDBOutputService> poolDb;
00063 if( !poolDb.isAvailable() )
00064 {
00065 throw cond::Exception( "DataWriter: PoolDBOutputService not available."
00066 ) ;
00067 }
00068
00069 cond::DbSession session = poolDb->session();
00070 cond::DbScopedTransaction tr(session);
00071 tr.start(false);
00072
00073
00074 boost::shared_ptr<L1TriggerKeyList> pointer(keyList);
00075 std::string payloadToken = session.storeObject(pointer.get(),
00076 cond::classNameForTypeId(typeid(L1TriggerKeyList))
00077 );
00078
00079
00080
00081 tr.commit ();
00082
00083
00084 updateIOV( "L1TriggerKeyListRcd",
00085 payloadToken,
00086 sinceRun,
00087 logTransactions ) ;
00088 }
00089
00090 bool
00091 DataWriter::updateIOV( const std::string& esRecordName,
00092 const std::string& payloadToken,
00093 edm::RunNumber_t sinceRun,
00094 bool logTransactions )
00095 {
00096 edm::LogVerbatim( "L1-O2O" ) << esRecordName
00097 << " PAYLOAD TOKEN " << payloadToken ;
00098
00099 edm::Service<cond::service::PoolDBOutputService> poolDb;
00100 if (!poolDb.isAvailable())
00101 {
00102 throw cond::Exception( "DataWriter: PoolDBOutputService not available."
00103 ) ;
00104 }
00105
00106 bool iovUpdated = true ;
00107
00108 if( poolDb->isNewTagRequest( esRecordName ) )
00109 {
00110 sinceRun = poolDb->beginOfTime() ;
00111 poolDb->createNewIOV( payloadToken,
00112 sinceRun,
00113 poolDb->endOfTime(),
00114 esRecordName,
00115 logTransactions ) ;
00116 }
00117 else
00118 {
00119 cond::TagInfo tagInfo ;
00120 poolDb->tagInfo( esRecordName, tagInfo ) ;
00121
00122 if( sinceRun == 0 )
00123 {
00124 sinceRun = tagInfo.lastInterval.first ;
00125 ++sinceRun ;
00126 }
00127
00128 if( tagInfo.lastPayloadToken != payloadToken )
00129 {
00130 poolDb->appendSinceTime( payloadToken,
00131 sinceRun,
00132 esRecordName,
00133 logTransactions ) ;
00134 }
00135 else
00136 {
00137 iovUpdated = false ;
00138 edm::LogVerbatim( "L1-O2O" ) << "IOV already up to date." ;
00139 }
00140 }
00141
00142 if( iovUpdated )
00143 {
00144 edm::LogVerbatim( "L1-O2O" ) << esRecordName
00145 << " SINCE " << sinceRun ;
00146 }
00147
00148 return iovUpdated ;
00149 }
00150
00151 std::string
00152 DataWriter::payloadToken( const std::string& recordName,
00153 edm::RunNumber_t runNumber )
00154 {
00155 edm::Service<cond::service::PoolDBOutputService> poolDb;
00156 if( !poolDb.isAvailable() )
00157 {
00158 throw cond::Exception( "DataWriter: PoolDBOutputService not available."
00159 ) ;
00160 }
00161
00162
00163 std::string iovTag = poolDb->tag( recordName ) ;
00164
00165
00166 cond::DbSession session = poolDb->session();
00167 cond::DbScopedTransaction tr(session);
00168 tr.start(true);
00169 cond::MetaData metadata(session ) ;
00170 std::string iovToken ;
00171 if( metadata.hasTag( iovTag ) )
00172 {
00173 iovToken = metadata.getToken( iovTag ) ;
00174 }
00175 if( iovToken.empty() )
00176 {
00177 return std::string() ;
00178 }
00179
00180
00181
00182 cond::IOVService iovService( session ) ;
00183 std::string payloadToken = iovService.payloadToken( iovToken, runNumber ) ;
00184
00185 tr.commit() ;
00186 return payloadToken ;
00187 }
00188
00189 std::string
00190 DataWriter::lastPayloadToken( const std::string& recordName )
00191 {
00192 edm::Service<cond::service::PoolDBOutputService> poolDb;
00193 if( !poolDb.isAvailable() )
00194 {
00195 throw cond::Exception( "DataWriter: PoolDBOutputService not available."
00196 ) ;
00197 }
00198
00199 cond::TagInfo tagInfo ;
00200 poolDb->tagInfo( recordName, tagInfo ) ;
00201 return tagInfo.lastPayloadToken ;
00202 }
00203
00204 bool
00205 DataWriter::fillLastTriggerKeyList( L1TriggerKeyList& output )
00206 {
00207 std::string keyListToken =
00208 lastPayloadToken( "L1TriggerKeyListRcd" ) ;
00209 if( keyListToken.empty() )
00210 {
00211 return false ;
00212 }
00213 else
00214 {
00215 readObject( keyListToken, output ) ;
00216 return true ;
00217 }
00218 }
00219
00220 }