CMS 3D CMS Logo

L1CondDBPayloadWriterExt.cc
Go to the documentation of this file.
2 
7 
8 #include <memory>
9 
17 
18 using DataWriterExtPtr = std::unique_ptr<l1t::DataWriterExt>;
19 using RecordToWriterMap = std::map<std::string, DataWriterExtPtr>;
20 
22 public:
24  ~L1CondDBPayloadWriterExt() override;
25 
26 private:
27  void beginJob() override;
28  void analyze(const edm::Event&, const edm::EventSetup&) override;
29  void endJob() override;
30 
31  // ----------member data ---------------------------
33  // std::string m_tag ; // tag is known by PoolDBOutputService
34 
35  // set to false to write config data without valid TSC key
37 
38  // set to false to write config data only
40 
41  // substitute new payload tokens for existing keys in L1TriggerKeyListExt
43 
45 
46  // if true, do not retrieve L1TriggerKeyListExt from EventSetup
48 
49  // Token to access L1TriggerKeyExt data in the event setup
51 };
52 
54  : m_writeL1TriggerKeyExt(iConfig.getParameter<bool>("writeL1TriggerKeyExt")),
55  m_writeConfigData(iConfig.getParameter<bool>("writeConfigData")),
56  m_overwriteKeys(iConfig.getParameter<bool>("overwriteKeys")),
57  m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
58  m_newL1TriggerKeyListExt(iConfig.getParameter<bool>("newL1TriggerKeyListExt")),
59  theL1TriggerKeyExtToken_(esConsumes()) {
60  auto cc = consumesCollector();
61  for (const auto& sysWriter : iConfig.getParameter<std::vector<std::string>>("sysWriters")) {
62  //construct writer
63  DataWriterExtPtr writer = std::make_unique<l1t::DataWriterExt>(sysWriter);
64  writer->getWriter()->setToken(cc);
65  m_rcdToWriterMap[sysWriter] = std::move(writer); //the sysWriter holds info in 'rcd@prod' format
66  }
67 }
68 
70  // do anything here that needs to be done at desctruction time
71  // (e.g. close files, deallocate resources etc.)
72 }
73 
74 // ------------ method called to for each event ------------
76  using namespace edm;
77 
78  // Get L1TriggerKeyListExt and make a copy
79  L1TriggerKeyListExt oldKeyList;
80  l1t::DataWriterExt& m_writer = *m_rcdToWriterMap.at("L1TriggerKeyExtRcd@L1TriggerKeyExt");
81 
82  if (not(m_newL1TriggerKeyListExt or m_writer.fillLastTriggerKeyList(oldKeyList)))
83  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
84 
85  L1TriggerKeyListExt* keyList = nullptr;
86 
87  // Write L1TriggerKeyExt to ORCON with no IOV
90  // Before calling writePayload(), check if TSC key is already in
91  // L1TriggerKeyListExt. writePayload() will not catch this situation in
92  // the case of dummy configurations.
93  bool triggerKeyOK = true;
94  try {
95  // Get L1TriggerKeyExt
97  if (!m_overwriteKeys) {
98  triggerKeyOK = oldKeyList.token(key.tscKey()).empty();
99  }
100  } catch (l1t::DataAlreadyPresentException& ex) {
101  triggerKeyOK = false;
102  edm::LogVerbatim("L1-O2O") << ex.what();
103  }
104 
105  if (triggerKeyOK and m_writeL1TriggerKeyExt) {
106  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyExtRcd@L1TriggerKeyExt: " << key.tscKey()
107  << " (about to run writePayload)";
108  token = m_writer.writePayload(iSetup);
109  }
110 
111  // If L1TriggerKeyExt is invalid (empty), then all configuration data is already in DB
112  // m_writeL1TriggerKeyExt the naming is misleading,
113  // the bool is used to say to the module whether it runs or not to update a L1TriggerKeyExtRcd
114  // (so if no payload for L1TriggerKeyExtRcd AND you run for updating L1TriggerKeyExtRcd ==> you have nothing to update)
115  if (token.empty() and m_writeL1TriggerKeyExt) {
116  edm::LogInfo("L1CondDBPayloadWriterExt::analyze") << " token = " << token;
117  return;
118  }
119 
120  // Record token in L1TriggerKeyListExt
122  keyList = new L1TriggerKeyListExt(oldKeyList);
123  if (not keyList->addKey(key.tscKey(), token, m_overwriteKeys))
124  throw cond::Exception("L1CondDBPayloadWriter: TSC key " + key.tscKey() + " already in L1TriggerKeyListExt");
125  }
126 
127  if (not m_writeConfigData) {
128  // Write L1TriggerKeyListExt to ORCON
129  if (keyList)
130  m_writer.writeKeyList(keyList, 0, m_logTransactions);
131  return;
132  }
133 
134  // Loop over record@type in L1TriggerKeyExt
135  // (as before make writers, try to write payload and if needed handle exceptions)
136 
137  // this is not needed maps have implemented begin and end methods for their iterators
138  // L1TriggerKeyExt::RecordToKey::const_iterator it = key.recordToKeyMap().begin();
139  // L1TriggerKeyExt::RecordToKey::const_iterator end = key.recordToKeyMap().end();
140  // for (; it != end; ++it) {
141 
142  bool throwException = false;
143  for (const auto& it : key.recordToKeyMap()) {
144  // If there isn't any WriterProxyT constructed for this rcd, continue
145  // (the missing rcds are left out for a reason - those are static that throw exceptions that cannot be handled in 12_3)
146  if (m_rcdToWriterMap.find(it.first) == m_rcdToWriterMap.end())
147  continue;
148 
149  // Do nothing if object key is null.
150  // (Panos) this might not be working as the "empty" keys are L1TriggerKeyExt::kEmptyKey (std::string(""))
151  if (it.second == L1TriggerKeyExt::kNullKey) {
152  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: null object key for " << it.first
153  << "; skipping this record.";
154  continue;
155  }
156 
157  // Check key is new before writing
158  if (oldKeyList.token(it.first, it.second).empty() || m_overwriteKeys) {
159  // Write data to ORCON with no IOV
160  if (!oldKeyList.token(it.first, it.second).empty()) {
161  edm::LogVerbatim("L1-O2O") << "*** Overwriting payload: object key for " << it.first << ": " << it.second;
162  } else {
163  edm::LogVerbatim("L1-O2O") << "object key for " << it.first << ": " << it.second;
164  }
165 
166  try {
167  edm::LogVerbatim("L1-O2O") << "about to run writePayload for " << it.first;
168  token = m_rcdToWriterMap.at(it.first)->writePayload(iSetup);
169  } catch (l1t::DataInvalidException& ex) {
170  edm::LogVerbatim("L1-O2O") << ex.what() << " Skipping to next record.";
171  throwException = true;
172  continue;
173  }
174 
175  if (!token.empty()) {
176  // Record token in L1TriggerKeyListExt
177  if (!keyList)
178  keyList = new L1TriggerKeyListExt(oldKeyList);
179  // The following should never happen because of the check
180  // above, but just in case....
181  if (!(keyList->addKey(it.first, it.second, token, m_overwriteKeys)))
182  throw cond::Exception("L1CondDBPayloadWriter")
183  << "subsystem key " << it.second << " for " << it.first << " already in L1TriggerKeyListExt";
184  }
185 
186  } else
187  edm::LogVerbatim("L1-O2O") << "L1CondDBPayloadWriter: object key " << it.second << " for " << it.first
188  << " already in L1TriggerKeyListExt";
189 
190  } // for rcds from keys
191 
192  if (keyList) // Write L1TriggerKeyListExt to ORCON
193  m_writer.writeKeyList(keyList, 0, m_logTransactions);
194 
195  if (throwException)
196  throw l1t::DataInvalidException("Payload problem found.");
197 }
198 
199 // ------------ method called once each job just before starting event loop ------------
201 
202 // ------------ method called once each job just after ending the event loop ------------
204 
205 //define this as a plug-in
persistency::Exception Exception
Definition: Exception.h:25
void analyze(const edm::Event &, const edm::EventSetup &) override
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
static const std::string kNullKey
Log< level::Error, false > LogError
void writeKeyList(L1TriggerKeyListExt *keyList, edm::RunNumber_t sinceRun=0, bool logTransactions=false)
int iEvent
Definition: GenABIO.cc:224
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::unique_ptr< l1t::DataWriterExt > DataWriterExtPtr
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1CondDBPayloadWriterExt(const edm::ParameterSet &)
std::map< std::string, DataWriterExtPtr > RecordToWriterMap
Log< level::Info, false > LogInfo
std::string token(const std::string &tscKey) const
HLT enums.
bool addKey(const std::string &tscKey, const std::string &payloadToken, bool overwriteKey=false)
std::string writePayload(const edm::EventSetup &setup)
char const * what() const noexcept override
Definition: Exception.cc:103
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
def move(src, dest)
Definition: eostools.py:511
edm::ESGetToken< L1TriggerKeyExt, L1TriggerKeyExtRcd > theL1TriggerKeyExtToken_