CMS 3D CMS Logo

L1CondDBIOVWriterExt.cc
Go to the documentation of this file.
1 #include <sstream>
2 
5 
10 
12 
14  : m_tscKey( iConfig.getParameter<std::string> ("tscKey") ),
15  m_rsKey( iConfig.getParameter<std::string> ("rsKey") ),
16  m_ignoreTriggerKey( iConfig.getParameter<bool> ("ignoreTriggerKey") ),
17  m_logKeys( iConfig.getParameter<bool>( "logKeys" ) ),
18  m_logTransactions( iConfig.getParameter<bool>( "logTransactions" ) ),
19  m_forceUpdate( iConfig.getParameter<bool>( "forceUpdate" ) )
20 {
21  //now do what ever initialization is needed
22  typedef std::vector<edm::ParameterSet> ToSave;
23  ToSave toSave = iConfig.getParameter<ToSave> ("toPut");
24  for (ToSave::const_iterator it = toSave.begin (); it != toSave.end (); it++)
25  {
26  std::string record = it->getParameter<std::string> ("record");
27  std::string type = it->getParameter<std::string> ("type");
28  m_recordTypes.push_back( record + "@" + type ) ;
29  }
30 }
31 
32 
34 {
35 
36  // do anything here that needs to be done at desctruction time
37  // (e.g. close files, deallocate resources etc.)
38 
39 }
40 
41 // ------------ method called to for each event ------------
42 void
44 {
45  using namespace edm;
46 
47  // Get L1TriggerKeyListExt
48  L1TriggerKeyListExt keyList ;
49  l1t::DataWriterExt dataWriter ;
50  if( !dataWriter.fillLastTriggerKeyList( keyList ) )
51  {
52  edm::LogError( "L1-O2O" )
53  << "Problem getting last L1TriggerKeyListExt" ;
54  }
55 
56  unsigned long long run = iEvent.id().run() ;
57 
58  L1TriggerKeyExt::RecordToKey recordTypeToKeyMap ;
59 
60  bool triggerKeyIOVUpdated = true ;
61 
62  // Start log string, convert run number into string
63  std::stringstream ss ;
64  ss << run ;
65  std::string log = "KEYLOG runNumber=" + ss.str() ;
66  bool logRecords = true ;
67 
68  std::string m_Key = m_tscKey + ":" + m_rsKey;
69 
70  if( !m_ignoreTriggerKey )
71  {
72  if( !m_tscKey.empty() && !m_rsKey.empty() )
73  {
74  edm::LogVerbatim( "L1-O2O" )
75  << "Object key for L1TriggerKeyExt@L1TriggerKeyExtRcd: "
76  << m_tscKey << " : " << m_rsKey ;
77 
78  // Use TSC key and L1TriggerKeyListExt to find next run's
79  // L1TriggerKey token
80  std::string keyToken = keyList.token( m_Key ) ;
81 
82  // Update IOV sequence for this token with since-time = new run
83  triggerKeyIOVUpdated =
84  m_writer.updateIOV( "L1TriggerKeyExtRcd", keyToken, run, m_logTransactions ) ;
85 
86  // Read current L1TriggerKeyExt directly from ORCON using token
88  m_writer.readObject( keyToken, key ) ;
89 
90  recordTypeToKeyMap = key.recordToKeyMap() ;
91 
92  // Replace spaces in key with ?s. Do reverse substitution when
93  // making L1TriggerKeyExt.
94  std::string tmpKey = m_Key ;
95  replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
96  log += " tscKey:rsKey=" + tmpKey ;
97  logRecords = false ;
98  }
99  else
100  {
101  // For use with Run Settings, no corresponding L1TrigerKey in
102  // ORCON.
103 
104  // Get L1TriggerKeyExt from EventSetup
106  iSetup.get< L1TriggerKeyExtRcd >().get( esKey ) ;
107 
108  recordTypeToKeyMap = esKey->recordToKeyMap() ;
109  }
110  }
111  else
112  {
113  std::vector<std::string >::const_iterator
114  recordTypeItr = m_recordTypes.begin() ;
115  std::vector<std::string >::const_iterator
116  recordTypeEnd = m_recordTypes.end() ;
117 
118  for( ; recordTypeItr != recordTypeEnd ; ++recordTypeItr )
119  {
120  recordTypeToKeyMap.insert(
121  std::make_pair( *recordTypeItr, m_Key ) ) ;
122  }
123  }
124 
125  // If L1TriggerKeyExt IOV was already up to date, then so are all its
126  // sub-records.
127  bool throwException = false ;
128 
129  if( triggerKeyIOVUpdated || m_forceUpdate )
130  {
131  // Loop over record@type in L1TriggerKeyExt
132  L1TriggerKeyExt::RecordToKey::const_iterator itr =
133  recordTypeToKeyMap.begin() ;
134  L1TriggerKeyExt::RecordToKey::const_iterator end =
135  recordTypeToKeyMap.end() ;
136 
137  for( ; itr != end ; ++itr )
138  {
139  std::string recordType = itr->first ;
140  std::string objectKey = itr->second ;
141 
142  std::string recordName( recordType,
143  0, recordType.find_first_of("@") ) ;
144 
145  if( logRecords )
146  {
147  // Replace spaces in key with ?s. Do reverse substitution when
148  // making L1TriggerKeyExt.
149  std::string tmpKey = objectKey ;
150  replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
151  log += " " + recordName + "Key=" + tmpKey ;
152  }
153 
154  // Do nothing if object key is null.
155  if( objectKey == L1TriggerKeyExt::kNullKey )
156  {
157  edm::LogVerbatim( "L1-O2O" )
158  << "L1CondDBIOVWriterExt: null object key for "
159  << recordType << "; skipping this record." ;
160  }
161  else
162  {
163  // Find payload token
164  edm::LogVerbatim( "L1-O2O" )
165  << "Object key for "
166  << recordType << ": " << objectKey ;
167 
168  std::string payloadToken = keyList.token( recordType,
169  objectKey ) ;
170  if( payloadToken.empty() )
171  {
172  edm::LogVerbatim( "L1-O2O" )
173  << "L1CondDBIOVWriterExt: empty payload token for " +
174  recordType + ", key " + objectKey ;
175 
176  throwException = true ;
177  }
178  else
179  {
181  payloadToken,
182  run,
184  }
185  }
186  }
187  }
188 
189  if( m_logKeys )
190  {
191  edm::LogVerbatim( "L1-O2O" ) << log ;
192  }
193 
194  if( throwException )
195  {
196  throw cond::Exception( "L1CondDBIOVWriterExt: empty payload tokens" ) ;
197  }
198 }
199 
200 
201 // ------------ method called once each job just before starting event loop ------------
202 void
204 {
205 }
206 
207 // ------------ method called once each job just after ending the event loop ------------
208 void
210 }
211 
212 //define this as a plug-in
213 //DEFINE_FWK_MODULE(L1CondDBIOVWriterExt);
RunNumber_t run() const
Definition: EventID.h:39
persistency::Exception Exception
Definition: Exception.h:25
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:79
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
JetCorrectorParameters::Record record
Definition: classes.h:7
static const std::string kNullKey
def replace(string, replacements)
L1CondDBIOVWriterExt(const edm::ParameterSet &)
const RecordToKey & recordToKeyMap() const
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
int iEvent
Definition: GenABIO.cc:230
std::vector< std::string > m_recordTypes
#define end
Definition: vmac.h:37
std::map< std::string, std::string > RecordToKey
std::string m_tscKey
l1t::DataWriter m_writer ;
const T & get() const
Definition: EventSetup.h:55
l1t::DataWriterExt m_writer
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
std::string token(const std::string &tscKey) const
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14