CMS 3D CMS Logo

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  //now do what ever initialization is needed
17 }
18 
20  // do anything here that needs to be done at desctruction time
21  // (e.g. close files, deallocate resources etc.)
22 }
23 
24 // ------------ method called to for each event ------------
26  using namespace edm;
27 
28  // Get L1TriggerKeyListExt and make a copy
29  L1TriggerKeyListExt oldKeyList;
30 
32  if (!m_writer.fillLastTriggerKeyList(oldKeyList)) {
33  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
34  }
35  }
36 
37  L1TriggerKeyListExt* keyList = nullptr;
38 
39  // Write L1TriggerKeyExt to ORCON with no IOV
42 
43  // Before calling writePayload(), check if TSC key is already in
44  // L1TriggerKeyListExt. writePayload() will not catch this situation in
45  // the case of dummy configurations.
46  bool triggerKeyOK = true;
47  try {
48  // Get L1TriggerKeyExt
49  iSetup.get<L1TriggerKeyExtRcd>().get(key);
50 
51  if (!m_overwriteKeys) {
52  triggerKeyOK = oldKeyList.token(key->tscKey()).empty();
53  }
54  } catch (l1t::DataAlreadyPresentException& ex) {
55  triggerKeyOK = false;
56  edm::LogVerbatim("L1-O2O") << ex.what();
57  }
58 
59  if (triggerKeyOK && m_writeL1TriggerKeyExt) {
60  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyExtRcd@L1TriggerKeyExt: " << key->tscKey();
61  token = m_writer.writePayload(iSetup, "L1TriggerKeyExtRcd@L1TriggerKeyExt");
62  }
63 
64  // If L1TriggerKeyExt is invalid, then all configuration data is already in DB
65  bool throwException = false;
66 
67  if (!token.empty() || !m_writeL1TriggerKeyExt) {
68  // Record token in L1TriggerKeyListExt
70  keyList = new L1TriggerKeyListExt(oldKeyList);
71  if (!(keyList->addKey(key->tscKey(), token, m_overwriteKeys))) {
72  throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key->tscKey() + " already in L1TriggerKeyListExt");
73  }
74  }
75 
76  if (m_writeConfigData) {
77  // Loop over record@type in L1TriggerKeyExt
78  L1TriggerKeyExt::RecordToKey::const_iterator it = key->recordToKeyMap().begin();
79  L1TriggerKeyExt::RecordToKey::const_iterator end = key->recordToKeyMap().end();
80 
81  for (; it != end; ++it) {
82  // Do nothing if object key is null.
83  if (it->second == L1TriggerKeyExt::kNullKey) {
84  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: null object key for " << it->first
85  << "; skipping this record.";
86  } else {
87  // Check key is new before writing
88  if (oldKeyList.token(it->first, it->second).empty() || m_overwriteKeys) {
89  // Write data to ORCON with no IOV
90  if (!oldKeyList.token(it->first, it->second).empty()) {
91  edm::LogVerbatim("L1-O2O") << "*** Overwriting payload: object key for " << it->first << ": "
92  << it->second;
93  } else {
94  edm::LogVerbatim("L1-O2O") << "object key for " << it->first << ": " << it->second;
95  }
96 
97  try {
98  token = m_writer.writePayload(iSetup, it->first);
99  } catch (l1t::DataInvalidException& ex) {
100  edm::LogVerbatim("L1-O2O") << ex.what() << " Skipping to next record.";
101 
102  throwException = true;
103 
104  continue;
105  }
106 
107  if (!token.empty()) {
108  // Record token in L1TriggerKeyListExt
109  if (!keyList) {
110  keyList = new L1TriggerKeyListExt(oldKeyList);
111  }
112 
113  if (!(keyList->addKey(it->first, it->second, token, m_overwriteKeys))) {
114  // This should never happen because of the check
115  // above, but just in case....
116  throw cond::Exception("L1CondDBPayloadWriter: subsystem key " + it->second + " for " + it->first +
117  " already in L1TriggerKeyListExt");
118  }
119  }
120  } else {
121  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: object key " << it->second << " for " << it->first
122  << " already in L1TriggerKeyListExt";
123  }
124  }
125  }
126  }
127  }
128 
129  if (keyList) {
130  // Write L1TriggerKeyListExt to ORCON
132  }
133 
134  if (throwException) {
135  throw l1t::DataInvalidException("Payload problem found.");
136  }
137 }
138 
139 // ------------ method called once each job just before starting event loop ------------
141 
142 // ------------ method called once each job just after ending the event loop ------------
144 
145 //define this as a plug-in
146 //DEFINE_FWK_MODULE(L1CondDBPayloadWriterExt);
persistency::Exception Exception
Definition: Exception.h:25
void analyze(const edm::Event &, const edm::EventSetup &) override
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
static const std::string kNullKey
char const * what() const override
Definition: Exception.cc:103
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
const RecordToKey & recordToKeyMap() const
int iEvent
Definition: GenABIO.cc:224
#define end
Definition: vmac.h:39
L1CondDBPayloadWriterExt(const edm::ParameterSet &)
std::string writePayload(const edm::EventSetup &setup, const std::string &recordType)
HLT enums.
T get() const
Definition: EventSetup.h:73
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)
const std::string & tscKey() const
std::string token(const std::string &tscKey) const
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12