24 #include "RelationalAccess/ISessionProxy.h" 25 #include "RelationalAccess/ITransaction.h" 26 #include "RelationalAccess/ISchema.h" 27 #include "RelationalAccess/ITable.h" 28 #include "RelationalAccess/ICursor.h" 29 #include "RelationalAccess/IQuery.h" 30 #include "CoralBase/AttributeList.h" 31 #include "CoralBase/AttributeSpecification.h" 32 #include "CoralBase/Attribute.h" 49 : copyData(ps.getUntrackedParameter<
bool>(
"copyData",
true)),
50 minBrickId(ps.getUntrackedParameter<
int>(
"minBrick", 0)),
51 maxBrickId(ps.getUntrackedParameter<
int>(
"maxBrick", 999999999)),
52 minRunId(ps.getUntrackedParameter<
int>(
"minRun", 0)),
53 maxRunId(ps.getUntrackedParameter<
int>(
"maxRun", 999999999)),
55 onlineConnect(ps.getParameter<
std::
string>(
"onlineDB")),
57 onlineAuthSys(ps.getUntrackedParameter<
int>(
"onlineAuthSys", 1)),
58 brickContainer(ps.getParameter<
std::
string>(
"container")),
76 std::cout <<
"last configuration key already copied for run: " << last << std::endl;
78 std::vector<DTConfigKey> lastKey;
79 std::cout <<
"check for last " << std::endl;
88 std::cout <<
"get last payload" << std::endl;
90 std::cout <<
"get last full key" << std::endl;
91 lastKey = payload->fullKey();
93 std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
94 std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
95 while (keyIter != keyIend) {
111 std::cout <<
"check for new runs since " << lastRun << std::endl;
113 std::cout <<
"configure DbConnection" << std::endl;
118 std::cout <<
"create/open DbSession" << std::endl;
120 std::cout <<
"start transaction" << std::endl;
121 isession->transaction().start(
true);
126 std::cout <<
"get run config..." << std::endl;
127 std::map<int, std::vector<int>*> runMap;
128 std::map<int, std::vector<DTConfigKey>*> rhcMap;
129 coral::ITable& runHistoryTable =
isession->nominalSchema().tableHandle(
"RUNHISTORY");
130 std::unique_ptr<coral::IQuery> runHistoryQuery(runHistoryTable.newQuery());
131 runHistoryQuery->addToOutputList(
"RUN");
132 runHistoryQuery->addToOutputList(
"RHID");
133 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
134 while (runHistoryCursor.next()) {
135 const coral::AttributeList& row = runHistoryCursor.currentRow();
136 int runId = row[
"RUN"].data<
int>();
137 int rhcId =
static_cast<int>(row[
"RHID"].data<
int>());
139 if (static_cast<unsigned>(runId) <=
lastRun)
146 std::cout <<
"schedule config key copy for run " << runId <<
" ---> RHID " << rhcId << std::endl;
148 std::vector<int>* rhlPtr =
nullptr;
149 std::map<int, std::vector<int>*>::const_iterator runIter;
150 if ((runIter = runMap.find(runId)) != runMap.end())
151 rhlPtr = runIter->second;
153 runMap.insert(std::pair<
int, std::vector<int>*>(runId, rhlPtr =
new std::vector<int>));
155 rhlPtr->push_back(rhcId);
157 if (rhcMap.find(rhcId) == rhcMap.end())
158 rhcMap.insert(std::pair<
int, std::vector<DTConfigKey>*>(rhcId,
new std::vector<DTConfigKey>));
161 std::cout <<
"no new run found" << std::endl;
164 std::cout <<
"retrieve CCB map" << std::endl;
165 std::map<int, DTCCBId> ccbMap;
166 coral::ITable& ccbMapTable =
isession->nominalSchema().tableHandle(
"CCBMAP");
167 std::unique_ptr<coral::IQuery> ccbMapQuery(ccbMapTable.newQuery());
168 ccbMapQuery->addToOutputList(
"CCBID");
169 ccbMapQuery->addToOutputList(
"WHEEL");
170 ccbMapQuery->addToOutputList(
"SECTOR");
171 ccbMapQuery->addToOutputList(
"STATION");
172 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
173 while (ccbMapCursor.next()) {
174 const coral::AttributeList& row = ccbMapCursor.currentRow();
175 int ccb = row[
"CCBID"].data<
int>();
176 int wheel = row[
"WHEEL"].data<
int>();
177 int sector = row[
"SECTOR"].data<
int>();
178 int station = row[
"STATION"].data<
int>();
182 ccbId.sectorId = sector;
183 ccbMap.insert(std::pair<int, DTCCBId>(ccb, ccbId));
187 std::cout <<
"retrieve brick types" << std::endl;
188 std::map<int, int> bktMap;
189 coral::AttributeList emptyBindVariableList;
190 std::unique_ptr<coral::IQuery> brickTypeQuery(
isession->nominalSchema().newQuery());
191 brickTypeQuery->addToTableList(
"CFGBRICKS");
192 brickTypeQuery->addToTableList(
"BRKT2CSETT");
194 std::string bTypeCondition =
"CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
195 brickTypeQuery->addToOutputList(
"CFGBRICKS.BRKID");
196 brickTypeQuery->addToOutputList(
"BRKT2CSETT.CSETTYPE");
197 brickTypeQuery->setCondition(bTypeCondition, emptyBindVariableList);
198 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
199 while (brickTypeCursor.next()) {
200 const coral::AttributeList& row = brickTypeCursor.currentRow();
201 int id = row[
"CFGBRICKS.BRKID"].data<
int>();
202 int bt = row[
"BRKT2CSETT.CSETTYPE"].data<
short>();
206 bktMap.insert(std::pair<int, int>(
id, bt));
210 std::cout <<
"retrieve RH relations" << std::endl;
211 std::map<int, int> cfgMap;
212 coral::ITable& rhcRelTable =
isession->nominalSchema().tableHandle(
"RHRELATIONS");
213 std::unique_ptr<coral::IQuery> rhcRelQuery(rhcRelTable.newQuery());
214 rhcRelQuery->addToOutputList(
"RHID");
215 rhcRelQuery->addToOutputList(
"CONFKEY");
216 rhcRelQuery->addToOutputList(
"CSETTYPEID");
217 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
218 while (rhcRelCursor.next()) {
219 const coral::AttributeList& row = rhcRelCursor.currentRow();
220 int rhc = row[
"RHID"].data<
int>();
221 int key = row[
"CONFKEY"].data<
int>();
222 int cfg = row[
"CSETTYPEID"].data<
int>();
224 std::map<int, std::vector<DTConfigKey>*>::iterator rhcIter = rhcMap.find(rhc);
225 std::map<int, std::vector<DTConfigKey>*>::iterator rhcIend = rhcMap.end();
226 if (rhcIter == rhcIend)
228 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
232 keyPtr->push_back(confList);
234 if (cfgMap.find(cfg) == cfgMap.end())
235 cfgMap.insert(std::pair<int, int>(key, rhc));
239 std::cout <<
"retrieve CCB configuration keys" << std::endl;
240 std::map<int, std::map<int, int>*> keyMap;
241 std::map<int, int> cckMap;
242 coral::ITable& ccbRelTable =
isession->nominalSchema().tableHandle(
"CCBRELATIONS");
243 std::unique_ptr<coral::IQuery> ccbRelQuery(ccbRelTable.newQuery());
244 ccbRelQuery->addToOutputList(
"CONFKEY");
245 ccbRelQuery->addToOutputList(
"CCBID");
246 ccbRelQuery->addToOutputList(
"CONFCCBKEY");
247 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
248 while (ccbRelCursor.next()) {
249 const coral::AttributeList& row = ccbRelCursor.currentRow();
250 int cfg = row[
"CONFKEY"].data<
int>();
251 int ccb = row[
"CCBID"].data<
int>();
252 int key = row[
"CONFCCBKEY"].data<
int>();
254 if (cfgMap.find(cfg) == cfgMap.end())
257 std::map<int, int>* mapPtr =
nullptr;
258 std::map<int, std::map<int, int>*>::const_iterator keyIter;
259 if ((keyIter = keyMap.find(cfg)) != keyMap.end())
260 mapPtr = keyIter->second;
262 keyMap.insert(std::pair<
int, std::map<int, int>*>(cfg, mapPtr =
new std::map<int, int>));
272 std::map<int, int>& mapRef(*mapPtr);
273 mapRef.insert(std::pair<int, int>(ccb, key));
275 if (cckMap.find(key) == cckMap.end())
276 cckMap.insert(std::pair<int, int>(key, ccb));
280 std::cout <<
"retrieve CCB configuration bricks" << std::endl;
281 std::map<int, std::vector<int>*> brkMap;
282 coral::ITable& confBrickTable =
isession->nominalSchema().tableHandle(
"CFG2BRKREL");
283 std::unique_ptr<coral::IQuery> confBrickQuery(confBrickTable.newQuery());
284 confBrickQuery->addToOutputList(
"CONFID");
285 confBrickQuery->addToOutputList(
"BRKID");
286 coral::ICursor& confBrickCursor = confBrickQuery->execute();
287 while (confBrickCursor.next()) {
288 const coral::AttributeList& row = confBrickCursor.currentRow();
289 int key = row[
"CONFID"].data<
int>();
290 int brk = row[
"BRKID"].data<
int>();
292 if (cckMap.find(key) == cckMap.end())
299 std::vector<int>* brkPtr =
nullptr;
300 std::map<int, std::vector<int>*>::const_iterator brkIter;
302 if ((brkIter = brkMap.find(key)) != brkMap.end())
303 brkPtr = brkIter->second;
305 brkMap.insert(std::pair<
int, std::vector<int>*>(key, brkPtr =
new std::vector<int>));
311 brkPtr->push_back(brk);
315 std::map<int, std::vector<int>*>::const_iterator runIter = runMap.begin();
316 std::map<int, std::vector<int>*>::const_iterator runIend = runMap.end();
317 while (runIter != runIend) {
318 const std::pair<int, std::vector<int>*>& runEntry = *runIter++;
320 int run = runEntry.first;
321 std::vector<DTConfigKey> cfl;
323 std::vector<int>* rhlPtr = runEntry.second;
324 std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
325 std::vector<int>::const_iterator rhlIend = rhlPtr->end();
327 while (rhlIter != rhlIend) {
328 int rhc = *rhlIter++;
329 std::cout <<
"retrieve configuration bricks for run " << run <<
" ---> RH " << rhc << std::endl;
334 std::map<int, std::vector<DTConfigKey>*>::const_iterator rhcIter;
336 if ((rhcIter = rhcMap.find(rhc)) == rhcMap.end())
338 std::vector<DTConfigKey>* listPtr = rhcIter->second;
340 if (listPtr ==
nullptr)
342 std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
343 std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
344 while (bkiIter != bkiIend)
345 cfl.push_back(*bkiIter++);
355 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
356 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
357 while (cfgIter != cfgIend) {
367 std::map<int, int>* mapPtr =
nullptr;
368 std::map<int, std::map<int, int>*>::const_iterator keyIter;
371 if ((keyIter = keyMap.find(cfg)) != keyMap.end())
372 mapPtr = keyIter->second;
373 if (mapPtr ==
nullptr)
375 std::map<int, int>::const_iterator ccmIter = mapPtr->begin();
376 std::map<int, int>::const_iterator ccmIend = mapPtr->end();
377 while (ccmIter != ccmIend) {
378 const std::pair<int, int>& ccmEntry = *ccmIter++;
380 int ccb = ccmEntry.first;
381 int key = ccmEntry.second;
385 std::map<int, DTCCBId>::const_iterator ccbIter;
388 if ((ccbIter = ccbMap.find(ccb)) == ccbMap.end())
390 const DTCCBId& chaId = ccbIter->second;
397 std::map<int, std::vector<int>*>::const_iterator brkIter;
398 if ((brkIter = brkMap.find(key)) == brkMap.end())
400 std::vector<int>* brkPtr = brkIter->second;
402 if (brkPtr ==
nullptr)
405 std::vector<int> bkList;
409 std::map<int, int>::const_iterator bktIter;
410 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
411 std::vector<int>::const_iterator bkiIend = brkPtr->end();
412 while (bkiIter != bkiIend) {
413 int brickId = *bkiIter++;
416 if ((bktIter = bktMap.find(brickId)) == bktMap.end())
418 if (bktIter->second == cft)
419 bkList.push_back(brickId);
426 std::cout <<
"writing payload : " <<
sizeof(*fullConf) <<
" ( " << (fullConf->
end() - fullConf->
begin()) <<
" ) " 436 std::cout <<
"open POOL out db " << std::endl;
439 std::cout <<
"start queries " << std::endl;
440 std::map<int, bool> activeConfigMap;
441 coral::ITable& fullConfigTable =
isession->nominalSchema().tableHandle(
"CONFIGSETS");
442 std::unique_ptr<coral::IQuery> fullConfigQuery(fullConfigTable.newQuery());
443 fullConfigQuery->addToOutputList(
"CONFKEY");
444 fullConfigQuery->addToOutputList(
"NAME");
445 fullConfigQuery->addToOutputList(
"RUN");
446 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
447 while (fullConfigCursor.next()) {
448 const coral::AttributeList& row = fullConfigCursor.currentRow();
449 int fullConfigId = row[
"CONFKEY"].data<
int>();
450 int fullConfigRN = row[
"RUN"].data<
int>();
452 activeConfigMap.insert(std::pair<int, bool>(fullConfigId,
true));
454 activeConfigMap.insert(std::pair<int, bool>(fullConfigId,
false));
459 std::map<int, bool> activeCCBCfgMap;
460 coral::ITable& fullCCBCfgTable =
isession->nominalSchema().tableHandle(
"CCBRELATIONS");
461 std::unique_ptr<coral::IQuery> fullCCBCfgQuery(fullCCBCfgTable.newQuery());
462 fullCCBCfgQuery->addToOutputList(
"CONFKEY");
463 fullCCBCfgQuery->addToOutputList(
"CONFCCBKEY");
464 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
465 while (fullCCBCfgCursor.next()) {
466 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
467 int fullConfigId = row[
"CONFKEY"].data<
int>();
468 int fullCCBCfgId = row[
"CONFCCBKEY"].data<
int>();
471 std::map<int, bool>::const_iterator cfgIter;
472 if ((cfgIter = activeConfigMap.find(fullConfigId)) == activeConfigMap.end())
474 if (!(cfgIter->second))
476 if (activeCCBCfgMap.find(fullCCBCfgId) == activeCCBCfgMap.end())
477 activeCCBCfgMap.insert(std::pair<int, bool>(fullCCBCfgId,
true));
481 std::map<int, bool> activeCfgBrkMap;
482 coral::ITable& ccbConfBrkTable =
isession->nominalSchema().tableHandle(
"CFG2BRKREL");
483 std::unique_ptr<coral::IQuery> ccbConfBrickQuery(ccbConfBrkTable.newQuery());
484 ccbConfBrickQuery->addToOutputList(
"CONFID");
485 ccbConfBrickQuery->addToOutputList(
"BRKID");
486 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
487 while (ccbConfBrickCursor.next()) {
488 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
489 int fullCCBCfgId = row[
"CONFID"].data<
int>();
490 int ccbConfBrkId = row[
"BRKID"].data<
int>();
493 std::map<int, bool>::const_iterator ccbIter;
494 if ((ccbIter = activeCCBCfgMap.find(fullCCBCfgId)) == activeCCBCfgMap.end())
496 if (!(ccbIter->second))
498 if (activeCfgBrkMap.find(ccbConfBrkId) == activeCfgBrkMap.end())
499 activeCfgBrkMap.insert(std::pair<int, bool>(ccbConfBrkId,
true));
504 coral::ITable& brickConfigTable =
isession->nominalSchema().tableHandle(
"CFGBRICKS");
505 std::unique_ptr<coral::IQuery> brickConfigQuery(brickConfigTable.newQuery());
506 brickConfigQuery->addToOutputList(
"BRKID");
507 brickConfigQuery->addToOutputList(
"BRKNAME");
508 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
510 std::vector<int> missingList;
511 while (brickConfigCursor.next()) {
512 const coral::AttributeList& row = brickConfigCursor.currentRow();
513 int brickConfigId = row[
"BRKID"].data<
int>();
520 std::map<int, bool>::const_iterator brkIter;
521 if ((brkIter = activeCfgBrkMap.find(brickConfigId)) == activeCfgBrkMap.end())
523 if (!(brkIter->second))
526 std::cout <<
"brick " << brickConfigId <<
" : " << brickConfigName << std::endl;
527 bool brickFound =
false;
530 if (brickCheck.get())
531 brickFound = (brickCheck->getId() == brickConfigId);
535 std::cout <<
"brick " << brickConfigId <<
" missing, copy request" << std::endl;
536 missingList.push_back(brickConfigId);
540 std::vector<int>::const_iterator brickIter = missingList.begin();
541 std::vector<int>::const_iterator brickIend = missingList.end();
542 while (brickIter != brickIend) {
543 int brickConfigId = *brickIter++;
545 coral::AttributeList bindVariableList;
546 bindVariableList.extend(
"brickId",
typeid(
int));
547 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
548 std::unique_ptr<coral::IQuery> brickDataQuery(
isession->nominalSchema().newQuery());
549 brickDataQuery->addToTableList(
"CFGRELATIONS");
550 brickDataQuery->addToTableList(
"CONFIGCMDS");
551 std::string brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
552 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
553 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID");
554 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA");
555 brickDataQuery->setCondition(brickCondition, bindVariableList);
556 coral::ICursor& brickDataCursor = brickDataQuery->execute();
558 brickData->
setId(brickConfigId);
559 while (brickDataCursor.next()) {
560 const coral::AttributeList& row = brickDataCursor.currentRow();
561 brickData->
add(row[
"CONFIGCMDS.CONFDATA"].data<std::string>());
564 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
574 if (cfgl.size() != cfgr.size())
576 std::map<int, int> lmap;
577 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
578 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
579 while (lIter != lIend) {
583 std::map<int, int> rmap;
584 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
585 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
586 while (rIter != rIend) {
590 std::map<int, int>::const_iterator lmIter = lmap.begin();
591 std::map<int, int>::const_iterator lmIend = lmap.end();
592 std::map<int, int>::const_iterator rmIter = rmap.begin();
593 std::map<int, int>::const_iterator rmIend = rmap.end();
594 while ((lmIter != lmIend) && (rmIter != rmIend)) {
595 const std::pair<int, int>& lEntry = *lmIter++;
596 const std::pair<int, int>& rEntry = *rmIter++;
597 if (lEntry.first != rEntry.first)
599 if (lEntry.second != rEntry.second)
edm::Ref< Container > Ref
cond::persistency::ConnectionPool connection
void setList(const cond::persistency::KeyList *list)
void add(const std::string &data)
std::string brickContainer
const_iterator end() const
OldContainer m_to_transfer
std::string onlineAuthentication
cond::ValidityInterval lastInterval
unsigned long long Time_t
void setAuthenticationSystem(int authSysCode)
std::string id() const override
std::string onlineConnect
static bool sameConfigList(const std::vector< DTConfigKey > &cfgl, const std::vector< DTConfigKey > &cfgr)
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
std::shared_ptr< coral::ISessionProxy > isession
~DTKeyedConfigHandler() override
std::shared_ptr< T > getUsingKey(unsigned long long key) const
void setFullKey(const std::vector< DTConfigKey > &)
void getNewObjects() override
DTKeyedConfigHandler(const edm::ParameterSet &ps)
const_iterator begin() const
void setAuthenticationPath(const std::string &p)
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
const cond::persistency::KeyList * keyList
int appendConfigKey(int wheelId, int stationId, int sectorId, const std::vector< int > &confKey)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
cond::TagInfo_t const & tagInfo() const