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.18 2010/02/10 02:53:44 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 {
54  //now do what ever initialization is needed
55  typedef std::vector<edm::ParameterSet> ToSave;
56  ToSave toSave = iConfig.getParameter<ToSave> ("toPut");
57  for (ToSave::const_iterator it = toSave.begin (); it != toSave.end (); it++)
58  {
59  std::string record = it->getParameter<std::string> ("record");
60  std::string type = it->getParameter<std::string> ("type");
61  m_recordTypes.push_back( record + "@" + type ) ;
62  }
63 }
64 
65 
67 {
68 
69  // do anything here that needs to be done at desctruction time
70  // (e.g. close files, deallocate resources etc.)
71 
72 }
73 
74 
75 //
76 // member functions
77 //
78 
79 // ------------ method called to for each event ------------
80 void
82 {
83  using namespace edm;
84 
85  // Get L1TriggerKeyList
86  L1TriggerKeyList keyList ;
87  l1t::DataWriter dataWriter ;
88  if( !dataWriter.fillLastTriggerKeyList( keyList ) )
89  {
90  edm::LogError( "L1-O2O" )
91  << "Problem getting last L1TriggerKeyList" ;
92  }
93 
94  unsigned long long run = iEvent.id().run() ;
95 
96  L1TriggerKey::RecordToKey recordTypeToKeyMap ;
97 
98  bool triggerKeyIOVUpdated = true ;
99 
100  // Start log string, convert run number into string
101  std::stringstream ss ;
102  ss << run ;
103  std::string log = "KEYLOG runNumber=" + ss.str() ;
104  bool logRecords = true ;
105 
106  if( !m_ignoreTriggerKey )
107  {
108  if( !m_tscKey.empty() )
109  {
110  edm::LogVerbatim( "L1-O2O" )
111  << "Object key for L1TriggerKey@L1TriggerKeyRcd: "
112  << m_tscKey ;
113 
114  // Use TSC key and L1TriggerKeyList to find next run's
115  // L1TriggerKey token
116  std::string keyToken = keyList.token( m_tscKey ) ;
117 
118  // Update IOV sequence for this token with since-time = new run
119  triggerKeyIOVUpdated =
120  m_writer.updateIOV( "L1TriggerKeyRcd", keyToken, run, m_logTransactions ) ;
121 
122  // Read current L1TriggerKey directly from ORCON using token
123  L1TriggerKey key ;
124  m_writer.readObject( keyToken, key ) ;
125 
126  recordTypeToKeyMap = key.recordToKeyMap() ;
127 
128  // Replace spaces in key with ?s. Do reverse substitution when
129  // making L1TriggerKey.
130  std::string tmpKey = m_tscKey ;
131  replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
132  log += " tscKey=" + tmpKey ;
133  logRecords = false ;
134  }
135  else
136  {
137  // For use with Run Settings, no corresponding L1TrigerKey in
138  // ORCON.
139 
140  // Get L1TriggerKey from EventSetup
142  iSetup.get< L1TriggerKeyRcd >().get( esKey ) ;
143 
144  recordTypeToKeyMap = esKey->recordToKeyMap() ;
145  }
146  }
147  else
148  {
149  std::vector<std::string >::const_iterator
150  recordTypeItr = m_recordTypes.begin() ;
151  std::vector<std::string >::const_iterator
152  recordTypeEnd = m_recordTypes.end() ;
153 
154  for( ; recordTypeItr != recordTypeEnd ; ++recordTypeItr )
155  {
156  recordTypeToKeyMap.insert(
157  std::make_pair( *recordTypeItr, m_tscKey ) ) ;
158  }
159  }
160 
161  // If L1TriggerKey IOV was already up to date, then so are all its
162  // sub-records.
163  bool throwException = false ;
164 
165  if( triggerKeyIOVUpdated )
166  {
167  // Loop over record@type in L1TriggerKey
168  L1TriggerKey::RecordToKey::const_iterator itr =
169  recordTypeToKeyMap.begin() ;
170  L1TriggerKey::RecordToKey::const_iterator end =
171  recordTypeToKeyMap.end() ;
172 
173  for( ; itr != end ; ++itr )
174  {
175  std::string recordType = itr->first ;
176  std::string objectKey = itr->second ;
177 
178  std::string recordName( recordType,
179  0, recordType.find_first_of("@") ) ;
180 
181  if( logRecords )
182  {
183  // Replace spaces in key with ?s. Do reverse substitution when
184  // making L1TriggerKey.
185  std::string tmpKey = objectKey ;
186  replace( tmpKey.begin(), tmpKey.end(), ' ', '?' ) ;
187  log += " " + recordName + "Key=" + tmpKey ;
188  }
189 
190  // Do nothing if object key is null.
191  if( objectKey == L1TriggerKey::kNullKey )
192  {
193  edm::LogVerbatim( "L1-O2O" )
194  << "L1CondDBIOVWriter: null object key for "
195  << recordType << "; skipping this record." ;
196  }
197  else
198  {
199  // Find payload token
200  edm::LogVerbatim( "L1-O2O" )
201  << "Object key for "
202  << recordType << ": " << objectKey ;
203 
204  std::string payloadToken = keyList.token( recordType,
205  objectKey ) ;
206  if( payloadToken.empty() )
207  {
208  edm::LogVerbatim( "L1-O2O" )
209  << "L1CondDBIOVWriter: empty payload token for " +
210  recordType + ", key " + objectKey ;
211 
212  throwException = true ;
213  }
214  else
215  {
217  payloadToken,
218  run,
220  }
221  }
222  }
223  }
224 
225  if( m_logKeys )
226  {
227  edm::LogVerbatim( "L1-O2O" ) << log ;
228  }
229 
230  if( throwException )
231  {
232  throw cond::Exception( "L1CondDBIOVWriter: empty payload tokens" ) ;
233  }
234 }
235 
236 
237 // ------------ method called once each job just before starting event loop ------------
238 void
240 {
241 }
242 
243 // ------------ method called once each job just after ending the event loop ------------
244 void
246 }
247 
248 //define this as a plug-in
249 //DEFINE_FWK_MODULE(L1CondDBIOVWriter);
RunNumber_t run() const
Definition: EventID.h:42
type
Definition: HCALResponse.h:22
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:11
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
Log< T >::type log(const T &t)
Definition: Log.h:22
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:92
virtual void beginJob()