CMS 3D CMS Logo

L1CondDBPayloadWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1CondDBPayloadWriter
4 // Class: L1CondDBPayloadWriter
5 //
13 //
14 // Original Author: Werner Man-Li Sun
15 // Created: Sun Mar 2 07:05:15 CET 2008
16 // $Id: L1CondDBPayloadWriter.cc,v 1.17 2010/02/09 21:52:35 wsun Exp $
17 //
18 //
19 
20 
21 // system include files
22 
23 // user include files
25 
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_writeL1TriggerKey( iConfig.getParameter< bool >( "writeL1TriggerKey" )),
50  m_writeConfigData( iConfig.getParameter< bool >( "writeConfigData" ) ),
51  m_overwriteKeys( iConfig.getParameter< bool >( "overwriteKeys" ) ),
52  m_logTransactions( iConfig.getParameter<bool>( "logTransactions" ) ),
53  m_newL1TriggerKeyList( iConfig.getParameter< bool >( "newL1TriggerKeyList" ) )
54 {
55  //now do what ever initialization is needed
56 
57 }
58 
59 
61 {
62 
63  // do anything here that needs to be done at desctruction time
64  // (e.g. close files, deallocate resources etc.)
65 
66 }
67 
68 
69 //
70 // member functions
71 //
72 
73 // ------------ method called to for each event ------------
74 void
76  const edm::EventSetup& iSetup)
77 {
78  using namespace edm;
79 
80  // Get L1TriggerKeyList and make a copy
81  L1TriggerKeyList oldKeyList ;
82 
84  {
85  if( !m_writer.fillLastTriggerKeyList( oldKeyList ) )
86  {
87  edm::LogError( "L1-O2O" )
88  << "Problem getting last L1TriggerKeyList" ;
89  }
90  }
91 
92  L1TriggerKeyList* keyList = nullptr ;
93 
94  // Write L1TriggerKey to ORCON with no IOV
95  std::string token ;
97 
98  // Before calling writePayload(), check if TSC key is already in
99  // L1TriggerKeyList. writePayload() will not catch this situation in
100  // the case of dummy configurations.
101  bool triggerKeyOK = true ;
102  try
103  {
104  // Get L1TriggerKey
105  iSetup.get< L1TriggerKeyRcd >().get( key ) ;
106 
107  if( !m_overwriteKeys )
108  {
109  triggerKeyOK = oldKeyList.token( key->tscKey() ) == "" ;
110  }
111  }
113  {
114  triggerKeyOK = false ;
115  edm::LogVerbatim( "L1-O2O" ) << ex.what() ;
116  }
117 
118  if( triggerKeyOK && m_writeL1TriggerKey )
119  {
120  edm::LogVerbatim( "L1-O2O" )
121  << "Object key for L1TriggerKeyRcd@L1TriggerKey: "
122  << key->tscKey() ;
123  token = m_writer.writePayload( iSetup,
124  "L1TriggerKeyRcd@L1TriggerKey" ) ;
125  }
126 
127  // If L1TriggerKey is invalid, then all configuration data is already in DB
128  bool throwException = false ;
129 
130  if( !token.empty() || !m_writeL1TriggerKey )
131  {
132  // Record token in L1TriggerKeyList
133  if( m_writeL1TriggerKey )
134  {
135  keyList = new L1TriggerKeyList( oldKeyList ) ;
136  if( !( keyList->addKey( key->tscKey(),
137  token,
138  m_overwriteKeys ) ) )
139  {
140  throw cond::Exception( "L1CondDBPayloadWriter: TSC key "
141  + key->tscKey()
142  + " already in L1TriggerKeyList" ) ;
143  }
144  }
145 
146  if( m_writeConfigData )
147  {
148  // Loop over record@type in L1TriggerKey
149  L1TriggerKey::RecordToKey::const_iterator it =
150  key->recordToKeyMap().begin() ;
151  L1TriggerKey::RecordToKey::const_iterator end =
152  key->recordToKeyMap().end() ;
153 
154  for( ; it != end ; ++it )
155  {
156  // Do nothing if object key is null.
157  if( it->second == L1TriggerKey::kNullKey )
158  {
159  edm::LogVerbatim( "L1-O2O" )
160  << "L1CondDBPayloadWriter: null object key for "
161  << it->first << "; skipping this record." ;
162  }
163  else
164  {
165  // Check key is new before writing
166  if( oldKeyList.token( it->first, it->second ) == "" ||
168  {
169  // Write data to ORCON with no IOV
170  if( oldKeyList.token( it->first, it->second ) != "" )
171  {
172  edm::LogVerbatim( "L1-O2O" )
173  << "*** Overwriting payload: object key for "
174  << it->first << ": " << it->second ;
175  }
176  else
177  {
178  edm::LogVerbatim( "L1-O2O" )
179  << "object key for "
180  << it->first << ": " << it->second ;
181  }
182 
183  try
184  {
185  token = m_writer.writePayload( iSetup, it->first ) ;
186  }
187  catch( l1t::DataInvalidException& ex )
188  {
189  edm::LogVerbatim( "L1-O2O" )
190  << ex.what()
191  << " Skipping to next record." ;
192 
193  throwException = true ;
194 
195  continue ;
196  }
197 
198  if( !token.empty() )
199  {
200  // Record token in L1TriggerKeyList
201  if( !keyList )
202  {
203  keyList = new L1TriggerKeyList( oldKeyList ) ;
204  }
205 
206  if( !( keyList->addKey( it->first,
207  it->second,
208  token,
209  m_overwriteKeys ) ) )
210  {
211  // This should never happen because of the check
212  // above, but just in case....
213  throw cond::Exception(
214  "L1CondDBPayloadWriter: subsystem key "
215  + it->second + " for " + it->first
216  + " already in L1TriggerKeyList" ) ;
217  }
218  }
219  }
220  else
221  {
222  edm::LogVerbatim( "L1-O2O" )
223  << "L1CondDBPayloadWriter: object key "
224  << it->second << " for " << it->first
225  << " already in L1TriggerKeyList" ;
226  }
227  }
228  }
229  }
230  }
231 
232  if( keyList )
233  {
234  // Write L1TriggerKeyList to ORCON
235  m_writer.writeKeyList( keyList, 0, m_logTransactions ) ;
236  }
237 
238  if( throwException )
239  {
240  throw l1t::DataInvalidException( "Payload problem found." ) ;
241  }
242 }
243 
244 
245 // ------------ method called once each job just before starting event loop ------------
246 void
248 {
249 }
250 
251 // ------------ method called once each job just after ending the event loop ------------
252 void
254 }
255 
256 //define this as a plug-in
257 //DEFINE_FWK_MODULE(L1CondDBPayloadWriter);
persistency::Exception Exception
Definition: Exception.h:25
static const std::string kNullKey
Definition: L1TriggerKey.h:42
#define nullptr
char const * what() const override
Definition: Exception.cc:103
int iEvent
Definition: GenABIO.cc:224
const RecordToKey & recordToKeyMap() const
Definition: L1TriggerKey.h:94
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:19
#define end
Definition: vmac.h:39
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:61
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:198
void analyze(const edm::Event &, const edm::EventSetup &) override
L1CondDBPayloadWriter(const edm::ParameterSet &)
std::string token(const std::string &tscKey) const
const std::string & tscKey() const
Definition: L1TriggerKey.h:87
HLT enums.
T get() const
Definition: EventSetup.h:71
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14