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  l1TriggerKeyToken_(esConsumes()) {}
50 
52  // do anything here that needs to be done at desctruction time
53  // (e.g. close files, deallocate resources etc.)
54 }
55 
56 //
57 // member functions
58 //
59 
60 // ------------ method called to for each event ------------
62  using namespace edm;
63 
64  // Get L1TriggerKeyList and make a copy
65  L1TriggerKeyList oldKeyList;
66 
67  if (!m_newL1TriggerKeyList) {
68  if (!m_writer.fillLastTriggerKeyList(oldKeyList)) {
69  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
70  }
71  }
72 
73  L1TriggerKeyList* keyList = nullptr;
74 
75  // Write L1TriggerKey to ORCON with no IOV
78 
79  // Before calling writePayload(), check if TSC key is already in
80  // L1TriggerKeyList. writePayload() will not catch this situation in
81  // the case of dummy configurations.
82  bool triggerKeyOK = true;
83  try {
84  // Get L1TriggerKey
86 
87  if (!m_overwriteKeys) {
88  triggerKeyOK = oldKeyList.token(key->tscKey()).empty();
89  }
90  } catch (l1t::DataAlreadyPresentException& ex) {
91  triggerKeyOK = false;
92  edm::LogVerbatim("L1-O2O") << ex.what();
93  }
94 
95  if (triggerKeyOK && m_writeL1TriggerKey) {
96  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyRcd@L1TriggerKey: " << key->tscKey();
97  token = m_writer.writePayload(iSetup, "L1TriggerKeyRcd@L1TriggerKey");
98  }
99 
100  // If L1TriggerKey is invalid, then all configuration data is already in DB
101  bool throwException = false;
102 
103  if (!token.empty() || !m_writeL1TriggerKey) {
104  // Record token in L1TriggerKeyList
105  if (m_writeL1TriggerKey) {
106  keyList = new L1TriggerKeyList(oldKeyList);
107  if (!(keyList->addKey(key->tscKey(), token, m_overwriteKeys))) {
108  throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key->tscKey() + " already in L1TriggerKeyList");
109  }
110  }
111 
112  if (m_writeConfigData) {
113  // Loop over record@type in L1TriggerKey
114  L1TriggerKey::RecordToKey::const_iterator it = key->recordToKeyMap().begin();
115  L1TriggerKey::RecordToKey::const_iterator end = key->recordToKeyMap().end();
116 
117  for (; it != end; ++it) {
118  // Do nothing if object key is null.
119  if (it->second == L1TriggerKey::kNullKey) {
120  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: null object key for " << it->first
121  << "; skipping this record.";
122  } else {
123  // Check key is new before writing
124  if (oldKeyList.token(it->first, it->second).empty() || m_overwriteKeys) {
125  // Write data to ORCON with no IOV
126  if (!oldKeyList.token(it->first, it->second).empty()) {
127  edm::LogVerbatim("L1-O2O") << "*** Overwriting payload: object key for " << it->first << ": "
128  << it->second;
129  } else {
130  edm::LogVerbatim("L1-O2O") << "object key for " << it->first << ": " << it->second;
131  }
132 
133  try {
134  token = m_writer.writePayload(iSetup, it->first);
135  } catch (l1t::DataInvalidException& ex) {
136  edm::LogVerbatim("L1-O2O") << ex.what() << " Skipping to next record.";
137 
138  throwException = true;
139 
140  continue;
141  }
142 
143  if (!token.empty()) {
144  // Record token in L1TriggerKeyList
145  if (!keyList) {
146  keyList = new L1TriggerKeyList(oldKeyList);
147  }
148 
149  if (!(keyList->addKey(it->first, it->second, token, m_overwriteKeys))) {
150  // This should never happen because of the check
151  // above, but just in case....
152  throw cond::Exception("L1CondDBPayloadWriter: subsystem key " + it->second + " for " + it->first +
153  " already in L1TriggerKeyList");
154  }
155  }
156  } else {
157  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: object key " << it->second << " for " << it->first
158  << " already in L1TriggerKeyList";
159  }
160  }
161  }
162  }
163  }
164 
165  if (keyList) {
166  // Write L1TriggerKeyList to ORCON
168  }
169 
170  if (throwException) {
171  throw l1t::DataInvalidException("Payload problem found.");
172  }
173 }
174 
175 // ------------ method called once each job just before starting event loop ------------
177 
178 // ------------ method called once each job just after ending the event loop ------------
180 
181 //define this as a plug-in
182 //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:151
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12