29 #include "RelationalAccess/ISchema.h"
30 #include "RelationalAccess/ITable.h"
31 #include "RelationalAccess/ICursor.h"
32 #include "RelationalAccess/IQuery.h"
33 #include "CoralBase/AttributeList.h"
34 #include "CoralBase/AttributeSpecification.h"
35 #include "CoralBase/Attribute.h"
51 copyData( ps.getUntrackedParameter<bool> (
"copyData",
true ) ),
52 minBrickId( ps.getUntrackedParameter<int> (
"minBrick", 0 ) ),
53 maxBrickId( ps.getUntrackedParameter<int> (
"maxBrick", 999999999 ) ),
54 minRunId( ps.getUntrackedParameter<int> (
"minRun", 0 ) ),
55 maxRunId( ps.getUntrackedParameter<int> (
"maxRun", 999999999 ) ),
56 dataTag( ps.getParameter<std::string> (
"tag" ) ),
57 onlineConnect( ps.getParameter<std::string> (
"onlineDB" ) ),
58 onlineAuthentication( ps.getParameter<std::string> (
59 "onlineAuthentication" ) ),
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;
124 std::cout <<
"create DbSession" << std::endl;
126 std::cout <<
"open session" << std::endl;
128 std::cout <<
"start transaction" << std::endl;
135 std::cout <<
"get run config..." << std::endl;
136 std::map<int,std::vector<int>*> runMap;
137 std::map<int,std::vector<DTConfigKey>*> rhcMap;
138 coral::ITable& runHistoryTable =
140 std::auto_ptr<coral::IQuery>
141 runHistoryQuery( runHistoryTable.newQuery() );
142 runHistoryQuery->addToOutputList(
"RUN" );
143 runHistoryQuery->addToOutputList(
"RHID" );
144 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
145 while( runHistoryCursor.next() ) {
146 const coral::AttributeList& row = runHistoryCursor.currentRow();
147 int runId = row[
"RUN"].data<
int>();
148 int rhcId =
static_cast<int>( row[
"RHID"].data<
int>() );
150 if ( static_cast<unsigned>( runId ) <=
lastRun )
continue;
154 std::cout <<
"schedule config key copy for run "
155 << runId <<
" ---> RHID " << rhcId << std::endl;
157 std::vector<int>* rhlPtr = 0;
158 std::map<int,std::vector<int>*>::const_iterator runIter;
159 if ( ( runIter = runMap.find( runId ) ) != runMap.end() )
160 rhlPtr = runIter->second;
161 else runMap.insert( std::pair<
int,std::vector<int>*>( runId,
162 rhlPtr =
new std::vector<int> ) );
164 rhlPtr->push_back( rhcId );
166 if ( rhcMap.find( rhcId ) == rhcMap.end() )
167 rhcMap.insert( std::pair<
int,std::vector<DTConfigKey>*>( rhcId,
168 new std::vector<DTConfigKey> ) );
170 if ( !runMap.size() )
std::cout <<
"no new run found" << std::endl;
173 std::cout <<
"retrieve CCB map" << std::endl;
174 std::map<int,DTCCBId> ccbMap;
175 coral::ITable& ccbMapTable =
177 std::auto_ptr<coral::IQuery>
178 ccbMapQuery( ccbMapTable.newQuery() );
179 ccbMapQuery->addToOutputList(
"CCBID" );
180 ccbMapQuery->addToOutputList(
"WHEEL" );
181 ccbMapQuery->addToOutputList(
"SECTOR" );
182 ccbMapQuery->addToOutputList(
"STATION" );
183 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
184 while( ccbMapCursor.next() ) {
185 const coral::AttributeList& row = ccbMapCursor.currentRow();
186 int ccb = row[
"CCBID" ].data<
int>();
187 int wheel = row[
"WHEEL" ].data<
int>();
188 int sector = row[
"SECTOR" ].data<
int>();
189 int station = row[
"STATION"].data<
int>();
191 ccbId. wheelId = wheel;
193 ccbId. sectorId = sector;
194 ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
198 std::cout <<
"retrieve brick types" << std::endl;
199 std::map<int,int> bktMap;
200 coral::AttributeList emptyBindVariableList;
201 std::auto_ptr<coral::IQuery>
203 brickTypeQuery->addToTableList(
"CFGBRICKS" );
204 brickTypeQuery->addToTableList(
"BRKT2CSETT" );
206 std::string bTypeCondition =
"CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
207 brickTypeQuery->addToOutputList(
"CFGBRICKS.BRKID" );
208 brickTypeQuery->addToOutputList(
"BRKT2CSETT.CSETTYPE" );
209 brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
210 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
211 while( brickTypeCursor.next() ) {
212 const coral::AttributeList& row = brickTypeCursor.currentRow();
213 int id = row[
"CFGBRICKS.BRKID" ].data<
int>();
214 int bt = row[
"BRKT2CSETT.CSETTYPE"].data<
short>();
218 bktMap.insert( std::pair<int,int>(
id, bt ) );
222 std::cout <<
"retrieve RH relations" << std::endl;
223 std::map<int,int> cfgMap;
224 coral::ITable& rhcRelTable =
226 std::auto_ptr<coral::IQuery>
227 rhcRelQuery( rhcRelTable.newQuery() );
228 rhcRelQuery->addToOutputList(
"RHID" );
229 rhcRelQuery->addToOutputList(
"CONFKEY" );
230 rhcRelQuery->addToOutputList(
"CSETTYPEID" );
231 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
232 while( rhcRelCursor.next() ) {
233 const coral::AttributeList& row = rhcRelCursor.currentRow();
234 int rhc = row[
"RHID" ].data<
int>();
235 int key = row[
"CONFKEY" ].data<
int>();
236 int cfg = row[
"CSETTYPEID"].data<
int>();
238 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
240 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
242 if ( rhcIter == rhcIend )
continue;
243 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
247 keyPtr->push_back( confList );
249 if ( cfgMap.find( cfg ) == cfgMap.end() )
250 cfgMap.insert( std::pair<int,int>( key, rhc ) );
254 std::cout <<
"retrieve CCB configuration keys" << std::endl;
255 std::map<int,std::map<int,int>*> keyMap;
256 std::map<int,int> cckMap;
257 coral::ITable& ccbRelTable =
259 std::auto_ptr<coral::IQuery>
260 ccbRelQuery( ccbRelTable.newQuery() );
261 ccbRelQuery->addToOutputList(
"CONFKEY" );
262 ccbRelQuery->addToOutputList(
"CCBID" );
263 ccbRelQuery->addToOutputList(
"CONFCCBKEY" );
264 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
265 while( ccbRelCursor.next() ) {
266 const coral::AttributeList& row = ccbRelCursor.currentRow();
267 int cfg = row[
"CONFKEY" ].data<
int>();
268 int ccb = row[
"CCBID" ].data<
int>();
269 int key = row[
"CONFCCBKEY"].data<
int>();
271 if ( cfgMap.find( cfg ) == cfgMap.end() )
continue;
273 std::map<int,int>* mapPtr = 0;
274 std::map<int,std::map<int,int>*>::const_iterator keyIter;
275 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
276 mapPtr = keyIter->second;
277 else keyMap.insert( std::pair<
int,std::map<int,int>*>( cfg,
278 mapPtr =
new std::map<int,int> ) );
288 std::map<int,int>& mapRef( *mapPtr );
289 mapRef.insert( std::pair<int,int>( ccb, key ) );
291 if ( cckMap.find( key ) == cckMap.end() )
292 cckMap.insert( std::pair<int,int>( key, ccb ) );
296 std::cout <<
"retrieve CCB configuration bricks" << std::endl;
297 std::map<int,std::vector<int>*> brkMap;
298 coral::ITable& confBrickTable =
300 std::auto_ptr<coral::IQuery>
301 confBrickQuery( confBrickTable.newQuery() );
302 confBrickQuery->addToOutputList(
"CONFID" );
303 confBrickQuery->addToOutputList(
"BRKID" );
304 coral::ICursor& confBrickCursor = confBrickQuery->execute();
305 while( confBrickCursor.next() ) {
306 const coral::AttributeList& row = confBrickCursor.currentRow();
307 int key = row[
"CONFID"].data<
int>();
308 int brk = row[
"BRKID" ].data<
int>();
310 if ( cckMap.find( key ) == cckMap.end() )
continue;
316 std::vector<int>* brkPtr = 0;
317 std::map<int,std::vector<int>*>::const_iterator brkIter;
319 if ( ( brkIter = brkMap.find( key ) ) != brkMap.end() )
320 brkPtr = brkIter->second;
321 else brkMap.insert( std::pair<
int,std::vector<int>*>( key,
322 brkPtr =
new std::vector<int> ) );
328 brkPtr->push_back( brk );
332 std::map<int,std::vector<int>*>::const_iterator runIter = runMap.begin();
333 std::map<int,std::vector<int>*>::const_iterator runIend = runMap.end();
334 while ( runIter != runIend ) {
335 const std::pair<int,std::vector<int>*>& runEntry = *runIter++;
337 int run = runEntry.first;
338 std::vector<DTConfigKey> cfl;
340 std::vector<int>* rhlPtr = runEntry.second;
341 std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
342 std::vector<int>::const_iterator rhlIend = rhlPtr->end();
344 while ( rhlIter != rhlIend ) {
345 int rhc = *rhlIter++;
346 std::cout <<
"retrieve configuration bricks for run " << run
347 <<
" ---> RH " << rhc << std::endl;
352 std::map<int,std::vector<DTConfigKey>*>::const_iterator rhcIter;
354 if ( ( rhcIter = rhcMap.find( rhc ) ) == rhcMap.end() )
continue;
355 std::vector<DTConfigKey>* listPtr = rhcIter->second;
357 if ( listPtr == 0 )
continue;
358 std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
359 std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
360 while ( bkiIter != bkiIend ) cfl.push_back( *bkiIter++ );
369 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
370 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
371 while ( cfgIter != cfgIend ) {
381 std::map<int,int>* mapPtr = 0;
382 std::map<int,std::map<int,int>*>::const_iterator keyIter;
385 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
386 mapPtr = keyIter->second;
387 if ( mapPtr == 0 )
continue;
388 std::map<int,int>::const_iterator ccmIter = mapPtr->begin();
389 std::map<int,int>::const_iterator ccmIend = mapPtr->end();
390 while ( ccmIter != ccmIend ) {
391 const std::pair<int,int>& ccmEntry = *ccmIter++;
393 int ccb = ccmEntry.first;
394 int key = ccmEntry.second;
398 std::map<int,DTCCBId>::const_iterator ccbIter;
401 if ( ( ccbIter = ccbMap.find( ccb ) ) == ccbMap.end() )
continue;
402 const DTCCBId& chaId = ccbIter->second;
409 std::map<int,std::vector<int>*>::const_iterator brkIter;
410 if ( ( brkIter = brkMap.find( key ) ) == brkMap.end() )
continue;
411 std::vector<int>* brkPtr = brkIter->second;
413 if ( brkPtr == 0 )
continue;
415 std::vector<int> bkList;
416 bkList.reserve( 20 );
419 std::map<int,int>::const_iterator bktIter;
420 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
421 std::vector<int>::const_iterator bkiIend = brkPtr->end();
422 while ( bkiIter != bkiIend ) {
423 int brickId = *bkiIter++;
426 if ( ( bktIter = bktMap.find( brickId ) ) == bktMap.end() )
continue;
427 if ( bktIter->second == cft ) bkList.push_back( brickId );
437 std::cout <<
"writing payload : " <<
sizeof( *fullConf )
438 <<
" ( " << ( fullConf->
end() - fullConf->
begin() )
439 <<
" ) " << std::endl;
452 std::cout <<
"open POOL out db " << std::endl;
455 std::cout <<
"start queries " << std::endl;
456 std::map<int,bool> activeConfigMap;
457 coral::ITable& fullConfigTable =
459 std::auto_ptr<coral::IQuery>
460 fullConfigQuery( fullConfigTable.newQuery() );
461 fullConfigQuery->addToOutputList(
"CONFKEY" );
462 fullConfigQuery->addToOutputList(
"NAME" );
463 fullConfigQuery->addToOutputList(
"RUN" );
464 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
465 while( fullConfigCursor.next() ) {
466 const coral::AttributeList& row = fullConfigCursor.currentRow();
467 int fullConfigId = row[
"CONFKEY"].data<
int>();
468 int fullConfigRN = row[
"RUN" ].data<
int>();
469 if ( fullConfigRN ) activeConfigMap.insert(
470 std::pair<int,bool>( fullConfigId,
true ) );
471 else activeConfigMap.insert(
472 std::pair<int,bool>( fullConfigId,
false ) );
473 std::string fullConfigName = row[
"NAME"].data<std::string>();
477 std::map<int,bool> activeCCBCfgMap;
478 coral::ITable& fullCCBCfgTable =
480 std::auto_ptr<coral::IQuery>
481 fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
482 fullCCBCfgQuery->addToOutputList(
"CONFKEY" );
483 fullCCBCfgQuery->addToOutputList(
"CONFCCBKEY" );
484 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
485 while( fullCCBCfgCursor.next() ) {
486 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
487 int fullConfigId = row[
"CONFKEY" ].data<
int>();
488 int fullCCBCfgId = row[
"CONFCCBKEY"].data<
int>();
491 std::map<int,bool>::const_iterator cfgIter;
492 if ( ( cfgIter = activeConfigMap.find( fullConfigId ) )
493 == activeConfigMap.end() )
continue;
494 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
495 activeCCBCfgMap.end() )
496 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId,
true ) );
500 std::map<int,bool> activeCfgBrkMap;
501 coral::ITable& ccbConfBrkTable =
503 std::auto_ptr<coral::IQuery>
504 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
505 ccbConfBrickQuery->addToOutputList(
"CONFID" );
506 ccbConfBrickQuery->addToOutputList(
"BRKID" );
507 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
508 while( ccbConfBrickCursor.next() ) {
509 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
510 int fullCCBCfgId = row[
"CONFID"].data<
int>();
511 int ccbConfBrkId = row[
"BRKID" ].data<
int>();
514 std::map<int,bool>::const_iterator ccbIter;
515 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
516 == activeCCBCfgMap.end() )
continue;
517 if ( !( ccbIter->second ) )
continue;
518 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
519 activeCfgBrkMap.end() )
520 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId,
true ) );
525 coral::ITable& brickConfigTable =
527 std::auto_ptr<coral::IQuery>
528 brickConfigQuery( brickConfigTable.newQuery() );
529 brickConfigQuery->addToOutputList(
"BRKID" );
530 brickConfigQuery->addToOutputList(
"BRKNAME" );
531 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
533 std::vector<int> missingList;
534 std::vector<unsigned long long> checkedKeys;
535 while( brickConfigCursor.next() ) {
536 const coral::AttributeList& row = brickConfigCursor.currentRow();
537 int brickConfigId = row[
"BRKID"].data<
int>();
542 std::map<int,bool>::const_iterator brkIter;
543 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
544 == activeCfgBrkMap.end() )
continue;
545 if ( !( brkIter->second ) )
continue;
546 std::string brickConfigName = row[
"BRKNAME"].data<std::string>();
548 <<
" : " << brickConfigName << std::endl;
549 checkedKeys.push_back( brickConfigId );
550 bool brickFound =
false;
554 if ( brickCheck != 0 ) brickFound =
555 ( brickCheck->
getId() == brickConfigId );
560 std::cout <<
"brick " << brickConfigId <<
" missing, copy request"
562 missingList.push_back( brickConfigId );
568 std::vector<int>::const_iterator brickIter = missingList.begin();
569 std::vector<int>::const_iterator brickIend = missingList.end();
570 while ( brickIter != brickIend ) {
571 int brickConfigId = *brickIter++;
573 coral::AttributeList bindVariableList;
574 bindVariableList.extend(
"brickId",
typeid(
int) );
575 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
576 std::auto_ptr<coral::IQuery>
578 brickDataQuery->addToTableList(
"CFGRELATIONS" );
579 brickDataQuery->addToTableList(
"CONFIGCMDS" );
581 brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
582 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
583 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID" );
584 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA" );
585 brickDataQuery->setCondition( brickCondition, bindVariableList );
586 coral::ICursor& brickDataCursor = brickDataQuery->execute();
588 brickData->
setId( brickConfigId );
589 while( brickDataCursor.next() ) {
590 const coral::AttributeList& row = brickDataCursor.currentRow();
591 brickData->
add( row[
"CONFIGCMDS.CONFDATA"].data<std::string>() );
594 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
609 const std::vector<DTConfigKey>& cfgl,
610 const std::vector<DTConfigKey>& cfgr ) {
611 if ( cfgl.size() != cfgr.size() )
return false;
612 std::map<int,int> lmap;
613 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
614 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
615 while ( lIter != lIend ) {
619 std::map<int,int> rmap;
620 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
621 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
622 while ( rIter != rIend ) {
626 std::map<int,int>::const_iterator lmIter = lmap.begin();
627 std::map<int,int>::const_iterator lmIend = lmap.end();
628 std::map<int,int>::const_iterator rmIter = rmap.begin();
629 std::map<int,int>::const_iterator rmIend = rmap.end();
630 while ( ( lmIter != lmIend ) &&
631 ( rmIter != rmIend ) ) {
632 const std::pair<int,int>& lEntry = *lmIter++;
633 const std::pair<int,int>& rEntry = *rmIter++;
634 if ( lEntry.first != rEntry.first )
return false;
635 if ( lEntry.second != rEntry.second )
return false;
static void setList(cond::KeyList *list)
edm::Ref< Container > Ref
void setFullKey(std::vector< DTConfigKey >)
void load(std::vector< unsigned long long > const &keys)
DbTransaction & transaction()
void open(const std::string &connectionString, bool readOnly=false)
void add(const std::string &data)
int commit()
commit transaction.
DbConnectionConfiguration & configuration()
std::string brickContainer
const_iterator end() const
OldContainer m_to_transfer
cond::TagInfo const & tagInfo() const
std::string onlineAuthentication
int start(bool readOnly=false)
start transaction
unsigned long long Time_t
std::string onlineConnect
static bool sameConfigList(const std::vector< DTConfigKey > &cfgl, const std::vector< DTConfigKey > &cfgr)
std::pair< std::string, MonitorElement * > entry
T const * get(int n) const
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
cond::DbConnection connection
static cond::KeyList * keyList
DbSession createSession() const
coral::ISchema & nominalSchema()
virtual ~DTKeyedConfigHandler()
void setAuthenticationPath(const std::string &p)
cond::ValidityInterval lastInterval
perl if(1 lt scalar(@::datatypes))
DTKeyedConfigHandler(const edm::ParameterSet &ps)
const_iterator begin() const
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