24 #include "RelationalAccess/ISchema.h"
25 #include "RelationalAccess/ITable.h"
26 #include "RelationalAccess/ICursor.h"
27 #include "RelationalAccess/IQuery.h"
28 #include "CoralBase/AttributeList.h"
29 #include "CoralBase/AttributeSpecification.h"
30 #include "CoralBase/Attribute.h"
47 copyData( ps.getUntrackedParameter<bool> (
"copyData",
true ) ),
48 minBrickId( ps.getUntrackedParameter<int> (
"minBrick", 0 ) ),
49 maxBrickId( ps.getUntrackedParameter<int> (
"maxBrick", 999999999 ) ),
50 minRunId( ps.getUntrackedParameter<int> (
"minRun", 0 ) ),
51 maxRunId( ps.getUntrackedParameter<int> (
"maxRun", 999999999 ) ),
52 dataTag( ps.getParameter<std::
string> (
"tag" ) ),
53 onlineConnect( ps.getParameter<std::
string> (
"onlineDB" ) ),
54 onlineAuthentication( ps.getParameter<std::
string> (
55 "onlineAuthentication" ) ),
56 brickContainer( ps.getParameter<std::
string> (
"container" ) ),
59 std::cout <<
" PopCon application for DT configuration export "
77 std::cout <<
"last configuration key already copied for run: "
80 std::vector<DTConfigKey> lastKey;
81 std::cout <<
"check for last " << std::endl;
91 std::cout <<
"get last payload" << std::endl;
93 std::cout <<
"get last full key" << std::endl;
94 lastKey = payload->fullKey();
96 std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
97 std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
98 while ( keyIter != keyIend ) {
101 << cfgKeyList.
confKey << std::endl;
114 std::cout <<
"check for new runs since " << lastRun << std::endl;
116 std::cout <<
"configure DbConnection" << std::endl;
120 std::cout <<
"create/open DbSession" << std::endl;
122 std::cout <<
"start transaction" << std::endl;
129 std::cout <<
"get run config..." << std::endl;
130 std::map<int,std::vector<int>*> runMap;
131 std::map<int,std::vector<DTConfigKey>*> rhcMap;
132 coral::ITable& runHistoryTable =
134 std::auto_ptr<coral::IQuery>
135 runHistoryQuery( runHistoryTable.newQuery() );
136 runHistoryQuery->addToOutputList(
"RUN" );
137 runHistoryQuery->addToOutputList(
"RHID" );
138 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
139 while( runHistoryCursor.next() ) {
140 const coral::AttributeList& row = runHistoryCursor.currentRow();
141 int runId = row[
"RUN"].data<
int>();
142 int rhcId =
static_cast<int>( row[
"RHID"].data<
int>() );
144 if ( static_cast<unsigned>( runId ) <=
lastRun )
continue;
148 std::cout <<
"schedule config key copy for run "
149 << runId <<
" ---> RHID " << rhcId << std::endl;
151 std::vector<int>* rhlPtr = 0;
152 std::map<int,std::vector<int>*>::const_iterator runIter;
153 if ( ( runIter = runMap.find( runId ) ) != runMap.end() )
154 rhlPtr = runIter->second;
155 else runMap.insert( std::pair<
int,std::vector<int>*>( runId,
156 rhlPtr =
new std::vector<int> ) );
158 rhlPtr->push_back( rhcId );
160 if ( rhcMap.find( rhcId ) == rhcMap.end() )
161 rhcMap.insert( std::pair<
int,std::vector<DTConfigKey>*>( rhcId,
162 new std::vector<DTConfigKey> ) );
164 if ( !runMap.size() )
std::cout <<
"no new run found" << std::endl;
167 std::cout <<
"retrieve CCB map" << std::endl;
168 std::map<int,DTCCBId> ccbMap;
169 coral::ITable& ccbMapTable =
171 std::auto_ptr<coral::IQuery>
172 ccbMapQuery( ccbMapTable.newQuery() );
173 ccbMapQuery->addToOutputList(
"CCBID" );
174 ccbMapQuery->addToOutputList(
"WHEEL" );
175 ccbMapQuery->addToOutputList(
"SECTOR" );
176 ccbMapQuery->addToOutputList(
"STATION" );
177 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
178 while( ccbMapCursor.next() ) {
179 const coral::AttributeList& row = ccbMapCursor.currentRow();
180 int ccb = row[
"CCBID" ].data<
int>();
181 int wheel = row[
"WHEEL" ].data<
int>();
182 int sector = row[
"SECTOR" ].data<
int>();
183 int station = row[
"STATION"].data<
int>();
185 ccbId. wheelId = wheel;
187 ccbId. sectorId = sector;
188 ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
192 std::cout <<
"retrieve brick types" << std::endl;
193 std::map<int,int> bktMap;
194 coral::AttributeList emptyBindVariableList;
195 std::auto_ptr<coral::IQuery>
197 brickTypeQuery->addToTableList(
"CFGBRICKS" );
198 brickTypeQuery->addToTableList(
"BRKT2CSETT" );
200 std::string bTypeCondition =
"CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
201 brickTypeQuery->addToOutputList(
"CFGBRICKS.BRKID" );
202 brickTypeQuery->addToOutputList(
"BRKT2CSETT.CSETTYPE" );
203 brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
204 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
205 while( brickTypeCursor.next() ) {
206 const coral::AttributeList& row = brickTypeCursor.currentRow();
207 int id = row[
"CFGBRICKS.BRKID" ].data<
int>();
208 int bt = row[
"BRKT2CSETT.CSETTYPE"].data<
short>();
212 bktMap.insert( std::pair<int,int>(
id, bt ) );
216 std::cout <<
"retrieve RH relations" << std::endl;
217 std::map<int,int> cfgMap;
218 coral::ITable& rhcRelTable =
220 std::auto_ptr<coral::IQuery>
221 rhcRelQuery( rhcRelTable.newQuery() );
222 rhcRelQuery->addToOutputList(
"RHID" );
223 rhcRelQuery->addToOutputList(
"CONFKEY" );
224 rhcRelQuery->addToOutputList(
"CSETTYPEID" );
225 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
226 while( rhcRelCursor.next() ) {
227 const coral::AttributeList& row = rhcRelCursor.currentRow();
228 int rhc = row[
"RHID" ].data<
int>();
229 int key = row[
"CONFKEY" ].data<
int>();
230 int cfg = row[
"CSETTYPEID"].data<
int>();
232 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
234 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
236 if ( rhcIter == rhcIend )
continue;
237 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
241 keyPtr->push_back( confList );
243 if ( cfgMap.find( cfg ) == cfgMap.end() )
244 cfgMap.insert( std::pair<int,int>( key, rhc ) );
248 std::cout <<
"retrieve CCB configuration keys" << std::endl;
249 std::map<int,std::map<int,int>*> keyMap;
250 std::map<int,int> cckMap;
251 coral::ITable& ccbRelTable =
253 std::auto_ptr<coral::IQuery>
254 ccbRelQuery( ccbRelTable.newQuery() );
255 ccbRelQuery->addToOutputList(
"CONFKEY" );
256 ccbRelQuery->addToOutputList(
"CCBID" );
257 ccbRelQuery->addToOutputList(
"CONFCCBKEY" );
258 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
259 while( ccbRelCursor.next() ) {
260 const coral::AttributeList& row = ccbRelCursor.currentRow();
261 int cfg = row[
"CONFKEY" ].data<
int>();
262 int ccb = row[
"CCBID" ].data<
int>();
263 int key = row[
"CONFCCBKEY"].data<
int>();
265 if ( cfgMap.find( cfg ) == cfgMap.end() )
continue;
267 std::map<int,int>* mapPtr = 0;
268 std::map<int,std::map<int,int>*>::const_iterator keyIter;
269 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
270 mapPtr = keyIter->second;
271 else keyMap.insert( std::pair<
int,std::map<int,int>*>( cfg,
272 mapPtr =
new std::map<int,int> ) );
282 std::map<int,int>& mapRef( *mapPtr );
283 mapRef.insert( std::pair<int,int>( ccb, key ) );
285 if ( cckMap.find( key ) == cckMap.end() )
286 cckMap.insert( std::pair<int,int>( key, ccb ) );
290 std::cout <<
"retrieve CCB configuration bricks" << std::endl;
291 std::map<int,std::vector<int>*> brkMap;
292 coral::ITable& confBrickTable =
294 std::auto_ptr<coral::IQuery>
295 confBrickQuery( confBrickTable.newQuery() );
296 confBrickQuery->addToOutputList(
"CONFID" );
297 confBrickQuery->addToOutputList(
"BRKID" );
298 coral::ICursor& confBrickCursor = confBrickQuery->execute();
299 while( confBrickCursor.next() ) {
300 const coral::AttributeList& row = confBrickCursor.currentRow();
301 int key = row[
"CONFID"].data<
int>();
302 int brk = row[
"BRKID" ].data<
int>();
304 if ( cckMap.find( key ) == cckMap.end() )
continue;
310 std::vector<int>* brkPtr = 0;
311 std::map<int,std::vector<int>*>::const_iterator brkIter;
313 if ( ( brkIter = brkMap.find( key ) ) != brkMap.end() )
314 brkPtr = brkIter->second;
315 else brkMap.insert( std::pair<
int,std::vector<int>*>( key,
316 brkPtr =
new std::vector<int> ) );
322 brkPtr->push_back( brk );
326 std::map<int,std::vector<int>*>::const_iterator runIter = runMap.begin();
327 std::map<int,std::vector<int>*>::const_iterator runIend = runMap.end();
328 while ( runIter != runIend ) {
329 const std::pair<int,std::vector<int>*>& runEntry = *runIter++;
331 int run = runEntry.first;
332 std::vector<DTConfigKey> cfl;
334 std::vector<int>* rhlPtr = runEntry.second;
335 std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
336 std::vector<int>::const_iterator rhlIend = rhlPtr->end();
338 while ( rhlIter != rhlIend ) {
339 int rhc = *rhlIter++;
340 std::cout <<
"retrieve configuration bricks for run " << run
341 <<
" ---> RH " << rhc << std::endl;
346 std::map<int,std::vector<DTConfigKey>*>::const_iterator rhcIter;
348 if ( ( rhcIter = rhcMap.find( rhc ) ) == rhcMap.end() )
continue;
349 std::vector<DTConfigKey>* listPtr = rhcIter->second;
351 if ( listPtr == 0 )
continue;
352 std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
353 std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
354 while ( bkiIter != bkiIend ) cfl.push_back( *bkiIter++ );
363 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
364 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
365 while ( cfgIter != cfgIend ) {
375 std::map<int,int>* mapPtr = 0;
376 std::map<int,std::map<int,int>*>::const_iterator keyIter;
379 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
380 mapPtr = keyIter->second;
381 if ( mapPtr == 0 )
continue;
382 std::map<int,int>::const_iterator ccmIter = mapPtr->begin();
383 std::map<int,int>::const_iterator ccmIend = mapPtr->end();
384 while ( ccmIter != ccmIend ) {
385 const std::pair<int,int>& ccmEntry = *ccmIter++;
387 int ccb = ccmEntry.first;
388 int key = ccmEntry.second;
392 std::map<int,DTCCBId>::const_iterator ccbIter;
395 if ( ( ccbIter = ccbMap.find( ccb ) ) == ccbMap.end() )
continue;
396 const DTCCBId& chaId = ccbIter->second;
403 std::map<int,std::vector<int>*>::const_iterator brkIter;
404 if ( ( brkIter = brkMap.find( key ) ) == brkMap.end() )
continue;
405 std::vector<int>* brkPtr = brkIter->second;
407 if ( brkPtr == 0 )
continue;
409 std::vector<int> bkList;
410 bkList.reserve( 20 );
413 std::map<int,int>::const_iterator bktIter;
414 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
415 std::vector<int>::const_iterator bkiIend = brkPtr->end();
416 while ( bkiIter != bkiIend ) {
417 int brickId = *bkiIter++;
420 if ( ( bktIter = bktMap.find( brickId ) ) == bktMap.end() )
continue;
421 if ( bktIter->second == cft ) bkList.push_back( brickId );
431 std::cout <<
"writing payload : " <<
sizeof( *fullConf )
432 <<
" ( " << ( fullConf->
end() - fullConf->
begin() )
433 <<
" ) " << std::endl;
446 std::cout <<
"open POOL out db " << std::endl;
449 std::cout <<
"start queries " << std::endl;
450 std::map<int,bool> activeConfigMap;
451 coral::ITable& fullConfigTable =
453 std::auto_ptr<coral::IQuery>
454 fullConfigQuery( fullConfigTable.newQuery() );
455 fullConfigQuery->addToOutputList(
"CONFKEY" );
456 fullConfigQuery->addToOutputList(
"NAME" );
457 fullConfigQuery->addToOutputList(
"RUN" );
458 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
459 while( fullConfigCursor.next() ) {
460 const coral::AttributeList& row = fullConfigCursor.currentRow();
461 int fullConfigId = row[
"CONFKEY"].data<
int>();
462 int fullConfigRN = row[
"RUN" ].data<
int>();
463 if ( fullConfigRN ) activeConfigMap.insert(
464 std::pair<int,bool>( fullConfigId,
true ) );
465 else activeConfigMap.insert(
466 std::pair<int,bool>( fullConfigId,
false ) );
471 std::map<int,bool> activeCCBCfgMap;
472 coral::ITable& fullCCBCfgTable =
474 std::auto_ptr<coral::IQuery>
475 fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
476 fullCCBCfgQuery->addToOutputList(
"CONFKEY" );
477 fullCCBCfgQuery->addToOutputList(
"CONFCCBKEY" );
478 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
479 while( fullCCBCfgCursor.next() ) {
480 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
481 int fullConfigId = row[
"CONFKEY" ].data<
int>();
482 int fullCCBCfgId = row[
"CONFCCBKEY"].data<
int>();
485 std::map<int,bool>::const_iterator cfgIter;
486 if ( ( cfgIter = activeConfigMap.find( fullConfigId ) )
487 == activeConfigMap.end() )
continue;
488 if ( !( cfgIter->second ) )
continue;
489 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
490 activeCCBCfgMap.end() )
491 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId,
true ) );
495 std::map<int,bool> activeCfgBrkMap;
496 coral::ITable& ccbConfBrkTable =
498 std::auto_ptr<coral::IQuery>
499 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
500 ccbConfBrickQuery->addToOutputList(
"CONFID" );
501 ccbConfBrickQuery->addToOutputList(
"BRKID" );
502 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
503 while( ccbConfBrickCursor.next() ) {
504 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
505 int fullCCBCfgId = row[
"CONFID"].data<
int>();
506 int ccbConfBrkId = row[
"BRKID" ].data<
int>();
509 std::map<int,bool>::const_iterator ccbIter;
510 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
511 == activeCCBCfgMap.end() )
continue;
512 if ( !( ccbIter->second ) )
continue;
513 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
514 activeCfgBrkMap.end() )
515 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId,
true ) );
520 coral::ITable& brickConfigTable =
522 std::auto_ptr<coral::IQuery>
523 brickConfigQuery( brickConfigTable.newQuery() );
524 brickConfigQuery->addToOutputList(
"BRKID" );
525 brickConfigQuery->addToOutputList(
"BRKNAME" );
526 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
528 std::vector<int> missingList;
529 std::vector<unsigned long long> checkedKeys;
530 while( brickConfigCursor.next() ) {
531 const coral::AttributeList& row = brickConfigCursor.currentRow();
532 int brickConfigId = row[
"BRKID"].data<
int>();
537 std::map<int,bool>::const_iterator brkIter;
538 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
539 == activeCfgBrkMap.end() )
continue;
540 if ( !( brkIter->second ) )
continue;
543 <<
" : " << brickConfigName << std::endl;
544 checkedKeys.push_back( brickConfigId );
545 bool brickFound =
false;
549 if ( brickCheck.get() ) brickFound =
550 ( brickCheck->getId() == brickConfigId );
555 std::cout <<
"brick " << brickConfigId <<
" missing, copy request"
557 missingList.push_back( brickConfigId );
563 std::vector<int>::const_iterator brickIter = missingList.begin();
564 std::vector<int>::const_iterator brickIend = missingList.end();
565 while ( brickIter != brickIend ) {
566 int brickConfigId = *brickIter++;
568 coral::AttributeList bindVariableList;
569 bindVariableList.extend(
"brickId",
typeid(
int) );
570 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
571 std::auto_ptr<coral::IQuery>
573 brickDataQuery->addToTableList(
"CFGRELATIONS" );
574 brickDataQuery->addToTableList(
"CONFIGCMDS" );
576 brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
577 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
578 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID" );
579 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA" );
580 brickDataQuery->setCondition( brickCondition, bindVariableList );
581 coral::ICursor& brickDataCursor = brickDataQuery->execute();
583 brickData->
setId( brickConfigId );
584 while( brickDataCursor.next() ) {
585 const coral::AttributeList& row = brickDataCursor.currentRow();
586 brickData->
add( row[
"CONFIGCMDS.CONFDATA"].data<std::string>() );
589 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
604 const std::vector<DTConfigKey>& cfgl,
605 const std::vector<DTConfigKey>& cfgr ) {
606 if ( cfgl.size() != cfgr.size() )
return false;
607 std::map<int,int> lmap;
608 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
609 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
610 while ( lIter != lIend ) {
614 std::map<int,int> rmap;
615 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
616 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
617 while ( rIter != rIend ) {
621 std::map<int,int>::const_iterator lmIter = lmap.begin();
622 std::map<int,int>::const_iterator lmIend = lmap.end();
623 std::map<int,int>::const_iterator rmIter = rmap.begin();
624 std::map<int,int>::const_iterator rmIend = rmap.end();
625 while ( ( lmIter != lmIend ) &&
626 ( rmIter != rmIend ) ) {
627 const std::pair<int,int>& lEntry = *lmIter++;
628 const std::pair<int,int>& rEntry = *rmIter++;
629 if ( lEntry.first != rEntry.first )
return false;
630 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