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 ) ),
54 dataTag( ps.getParameter<std::
string> (
"tag" ) ),
55 onlineConnect( ps.getParameter<std::
string> (
"onlineDB" ) ),
56 onlineAuthentication( ps.getParameter<std::
string> (
57 "onlineAuthentication" ) ),
58 onlineAuthSys( ps.getUntrackedParameter<int>(
"onlineAuthSys",1 ) ),
59 brickContainer( ps.getParameter<std::
string> (
"container" ) ),
62 std::cout <<
" PopCon application for DT configuration export "
80 std::cout <<
"last configuration key already copied for run: "
83 std::vector<DTConfigKey> lastKey;
84 std::cout <<
"check for last " << std::endl;
94 std::cout <<
"get last payload" << std::endl;
96 std::cout <<
"get last full key" << std::endl;
97 lastKey = payload->fullKey();
99 std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
100 std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
101 while ( keyIter != keyIend ) {
104 << cfgKeyList.
confKey << std::endl;
117 std::cout <<
"check for new runs since " << lastRun << std::endl;
119 std::cout <<
"configure DbConnection" << std::endl;
124 std::cout <<
"create/open DbSession" << std::endl;
126 std::cout <<
"start transaction" << std::endl;
127 isession->transaction().start(
true );
132 std::cout <<
"get run config..." << std::endl;
133 std::map<int,std::vector<int>*> runMap;
134 std::map<int,std::vector<DTConfigKey>*> rhcMap;
135 coral::ITable& runHistoryTable =
136 isession->nominalSchema().tableHandle(
"RUNHISTORY" );
137 std::auto_ptr<coral::IQuery>
138 runHistoryQuery( runHistoryTable.newQuery() );
139 runHistoryQuery->addToOutputList(
"RUN" );
140 runHistoryQuery->addToOutputList(
"RHID" );
141 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
142 while( runHistoryCursor.next() ) {
143 const coral::AttributeList& row = runHistoryCursor.currentRow();
144 int runId = row[
"RUN"].data<
int>();
145 int rhcId =
static_cast<int>( row[
"RHID"].data<
int>() );
147 if ( static_cast<unsigned>( runId ) <=
lastRun )
continue;
151 std::cout <<
"schedule config key copy for run "
152 << runId <<
" ---> RHID " << rhcId << std::endl;
154 std::vector<int>* rhlPtr = 0;
155 std::map<int,std::vector<int>*>::const_iterator runIter;
156 if ( ( runIter = runMap.find( runId ) ) != runMap.end() )
157 rhlPtr = runIter->second;
158 else runMap.insert( std::pair<
int,std::vector<int>*>( runId,
159 rhlPtr =
new std::vector<int> ) );
161 rhlPtr->push_back( rhcId );
163 if ( rhcMap.find( rhcId ) == rhcMap.end() )
164 rhcMap.insert( std::pair<
int,std::vector<DTConfigKey>*>( rhcId,
165 new std::vector<DTConfigKey> ) );
167 if ( !runMap.size() )
std::cout <<
"no new run found" << std::endl;
170 std::cout <<
"retrieve CCB map" << std::endl;
171 std::map<int,DTCCBId> ccbMap;
172 coral::ITable& ccbMapTable =
173 isession->nominalSchema().tableHandle(
"CCBMAP" );
174 std::auto_ptr<coral::IQuery>
175 ccbMapQuery( ccbMapTable.newQuery() );
176 ccbMapQuery->addToOutputList(
"CCBID" );
177 ccbMapQuery->addToOutputList(
"WHEEL" );
178 ccbMapQuery->addToOutputList(
"SECTOR" );
179 ccbMapQuery->addToOutputList(
"STATION" );
180 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
181 while( ccbMapCursor.next() ) {
182 const coral::AttributeList& row = ccbMapCursor.currentRow();
183 int ccb = row[
"CCBID" ].data<
int>();
184 int wheel = row[
"WHEEL" ].data<
int>();
185 int sector = row[
"SECTOR" ].data<
int>();
186 int station = row[
"STATION"].data<
int>();
188 ccbId. wheelId = wheel;
190 ccbId. sectorId = sector;
191 ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
195 std::cout <<
"retrieve brick types" << std::endl;
196 std::map<int,int> bktMap;
197 coral::AttributeList emptyBindVariableList;
198 std::auto_ptr<coral::IQuery>
199 brickTypeQuery(
isession->nominalSchema().newQuery() );
200 brickTypeQuery->addToTableList(
"CFGBRICKS" );
201 brickTypeQuery->addToTableList(
"BRKT2CSETT" );
203 std::string bTypeCondition =
"CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
204 brickTypeQuery->addToOutputList(
"CFGBRICKS.BRKID" );
205 brickTypeQuery->addToOutputList(
"BRKT2CSETT.CSETTYPE" );
206 brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
207 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
208 while( brickTypeCursor.next() ) {
209 const coral::AttributeList& row = brickTypeCursor.currentRow();
210 int id = row[
"CFGBRICKS.BRKID" ].data<
int>();
211 int bt = row[
"BRKT2CSETT.CSETTYPE"].data<
short>();
215 bktMap.insert( std::pair<int,int>(
id, bt ) );
219 std::cout <<
"retrieve RH relations" << std::endl;
220 std::map<int,int> cfgMap;
221 coral::ITable& rhcRelTable =
222 isession->nominalSchema().tableHandle(
"RHRELATIONS" );
223 std::auto_ptr<coral::IQuery>
224 rhcRelQuery( rhcRelTable.newQuery() );
225 rhcRelQuery->addToOutputList(
"RHID" );
226 rhcRelQuery->addToOutputList(
"CONFKEY" );
227 rhcRelQuery->addToOutputList(
"CSETTYPEID" );
228 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
229 while( rhcRelCursor.next() ) {
230 const coral::AttributeList& row = rhcRelCursor.currentRow();
231 int rhc = row[
"RHID" ].data<
int>();
232 int key = row[
"CONFKEY" ].data<
int>();
233 int cfg = row[
"CSETTYPEID"].data<
int>();
235 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
237 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
239 if ( rhcIter == rhcIend )
continue;
240 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
244 keyPtr->push_back( confList );
246 if ( cfgMap.find( cfg ) == cfgMap.end() )
247 cfgMap.insert( std::pair<int,int>( key, rhc ) );
251 std::cout <<
"retrieve CCB configuration keys" << std::endl;
252 std::map<int,std::map<int,int>*> keyMap;
253 std::map<int,int> cckMap;
254 coral::ITable& ccbRelTable =
255 isession->nominalSchema().tableHandle(
"CCBRELATIONS" );
256 std::auto_ptr<coral::IQuery>
257 ccbRelQuery( ccbRelTable.newQuery() );
258 ccbRelQuery->addToOutputList(
"CONFKEY" );
259 ccbRelQuery->addToOutputList(
"CCBID" );
260 ccbRelQuery->addToOutputList(
"CONFCCBKEY" );
261 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
262 while( ccbRelCursor.next() ) {
263 const coral::AttributeList& row = ccbRelCursor.currentRow();
264 int cfg = row[
"CONFKEY" ].data<
int>();
265 int ccb = row[
"CCBID" ].data<
int>();
266 int key = row[
"CONFCCBKEY"].data<
int>();
268 if ( cfgMap.find( cfg ) == cfgMap.end() )
continue;
270 std::map<int,int>* mapPtr = 0;
271 std::map<int,std::map<int,int>*>::const_iterator keyIter;
272 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
273 mapPtr = keyIter->second;
274 else keyMap.insert( std::pair<
int,std::map<int,int>*>( cfg,
275 mapPtr =
new std::map<int,int> ) );
285 std::map<int,int>& mapRef( *mapPtr );
286 mapRef.insert( std::pair<int,int>( ccb, key ) );
288 if ( cckMap.find( key ) == cckMap.end() )
289 cckMap.insert( std::pair<int,int>( key, ccb ) );
293 std::cout <<
"retrieve CCB configuration bricks" << std::endl;
294 std::map<int,std::vector<int>*> brkMap;
295 coral::ITable& confBrickTable =
296 isession->nominalSchema().tableHandle(
"CFG2BRKREL" );
297 std::auto_ptr<coral::IQuery>
298 confBrickQuery( confBrickTable.newQuery() );
299 confBrickQuery->addToOutputList(
"CONFID" );
300 confBrickQuery->addToOutputList(
"BRKID" );
301 coral::ICursor& confBrickCursor = confBrickQuery->execute();
302 while( confBrickCursor.next() ) {
303 const coral::AttributeList& row = confBrickCursor.currentRow();
304 int key = row[
"CONFID"].data<
int>();
305 int brk = row[
"BRKID" ].data<
int>();
307 if ( cckMap.find( key ) == cckMap.end() )
continue;
313 std::vector<int>* brkPtr = 0;
314 std::map<int,std::vector<int>*>::const_iterator brkIter;
316 if ( ( brkIter = brkMap.find( key ) ) != brkMap.end() )
317 brkPtr = brkIter->second;
318 else brkMap.insert( std::pair<
int,std::vector<int>*>( key,
319 brkPtr =
new std::vector<int> ) );
325 brkPtr->push_back( brk );
329 std::map<int,std::vector<int>*>::const_iterator runIter = runMap.begin();
330 std::map<int,std::vector<int>*>::const_iterator runIend = runMap.end();
331 while ( runIter != runIend ) {
332 const std::pair<int,std::vector<int>*>& runEntry = *runIter++;
334 int run = runEntry.first;
335 std::vector<DTConfigKey> cfl;
337 std::vector<int>* rhlPtr = runEntry.second;
338 std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
339 std::vector<int>::const_iterator rhlIend = rhlPtr->end();
341 while ( rhlIter != rhlIend ) {
342 int rhc = *rhlIter++;
343 std::cout <<
"retrieve configuration bricks for run " << run
344 <<
" ---> RH " << rhc << std::endl;
349 std::map<int,std::vector<DTConfigKey>*>::const_iterator rhcIter;
351 if ( ( rhcIter = rhcMap.find( rhc ) ) == rhcMap.end() )
continue;
352 std::vector<DTConfigKey>* listPtr = rhcIter->second;
354 if ( listPtr == 0 )
continue;
355 std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
356 std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
357 while ( bkiIter != bkiIend ) cfl.push_back( *bkiIter++ );
366 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
367 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
368 while ( cfgIter != cfgIend ) {
378 std::map<int,int>* mapPtr = 0;
379 std::map<int,std::map<int,int>*>::const_iterator keyIter;
382 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
383 mapPtr = keyIter->second;
384 if ( mapPtr == 0 )
continue;
385 std::map<int,int>::const_iterator ccmIter = mapPtr->begin();
386 std::map<int,int>::const_iterator ccmIend = mapPtr->end();
387 while ( ccmIter != ccmIend ) {
388 const std::pair<int,int>& ccmEntry = *ccmIter++;
390 int ccb = ccmEntry.first;
391 int key = ccmEntry.second;
395 std::map<int,DTCCBId>::const_iterator ccbIter;
398 if ( ( ccbIter = ccbMap.find( ccb ) ) == ccbMap.end() )
continue;
399 const DTCCBId& chaId = ccbIter->second;
406 std::map<int,std::vector<int>*>::const_iterator brkIter;
407 if ( ( brkIter = brkMap.find( key ) ) == brkMap.end() )
continue;
408 std::vector<int>* brkPtr = brkIter->second;
410 if ( brkPtr == 0 )
continue;
412 std::vector<int> bkList;
413 bkList.reserve( 20 );
416 std::map<int,int>::const_iterator bktIter;
417 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
418 std::vector<int>::const_iterator bkiIend = brkPtr->end();
419 while ( bkiIter != bkiIend ) {
420 int brickId = *bkiIter++;
423 if ( ( bktIter = bktMap.find( brickId ) ) == bktMap.end() )
continue;
424 if ( bktIter->second == cft ) bkList.push_back( brickId );
434 std::cout <<
"writing payload : " <<
sizeof( *fullConf )
435 <<
" ( " << ( fullConf->
end() - fullConf->
begin() )
436 <<
" ) " << std::endl;
448 std::cout <<
"open POOL out db " << std::endl;
451 std::cout <<
"start queries " << std::endl;
452 std::map<int,bool> activeConfigMap;
453 coral::ITable& fullConfigTable =
454 isession->nominalSchema().tableHandle(
"CONFIGSETS" );
455 std::auto_ptr<coral::IQuery>
456 fullConfigQuery( fullConfigTable.newQuery() );
457 fullConfigQuery->addToOutputList(
"CONFKEY" );
458 fullConfigQuery->addToOutputList(
"NAME" );
459 fullConfigQuery->addToOutputList(
"RUN" );
460 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
461 while( fullConfigCursor.next() ) {
462 const coral::AttributeList& row = fullConfigCursor.currentRow();
463 int fullConfigId = row[
"CONFKEY"].data<
int>();
464 int fullConfigRN = row[
"RUN" ].data<
int>();
465 if ( fullConfigRN ) activeConfigMap.insert(
466 std::pair<int,bool>( fullConfigId,
true ) );
467 else activeConfigMap.insert(
468 std::pair<int,bool>( fullConfigId,
false ) );
473 std::map<int,bool> activeCCBCfgMap;
474 coral::ITable& fullCCBCfgTable =
475 isession->nominalSchema().tableHandle(
"CCBRELATIONS" );
476 std::auto_ptr<coral::IQuery>
477 fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
478 fullCCBCfgQuery->addToOutputList(
"CONFKEY" );
479 fullCCBCfgQuery->addToOutputList(
"CONFCCBKEY" );
480 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
481 while( fullCCBCfgCursor.next() ) {
482 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
483 int fullConfigId = row[
"CONFKEY" ].data<
int>();
484 int fullCCBCfgId = row[
"CONFCCBKEY"].data<
int>();
487 std::map<int,bool>::const_iterator cfgIter;
488 if ( ( cfgIter = activeConfigMap.find( fullConfigId ) )
489 == activeConfigMap.end() )
continue;
490 if ( !( cfgIter->second ) )
continue;
491 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
492 activeCCBCfgMap.end() )
493 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId,
true ) );
497 std::map<int,bool> activeCfgBrkMap;
498 coral::ITable& ccbConfBrkTable =
499 isession->nominalSchema().tableHandle(
"CFG2BRKREL" );
500 std::auto_ptr<coral::IQuery>
501 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
502 ccbConfBrickQuery->addToOutputList(
"CONFID" );
503 ccbConfBrickQuery->addToOutputList(
"BRKID" );
504 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
505 while( ccbConfBrickCursor.next() ) {
506 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
507 int fullCCBCfgId = row[
"CONFID"].data<
int>();
508 int ccbConfBrkId = row[
"BRKID" ].data<
int>();
511 std::map<int,bool>::const_iterator ccbIter;
512 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
513 == activeCCBCfgMap.end() )
continue;
514 if ( !( ccbIter->second ) )
continue;
515 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
516 activeCfgBrkMap.end() )
517 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId,
true ) );
522 coral::ITable& brickConfigTable =
523 isession->nominalSchema().tableHandle(
"CFGBRICKS" );
524 std::auto_ptr<coral::IQuery>
525 brickConfigQuery( brickConfigTable.newQuery() );
526 brickConfigQuery->addToOutputList(
"BRKID" );
527 brickConfigQuery->addToOutputList(
"BRKNAME" );
528 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
530 std::vector<int> missingList;
531 std::vector<unsigned long long> checkedKeys;
532 while( brickConfigCursor.next() ) {
533 const coral::AttributeList& row = brickConfigCursor.currentRow();
534 int brickConfigId = row[
"BRKID"].data<
int>();
539 std::map<int,bool>::const_iterator brkIter;
540 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
541 == activeCfgBrkMap.end() )
continue;
542 if ( !( brkIter->second ) )
continue;
545 <<
" : " << brickConfigName << std::endl;
546 checkedKeys.push_back( brickConfigId );
547 bool brickFound =
false;
551 if ( brickCheck.get() ) brickFound =
552 ( brickCheck->getId() == brickConfigId );
557 std::cout <<
"brick " << brickConfigId <<
" missing, copy request"
559 missingList.push_back( brickConfigId );
565 std::vector<int>::const_iterator brickIter = missingList.begin();
566 std::vector<int>::const_iterator brickIend = missingList.end();
567 while ( brickIter != brickIend ) {
568 int brickConfigId = *brickIter++;
570 coral::AttributeList bindVariableList;
571 bindVariableList.extend(
"brickId",
typeid(
int) );
572 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
573 std::auto_ptr<coral::IQuery>
574 brickDataQuery(
isession->nominalSchema().newQuery() );
575 brickDataQuery->addToTableList(
"CFGRELATIONS" );
576 brickDataQuery->addToTableList(
"CONFIGCMDS" );
578 brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
579 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
580 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID" );
581 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA" );
582 brickDataQuery->setCondition( brickCondition, bindVariableList );
583 coral::ICursor& brickDataCursor = brickDataQuery->execute();
585 brickData->
setId( brickConfigId );
586 while( brickDataCursor.next() ) {
587 const coral::AttributeList& row = brickDataCursor.currentRow();
588 brickData->
add( row[
"CONFIGCMDS.CONFDATA"].data<std::string>() );
591 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
606 const std::vector<DTConfigKey>& cfgl,
607 const std::vector<DTConfigKey>& cfgr ) {
608 if ( cfgl.size() != cfgr.size() )
return false;
609 std::map<int,int> lmap;
610 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
611 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
612 while ( lIter != lIend ) {
616 std::map<int,int> rmap;
617 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
618 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
619 while ( rIter != rIend ) {
623 std::map<int,int>::const_iterator lmIter = lmap.begin();
624 std::map<int,int>::const_iterator lmIend = lmap.end();
625 std::map<int,int>::const_iterator rmIter = rmap.begin();
626 std::map<int,int>::const_iterator rmIend = rmap.end();
627 while ( ( lmIter != lmIend ) &&
628 ( rmIter != rmIend ) ) {
629 const std::pair<int,int>& lEntry = *lmIter++;
630 const std::pair<int,int>& rEntry = *rmIter++;
631 if ( lEntry.first != rEntry.first )
return false;
632 if ( lEntry.second != rEntry.second )
return false;
edm::Ref< Container > Ref
cond::persistency::ConnectionPool connection
void add(const std::string &data)
boost::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
std::string brickContainer
boost::shared_ptr< T > get(size_t n) const
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 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)
boost::shared_ptr< coral::ISessionProxy > isession
virtual ~DTKeyedConfigHandler()
void setFullKey(const std::vector< DTConfigKey > &)
if(conf.exists("allCellsPositionCalc"))
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