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 // 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 // static data member definitions
42 //
43 
44 //
45 // constructors and destructor
46 //
48  : m_writeL1TriggerKey(iConfig.getParameter<bool>("writeL1TriggerKey")),
49  m_writeConfigData(iConfig.getParameter<bool>("writeConfigData")),
50  m_overwriteKeys(iConfig.getParameter<bool>("overwriteKeys")),
51  m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
52  m_newL1TriggerKeyList(iConfig.getParameter<bool>("newL1TriggerKeyList")) {
53  //now do what ever initialization is needed
54 }
55 
57  // do anything here that needs to be done at desctruction time
58  // (e.g. close files, deallocate resources etc.)
59 }
60 
61 //
62 // member functions
63 //
64 
65 // ------------ method called to for each event ------------
67  using namespace edm;
68 
69  // Get L1TriggerKeyList and make a copy
70  L1TriggerKeyList oldKeyList;
71 
72  if (!m_newL1TriggerKeyList) {
73  if (!m_writer.fillLastTriggerKeyList(oldKeyList)) {
74  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
75  }
76  }
77 
78  L1TriggerKeyList* keyList = nullptr;
79 
80  // Write L1TriggerKey to ORCON with no IOV
83 
84  // Before calling writePayload(), check if TSC key is already in
85  // L1TriggerKeyList. writePayload() will not catch this situation in
86  // the case of dummy configurations.
87  bool triggerKeyOK = true;
88  try {
89  // Get L1TriggerKey
90  iSetup.get<L1TriggerKeyRcd>().get(key);
91 
92  if (!m_overwriteKeys) {
93  triggerKeyOK = oldKeyList.token(key->tscKey()).empty();
94  }
95  } catch (l1t::DataAlreadyPresentException& ex) {
96  triggerKeyOK = false;
97  edm::LogVerbatim("L1-O2O") << ex.what();
98  }
99 
100  if (triggerKeyOK && m_writeL1TriggerKey) {
101  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyRcd@L1TriggerKey: " << key->tscKey();
102  token = m_writer.writePayload(iSetup, "L1TriggerKeyRcd@L1TriggerKey");
103  }
104 
105  // If L1TriggerKey is invalid, then all configuration data is already in DB
106  bool throwException = false;
107 
108  if (!token.empty() || !m_writeL1TriggerKey) {
109  // Record token in L1TriggerKeyList
110  if (m_writeL1TriggerKey) {
111  keyList = new L1TriggerKeyList(oldKeyList);
112  if (!(keyList->addKey(key->tscKey(), token, m_overwriteKeys))) {
113  throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key->tscKey() + " already in L1TriggerKeyList");
114  }
115  }
116 
117  if (m_writeConfigData) {
118  // Loop over record@type in L1TriggerKey
119  L1TriggerKey::RecordToKey::const_iterator it = key->recordToKeyMap().begin();
120  L1TriggerKey::RecordToKey::const_iterator end = key->recordToKeyMap().end();
121 
122  for (; it != end; ++it) {
123  // Do nothing if object key is null.
124  if (it->second == L1TriggerKey::kNullKey) {
125  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: null object key for " << it->first
126  << "; skipping this record.";
127  } else {
128  // Check key is new before writing
129  if (oldKeyList.token(it->first, it->second).empty() || m_overwriteKeys) {
130  // Write data to ORCON with no IOV
131  if (!oldKeyList.token(it->first, it->second).empty()) {
132  edm::LogVerbatim("L1-O2O") << "*** Overwriting payload: object key for " << it->first << ": "
133  << it->second;
134  } else {
135  edm::LogVerbatim("L1-O2O") << "object key for " << it->first << ": " << it->second;
136  }
137 
138  try {
139  token = m_writer.writePayload(iSetup, it->first);
140  } catch (l1t::DataInvalidException& ex) {
141  edm::LogVerbatim("L1-O2O") << ex.what() << " Skipping to next record.";
142 
143  throwException = true;
144 
145  continue;
146  }
147 
148  if (!token.empty()) {
149  // Record token in L1TriggerKeyList
150  if (!keyList) {
151  keyList = new L1TriggerKeyList(oldKeyList);
152  }
153 
154  if (!(keyList->addKey(it->first, it->second, token, m_overwriteKeys))) {
155  // This should never happen because of the check
156  // above, but just in case....
157  throw cond::Exception("L1CondDBPayloadWriter: subsystem key " + it->second + " for " + it->first +
158  " already in L1TriggerKeyList");
159  }
160  }
161  } else {
162  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: object key " << it->second << " for " << it->first
163  << " already in L1TriggerKeyList";
164  }
165  }
166  }
167  }
168  }
169 
170  if (keyList) {
171  // Write L1TriggerKeyList to ORCON
173  }
174 
175  if (throwException) {
176  throw l1t::DataInvalidException("Payload problem found.");
177  }
178 }
179 
180 // ------------ method called once each job just before starting event loop ------------
182 
183 // ------------ method called once each job just after ending the event loop ------------
185 
186 //define this as a plug-in
187 //DEFINE_FWK_MODULE(L1CondDBPayloadWriter);
L1CondDBPayloadWriter::m_logTransactions
bool m_logTransactions
Definition: L1CondDBPayloadWriter.h:61
electrons_cff.bool
bool
Definition: electrons_cff.py:372
MessageLogger.h
L1CondDBPayloadWriter::beginJob
void beginJob() override
Definition: L1CondDBPayloadWriter.cc:181
L1CondDBPayloadWriter::m_writeL1TriggerKey
bool m_writeL1TriggerKey
Definition: L1CondDBPayloadWriter.h:53
L1CondDBPayloadWriter.h
L1CondDBPayloadWriter::m_writeConfigData
bool m_writeConfigData
Definition: L1CondDBPayloadWriter.h:56
L1TriggerKeyRcd
Definition: L1TriggerKeyRcd.h:30
edm
HLT enums.
Definition: AlignableModifier.h:19
L1CondDBPayloadWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: L1CondDBPayloadWriter.cc:66
L1TriggerKeyList::addKey
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)
Definition: L1TriggerKeyList.cc:55
l1t::DataAlreadyPresentException
Definition: Exception.h:32
L1CondDBPayloadWriter::m_writer
l1t::DataWriter m_writer
Definition: L1CondDBPayloadWriter.h:49
cms::Exception::what
char const * what() const noexcept override
Definition: Exception.cc:103
l1t::DataInvalidException
Definition: Exception.h:51
end
#define end
Definition: vmac.h:39
L1TriggerKey::kNullKey
const static std::string kNullKey
Definition: L1TriggerKey.h:30
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
L1TriggerKey.h
L1CondDBPayloadWriter::L1CondDBPayloadWriter
L1CondDBPayloadWriter(const edm::ParameterSet &)
Definition: L1CondDBPayloadWriter.cc:47
l1t::DataWriter::writeKeyList
void writeKeyList(L1TriggerKeyList *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
Definition: DataWriter.cc:49
edm::ESHandle
Definition: DTSurvey.h:22
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1CondDBPayloadWriter::m_newL1TriggerKeyList
bool m_newL1TriggerKeyList
Definition: L1CondDBPayloadWriter.h:64
L1TriggerKeyList
Definition: L1TriggerKeyList.h:32
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
l1t::DataWriter::writePayload
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
Definition: DataWriter.cc:15
iEvent
int iEvent
Definition: GenABIO.cc:224
L1CondDBPayloadWriter::endJob
void endJob() override
Definition: L1CondDBPayloadWriter.cc:184
L1TriggerKeyList.h
cond::Exception
persistency::Exception Exception
Definition: Exception.h:25
edm::LogVerbatim
Definition: MessageLogger.h:297
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
L1TriggerKeyRcd.h
L1CondDBPayloadWriter::~L1CondDBPayloadWriter
~L1CondDBPayloadWriter() override
Definition: L1CondDBPayloadWriter.cc:56
L1CondDBPayloadWriter::m_overwriteKeys
bool m_overwriteKeys
Definition: L1CondDBPayloadWriter.h:59
l1t::DataWriter::fillLastTriggerKeyList
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:147
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
L1TriggerKeyList::token
std::string token(const std::string &tscKey) const
Definition: L1TriggerKeyList.cc:96
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
L1TriggerKeyListRcd.h
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316