CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1CondDBIOVWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1CondDBIOVWriter
4 // Class: L1CondDBIOVWriter
5 //
13 //
14 // Original Author: Werner Man-Li Sun
15 // Created: Sun Mar 2 20:09:46 CET 2008
16 // $Id: L1CondDBIOVWriter.cc,v 1.20 2011/05/10 19:16:56 wsun Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <sstream>
23 
24 // user include files
27 
32 
33 //
34 // class declaration
35 //
36 
37 //
38 // constants, enums and typedefs
39 //
40 
41 //
42 // static data member definitions
43 //
44 
45 //
46 // constructors and destructor
47 //
49  : m_tscKey( iConfig.getParameter<std::string> ("tscKey") ),
50  m_ignoreTriggerKey( iConfig.getParameter<bool> ("ignoreTriggerKey") ),
51  m_logKeys( iConfig.getParameter<bool>( "logKeys" ) ),
52  m_logTransactions( iConfig.getParameter<bool>( "logTransactions" ) ),
53  m_forceUpdate( iConfig.getParameter<bool>( "forceUpdate" ) )
54 {
55  //now do what ever initialization is needed
56  typedef std::vector<edm::ParameterSet> ToSave;
57  ToSave toSave = iConfig.getParameter<ToSave> ("toPut");
58  for (ToSave::const_iterator it = toSave.begin (); it != toSave.end (); it++)
59  {
60  std::string record = it->getParameter<std::string> ("record");
61  std::string type = it->getParameter<std::string> ("type");
62  m_recordTypes.push_back( record + "@" + type ) ;
63  }
64 }
65 
66 
68 {
69 
70  // do anything here that needs to be done at desctruction time
71  // (e.g. close files, deallocate resources etc.)
72 
73 }
74 
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called to for each event ------------
81 void
83 {
84  using namespace edm;
85 
86  // Get L1TriggerKeyList
87  L1TriggerKeyList keyList ;
88  l1t::DataWriter dataWriter ;
89  if( !dataWriter.fillLastTriggerKeyList( keyList ) )
90  {
91  edm::LogError( "L1-O2O" )
92  << "Problem getting last L1TriggerKeyList" ;
93  }
94 
95  unsigned long long run = iEvent.id().run() ;
96 
97  L1TriggerKey::RecordToKey recordTypeToKeyMap ;
98 
99  bool triggerKeyIOVUpdated = true ;
100 
101  // Start log string, convert run number into string
102  std::stringstream ss ;
103  ss << run ;
104  std::string log = "KEYLOG runNumber=" + ss.str() ;
105  bool logRecords = true ;
106 
107  if( !m_ignoreTriggerKey )
108  {
109  if( !m_tscKey.empty() )
110  {
111  edm::LogVerbatim( "L1-O2O" )
112  << "Object key for L1TriggerKey@L1TriggerKeyRcd: "
113  << m_tscKey ;
114 
115  // Use TSC key and L1TriggerKeyList to find next run's
116  // L1TriggerKey token
117  std::string keyToken = keyList.token( m_tscKey ) ;
118 
119  // Update IOV sequence for this token with since-time = new run
120  triggerKeyIOVUpdated =
121  m_writer.updateIOV( "L1TriggerKeyRcd", keyToken, run, m_logTransactions ) ;
122 
123  // Read current L1TriggerKey directly from ORCON using token
124  L1TriggerKey key ;
125  m_writer.readObject( keyToken, key ) ;
126 
127  recordTypeToKeyMap = key.recordToKeyMap() ;
128 
129  // Replace spaces in key with ?s. Do reverse substitution when
130  // making L1TriggerKey.
131  std::string tmpKey = m_tscKey ;
132  replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
133  log += " tscKey=" + tmpKey ;
134  logRecords = false ;
135  }
136  else
137  {
138  // For use with Run Settings, no corresponding L1TrigerKey in
139  // ORCON.
140 
141  // Get L1TriggerKey from EventSetup
143  iSetup.get< L1TriggerKeyRcd >().get( esKey ) ;
144 
145  recordTypeToKeyMap = esKey->recordToKeyMap() ;
146  }
147  }
148  else
149  {
150  std::vector<std::string >::const_iterator
151  recordTypeItr = m_recordTypes.begin() ;
152  std::vector<std::string >::const_iterator
153  recordTypeEnd = m_recordTypes.end() ;
154 
155  for( ; recordTypeItr != recordTypeEnd ; ++recordTypeItr )
156  {
157  recordTypeToKeyMap.insert(
158  std::make_pair( *recordTypeItr, m_tscKey ) ) ;
159  }
160  }
161 
162  // If L1TriggerKey IOV was already up to date, then so are all its
163  // sub-records.
164  bool throwException = false ;
165 
166  if( triggerKeyIOVUpdated || m_forceUpdate )
167  {
168  // Loop over record@type in L1TriggerKey
169  L1TriggerKey::RecordToKey::const_iterator itr =
170  recordTypeToKeyMap.begin() ;
171  L1TriggerKey::RecordToKey::const_iterator end =
172  recordTypeToKeyMap.end() ;
173 
174  for( ; itr != end ; ++itr )
175  {
176  std::string recordType = itr->first ;
177  std::string objectKey = itr->second ;
178 
179  std::string recordName( recordType,
180  0, recordType.find_first_of("@") ) ;
181 
182  if( logRecords )
183  {
184  // Replace spaces in key with ?s. Do reverse substitution when
185  // making L1TriggerKey.
186  std::string tmpKey = objectKey ;
187  replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
188  log += " " + recordName + "Key=" + tmpKey ;
189  }
190 
191  // Do nothing if object key is null.
192  if( objectKey == L1TriggerKey::kNullKey )
193  {
194  edm::LogVerbatim( "L1-O2O" )
195  << "L1CondDBIOVWriter: null object key for "
196  << recordType << "; skipping this record." ;
197  }
198  else
199  {
200  // Find payload token
201  edm::LogVerbatim( "L1-O2O" )
202  << "Object key for "
203  << recordType << ": " << objectKey ;
204 
205  std::string payloadToken = keyList.token( recordType,
206  objectKey ) ;
207  if( payloadToken.empty() )
208  {
209  edm::LogVerbatim( "L1-O2O" )
210  << "L1CondDBIOVWriter: empty payload token for " +
211  recordType + ", key " + objectKey ;
212 
213  throwException = true ;
214  }
215  else
216  {
218  payloadToken,
219  run,
221  }
222  }
223  }
224  }
225 
226  if( m_logKeys )
227  {
228  edm::LogVerbatim( "L1-O2O" ) << log ;
229  }
230 
231  if( throwException )
232  {
233  throw cond::Exception( "L1CondDBIOVWriter: empty payload tokens" ) ;
234  }
235 }
236 
237 
238 // ------------ method called once each job just before starting event loop ------------
239 void
241 {
242 }
243 
244 // ------------ method called once each job just after ending the event loop ------------
245 void
247 }
248 
249 //define this as a plug-in
250 //DEFINE_FWK_MODULE(L1CondDBIOVWriter);
RunNumber_t run() const
Definition: EventID.h:42
type
Definition: HCALResponse.h:21
l1t::DataWriter m_writer
T getParameter(std::string const &) const
std::map< std::string, std::string > RecordToKey
Definition: L1TriggerKey.h:24
JetCorrectorParameters::Record record
Definition: classes.h:13
virtual void endJob()
def replace
Definition: linker.py:10
std::vector< std::string > m_recordTypes
virtual void analyze(const edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:243
const RecordToKey & recordToKeyMap() const
Definition: L1TriggerKey.h:92
#define end
Definition: vmac.h:38
L1CondDBIOVWriter(const edm::ParameterSet &)
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:82
void throwException(std::string const &message, std::string const &methodName)
Definition: Exception.cc:17
const T & get() const
Definition: EventSetup.h:55
edm::EventID id() const
Definition: EventBase.h:56
list key
Definition: combine.py:13
static std::string kNullKey
Definition: L1TriggerKey.h:40
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:91
virtual void beginJob()