Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <sstream>
00023
00024
00025 #include "CondTools/L1Trigger/plugins/L1CondDBIOVWriter.h"
00026 #include "CondTools/L1Trigger/interface/DataWriter.h"
00027
00028 #include "CondFormats/L1TObjects/interface/L1TriggerKey.h"
00029 #include "CondFormats/DataRecord/interface/L1TriggerKeyRcd.h"
00030 #include "CondFormats/L1TObjects/interface/L1TriggerKeyList.h"
00031 #include "CondFormats/DataRecord/interface/L1TriggerKeyListRcd.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 L1CondDBIOVWriter::L1CondDBIOVWriter(const edm::ParameterSet& iConfig)
00049 : m_tscKey( iConfig.getParameter<std::string> ("tscKey") ),
00050 m_ignoreTriggerKey( iConfig.getParameter<bool> ("ignoreTriggerKey") ),
00051 m_logKeys( iConfig.getParameter<bool>( "logKeys" ) ),
00052 m_logTransactions( iConfig.getParameter<bool>( "logTransactions" ) ),
00053 m_forceUpdate( iConfig.getParameter<bool>( "forceUpdate" ) )
00054 {
00055
00056 typedef std::vector<edm::ParameterSet> ToSave;
00057 ToSave toSave = iConfig.getParameter<ToSave> ("toPut");
00058 for (ToSave::const_iterator it = toSave.begin (); it != toSave.end (); it++)
00059 {
00060 std::string record = it->getParameter<std::string> ("record");
00061 std::string type = it->getParameter<std::string> ("type");
00062 m_recordTypes.push_back( record + "@" + type ) ;
00063 }
00064 }
00065
00066
00067 L1CondDBIOVWriter::~L1CondDBIOVWriter()
00068 {
00069
00070
00071
00072
00073 }
00074
00075
00076
00077
00078
00079
00080
00081 void
00082 L1CondDBIOVWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00083 {
00084 using namespace edm;
00085
00086
00087 L1TriggerKeyList keyList ;
00088 l1t::DataWriter dataWriter ;
00089 if( !dataWriter.fillLastTriggerKeyList( keyList ) )
00090 {
00091 edm::LogError( "L1-O2O" )
00092 << "Problem getting last L1TriggerKeyList" ;
00093 }
00094
00095 unsigned long long run = iEvent.id().run() ;
00096
00097 L1TriggerKey::RecordToKey recordTypeToKeyMap ;
00098
00099 bool triggerKeyIOVUpdated = true ;
00100
00101
00102 std::stringstream ss ;
00103 ss << run ;
00104 std::string log = "KEYLOG runNumber=" + ss.str() ;
00105 bool logRecords = true ;
00106
00107 if( !m_ignoreTriggerKey )
00108 {
00109 if( !m_tscKey.empty() )
00110 {
00111 edm::LogVerbatim( "L1-O2O" )
00112 << "Object key for L1TriggerKey@L1TriggerKeyRcd: "
00113 << m_tscKey ;
00114
00115
00116
00117 std::string keyToken = keyList.token( m_tscKey ) ;
00118
00119
00120 triggerKeyIOVUpdated =
00121 m_writer.updateIOV( "L1TriggerKeyRcd", keyToken, run, m_logTransactions ) ;
00122
00123
00124 L1TriggerKey key ;
00125 m_writer.readObject( keyToken, key ) ;
00126
00127 recordTypeToKeyMap = key.recordToKeyMap() ;
00128
00129
00130
00131 std::string tmpKey = m_tscKey ;
00132 replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
00133 log += " tscKey=" + tmpKey ;
00134 logRecords = false ;
00135 }
00136 else
00137 {
00138
00139
00140
00141
00142 ESHandle< L1TriggerKey > esKey ;
00143 iSetup.get< L1TriggerKeyRcd >().get( esKey ) ;
00144
00145 recordTypeToKeyMap = esKey->recordToKeyMap() ;
00146 }
00147 }
00148 else
00149 {
00150 std::vector<std::string >::const_iterator
00151 recordTypeItr = m_recordTypes.begin() ;
00152 std::vector<std::string >::const_iterator
00153 recordTypeEnd = m_recordTypes.end() ;
00154
00155 for( ; recordTypeItr != recordTypeEnd ; ++recordTypeItr )
00156 {
00157 recordTypeToKeyMap.insert(
00158 std::make_pair( *recordTypeItr, m_tscKey ) ) ;
00159 }
00160 }
00161
00162
00163
00164 bool throwException = false ;
00165
00166 if( triggerKeyIOVUpdated || m_forceUpdate )
00167 {
00168
00169 L1TriggerKey::RecordToKey::const_iterator itr =
00170 recordTypeToKeyMap.begin() ;
00171 L1TriggerKey::RecordToKey::const_iterator end =
00172 recordTypeToKeyMap.end() ;
00173
00174 for( ; itr != end ; ++itr )
00175 {
00176 std::string recordType = itr->first ;
00177 std::string objectKey = itr->second ;
00178
00179 std::string recordName( recordType,
00180 0, recordType.find_first_of("@") ) ;
00181
00182 if( logRecords )
00183 {
00184
00185
00186 std::string tmpKey = objectKey ;
00187 replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
00188 log += " " + recordName + "Key=" + tmpKey ;
00189 }
00190
00191
00192 if( objectKey == L1TriggerKey::kNullKey )
00193 {
00194 edm::LogVerbatim( "L1-O2O" )
00195 << "L1CondDBIOVWriter: null object key for "
00196 << recordType << "; skipping this record." ;
00197 }
00198 else
00199 {
00200
00201 edm::LogVerbatim( "L1-O2O" )
00202 << "Object key for "
00203 << recordType << ": " << objectKey ;
00204
00205 std::string payloadToken = keyList.token( recordType,
00206 objectKey ) ;
00207 if( payloadToken.empty() )
00208 {
00209 edm::LogVerbatim( "L1-O2O" )
00210 << "L1CondDBIOVWriter: empty payload token for " +
00211 recordType + ", key " + objectKey ;
00212
00213 throwException = true ;
00214 }
00215 else
00216 {
00217 m_writer.updateIOV( recordName,
00218 payloadToken,
00219 run,
00220 m_logTransactions ) ;
00221 }
00222 }
00223 }
00224 }
00225
00226 if( m_logKeys )
00227 {
00228 edm::LogVerbatim( "L1-O2O" ) << log ;
00229 }
00230
00231 if( throwException )
00232 {
00233 throw cond::Exception( "L1CondDBIOVWriter: empty payload tokens" ) ;
00234 }
00235 }
00236
00237
00238
00239 void
00240 L1CondDBIOVWriter::beginJob()
00241 {
00242 }
00243
00244
00245 void
00246 L1CondDBIOVWriter::endJob() {
00247 }
00248
00249
00250