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 ) );
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 ( !( cfgIter->second ) )
continue;
495 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
496 activeCCBCfgMap.end() )
497 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId,
true ) );
501 std::map<int,bool> activeCfgBrkMap;
502 coral::ITable& ccbConfBrkTable =
504 std::auto_ptr<coral::IQuery>
505 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
506 ccbConfBrickQuery->addToOutputList(
"CONFID" );
507 ccbConfBrickQuery->addToOutputList(
"BRKID" );
508 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
509 while( ccbConfBrickCursor.next() ) {
510 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
511 int fullCCBCfgId = row[
"CONFID"].data<
int>();
512 int ccbConfBrkId = row[
"BRKID" ].data<
int>();
515 std::map<int,bool>::const_iterator ccbIter;
516 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
517 == activeCCBCfgMap.end() )
continue;
518 if ( !( ccbIter->second ) )
continue;
519 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
520 activeCfgBrkMap.end() )
521 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId,
true ) );
526 coral::ITable& brickConfigTable =
528 std::auto_ptr<coral::IQuery>
529 brickConfigQuery( brickConfigTable.newQuery() );
530 brickConfigQuery->addToOutputList(
"BRKID" );
531 brickConfigQuery->addToOutputList(
"BRKNAME" );
532 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
534 std::vector<int> missingList;
535 std::vector<unsigned long long> checkedKeys;
536 while( brickConfigCursor.next() ) {
537 const coral::AttributeList& row = brickConfigCursor.currentRow();
538 int brickConfigId = row[
"BRKID"].data<
int>();
543 std::map<int,bool>::const_iterator brkIter;
544 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
545 == activeCfgBrkMap.end() )
continue;
546 if ( !( brkIter->second ) )
continue;
549 <<
" : " << brickConfigName << std::endl;
550 checkedKeys.push_back( brickConfigId );
551 bool brickFound =
false;
555 if ( brickCheck != 0 ) brickFound =
556 ( brickCheck->
getId() == brickConfigId );
561 std::cout <<
"brick " << brickConfigId <<
" missing, copy request"
563 missingList.push_back( brickConfigId );
569 std::vector<int>::const_iterator brickIter = missingList.begin();
570 std::vector<int>::const_iterator brickIend = missingList.end();
571 while ( brickIter != brickIend ) {
572 int brickConfigId = *brickIter++;
574 coral::AttributeList bindVariableList;
575 bindVariableList.extend(
"brickId",
typeid(
int) );
576 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
577 std::auto_ptr<coral::IQuery>
579 brickDataQuery->addToTableList(
"CFGRELATIONS" );
580 brickDataQuery->addToTableList(
"CONFIGCMDS" );
582 brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
583 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
584 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID" );
585 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA" );
586 brickDataQuery->setCondition( brickCondition, bindVariableList );
587 coral::ICursor& brickDataCursor = brickDataQuery->execute();
589 brickData->
setId( brickConfigId );
590 while( brickDataCursor.next() ) {
591 const coral::AttributeList& row = brickDataCursor.currentRow();
592 brickData->
add( row[
"CONFIGCMDS.CONFDATA"].data<std::string>() );
595 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
610 const std::vector<DTConfigKey>& cfgl,
611 const std::vector<DTConfigKey>& cfgr ) {
612 if ( cfgl.size() != cfgr.size() )
return false;
613 std::map<int,int> lmap;
614 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
615 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
616 while ( lIter != lIend ) {
620 std::map<int,int> rmap;
621 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
622 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
623 while ( rIter != rIend ) {
627 std::map<int,int>::const_iterator lmIter = lmap.begin();
628 std::map<int,int>::const_iterator lmIend = lmap.end();
629 std::map<int,int>::const_iterator rmIter = rmap.begin();
630 std::map<int,int>::const_iterator rmIend = rmap.end();
631 while ( ( lmIter != lmIend ) &&
632 ( rmIter != rmIend ) ) {
633 const std::pair<int,int>& lEntry = *lmIter++;
634 const std::pair<int,int>& rEntry = *rmIter++;
635 if ( lEntry.first != rEntry.first )
return false;
636 if ( lEntry.second != rEntry.second )
return false;
static void setList(cond::KeyList *list)
edm::Ref< Container > Ref
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
void setFullKey(const std::vector< DTConfigKey > &)
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