test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1CondDBPayloadWriterExt.cc
Go to the documentation of this file.
2 
4 
9 
11  : m_writeL1TriggerKeyExt( iConfig.getParameter< bool >( "writeL1TriggerKeyExt" )),
12  m_writeConfigData( iConfig.getParameter< bool >( "writeConfigData" ) ),
13  m_overwriteKeys( iConfig.getParameter< bool >( "overwriteKeys" ) ),
14  m_logTransactions( iConfig.getParameter<bool>( "logTransactions" ) ),
15  m_newL1TriggerKeyListExt( iConfig.getParameter< bool >( "newL1TriggerKeyListExt" ) )
16 {
17  //now do what ever initialization is needed
18 
19 }
20 
21 
23 {
24 
25  // do anything here that needs to be done at desctruction time
26  // (e.g. close files, deallocate resources etc.)
27 
28 }
29 
30 
31 // ------------ method called to for each event ------------
32 void
34  const edm::EventSetup& iSetup)
35 {
36  using namespace edm;
37 
38  // Get L1TriggerKeyListExt and make a copy
39  L1TriggerKeyListExt oldKeyList ;
40 
42  {
43  if( !m_writer.fillLastTriggerKeyList( oldKeyList ) )
44  {
45  edm::LogError( "L1-O2O" )
46  << "Problem getting last L1TriggerKeyListExt" ;
47  }
48  }
49 
50  L1TriggerKeyListExt* keyList = 0 ;
51 
52  // Write L1TriggerKeyExt to ORCON with no IOV
55 
56  // Before calling writePayload(), check if TSC key is already in
57  // L1TriggerKeyListExt. writePayload() will not catch this situation in
58  // the case of dummy configurations.
59  bool triggerKeyOK = true ;
60  try
61  {
62  // Get L1TriggerKeyExt
63  iSetup.get< L1TriggerKeyExtRcd >().get( key ) ;
64 
65  if( !m_overwriteKeys )
66  {
67  triggerKeyOK = oldKeyList.token( key->tscKey() ) == "" ;
68  }
69  }
71  {
72  triggerKeyOK = false ;
73  edm::LogVerbatim( "L1-O2O" ) << ex.what() ;
74  }
75 
76  if( triggerKeyOK && m_writeL1TriggerKeyExt )
77  {
78  edm::LogVerbatim( "L1-O2O" )
79  << "Object key for L1TriggerKeyExtRcd@L1TriggerKeyExt: "
80  << key->tscKey() ;
81  token = m_writer.writePayload( iSetup,
82  "L1TriggerKeyExtRcd@L1TriggerKeyExt" ) ;
83  }
84 
85  // If L1TriggerKeyExt is invalid, then all configuration data is already in DB
86  bool throwException = false ;
87 
88  if( !token.empty() || !m_writeL1TriggerKeyExt )
89  {
90  // Record token in L1TriggerKeyListExt
92  {
93  keyList = new L1TriggerKeyListExt( oldKeyList ) ;
94  if( !( keyList->addKey( key->tscKey(),
95  token,
96  m_overwriteKeys ) ) )
97  {
98  throw cond::Exception( "L1CondDBPayloadWriter: TSC key "
99  + key->tscKey()
100  + " already in L1TriggerKeyListExt" ) ;
101  }
102  }
103 
104  if( m_writeConfigData )
105  {
106  // Loop over record@type in L1TriggerKeyExt
107  L1TriggerKeyExt::RecordToKey::const_iterator it =
108  key->recordToKeyMap().begin() ;
109  L1TriggerKeyExt::RecordToKey::const_iterator end =
110  key->recordToKeyMap().end() ;
111 
112  for( ; it != end ; ++it )
113  {
114  // Do nothing if object key is null.
115  if( it->second == L1TriggerKeyExt::kNullKey )
116  {
117  edm::LogVerbatim( "L1-O2O" )
118  << "L1CondDBPayloadWriter: null object key for "
119  << it->first << "; skipping this record." ;
120  }
121  else
122  {
123  // Check key is new before writing
124  if( oldKeyList.token( it->first, it->second ) == "" ||
126  {
127  // Write data to ORCON with no IOV
128  if( oldKeyList.token( it->first, it->second ) != "" )
129  {
130  edm::LogVerbatim( "L1-O2O" )
131  << "*** Overwriting payload: object key for "
132  << it->first << ": " << it->second ;
133  }
134  else
135  {
136  edm::LogVerbatim( "L1-O2O" )
137  << "object key for "
138  << it->first << ": " << it->second ;
139  }
140 
141  try
142  {
143  token = m_writer.writePayload( iSetup, it->first ) ;
144  }
145  catch( l1t::DataInvalidException& ex )
146  {
147  edm::LogVerbatim( "L1-O2O" )
148  << ex.what()
149  << " Skipping to next record." ;
150 
151  throwException = true ;
152 
153  continue ;
154  }
155 
156  if( !token.empty() )
157  {
158  // Record token in L1TriggerKeyListExt
159  if( !keyList )
160  {
161  keyList = new L1TriggerKeyListExt( oldKeyList ) ;
162  }
163 
164  if( !( keyList->addKey( it->first,
165  it->second,
166  token,
167  m_overwriteKeys ) ) )
168  {
169  // This should never happen because of the check
170  // above, but just in case....
171  throw cond::Exception(
172  "L1CondDBPayloadWriter: subsystem key "
173  + it->second + " for " + it->first
174  + " already in L1TriggerKeyListExt" ) ;
175  }
176  }
177  }
178  else
179  {
180  edm::LogVerbatim( "L1-O2O" )
181  << "L1CondDBPayloadWriter: object key "
182  << it->second << " for " << it->first
183  << " already in L1TriggerKeyListExt" ;
184  }
185  }
186  }
187  }
188  }
189 
190  if( keyList )
191  {
192  // Write L1TriggerKeyListExt to ORCON
193  m_writer.writeKeyList( keyList, 0, m_logTransactions ) ;
194  }
195 
196  if( throwException )
197  {
198  throw l1t::DataInvalidException( "Payload problem found." ) ;
199  }
200 }
201 
202 
203 // ------------ method called once each job just before starting event loop ------------
204 void
206 {
207 }
208 
209 // ------------ method called once each job just after ending the event loop ------------
210 void
212 }
213 
214 //define this as a plug-in
215 //DEFINE_FWK_MODULE(L1CondDBPayloadWriterExt);
persistency::Exception Exception
Definition: Exception.h:25
virtual char const * what() const
Definition: Exception.cc:141
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
static const std::string kNullKey
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
int iEvent
Definition: GenABIO.cc:230
#define end
Definition: vmac.h:37
L1CondDBPayloadWriterExt(const edm::ParameterSet &)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
const T & get() const
Definition: EventSetup.h:56
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
volatile std::atomic< bool > shutdown_flag false
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14