CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 // system include files
21 
22 // user include files
24 
26 
31 
32 //
33 // class declaration
34 //
35 
36 //
37 // constants, enums and typedefs
38 //
39 
40 //
41 // constructors and destructor
42 //
44  : m_writeL1TriggerKey(iConfig.getParameter<bool>("writeL1TriggerKey")),
45  m_writeConfigData(iConfig.getParameter<bool>("writeConfigData")),
46  m_overwriteKeys(iConfig.getParameter<bool>("overwriteKeys")),
47  m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
48  m_newL1TriggerKeyList(iConfig.getParameter<bool>("newL1TriggerKeyList")) {
49  //now do what ever initialization is needed
51 }
52 
54  // do anything here that needs to be done at desctruction time
55  // (e.g. close files, deallocate resources etc.)
56 }
57 
58 //
59 // member functions
60 //
61 
62 // ------------ method called to for each event ------------
64  using namespace edm;
65 
66  // Get L1TriggerKeyList and make a copy
67  L1TriggerKeyList oldKeyList;
68 
69  if (!m_newL1TriggerKeyList) {
70  if (!m_writer.fillLastTriggerKeyList(oldKeyList)) {
71  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
72  }
73  }
74 
75  L1TriggerKeyList* keyList = nullptr;
76 
77  // Write L1TriggerKey to ORCON with no IOV
80 
81  // Before calling writePayload(), check if TSC key is already in
82  // L1TriggerKeyList. writePayload() will not catch this situation in
83  // the case of dummy configurations.
84  bool triggerKeyOK = true;
85  try {
86  // Get L1TriggerKey
88 
89  if (!m_overwriteKeys) {
90  triggerKeyOK = oldKeyList.token(key->tscKey()).empty();
91  }
92  } catch (l1t::DataAlreadyPresentException& ex) {
93  triggerKeyOK = false;
94  edm::LogVerbatim("L1-O2O") << ex.what();
95  }
96 
97  if (triggerKeyOK && m_writeL1TriggerKey) {
98  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyRcd@L1TriggerKey: " << key->tscKey();
99  token = m_writer.writePayload(iSetup, "L1TriggerKeyRcd@L1TriggerKey");
100  }
101 
102  // If L1TriggerKey is invalid, then all configuration data is already in DB
103  bool throwException = false;
104 
105  if (!token.empty() || !m_writeL1TriggerKey) {
106  // Record token in L1TriggerKeyList
107  if (m_writeL1TriggerKey) {
108  keyList = new L1TriggerKeyList(oldKeyList);
109  if (!(keyList->addKey(key->tscKey(), token, m_overwriteKeys))) {
110  throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key->tscKey() + " already in L1TriggerKeyList");
111  }
112  }
113 
114  if (m_writeConfigData) {
115  // Loop over record@type in L1TriggerKey
116  L1TriggerKey::RecordToKey::const_iterator it = key->recordToKeyMap().begin();
117  L1TriggerKey::RecordToKey::const_iterator end = key->recordToKeyMap().end();
118 
119  for (; it != end; ++it) {
120  // Do nothing if object key is null.
121  if (it->second == L1TriggerKey::kNullKey) {
122  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: null object key for " << it->first
123  << "; skipping this record.";
124  } else {
125  // Check key is new before writing
126  if (oldKeyList.token(it->first, it->second).empty() || m_overwriteKeys) {
127  // Write data to ORCON with no IOV
128  if (!oldKeyList.token(it->first, it->second).empty()) {
129  edm::LogVerbatim("L1-O2O") << "*** Overwriting payload: object key for " << it->first << ": "
130  << it->second;
131  } else {
132  edm::LogVerbatim("L1-O2O") << "object key for " << it->first << ": " << it->second;
133  }
134 
135  try {
136  token = m_writer.writePayload(iSetup, it->first);
137  } catch (l1t::DataInvalidException& ex) {
138  edm::LogVerbatim("L1-O2O") << ex.what() << " Skipping to next record.";
139 
140  throwException = true;
141 
142  continue;
143  }
144 
145  if (!token.empty()) {
146  // Record token in L1TriggerKeyList
147  if (!keyList) {
148  keyList = new L1TriggerKeyList(oldKeyList);
149  }
150 
151  if (!(keyList->addKey(it->first, it->second, token, m_overwriteKeys))) {
152  // This should never happen because of the check
153  // above, but just in case....
154  throw cond::Exception("L1CondDBPayloadWriter: subsystem key " + it->second + " for " + it->first +
155  " already in L1TriggerKeyList");
156  }
157  }
158  } else {
159  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: object key " << it->second << " for " << it->first
160  << " already in L1TriggerKeyList";
161  }
162  }
163  }
164  }
165  }
166 
167  if (keyList) {
168  // Write L1TriggerKeyList to ORCON
170  }
171 
172  if (throwException) {
173  throw l1t::DataInvalidException("Payload problem found.");
174  }
175 }
176 
177 // ------------ method called once each job just before starting event loop ------------
179 
180 // ------------ method called once each job just after ending the event loop ------------
182 
183 //define this as a plug-in
184 //DEFINE_FWK_MODULE(L1CondDBPayloadWriter);
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
static const std::string kNullKey
Definition: L1TriggerKey.h:30
Log< level::Error, false > LogError
int iEvent
Definition: GenABIO.cc:224
tuple key
prepare the HTCondor submission files and eventually submit them
char const * what() const noexceptoverride
Definition: Exception.cc:103
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:15
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:49
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:147
void analyze(const edm::Event &, const edm::EventSetup &) override
L1CondDBPayloadWriter(const edm::ParameterSet &)
string end
Definition: dataset.py:937
edm::ESGetToken< L1TriggerKey, L1TriggerKeyRcd > l1TriggerKeyToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12