25 #include "RelationalAccess/ISchema.h"
26 #include "RelationalAccess/ITable.h"
27 #include "RelationalAccess/ICursor.h"
28 #include "RelationalAccess/IQuery.h"
29 #include "CoralBase/AttributeList.h"
30 #include "CoralBase/AttributeSpecification.h"
31 #include "CoralBase/Attribute.h"
48 copyData( ps.getUntrackedParameter<bool> (
"copyData",
true ) ),
49 minBrickId( ps.getUntrackedParameter<int> (
"minBrick", 0 ) ),
50 maxBrickId( ps.getUntrackedParameter<int> (
"maxBrick", 999999999 ) ),
51 minRunId( ps.getUntrackedParameter<int> (
"minRun", 0 ) ),
52 maxRunId( ps.getUntrackedParameter<int> (
"maxRun", 999999999 ) ),
53 dataTag( ps.getParameter<std::
string> (
"tag" ) ),
54 onlineConnect( ps.getParameter<std::
string> (
"onlineDB" ) ),
55 onlineAuthentication( ps.getParameter<std::
string> (
56 "onlineAuthentication" ) ),
57 brickContainer( ps.getParameter<std::
string> (
"container" ) ),
60 std::cout <<
" PopCon application for DT configuration export "
78 std::cout <<
"last configuration key already copied for run: "
81 std::vector<DTConfigKey> lastKey;
82 std::cout <<
"check for last " << std::endl;
92 std::cout <<
"get last payload" << std::endl;
94 std::cout <<
"get last full key" << std::endl;
95 lastKey = payload->fullKey();
97 std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
98 std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
99 while ( keyIter != keyIend ) {
102 << cfgKeyList.
confKey << std::endl;
115 std::cout <<
"check for new runs since " << lastRun << std::endl;
117 std::cout <<
"configure DbConnection" << std::endl;
121 std::cout <<
"create/open DbSession" << std::endl;
123 std::cout <<
"start transaction" << std::endl;
130 std::cout <<
"get run config..." << std::endl;
131 std::map<int,std::vector<int>*> runMap;
132 std::map<int,std::vector<DTConfigKey>*> rhcMap;
133 coral::ITable& runHistoryTable =
135 std::auto_ptr<coral::IQuery>
136 runHistoryQuery( runHistoryTable.newQuery() );
137 runHistoryQuery->addToOutputList(
"RUN" );
138 runHistoryQuery->addToOutputList(
"RHID" );
139 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
140 while( runHistoryCursor.next() ) {
141 const coral::AttributeList& row = runHistoryCursor.currentRow();
142 int runId = row[
"RUN"].data<
int>();
143 int rhcId =
static_cast<int>( row[
"RHID"].data<
int>() );
145 if ( static_cast<unsigned>( runId ) <=
lastRun )
continue;
149 std::cout <<
"schedule config key copy for run "
150 << runId <<
" ---> RHID " << rhcId << std::endl;
152 std::vector<int>* rhlPtr = 0;
153 std::map<int,std::vector<int>*>::const_iterator runIter;
154 if ( ( runIter = runMap.find( runId ) ) != runMap.end() )
155 rhlPtr = runIter->second;
156 else runMap.insert( std::pair<
int,std::vector<int>*>( runId,
157 rhlPtr =
new std::vector<int> ) );
159 rhlPtr->push_back( rhcId );
161 if ( rhcMap.find( rhcId ) == rhcMap.end() )
162 rhcMap.insert( std::pair<
int,std::vector<DTConfigKey>*>( rhcId,
163 new std::vector<DTConfigKey> ) );
165 if ( !runMap.size() )
std::cout <<
"no new run found" << std::endl;
168 std::cout <<
"retrieve CCB map" << std::endl;
169 std::map<int,DTCCBId> ccbMap;
170 coral::ITable& ccbMapTable =
172 std::auto_ptr<coral::IQuery>
173 ccbMapQuery( ccbMapTable.newQuery() );
174 ccbMapQuery->addToOutputList(
"CCBID" );
175 ccbMapQuery->addToOutputList(
"WHEEL" );
176 ccbMapQuery->addToOutputList(
"SECTOR" );
177 ccbMapQuery->addToOutputList(
"STATION" );
178 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
179 while( ccbMapCursor.next() ) {
180 const coral::AttributeList& row = ccbMapCursor.currentRow();
181 int ccb = row[
"CCBID" ].data<
int>();
182 int wheel = row[
"WHEEL" ].data<
int>();
183 int sector = row[
"SECTOR" ].data<
int>();
184 int station = row[
"STATION"].data<
int>();
186 ccbId. wheelId = wheel;
188 ccbId. sectorId = sector;
189 ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
193 std::cout <<
"retrieve brick types" << std::endl;
194 std::map<int,int> bktMap;
195 coral::AttributeList emptyBindVariableList;
196 std::auto_ptr<coral::IQuery>
198 brickTypeQuery->addToTableList(
"CFGBRICKS" );
199 brickTypeQuery->addToTableList(
"BRKT2CSETT" );
201 std::string bTypeCondition =
"CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
202 brickTypeQuery->addToOutputList(
"CFGBRICKS.BRKID" );
203 brickTypeQuery->addToOutputList(
"BRKT2CSETT.CSETTYPE" );
204 brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
205 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
206 while( brickTypeCursor.next() ) {
207 const coral::AttributeList& row = brickTypeCursor.currentRow();
208 int id = row[
"CFGBRICKS.BRKID" ].data<
int>();
209 int bt = row[
"BRKT2CSETT.CSETTYPE"].data<
short>();
213 bktMap.insert( std::pair<int,int>(
id, bt ) );
217 std::cout <<
"retrieve RH relations" << std::endl;
218 std::map<int,int> cfgMap;
219 coral::ITable& rhcRelTable =
221 std::auto_ptr<coral::IQuery>
222 rhcRelQuery( rhcRelTable.newQuery() );
223 rhcRelQuery->addToOutputList(
"RHID" );
224 rhcRelQuery->addToOutputList(
"CONFKEY" );
225 rhcRelQuery->addToOutputList(
"CSETTYPEID" );
226 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
227 while( rhcRelCursor.next() ) {
228 const coral::AttributeList& row = rhcRelCursor.currentRow();
229 int rhc = row[
"RHID" ].data<
int>();
230 int key = row[
"CONFKEY" ].data<
int>();
231 int cfg = row[
"CSETTYPEID"].data<
int>();
233 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
235 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
237 if ( rhcIter == rhcIend )
continue;
238 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
242 keyPtr->push_back( confList );
244 if ( cfgMap.find( cfg ) == cfgMap.end() )
245 cfgMap.insert( std::pair<int,int>( key, rhc ) );
249 std::cout <<
"retrieve CCB configuration keys" << std::endl;
250 std::map<int,std::map<int,int>*> keyMap;
251 std::map<int,int> cckMap;
252 coral::ITable& ccbRelTable =
254 std::auto_ptr<coral::IQuery>
255 ccbRelQuery( ccbRelTable.newQuery() );
256 ccbRelQuery->addToOutputList(
"CONFKEY" );
257 ccbRelQuery->addToOutputList(
"CCBID" );
258 ccbRelQuery->addToOutputList(
"CONFCCBKEY" );
259 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
260 while( ccbRelCursor.next() ) {
261 const coral::AttributeList& row = ccbRelCursor.currentRow();
262 int cfg = row[
"CONFKEY" ].data<
int>();
263 int ccb = row[
"CCBID" ].data<
int>();
264 int key = row[
"CONFCCBKEY"].data<
int>();
266 if ( cfgMap.find( cfg ) == cfgMap.end() )
continue;
268 std::map<int,int>* mapPtr = 0;
269 std::map<int,std::map<int,int>*>::const_iterator keyIter;
270 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
271 mapPtr = keyIter->second;
272 else keyMap.insert( std::pair<
int,std::map<int,int>*>( cfg,
273 mapPtr =
new std::map<int,int> ) );
283 std::map<int,int>& mapRef( *mapPtr );
284 mapRef.insert( std::pair<int,int>( ccb, key ) );
286 if ( cckMap.find( key ) == cckMap.end() )
287 cckMap.insert( std::pair<int,int>( key, ccb ) );
291 std::cout <<
"retrieve CCB configuration bricks" << std::endl;
292 std::map<int,std::vector<int>*> brkMap;
293 coral::ITable& confBrickTable =
295 std::auto_ptr<coral::IQuery>
296 confBrickQuery( confBrickTable.newQuery() );
297 confBrickQuery->addToOutputList(
"CONFID" );
298 confBrickQuery->addToOutputList(
"BRKID" );
299 coral::ICursor& confBrickCursor = confBrickQuery->execute();
300 while( confBrickCursor.next() ) {
301 const coral::AttributeList& row = confBrickCursor.currentRow();
302 int key = row[
"CONFID"].data<
int>();
303 int brk = row[
"BRKID" ].data<
int>();
305 if ( cckMap.find( key ) == cckMap.end() )
continue;
311 std::vector<int>* brkPtr = 0;
312 std::map<int,std::vector<int>*>::const_iterator brkIter;
314 if ( ( brkIter = brkMap.find( key ) ) != brkMap.end() )
315 brkPtr = brkIter->second;
316 else brkMap.insert( std::pair<
int,std::vector<int>*>( key,
317 brkPtr =
new std::vector<int> ) );
323 brkPtr->push_back( brk );
327 std::map<int,std::vector<int>*>::const_iterator runIter = runMap.begin();
328 std::map<int,std::vector<int>*>::const_iterator runIend = runMap.end();
329 while ( runIter != runIend ) {
330 const std::pair<int,std::vector<int>*>& runEntry = *runIter++;
332 int run = runEntry.first;
333 std::vector<DTConfigKey> cfl;
335 std::vector<int>* rhlPtr = runEntry.second;
336 std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
337 std::vector<int>::const_iterator rhlIend = rhlPtr->end();
339 while ( rhlIter != rhlIend ) {
340 int rhc = *rhlIter++;
341 std::cout <<
"retrieve configuration bricks for run " << run
342 <<
" ---> RH " << rhc << std::endl;
347 std::map<int,std::vector<DTConfigKey>*>::const_iterator rhcIter;
349 if ( ( rhcIter = rhcMap.find( rhc ) ) == rhcMap.end() )
continue;
350 std::vector<DTConfigKey>* listPtr = rhcIter->second;
352 if ( listPtr == 0 )
continue;
353 std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
354 std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
355 while ( bkiIter != bkiIend ) cfl.push_back( *bkiIter++ );
364 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
365 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
366 while ( cfgIter != cfgIend ) {
376 std::map<int,int>* mapPtr = 0;
377 std::map<int,std::map<int,int>*>::const_iterator keyIter;
380 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
381 mapPtr = keyIter->second;
382 if ( mapPtr == 0 )
continue;
383 std::map<int,int>::const_iterator ccmIter = mapPtr->begin();
384 std::map<int,int>::const_iterator ccmIend = mapPtr->end();
385 while ( ccmIter != ccmIend ) {
386 const std::pair<int,int>& ccmEntry = *ccmIter++;
388 int ccb = ccmEntry.first;
389 int key = ccmEntry.second;
393 std::map<int,DTCCBId>::const_iterator ccbIter;
396 if ( ( ccbIter = ccbMap.find( ccb ) ) == ccbMap.end() )
continue;
397 const DTCCBId& chaId = ccbIter->second;
404 std::map<int,std::vector<int>*>::const_iterator brkIter;
405 if ( ( brkIter = brkMap.find( key ) ) == brkMap.end() )
continue;
406 std::vector<int>* brkPtr = brkIter->second;
408 if ( brkPtr == 0 )
continue;
410 std::vector<int> bkList;
411 bkList.reserve( 20 );
414 std::map<int,int>::const_iterator bktIter;
415 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
416 std::vector<int>::const_iterator bkiIend = brkPtr->end();
417 while ( bkiIter != bkiIend ) {
418 int brickId = *bkiIter++;
421 if ( ( bktIter = bktMap.find( brickId ) ) == bktMap.end() )
continue;
422 if ( bktIter->second == cft ) bkList.push_back( brickId );
432 std::cout <<
"writing payload : " <<
sizeof( *fullConf )
433 <<
" ( " << ( fullConf->
end() - fullConf->
begin() )
434 <<
" ) " << std::endl;
447 std::cout <<
"open POOL out db " << std::endl;
450 std::cout <<
"start queries " << std::endl;
451 std::map<int,bool> activeConfigMap;
452 coral::ITable& fullConfigTable =
454 std::auto_ptr<coral::IQuery>
455 fullConfigQuery( fullConfigTable.newQuery() );
456 fullConfigQuery->addToOutputList(
"CONFKEY" );
457 fullConfigQuery->addToOutputList(
"NAME" );
458 fullConfigQuery->addToOutputList(
"RUN" );
459 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
460 while( fullConfigCursor.next() ) {
461 const coral::AttributeList& row = fullConfigCursor.currentRow();
462 int fullConfigId = row[
"CONFKEY"].data<
int>();
463 int fullConfigRN = row[
"RUN" ].data<
int>();
464 if ( fullConfigRN ) activeConfigMap.insert(
465 std::pair<int,bool>( fullConfigId,
true ) );
466 else activeConfigMap.insert(
467 std::pair<int,bool>( fullConfigId,
false ) );
472 std::map<int,bool> activeCCBCfgMap;
473 coral::ITable& fullCCBCfgTable =
475 std::auto_ptr<coral::IQuery>
476 fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
477 fullCCBCfgQuery->addToOutputList(
"CONFKEY" );
478 fullCCBCfgQuery->addToOutputList(
"CONFCCBKEY" );
479 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
480 while( fullCCBCfgCursor.next() ) {
481 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
482 int fullConfigId = row[
"CONFKEY" ].data<
int>();
483 int fullCCBCfgId = row[
"CONFCCBKEY"].data<
int>();
486 std::map<int,bool>::const_iterator cfgIter;
487 if ( ( cfgIter = activeConfigMap.find( fullConfigId ) )
488 == activeConfigMap.end() )
continue;
489 if ( !( cfgIter->second ) )
continue;
490 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
491 activeCCBCfgMap.end() )
492 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId,
true ) );
496 std::map<int,bool> activeCfgBrkMap;
497 coral::ITable& ccbConfBrkTable =
499 std::auto_ptr<coral::IQuery>
500 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
501 ccbConfBrickQuery->addToOutputList(
"CONFID" );
502 ccbConfBrickQuery->addToOutputList(
"BRKID" );
503 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
504 while( ccbConfBrickCursor.next() ) {
505 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
506 int fullCCBCfgId = row[
"CONFID"].data<
int>();
507 int ccbConfBrkId = row[
"BRKID" ].data<
int>();
510 std::map<int,bool>::const_iterator ccbIter;
511 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
512 == activeCCBCfgMap.end() )
continue;
513 if ( !( ccbIter->second ) )
continue;
514 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
515 activeCfgBrkMap.end() )
516 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId,
true ) );
521 coral::ITable& brickConfigTable =
523 std::auto_ptr<coral::IQuery>
524 brickConfigQuery( brickConfigTable.newQuery() );
525 brickConfigQuery->addToOutputList(
"BRKID" );
526 brickConfigQuery->addToOutputList(
"BRKNAME" );
527 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
529 std::vector<int> missingList;
530 std::vector<unsigned long long> checkedKeys;
531 while( brickConfigCursor.next() ) {
532 const coral::AttributeList& row = brickConfigCursor.currentRow();
533 int brickConfigId = row[
"BRKID"].data<
int>();
538 std::map<int,bool>::const_iterator brkIter;
539 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
540 == activeCfgBrkMap.end() )
continue;
541 if ( !( brkIter->second ) )
continue;
544 <<
" : " << brickConfigName << std::endl;
545 checkedKeys.push_back( brickConfigId );
546 bool brickFound =
false;
550 if ( brickCheck.get() ) brickFound =
551 ( brickCheck->getId() == brickConfigId );
556 std::cout <<
"brick " << brickConfigId <<
" missing, copy request"
558 missingList.push_back( brickConfigId );
564 std::vector<int>::const_iterator brickIter = missingList.begin();
565 std::vector<int>::const_iterator brickIend = missingList.end();
566 while ( brickIter != brickIend ) {
567 int brickConfigId = *brickIter++;
569 coral::AttributeList bindVariableList;
570 bindVariableList.extend(
"brickId",
typeid(
int) );
571 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
572 std::auto_ptr<coral::IQuery>
574 brickDataQuery->addToTableList(
"CFGRELATIONS" );
575 brickDataQuery->addToTableList(
"CONFIGCMDS" );
577 brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
578 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
579 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID" );
580 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA" );
581 brickDataQuery->setCondition( brickCondition, bindVariableList );
582 coral::ICursor& brickDataCursor = brickDataQuery->execute();
584 brickData->
setId( brickConfigId );
585 while( brickDataCursor.next() ) {
586 const coral::AttributeList& row = brickDataCursor.currentRow();
587 brickData->
add( row[
"CONFIGCMDS.CONFDATA"].data<std::string>() );
590 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
605 const std::vector<DTConfigKey>& cfgl,
606 const std::vector<DTConfigKey>& cfgr ) {
607 if ( cfgl.size() != cfgr.size() )
return false;
608 std::map<int,int> lmap;
609 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
610 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
611 while ( lIter != lIend ) {
615 std::map<int,int> rmap;
616 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
617 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
618 while ( rIter != rIend ) {
622 std::map<int,int>::const_iterator lmIter = lmap.begin();
623 std::map<int,int>::const_iterator lmIend = lmap.end();
624 std::map<int,int>::const_iterator rmIter = rmap.begin();
625 std::map<int,int>::const_iterator rmIend = rmap.end();
626 while ( ( lmIter != lmIend ) &&
627 ( rmIter != rmIend ) ) {
628 const std::pair<int,int>& lEntry = *lmIter++;
629 const std::pair<int,int>& rEntry = *rmIter++;
630 if ( lEntry.first != rEntry.first )
return false;
631 if ( lEntry.second != rEntry.second )
return false;
edm::Ref< Container > Ref
cond::persistency::ConnectionPool connection
void add(const std::string &data)
void start(bool readOnly=true)
std::string brickContainer
boost::shared_ptr< T > get(size_t n) const
Transaction & transaction()
const_iterator end() const
OldContainer m_to_transfer
std::string onlineAuthentication
cond::persistency::Session isession
cond::ValidityInterval lastInterval
static cond::persistency::KeyList * keyList
unsigned long long Time_t
static void setList(cond::persistency::KeyList *list)
std::string onlineConnect
static bool sameConfigList(const std::vector< DTConfigKey > &cfgl, const std::vector< DTConfigKey > &cfgr)
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
coral::ISchema & nominalSchema()
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
virtual ~DTKeyedConfigHandler()
void setFullKey(const std::vector< DTConfigKey > &)
void load(const std::vector< unsigned long long > &keys)
DTKeyedConfigHandler(const edm::ParameterSet &ps)
const_iterator begin() const
void setAuthenticationPath(const std::string &p)
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