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" 50 copyData( ps.getUntrackedParameter<
bool> (
"copyData",
true ) ),
51 minBrickId( ps.getUntrackedParameter<
int> (
"minBrick", 0 ) ),
52 maxBrickId( ps.getUntrackedParameter<
int> (
"maxBrick", 999999999 ) ),
53 minRunId( ps.getUntrackedParameter<
int> (
"minRun", 0 ) ),
54 maxRunId( ps.getUntrackedParameter<
int> (
"maxRun", 999999999 ) ),
55 dataTag( ps.getParameter<
std::
string> (
"tag" ) ),
56 onlineConnect( ps.getParameter<
std::
string> (
"onlineDB" ) ),
57 onlineAuthentication( ps.getParameter<
std::
string> (
58 "onlineAuthentication" ) ),
59 onlineAuthSys( ps.getUntrackedParameter<
int>(
"onlineAuthSys",1 ) ),
60 brickContainer( ps.getParameter<
std::
string> (
"container" ) ),
63 std::cout <<
" PopCon application for DT configuration export " 81 std::cout <<
"last configuration key already copied for run: " 84 std::vector<DTConfigKey> lastKey;
85 std::cout <<
"check for last " << std::endl;
95 std::cout <<
"get last payload" << std::endl;
97 std::cout <<
"get last full key" << std::endl;
98 lastKey = payload->fullKey();
100 std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
101 std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
102 while ( keyIter != keyIend ) {
105 << cfgKeyList.
confKey << std::endl;
118 std::cout <<
"check for new runs since " << lastRun << std::endl;
120 std::cout <<
"configure DbConnection" << std::endl;
125 std::cout <<
"create/open DbSession" << std::endl;
127 std::cout <<
"start transaction" << std::endl;
128 isession->transaction().start(
true );
133 std::cout <<
"get run config..." << std::endl;
134 std::map<int,std::vector<int>*> runMap;
135 std::map<int,std::vector<DTConfigKey>*> rhcMap;
136 coral::ITable& runHistoryTable =
137 isession->nominalSchema().tableHandle(
"RUNHISTORY" );
138 std::auto_ptr<coral::IQuery>
139 runHistoryQuery( runHistoryTable.newQuery() );
140 runHistoryQuery->addToOutputList(
"RUN" );
141 runHistoryQuery->addToOutputList(
"RHID" );
142 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
143 while( runHistoryCursor.next() ) {
144 const coral::AttributeList& row = runHistoryCursor.currentRow();
145 int runId = row[
"RUN"].data<
int>();
146 int rhcId =
static_cast<int>( row[
"RHID"].data<
int>() );
148 if ( static_cast<unsigned>( runId ) <=
lastRun )
continue;
152 std::cout <<
"schedule config key copy for run " 153 << runId <<
" ---> RHID " << rhcId << std::endl;
155 std::vector<int>* rhlPtr =
nullptr;
156 std::map<int,std::vector<int>*>::const_iterator runIter;
157 if ( ( runIter = runMap.find( runId ) ) != runMap.end() )
158 rhlPtr = runIter->second;
159 else runMap.insert( std::pair<
int,std::vector<int>*>( runId,
160 rhlPtr =
new std::vector<int> ) );
162 rhlPtr->push_back( rhcId );
164 if ( rhcMap.find( rhcId ) == rhcMap.end() )
165 rhcMap.insert( std::pair<
int,std::vector<DTConfigKey>*>( rhcId,
166 new std::vector<DTConfigKey> ) );
168 if ( runMap.empty() )
std::cout <<
"no new run found" << std::endl;
171 std::cout <<
"retrieve CCB map" << std::endl;
172 std::map<int,DTCCBId> ccbMap;
173 coral::ITable& ccbMapTable =
174 isession->nominalSchema().tableHandle(
"CCBMAP" );
175 std::auto_ptr<coral::IQuery>
176 ccbMapQuery( ccbMapTable.newQuery() );
177 ccbMapQuery->addToOutputList(
"CCBID" );
178 ccbMapQuery->addToOutputList(
"WHEEL" );
179 ccbMapQuery->addToOutputList(
"SECTOR" );
180 ccbMapQuery->addToOutputList(
"STATION" );
181 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
182 while( ccbMapCursor.next() ) {
183 const coral::AttributeList& row = ccbMapCursor.currentRow();
184 int ccb = row[
"CCBID" ].data<
int>();
185 int wheel = row[
"WHEEL" ].data<
int>();
186 int sector = row[
"SECTOR" ].data<
int>();
187 int station = row[
"STATION"].data<
int>();
189 ccbId. wheelId =
wheel;
191 ccbId. sectorId = sector;
192 ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
196 std::cout <<
"retrieve brick types" << std::endl;
197 std::map<int,int> bktMap;
198 coral::AttributeList emptyBindVariableList;
199 std::auto_ptr<coral::IQuery>
200 brickTypeQuery(
isession->nominalSchema().newQuery() );
201 brickTypeQuery->addToTableList(
"CFGBRICKS" );
202 brickTypeQuery->addToTableList(
"BRKT2CSETT" );
204 std::string bTypeCondition =
"CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
205 brickTypeQuery->addToOutputList(
"CFGBRICKS.BRKID" );
206 brickTypeQuery->addToOutputList(
"BRKT2CSETT.CSETTYPE" );
207 brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
208 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
209 while( brickTypeCursor.next() ) {
210 const coral::AttributeList& row = brickTypeCursor.currentRow();
211 int id = row[
"CFGBRICKS.BRKID" ].data<
int>();
212 int bt = row[
"BRKT2CSETT.CSETTYPE"].data<
short>();
216 bktMap.insert( std::pair<int,int>(
id, bt ) );
220 std::cout <<
"retrieve RH relations" << std::endl;
221 std::map<int,int> cfgMap;
222 coral::ITable& rhcRelTable =
223 isession->nominalSchema().tableHandle(
"RHRELATIONS" );
224 std::auto_ptr<coral::IQuery>
225 rhcRelQuery( rhcRelTable.newQuery() );
226 rhcRelQuery->addToOutputList(
"RHID" );
227 rhcRelQuery->addToOutputList(
"CONFKEY" );
228 rhcRelQuery->addToOutputList(
"CSETTYPEID" );
229 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
230 while( rhcRelCursor.next() ) {
231 const coral::AttributeList& row = rhcRelCursor.currentRow();
232 int rhc = row[
"RHID" ].data<
int>();
233 int key = row[
"CONFKEY" ].data<
int>();
234 int cfg = row[
"CSETTYPEID"].data<
int>();
236 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
238 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
240 if ( rhcIter == rhcIend )
continue;
241 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
245 keyPtr->push_back( confList );
247 if ( cfgMap.find( cfg ) == cfgMap.end() )
248 cfgMap.insert( std::pair<int,int>( key, rhc ) );
252 std::cout <<
"retrieve CCB configuration keys" << std::endl;
253 std::map<int,std::map<int,int>*> keyMap;
254 std::map<int,int> cckMap;
255 coral::ITable& ccbRelTable =
256 isession->nominalSchema().tableHandle(
"CCBRELATIONS" );
257 std::auto_ptr<coral::IQuery>
258 ccbRelQuery( ccbRelTable.newQuery() );
259 ccbRelQuery->addToOutputList(
"CONFKEY" );
260 ccbRelQuery->addToOutputList(
"CCBID" );
261 ccbRelQuery->addToOutputList(
"CONFCCBKEY" );
262 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
263 while( ccbRelCursor.next() ) {
264 const coral::AttributeList& row = ccbRelCursor.currentRow();
265 int cfg = row[
"CONFKEY" ].data<
int>();
266 int ccb = row[
"CCBID" ].data<
int>();
267 int key = row[
"CONFCCBKEY"].data<
int>();
269 if ( cfgMap.find( cfg ) == cfgMap.end() )
continue;
271 std::map<int,int>* mapPtr =
nullptr;
272 std::map<int,std::map<int,int>*>::const_iterator keyIter;
273 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
274 mapPtr = keyIter->second;
275 else keyMap.insert( std::pair<
int,std::map<int,int>*>( cfg,
276 mapPtr =
new std::map<int,int> ) );
286 std::map<int,int>& mapRef( *mapPtr );
287 mapRef.insert( std::pair<int,int>( ccb, key ) );
289 if ( cckMap.find( key ) == cckMap.end() )
290 cckMap.insert( std::pair<int,int>( key, ccb ) );
294 std::cout <<
"retrieve CCB configuration bricks" << std::endl;
295 std::map<int,std::vector<int>*> brkMap;
296 coral::ITable& confBrickTable =
297 isession->nominalSchema().tableHandle(
"CFG2BRKREL" );
298 std::auto_ptr<coral::IQuery>
299 confBrickQuery( confBrickTable.newQuery() );
300 confBrickQuery->addToOutputList(
"CONFID" );
301 confBrickQuery->addToOutputList(
"BRKID" );
302 coral::ICursor& confBrickCursor = confBrickQuery->execute();
303 while( confBrickCursor.next() ) {
304 const coral::AttributeList& row = confBrickCursor.currentRow();
305 int key = row[
"CONFID"].data<
int>();
306 int brk = row[
"BRKID" ].data<
int>();
308 if ( cckMap.find( key ) == cckMap.end() )
continue;
314 std::vector<int>* brkPtr =
nullptr;
315 std::map<int,std::vector<int>*>::const_iterator brkIter;
317 if ( ( brkIter = brkMap.find( key ) ) != brkMap.end() )
318 brkPtr = brkIter->second;
319 else brkMap.insert( std::pair<
int,std::vector<int>*>( key,
320 brkPtr =
new std::vector<int> ) );
326 brkPtr->push_back( brk );
330 std::map<int,std::vector<int>*>::const_iterator runIter = runMap.begin();
331 std::map<int,std::vector<int>*>::const_iterator runIend = runMap.end();
332 while ( runIter != runIend ) {
333 const std::pair<int,std::vector<int>*>& runEntry = *runIter++;
335 int run = runEntry.first;
336 std::vector<DTConfigKey> cfl;
338 std::vector<int>* rhlPtr = runEntry.second;
339 std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
340 std::vector<int>::const_iterator rhlIend = rhlPtr->end();
342 while ( rhlIter != rhlIend ) {
343 int rhc = *rhlIter++;
344 std::cout <<
"retrieve configuration bricks for run " << run
345 <<
" ---> RH " << rhc << std::endl;
350 std::map<int,std::vector<DTConfigKey>*>::const_iterator rhcIter;
352 if ( ( rhcIter = rhcMap.find( rhc ) ) == rhcMap.end() )
continue;
353 std::vector<DTConfigKey>* listPtr = rhcIter->second;
355 if ( listPtr ==
nullptr )
continue;
356 std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
357 std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
358 while ( bkiIter != bkiIend ) cfl.push_back( *bkiIter++ );
367 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
368 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
369 while ( cfgIter != cfgIend ) {
379 std::map<int,int>* mapPtr =
nullptr;
380 std::map<int,std::map<int,int>*>::const_iterator keyIter;
383 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
384 mapPtr = keyIter->second;
385 if ( mapPtr ==
nullptr )
continue;
386 std::map<int,int>::const_iterator ccmIter = mapPtr->begin();
387 std::map<int,int>::const_iterator ccmIend = mapPtr->end();
388 while ( ccmIter != ccmIend ) {
389 const std::pair<int,int>& ccmEntry = *ccmIter++;
391 int ccb = ccmEntry.first;
392 int key = ccmEntry.second;
396 std::map<int,DTCCBId>::const_iterator ccbIter;
399 if ( ( ccbIter = ccbMap.find( ccb ) ) == ccbMap.end() )
continue;
400 const DTCCBId& chaId = ccbIter->second;
407 std::map<int,std::vector<int>*>::const_iterator brkIter;
408 if ( ( brkIter = brkMap.find( key ) ) == brkMap.end() )
continue;
409 std::vector<int>* brkPtr = brkIter->second;
411 if ( brkPtr ==
nullptr )
continue;
413 std::vector<int> bkList;
414 bkList.reserve( 20 );
417 std::map<int,int>::const_iterator bktIter;
418 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
419 std::vector<int>::const_iterator bkiIend = brkPtr->end();
420 while ( bkiIter != bkiIend ) {
421 int brickId = *bkiIter++;
424 if ( ( bktIter = bktMap.find( brickId ) ) == bktMap.end() )
continue;
425 if ( bktIter->second == cft ) bkList.push_back( brickId );
435 std::cout <<
"writing payload : " <<
sizeof( *fullConf )
436 <<
" ( " << ( fullConf->
end() - fullConf->
begin() )
437 <<
" ) " << std::endl;
449 std::cout <<
"open POOL out db " << std::endl;
452 std::cout <<
"start queries " << std::endl;
453 std::map<int,bool> activeConfigMap;
454 coral::ITable& fullConfigTable =
455 isession->nominalSchema().tableHandle(
"CONFIGSETS" );
456 std::auto_ptr<coral::IQuery>
457 fullConfigQuery( fullConfigTable.newQuery() );
458 fullConfigQuery->addToOutputList(
"CONFKEY" );
459 fullConfigQuery->addToOutputList(
"NAME" );
460 fullConfigQuery->addToOutputList(
"RUN" );
461 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
462 while( fullConfigCursor.next() ) {
463 const coral::AttributeList& row = fullConfigCursor.currentRow();
464 int fullConfigId = row[
"CONFKEY"].data<
int>();
465 int fullConfigRN = row[
"RUN" ].data<
int>();
466 if ( fullConfigRN ) activeConfigMap.insert(
467 std::pair<int,bool>( fullConfigId,
true ) );
468 else activeConfigMap.insert(
469 std::pair<int,bool>( fullConfigId,
false ) );
474 std::map<int,bool> activeCCBCfgMap;
475 coral::ITable& fullCCBCfgTable =
476 isession->nominalSchema().tableHandle(
"CCBRELATIONS" );
477 std::auto_ptr<coral::IQuery>
478 fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
479 fullCCBCfgQuery->addToOutputList(
"CONFKEY" );
480 fullCCBCfgQuery->addToOutputList(
"CONFCCBKEY" );
481 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
482 while( fullCCBCfgCursor.next() ) {
483 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
484 int fullConfigId = row[
"CONFKEY" ].data<
int>();
485 int fullCCBCfgId = row[
"CONFCCBKEY"].data<
int>();
488 std::map<int,bool>::const_iterator cfgIter;
489 if ( ( cfgIter = activeConfigMap.find( fullConfigId ) )
490 == activeConfigMap.end() )
continue;
491 if ( !( cfgIter->second ) )
continue;
492 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
493 activeCCBCfgMap.end() )
494 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId,
true ) );
498 std::map<int,bool> activeCfgBrkMap;
499 coral::ITable& ccbConfBrkTable =
500 isession->nominalSchema().tableHandle(
"CFG2BRKREL" );
501 std::auto_ptr<coral::IQuery>
502 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
503 ccbConfBrickQuery->addToOutputList(
"CONFID" );
504 ccbConfBrickQuery->addToOutputList(
"BRKID" );
505 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
506 while( ccbConfBrickCursor.next() ) {
507 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
508 int fullCCBCfgId = row[
"CONFID"].data<
int>();
509 int ccbConfBrkId = row[
"BRKID" ].data<
int>();
512 std::map<int,bool>::const_iterator ccbIter;
513 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
514 == activeCCBCfgMap.end() )
continue;
515 if ( !( ccbIter->second ) )
continue;
516 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
517 activeCfgBrkMap.end() )
518 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId,
true ) );
523 coral::ITable& brickConfigTable =
524 isession->nominalSchema().tableHandle(
"CFGBRICKS" );
525 std::auto_ptr<coral::IQuery>
526 brickConfigQuery( brickConfigTable.newQuery() );
527 brickConfigQuery->addToOutputList(
"BRKID" );
528 brickConfigQuery->addToOutputList(
"BRKNAME" );
529 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
531 std::vector<int> missingList;
532 std::vector<unsigned long long> checkedKeys;
533 while( brickConfigCursor.next() ) {
534 const coral::AttributeList& row = brickConfigCursor.currentRow();
535 int brickConfigId = row[
"BRKID"].data<
int>();
540 std::map<int,bool>::const_iterator brkIter;
541 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
542 == activeCfgBrkMap.end() )
continue;
543 if ( !( brkIter->second ) )
continue;
546 <<
" : " << brickConfigName << std::endl;
547 checkedKeys.push_back( brickConfigId );
548 bool brickFound =
false;
552 if ( brickCheck.get() ) brickFound =
553 ( brickCheck->getId() == brickConfigId );
558 std::cout <<
"brick " << brickConfigId <<
" missing, copy request" 560 missingList.push_back( brickConfigId );
566 std::vector<int>::const_iterator brickIter = missingList.begin();
567 std::vector<int>::const_iterator brickIend = missingList.end();
568 while ( brickIter != brickIend ) {
569 int brickConfigId = *brickIter++;
571 coral::AttributeList bindVariableList;
572 bindVariableList.extend(
"brickId",
typeid(
int) );
573 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
574 std::auto_ptr<coral::IQuery>
575 brickDataQuery(
isession->nominalSchema().newQuery() );
576 brickDataQuery->addToTableList(
"CFGRELATIONS" );
577 brickDataQuery->addToTableList(
"CONFIGCMDS" );
579 brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
580 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
581 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID" );
582 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA" );
583 brickDataQuery->setCondition( brickCondition, bindVariableList );
584 coral::ICursor& brickDataCursor = brickDataQuery->execute();
586 brickData->
setId( brickConfigId );
587 while( brickDataCursor.next() ) {
588 const coral::AttributeList& row = brickDataCursor.currentRow();
589 brickData->
add( row[
"CONFIGCMDS.CONFDATA"].data<std::string>() );
592 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
607 const std::vector<DTConfigKey>& cfgl,
608 const std::vector<DTConfigKey>& cfgr ) {
609 if ( cfgl.size() != cfgr.size() )
return false;
610 std::map<int,int> lmap;
611 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
612 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
613 while ( lIter != lIend ) {
617 std::map<int,int> rmap;
618 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
619 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
620 while ( rIter != rIend ) {
624 std::map<int,int>::const_iterator lmIter = lmap.begin();
625 std::map<int,int>::const_iterator lmIend = lmap.end();
626 std::map<int,int>::const_iterator rmIter = rmap.begin();
627 std::map<int,int>::const_iterator rmIend = rmap.end();
628 while ( ( lmIter != lmIend ) &&
629 ( rmIter != rmIend ) ) {
630 const std::pair<int,int>& lEntry = *lmIter++;
631 const std::pair<int,int>& rEntry = *rmIter++;
632 if ( lEntry.first != rEntry.first )
return false;
633 if ( lEntry.second != rEntry.second )
return false;
edm::Ref< Container > Ref
cond::persistency::ConnectionPool connection
void add(const std::string &data)
std::string brickContainer
const_iterator end() const
OldContainer m_to_transfer
std::string onlineAuthentication
cond::ValidityInterval lastInterval
static cond::persistency::KeyList * keyList
unsigned long long Time_t
static void setList(cond::persistency::KeyList *list)
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
std::shared_ptr< T > get(size_t n) const
~DTKeyedConfigHandler() override
void setFullKey(const std::vector< DTConfigKey > &)
void getNewObjects() override
void load(const std::vector< unsigned long long > &keys)
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)
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