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