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