test
CMS 3D CMS Logo

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