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;
132 std::cout <<
"get run config..." << std::endl;
135 std::map<int,int> runMap;
136 std::map<int,std::vector<DTConfigKey>*> rhcMap;
137 coral::ITable& runHistoryTable =
139 std::auto_ptr<coral::IQuery>
140 runHistoryQuery( runHistoryTable.newQuery() );
141 runHistoryQuery->addToOutputList(
"RUN" );
142 runHistoryQuery->addToOutputList(
"RHID" );
143 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
144 while( runHistoryCursor.next() ) {
145 const coral::AttributeList& row = runHistoryCursor.currentRow();
146 int runId = row[
"RUN"].data<
int>();
147 int rhcId =
static_cast<int>( row[
"RHID"].data<
int>() );
148 if ( static_cast<unsigned>( runId ) <=
lastRun )
continue;
151 std::cout <<
"schedule config key copy for run "
152 << runId <<
" ---> RHID " << rhcId << std::endl;
153 if ( runMap.find( runId ) == runMap.end() )
154 runMap.insert( std::pair<int,int>( runId, rhcId ) );
155 if ( rhcMap.find( rhcId ) == rhcMap.end() )
156 rhcMap.insert( std::pair<
int,std::vector<DTConfigKey>*>(
158 new std::vector<DTConfigKey> ) );
161 if ( !runMap.size() )
std::cout <<
"no new run found" << std::endl;
164 std::cout <<
"retrieve CCB map" << std::endl;
165 std::map<int,DTCCBId> ccbMap;
166 coral::ITable& ccbMapTable =
168 std::auto_ptr<coral::IQuery>
169 ccbMapQuery( ccbMapTable.newQuery() );
170 ccbMapQuery->addToOutputList(
"CCBID" );
171 ccbMapQuery->addToOutputList(
"WHEEL" );
172 ccbMapQuery->addToOutputList(
"SECTOR" );
173 ccbMapQuery->addToOutputList(
"STATION" );
174 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
175 while( ccbMapCursor.next() ) {
176 const coral::AttributeList& row = ccbMapCursor.currentRow();
177 int ccb = row[
"CCBID" ].data<
int>();
178 int wheel = row[
"WHEEL" ].data<
int>();
179 int sector = row[
"SECTOR" ].data<
int>();
180 int station = row[
"STATION"].data<
int>();
182 ccbId. wheelId = wheel;
184 ccbId. sectorId = sector;
185 ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
189 std::cout <<
"retrieve brick types" << std::endl;
190 std::map<int,int> bktMap;
191 coral::AttributeList emptyBindVariableList;
192 std::auto_ptr<coral::IQuery>
194 brickTypeQuery->addToTableList(
"CFGBRICKS" );
195 brickTypeQuery->addToTableList(
"BRKT2CSETT" );
196 std::string bTypeCondition =
"CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
197 brickTypeQuery->addToOutputList(
"CFGBRICKS.BRKID" );
198 brickTypeQuery->addToOutputList(
"BRKT2CSETT.CSETTYPE" );
199 brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
200 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
201 while( brickTypeCursor.next() ) {
202 const coral::AttributeList& row = brickTypeCursor.currentRow();
203 int id = row[
"CFGBRICKS.BRKID" ].data<
int>();
204 int bt = row[
"BRKT2CSETT.CSETTYPE"].data<
short>();
208 bktMap.insert( std::pair<int,int>(
id, bt ) );
212 std::cout <<
"retrieve RH relations" << std::endl;
213 std::map<int,int> cfgMap;
214 coral::ITable& rhcRelTable =
216 std::auto_ptr<coral::IQuery>
217 rhcRelQuery( rhcRelTable.newQuery() );
218 rhcRelQuery->addToOutputList(
"RHID" );
219 rhcRelQuery->addToOutputList(
"CONFKEY" );
220 rhcRelQuery->addToOutputList(
"CSETTYPEID" );
221 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
223 while( rhcRelCursor.next() ) {
224 const coral::AttributeList& row = rhcRelCursor.currentRow();
225 int rhc = row[
"RHID" ].data<
int>();
226 int key = row[
"CONFKEY" ].data<
int>();
227 int cfg = row[
"CSETTYPEID"].data<
int>();
229 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
231 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
233 if ( rhcIter == rhcIend )
continue;
234 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
239 keyPtr->push_back( confList );
240 if ( cfgMap.find( cfg ) == cfgMap.end() )
241 cfgMap.insert( std::pair<int,int>( key, rhc ) );
245 std::cout <<
"retrieve CCB configuration keys" << std::endl;
246 std::map<int,std::map<int,int>*> keyMap;
247 std::map<int,int> cckMap;
248 coral::ITable& ccbRelTable =
250 std::auto_ptr<coral::IQuery>
251 ccbRelQuery( ccbRelTable.newQuery() );
252 ccbRelQuery->addToOutputList(
"CONFKEY" );
253 ccbRelQuery->addToOutputList(
"CCBID" );
254 ccbRelQuery->addToOutputList(
"CONFCCBKEY" );
255 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
257 while( ccbRelCursor.next() ) {
258 const coral::AttributeList& row = ccbRelCursor.currentRow();
259 int cfg = row[
"CONFKEY" ].data<
int>();
260 int ccb = row[
"CCBID" ].data<
int>();
261 int key = row[
"CONFCCBKEY"].data<
int>();
263 if ( cfgMap.find( cfg ) == cfgMap.end() )
continue;
264 std::map<int,std::map<int,int>*>::const_iterator keyIter =
266 std::map<int,std::map<int,int>*>::const_iterator keyIend =
268 std::map<int,int>* mapPtr = 0;
270 if ( keyIter != keyIend ) mapPtr = keyIter->second;
272 std::pair<
int,std::map<int,int>*>( cfg,
273 mapPtr =
new std::map<int,int> ) );
275 std::map<int,int>& mapRef( *mapPtr );
276 mapRef.insert( std::pair<int,int>( ccb, key ) );
278 if ( cckMap.find( key ) == cckMap.end() )
279 cckMap.insert( std::pair<int,int>( key, ccb ) );
283 std::cout <<
"retrieve CCB configuration bricks" << std::endl;
284 std::map<int,std::vector<int>*> brkMap;
285 coral::ITable& confBrickTable =
287 std::auto_ptr<coral::IQuery>
288 confBrickQuery( confBrickTable.newQuery() );
289 confBrickQuery->addToOutputList(
"CONFID" );
290 confBrickQuery->addToOutputList(
"BRKID" );
291 coral::ICursor& confBrickCursor = confBrickQuery->execute();
293 while( confBrickCursor.next() ) {
294 const coral::AttributeList& row = confBrickCursor.currentRow();
295 int key = row[
"CONFID"].data<
int>();
296 int brk = row[
"BRKID" ].data<
int>();
298 if ( cckMap.find( key ) == cckMap.end() )
continue;
299 std::map<int,std::vector<int>*>::const_iterator brkIter =
301 std::map<int,std::vector<int>*>::const_iterator brkIend =
304 std::vector<int>* brkPtr = 0;
305 if ( brkIter != brkIend ) brkPtr = brkIter->second;
307 std::pair<
int,std::vector<int>*>( key,
308 brkPtr =
new std::vector<int> ) );
310 brkPtr->push_back( brk );
314 std::map<int,int>::const_iterator runIter = runMap.begin();
315 std::map<int,int>::const_iterator runIend = runMap.end();
316 while ( runIter != runIend ) {
317 const std::pair<int,int>& runEntry = *runIter++;
319 int run = runEntry.first;
320 int rhc = runEntry.second;
321 std::map<int,std::vector<DTConfigKey>*>::const_iterator
322 rhcIter = rhcMap.find( rhc );
323 std::map<int,std::vector<DTConfigKey>*>::const_iterator
324 rhcIend = rhcMap.end();
325 if ( rhcIter == rhcIend )
continue;
326 if ( rhcIter->second == 0 ) {
327 std::cout <<
"RHC not found for run: " << run << std::endl;
330 if ( rhcIter->second->size() == 0 )
331 std::cout <<
"empty RHC for run: " << run << std::endl;
332 std::vector<DTConfigKey>& cfl = *( rhcIter->second );
335 std::cout <<
"retrieve configuration bricks for run " << run
336 <<
" ---> RH " << rhc << std::endl;
342 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
343 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
344 while ( cfgIter != cfgIend ) {
350 std::map<int,std::map<int,int>*>::const_iterator keyIter =
352 std::map<int,std::map<int,int>*>::const_iterator keyIend =
354 std::map<int,int>* mapPtr = 0;
355 if ( keyIter != keyIend ) mapPtr = keyIter->second;
356 if ( mapPtr == 0 )
continue;
358 std::map<int,int>::const_iterator ccbIter = mapPtr->begin();
359 std::map<int,int>::const_iterator ccbIend = mapPtr->end();
360 while ( ccbIter != ccbIend ) {
361 const std::pair<int,int>& ccbEntry = *ccbIter++;
363 int ccb = ccbEntry.first;
364 int key = ccbEntry.second;
366 std::map<int,DTCCBId>::const_iterator ccbIter = ccbMap.find( ccb );
367 std::map<int,DTCCBId>::const_iterator ccbIend = ccbMap.end();
368 if ( ccbIter == ccbIend )
continue;
369 const DTCCBId& chaId = ccbIter->second;
371 std::map<int,std::vector<int>*>::const_iterator brkIter =
373 std::map<int,std::vector<int>*>::const_iterator brkIend =
375 if ( brkIter == brkIend )
continue;
376 std::vector<int>* brkPtr = brkIter->second;
377 if ( brkPtr == 0 )
continue;
379 std::vector<int> bkList;
380 bkList.reserve( 20 );
381 std::map<int,int>::const_iterator bktIter = bktMap.begin();
382 std::map<int,int>::const_iterator bktIend = bktMap.end();
383 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
384 std::vector<int>::const_iterator bkiIend = brkPtr->end();
385 while ( bkiIter != bkiIend ) {
386 int brickId = *bkiIter++;
387 bktIter = bktMap.find( brickId );
388 if ( bktIter == bktIend )
continue;
389 if ( bktIter->second == cft ) bkList.push_back( brickId );
399 std::cout <<
"writing payload : " <<
sizeof( *fullConf )
400 <<
" ( " << ( fullConf->
end() - fullConf->
begin() )
401 <<
" ) " << std::endl;
414 std::cout <<
"open POOL out db " << std::endl;
417 std::cout <<
"start queries " << std::endl;
418 std::map<int,bool> activeConfigMap;
419 coral::ITable& fullConfigTable =
421 std::auto_ptr<coral::IQuery>
422 fullConfigQuery( fullConfigTable.newQuery() );
423 fullConfigQuery->addToOutputList(
"CONFKEY" );
424 fullConfigQuery->addToOutputList(
"NAME" );
425 fullConfigQuery->addToOutputList(
"RUN" );
426 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
427 while( fullConfigCursor.next() ) {
428 const coral::AttributeList& row = fullConfigCursor.currentRow();
429 int fullConfigId = row[
"CONFKEY"].data<
int>();
430 int fullConfigRN = row[
"RUN" ].data<
int>();
431 if ( fullConfigRN ) activeConfigMap.insert(
432 std::pair<int,bool>( fullConfigId,
true ) );
433 else activeConfigMap.insert(
434 std::pair<int,bool>( fullConfigId,
false ) );
435 std::string fullConfigName = row[
"NAME"].data<std::string>();
439 std::map<int,bool> activeCCBCfgMap;
440 coral::ITable& fullCCBCfgTable =
442 std::auto_ptr<coral::IQuery>
443 fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
444 fullCCBCfgQuery->addToOutputList(
"CONFKEY" );
445 fullCCBCfgQuery->addToOutputList(
"CONFCCBKEY" );
446 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
447 while( fullCCBCfgCursor.next() ) {
448 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
449 int fullConfigId = row[
"CONFKEY" ].data<
int>();
450 int fullCCBCfgId = row[
"CONFCCBKEY"].data<
int>();
451 std::map<int,bool>::const_iterator cfgIter =
452 activeConfigMap.find( fullConfigId );
453 if ( cfgIter == activeConfigMap.end() )
continue;
454 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
455 activeCCBCfgMap.end() )
456 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId,
true ) );
460 std::map<int,bool> activeCfgBrkMap;
461 coral::ITable& ccbConfBrkTable =
463 std::auto_ptr<coral::IQuery>
464 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
465 ccbConfBrickQuery->addToOutputList(
"CONFID" );
466 ccbConfBrickQuery->addToOutputList(
"BRKID" );
467 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
468 while( ccbConfBrickCursor.next() ) {
469 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
470 int fullCCBCfgId = row[
"CONFID"].data<
int>();
471 int ccbConfBrkId = row[
"BRKID" ].data<
int>();
472 std::map<int,bool>::const_iterator ccbIter =
473 activeCCBCfgMap.find( fullCCBCfgId );
474 if ( ccbIter == activeCCBCfgMap.end() )
continue;
475 if ( !( ccbIter->second ) )
continue;
476 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
477 activeCfgBrkMap.end() )
478 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId,
true ) );
483 coral::ITable& brickConfigTable =
485 std::auto_ptr<coral::IQuery>
486 brickConfigQuery( brickConfigTable.newQuery() );
487 brickConfigQuery->addToOutputList(
"BRKID" );
488 brickConfigQuery->addToOutputList(
"BRKNAME" );
489 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
491 std::vector<int> missingList;
492 std::vector<unsigned long long> checkedKeys;
493 while( brickConfigCursor.next() ) {
494 const coral::AttributeList& row = brickConfigCursor.currentRow();
495 int brickConfigId = row[
"BRKID"].data<
int>();
498 std::map<int,bool>::const_iterator brkIter =
499 activeCfgBrkMap.find( brickConfigId );
500 if ( brkIter == activeCfgBrkMap.end() )
continue;
501 if ( !( brkIter->second ) )
continue;
502 std::string brickConfigName = row[
"BRKNAME"].data<std::string>();
504 <<
" : " << brickConfigName << std::endl;
505 checkedKeys.push_back( brickConfigId );
506 bool brickFound =
false;
510 if ( brickCheck != 0 ) brickFound =
511 ( brickCheck->
getId() == brickConfigId );
516 std::cout <<
"brick " << brickConfigId <<
" missing, copy request"
518 missingList.push_back( brickConfigId );
524 std::vector<int>::const_iterator brickIter = missingList.begin();
525 std::vector<int>::const_iterator brickIend = missingList.end();
526 while ( brickIter != brickIend ) {
527 int brickConfigId = *brickIter++;
529 coral::AttributeList bindVariableList;
530 bindVariableList.extend(
"brickId",
typeid(
int) );
531 bindVariableList[
"brickId"].data<
int>() = brickConfigId;
532 std::auto_ptr<coral::IQuery>
534 brickDataQuery->addToTableList(
"CFGRELATIONS" );
535 brickDataQuery->addToTableList(
"CONFIGCMDS" );
537 brickCondition =
"CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
538 brickCondition +=
" and CFGRELATIONS.BRKID=:brickId";
539 brickDataQuery->addToOutputList(
"CFGRELATIONS.BRKID" );
540 brickDataQuery->addToOutputList(
"CONFIGCMDS.CONFDATA" );
541 brickDataQuery->setCondition( brickCondition, bindVariableList );
542 coral::ICursor& brickDataCursor = brickDataQuery->execute();
544 brickData->
setId( brickConfigId );
545 while( brickDataCursor.next() ) {
546 const coral::AttributeList& row = brickDataCursor.currentRow();
547 brickData->
add( row[
"CONFIGCMDS.CONFDATA"].data<std::string>() );
550 std::cout <<
"now writing brick: " << brickConfigId << std::endl;
565 const std::vector<DTConfigKey>& cfgl,
566 const std::vector<DTConfigKey>& cfgr ) {
567 if ( cfgl.size() != cfgr.size() )
return false;
568 std::map<int,int> lmap;
569 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
570 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
571 while ( lIter != lIend ) {
575 std::map<int,int> rmap;
576 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
577 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
578 while ( rIter != rIend ) {
582 std::map<int,int>::const_iterator lmIter = lmap.begin();
583 std::map<int,int>::const_iterator lmIend = lmap.end();
584 std::map<int,int>::const_iterator rmIter = rmap.begin();
585 std::map<int,int>::const_iterator rmIend = rmap.end();
586 while ( ( lmIter != lmIend ) &&
587 ( rmIter != rmIend ) ) {
588 const std::pair<int,int>& lEntry = *lmIter++;
589 const std::pair<int,int>& rEntry = *rmIter++;
590 if ( lEntry.first != rEntry.first )
return false;
591 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
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