00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "CondTools/DT/interface/DTKeyedConfigHandler.h"
00014
00015
00016
00017
00018 #include "CondFormats/DTObjects/interface/DTCCBConfig.h"
00019 #include "CondFormats/DTObjects/interface/DTKeyedConfig.h"
00020
00021
00022 #include "CondCore/DBCommon/interface/DbTransaction.h"
00023
00024 #include "FWCore/ServiceRegistry/interface/Service.h"
00025 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00026 #include "CondCore/DBOutputService/interface/KeyedElement.h"
00027 #include "CondCore/IOVService/interface/KeyList.h"
00028
00029 #include "RelationalAccess/ISchema.h"
00030 #include "RelationalAccess/ITable.h"
00031 #include "RelationalAccess/ICursor.h"
00032 #include "RelationalAccess/IQuery.h"
00033 #include "CoralBase/AttributeList.h"
00034 #include "CoralBase/AttributeSpecification.h"
00035 #include "CoralBase/Attribute.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 cond::KeyList* DTKeyedConfigHandler::keyList = 0;
00046
00047
00048
00049
00050 DTKeyedConfigHandler::DTKeyedConfigHandler( const edm::ParameterSet& ps ):
00051 copyData( ps.getUntrackedParameter<bool> ( "copyData", true ) ),
00052 minBrickId( ps.getUntrackedParameter<int> ( "minBrick", 0 ) ),
00053 maxBrickId( ps.getUntrackedParameter<int> ( "maxBrick", 999999999 ) ),
00054 minRunId( ps.getUntrackedParameter<int> ( "minRun", 0 ) ),
00055 maxRunId( ps.getUntrackedParameter<int> ( "maxRun", 999999999 ) ),
00056 dataTag( ps.getParameter<std::string> ( "tag" ) ),
00057 onlineConnect( ps.getParameter<std::string> ( "onlineDB" ) ),
00058 onlineAuthentication( ps.getParameter<std::string> (
00059 "onlineAuthentication" ) ),
00060 brickContainer( ps.getParameter<std::string> ( "container" ) ),
00061 connection(),
00062 isession() {
00063 std::cout << " PopCon application for DT configuration export "
00064 << onlineAuthentication << std::endl;
00065 }
00066
00067
00068
00069
00070 DTKeyedConfigHandler::~DTKeyedConfigHandler() {
00071 }
00072
00073
00074
00075
00076 void DTKeyedConfigHandler::getNewObjects() {
00077
00078
00079 cond::TagInfo const & ti = tagInfo();
00080 unsigned int last = ti.lastInterval.first;
00081 std::cout << "last configuration key already copied for run: "
00082 << last << std::endl;
00083
00084 std::vector<DTConfigKey> lastKey;
00085 std::cout << "check for last " << std::endl;
00086 if ( last == 0 ) {
00087 DTCCBConfig* dummyConf = new DTCCBConfig( dataTag );
00088 dummyConf->setStamp( 0 );
00089 dummyConf->setFullKey( lastKey );
00090 cond::Time_t snc = 1;
00091 std::cout << "write dummy " << std::endl;
00092 m_to_transfer.push_back( std::make_pair( dummyConf, snc ) );
00093 }
00094 else {
00095 std::cout << "get last payload" << std::endl;
00096 Ref payload = lastPayload();
00097 std::cout << "get last full key" << std::endl;
00098 lastKey = payload->fullKey();
00099 std::cout << "last key: " << std::endl;
00100 std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
00101 std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
00102 while ( keyIter != keyIend ) {
00103 const DTConfigKey& cfgKeyList = *keyIter++;
00104 std::cout << cfgKeyList.confType << " : "
00105 << cfgKeyList.confKey << std::endl;
00106 }
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 if ( !copyData ) return;
00116
00117 unsigned lastRun = last;
00118 std::cout << "check for new runs since " << lastRun << std::endl;
00119
00120 std::cout << "configure DbConnection" << std::endl;
00121
00122 connection.configuration().setAuthenticationPath( onlineAuthentication );
00123 connection.configure();
00124 std::cout << "create DbSession" << std::endl;
00125 isession = connection.createSession();
00126 std::cout << "open session" << std::endl;
00127 isession.open( onlineConnect );
00128 std::cout << "start transaction" << std::endl;
00129 isession.transaction().start();
00130
00131
00132 chkConfigList();
00133
00134
00135 std::cout << "get run config..." << std::endl;
00136 std::map<int,std::vector<int>*> runMap;
00137 std::map<int,std::vector<DTConfigKey>*> rhcMap;
00138 coral::ITable& runHistoryTable =
00139 isession.nominalSchema().tableHandle( "RUNHISTORY" );
00140 std::auto_ptr<coral::IQuery>
00141 runHistoryQuery( runHistoryTable.newQuery() );
00142 runHistoryQuery->addToOutputList( "RUN" );
00143 runHistoryQuery->addToOutputList( "RHID" );
00144 coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
00145 while( runHistoryCursor.next() ) {
00146 const coral::AttributeList& row = runHistoryCursor.currentRow();
00147 int runId = row[ "RUN"].data<int>();
00148 int rhcId = static_cast<int>( row["RHID"].data<int>() );
00149
00150 if ( static_cast<unsigned>( runId ) <= lastRun ) continue;
00151
00152 if ( runId < minRunId ) continue;
00153 if ( runId > maxRunId ) continue;
00154 std::cout << "schedule config key copy for run "
00155 << runId << " ---> RHID " << rhcId << std::endl;
00156
00157 std::vector<int>* rhlPtr = 0;
00158 std::map<int,std::vector<int>*>::const_iterator runIter;
00159 if ( ( runIter = runMap.find( runId ) ) != runMap.end() )
00160 rhlPtr = runIter->second;
00161 else runMap.insert( std::pair<int,std::vector<int>*>( runId,
00162 rhlPtr = new std::vector<int> ) );
00163
00164 rhlPtr->push_back( rhcId );
00165
00166 if ( rhcMap.find( rhcId ) == rhcMap.end() )
00167 rhcMap.insert( std::pair<int,std::vector<DTConfigKey>*>( rhcId,
00168 new std::vector<DTConfigKey> ) );
00169 }
00170 if ( !runMap.size() ) std::cout << "no new run found" << std::endl;
00171
00172
00173 std::cout << "retrieve CCB map" << std::endl;
00174 std::map<int,DTCCBId> ccbMap;
00175 coral::ITable& ccbMapTable =
00176 isession.nominalSchema().tableHandle( "CCBMAP" );
00177 std::auto_ptr<coral::IQuery>
00178 ccbMapQuery( ccbMapTable.newQuery() );
00179 ccbMapQuery->addToOutputList( "CCBID" );
00180 ccbMapQuery->addToOutputList( "WHEEL" );
00181 ccbMapQuery->addToOutputList( "SECTOR" );
00182 ccbMapQuery->addToOutputList( "STATION" );
00183 coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
00184 while( ccbMapCursor.next() ) {
00185 const coral::AttributeList& row = ccbMapCursor.currentRow();
00186 int ccb = row["CCBID" ].data<int>();
00187 int wheel = row["WHEEL" ].data<int>();
00188 int sector = row["SECTOR" ].data<int>();
00189 int station = row["STATION"].data<int>();
00190 DTCCBId ccbId;
00191 ccbId. wheelId = wheel;
00192 ccbId.stationId = station;
00193 ccbId. sectorId = sector;
00194 ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
00195 }
00196
00197
00198 std::cout << "retrieve brick types" << std::endl;
00199 std::map<int,int> bktMap;
00200 coral::AttributeList emptyBindVariableList;
00201 std::auto_ptr<coral::IQuery>
00202 brickTypeQuery( isession.nominalSchema().newQuery() );
00203 brickTypeQuery->addToTableList( "CFGBRICKS" );
00204 brickTypeQuery->addToTableList( "BRKT2CSETT" );
00205
00206 std::string bTypeCondition = "CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
00207 brickTypeQuery->addToOutputList( "CFGBRICKS.BRKID" );
00208 brickTypeQuery->addToOutputList( "BRKT2CSETT.CSETTYPE" );
00209 brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
00210 coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
00211 while( brickTypeCursor.next() ) {
00212 const coral::AttributeList& row = brickTypeCursor.currentRow();
00213 int id = row["CFGBRICKS.BRKID" ].data<int>();
00214 int bt = row["BRKT2CSETT.CSETTYPE"].data<short>();
00215
00216
00217
00218 bktMap.insert( std::pair<int,int>( id, bt ) );
00219 }
00220
00221
00222 std::cout << "retrieve RH relations" << std::endl;
00223 std::map<int,int> cfgMap;
00224 coral::ITable& rhcRelTable =
00225 isession.nominalSchema().tableHandle( "RHRELATIONS" );
00226 std::auto_ptr<coral::IQuery>
00227 rhcRelQuery( rhcRelTable.newQuery() );
00228 rhcRelQuery->addToOutputList( "RHID" );
00229 rhcRelQuery->addToOutputList( "CONFKEY" );
00230 rhcRelQuery->addToOutputList( "CSETTYPEID" );
00231 coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
00232 while( rhcRelCursor.next() ) {
00233 const coral::AttributeList& row = rhcRelCursor.currentRow();
00234 int rhc = row["RHID" ].data<int>();
00235 int key = row["CONFKEY" ].data<int>();
00236 int cfg = row["CSETTYPEID"].data<int>();
00237
00238 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
00239 rhcMap.find( rhc );
00240 std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
00241 rhcMap.end();
00242 if ( rhcIter == rhcIend ) continue;
00243 std::vector<DTConfigKey>* keyPtr = rhcIter->second;
00244 DTConfigKey confList;
00245 confList.confType = cfg;
00246 confList.confKey = key;
00247 keyPtr->push_back( confList );
00248
00249 if ( cfgMap.find( cfg ) == cfgMap.end() )
00250 cfgMap.insert( std::pair<int,int>( key, rhc ) );
00251 }
00252
00253
00254 std::cout << "retrieve CCB configuration keys" << std::endl;
00255 std::map<int,std::map<int,int>*> keyMap;
00256 std::map<int,int> cckMap;
00257 coral::ITable& ccbRelTable =
00258 isession.nominalSchema().tableHandle( "CCBRELATIONS" );
00259 std::auto_ptr<coral::IQuery>
00260 ccbRelQuery( ccbRelTable.newQuery() );
00261 ccbRelQuery->addToOutputList( "CONFKEY" );
00262 ccbRelQuery->addToOutputList( "CCBID" );
00263 ccbRelQuery->addToOutputList( "CONFCCBKEY" );
00264 coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
00265 while( ccbRelCursor.next() ) {
00266 const coral::AttributeList& row = ccbRelCursor.currentRow();
00267 int cfg = row["CONFKEY" ].data<int>();
00268 int ccb = row["CCBID" ].data<int>();
00269 int key = row["CONFCCBKEY"].data<int>();
00270
00271 if ( cfgMap.find( cfg ) == cfgMap.end() ) continue;
00272
00273 std::map<int,int>* mapPtr = 0;
00274 std::map<int,std::map<int,int>*>::const_iterator keyIter;
00275 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
00276 mapPtr = keyIter->second;
00277 else keyMap.insert( std::pair<int,std::map<int,int>*>( cfg,
00278 mapPtr = new std::map<int,int> ) );
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 std::map<int,int>& mapRef( *mapPtr );
00289 mapRef.insert( std::pair<int,int>( ccb, key ) );
00290
00291 if ( cckMap.find( key ) == cckMap.end() )
00292 cckMap.insert( std::pair<int,int>( key, ccb ) );
00293 }
00294
00295
00296 std::cout << "retrieve CCB configuration bricks" << std::endl;
00297 std::map<int,std::vector<int>*> brkMap;
00298 coral::ITable& confBrickTable =
00299 isession.nominalSchema().tableHandle( "CFG2BRKREL" );
00300 std::auto_ptr<coral::IQuery>
00301 confBrickQuery( confBrickTable.newQuery() );
00302 confBrickQuery->addToOutputList( "CONFID" );
00303 confBrickQuery->addToOutputList( "BRKID" );
00304 coral::ICursor& confBrickCursor = confBrickQuery->execute();
00305 while( confBrickCursor.next() ) {
00306 const coral::AttributeList& row = confBrickCursor.currentRow();
00307 int key = row["CONFID"].data<int>();
00308 int brk = row["BRKID" ].data<int>();
00309
00310 if ( cckMap.find( key ) == cckMap.end() ) continue;
00311
00312
00313
00314
00315
00316 std::vector<int>* brkPtr = 0;
00317 std::map<int,std::vector<int>*>::const_iterator brkIter;
00318
00319 if ( ( brkIter = brkMap.find( key ) ) != brkMap.end() )
00320 brkPtr = brkIter->second;
00321 else brkMap.insert( std::pair<int,std::vector<int>*>( key,
00322 brkPtr = new std::vector<int> ) );
00323
00324
00325
00326
00327
00328 brkPtr->push_back( brk );
00329 }
00330
00331
00332 std::map<int,std::vector<int>*>::const_iterator runIter = runMap.begin();
00333 std::map<int,std::vector<int>*>::const_iterator runIend = runMap.end();
00334 while ( runIter != runIend ) {
00335 const std::pair<int,std::vector<int>*>& runEntry = *runIter++;
00336
00337 int run = runEntry.first;
00338 std::vector<DTConfigKey> cfl;
00339
00340 std::vector<int>* rhlPtr = runEntry.second;
00341 std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
00342 std::vector<int>::const_iterator rhlIend = rhlPtr->end();
00343
00344 while ( rhlIter != rhlIend ) {
00345 int rhc = *rhlIter++;
00346 std::cout << "retrieve configuration bricks for run " << run
00347 << " ---> RH " << rhc << std::endl;
00348
00349
00350
00351
00352 std::map<int,std::vector<DTConfigKey>*>::const_iterator rhcIter;
00353
00354 if ( ( rhcIter = rhcMap.find( rhc ) ) == rhcMap.end() ) continue;
00355 std::vector<DTConfigKey>* listPtr = rhcIter->second;
00356
00357 if ( listPtr == 0 ) continue;
00358 std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
00359 std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
00360 while ( bkiIter != bkiIend ) cfl.push_back( *bkiIter++ );
00361 }
00362 if ( sameConfigList( cfl, lastKey ) ) continue;
00363 lastKey = cfl;
00364 DTCCBConfig* fullConf = new DTCCBConfig( dataTag );
00365
00366 fullConf->setStamp( run );
00367 fullConf->setFullKey( cfl );
00368
00369 std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
00370 std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
00371 while ( cfgIter != cfgIend ) {
00372 const DTConfigKey& cfgEntry = *cfgIter++;
00373 int cft = cfgEntry.confType;
00374 int cfg = cfgEntry.confKey;
00375
00376
00377
00378
00379
00380
00381 std::map<int,int>* mapPtr = 0;
00382 std::map<int,std::map<int,int>*>::const_iterator keyIter;
00383
00384
00385 if ( ( keyIter = keyMap.find( cfg ) ) != keyMap.end() )
00386 mapPtr = keyIter->second;
00387 if ( mapPtr == 0 ) continue;
00388 std::map<int,int>::const_iterator ccmIter = mapPtr->begin();
00389 std::map<int,int>::const_iterator ccmIend = mapPtr->end();
00390 while ( ccmIter != ccmIend ) {
00391 const std::pair<int,int>& ccmEntry = *ccmIter++;
00392
00393 int ccb = ccmEntry.first;
00394 int key = ccmEntry.second;
00395
00396
00397
00398 std::map<int,DTCCBId>::const_iterator ccbIter;
00399
00400
00401 if ( ( ccbIter = ccbMap.find( ccb ) ) == ccbMap.end() ) continue;
00402 const DTCCBId& chaId = ccbIter->second;
00403
00404
00405
00406
00407
00408
00409 std::map<int,std::vector<int>*>::const_iterator brkIter;
00410 if ( ( brkIter = brkMap.find( key ) ) == brkMap.end() ) continue;
00411 std::vector<int>* brkPtr = brkIter->second;
00412
00413 if ( brkPtr == 0 ) continue;
00414
00415 std::vector<int> bkList;
00416 bkList.reserve( 20 );
00417
00418
00419 std::map<int,int>::const_iterator bktIter;
00420 std::vector<int>::const_iterator bkiIter = brkPtr->begin();
00421 std::vector<int>::const_iterator bkiIend = brkPtr->end();
00422 while ( bkiIter != bkiIend ) {
00423 int brickId = *bkiIter++;
00424
00425
00426 if ( ( bktIter = bktMap.find( brickId ) ) == bktMap.end() ) continue;
00427 if ( bktIter->second == cft ) bkList.push_back( brickId );
00428 }
00429 fullConf->appendConfigKey( chaId.wheelId,
00430 chaId.stationId,
00431 chaId.sectorId,
00432 bkList );
00433 }
00434 }
00435 cond::Time_t snc = runEntry.first;
00436 m_to_transfer.push_back( std::make_pair( fullConf, snc ) );
00437 std::cout << "writing payload : " << sizeof( *fullConf )
00438 << " ( " << ( fullConf->end() - fullConf->begin() )
00439 << " ) " << std::endl;
00440 }
00441
00442 isession.transaction().commit();
00443 isession.close();
00444
00445 return;
00446
00447 }
00448
00449
00450 void DTKeyedConfigHandler::chkConfigList() {
00451
00452 std::cout << "open POOL out db " << std::endl;
00453 edm::Service<cond::service::PoolDBOutputService> outdb;
00454
00455 std::cout << "start queries " << std::endl;
00456 std::map<int,bool> activeConfigMap;
00457 coral::ITable& fullConfigTable =
00458 isession.nominalSchema().tableHandle( "CONFIGSETS" );
00459 std::auto_ptr<coral::IQuery>
00460 fullConfigQuery( fullConfigTable.newQuery() );
00461 fullConfigQuery->addToOutputList( "CONFKEY" );
00462 fullConfigQuery->addToOutputList( "NAME" );
00463 fullConfigQuery->addToOutputList( "RUN" );
00464 coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
00465 while( fullConfigCursor.next() ) {
00466 const coral::AttributeList& row = fullConfigCursor.currentRow();
00467 int fullConfigId = row["CONFKEY"].data<int>();
00468 int fullConfigRN = row["RUN" ].data<int>();
00469 if ( fullConfigRN ) activeConfigMap.insert(
00470 std::pair<int,bool>( fullConfigId, true ) );
00471 else activeConfigMap.insert(
00472 std::pair<int,bool>( fullConfigId, false ) );
00473 std::string fullConfigName = row["NAME"].data<std::string>();
00474 }
00475
00476
00477 std::map<int,bool> activeCCBCfgMap;
00478 coral::ITable& fullCCBCfgTable =
00479 isession.nominalSchema().tableHandle( "CCBRELATIONS" );
00480 std::auto_ptr<coral::IQuery>
00481 fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
00482 fullCCBCfgQuery->addToOutputList( "CONFKEY" );
00483 fullCCBCfgQuery->addToOutputList( "CONFCCBKEY" );
00484 coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
00485 while( fullCCBCfgCursor.next() ) {
00486 const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
00487 int fullConfigId = row["CONFKEY" ].data<int>();
00488 int fullCCBCfgId = row["CONFCCBKEY"].data<int>();
00489
00490
00491 std::map<int,bool>::const_iterator cfgIter;
00492 if ( ( cfgIter = activeConfigMap.find( fullConfigId ) )
00493 == activeConfigMap.end() ) continue;
00494 if ( !( cfgIter->second ) ) continue;
00495 if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
00496 activeCCBCfgMap.end() )
00497 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId, true ) );
00498 }
00499
00500
00501 std::map<int,bool> activeCfgBrkMap;
00502 coral::ITable& ccbConfBrkTable =
00503 isession.nominalSchema().tableHandle( "CFG2BRKREL" );
00504 std::auto_ptr<coral::IQuery>
00505 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
00506 ccbConfBrickQuery->addToOutputList( "CONFID" );
00507 ccbConfBrickQuery->addToOutputList( "BRKID" );
00508 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
00509 while( ccbConfBrickCursor.next() ) {
00510 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
00511 int fullCCBCfgId = row["CONFID"].data<int>();
00512 int ccbConfBrkId = row["BRKID" ].data<int>();
00513
00514
00515 std::map<int,bool>::const_iterator ccbIter;
00516 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
00517 == activeCCBCfgMap.end() ) continue;
00518 if ( !( ccbIter->second ) ) continue;
00519 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
00520 activeCfgBrkMap.end() )
00521 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId, true ) );
00522 }
00523
00524
00525
00526 coral::ITable& brickConfigTable =
00527 isession.nominalSchema().tableHandle( "CFGBRICKS" );
00528 std::auto_ptr<coral::IQuery>
00529 brickConfigQuery( brickConfigTable.newQuery() );
00530 brickConfigQuery->addToOutputList( "BRKID" );
00531 brickConfigQuery->addToOutputList( "BRKNAME" );
00532 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
00533 DTKeyedConfig* brickData = 0;
00534 std::vector<int> missingList;
00535 std::vector<unsigned long long> checkedKeys;
00536 while( brickConfigCursor.next() ) {
00537 const coral::AttributeList& row = brickConfigCursor.currentRow();
00538 int brickConfigId = row["BRKID"].data<int>();
00539 if ( brickConfigId < minBrickId ) continue;
00540 if ( brickConfigId > maxBrickId ) continue;
00541
00542
00543 std::map<int,bool>::const_iterator brkIter;
00544 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
00545 == activeCfgBrkMap.end() ) continue;
00546 if ( !( brkIter->second ) ) continue;
00547 std::string brickConfigName = row["BRKNAME"].data<std::string>();
00548 std::cout << "brick " << brickConfigId
00549 << " : " << brickConfigName << std::endl;
00550 checkedKeys.push_back( brickConfigId );
00551 bool brickFound = false;
00552 try {
00553 keyList->load( checkedKeys );
00554 const DTKeyedConfig* brickCheck = keyList->get<DTKeyedConfig>( 0 );
00555 if ( brickCheck != 0 ) brickFound =
00556 ( brickCheck->getId() == brickConfigId );
00557 }
00558 catch ( std::exception e ) {
00559 }
00560 if ( !brickFound ) {
00561 std::cout << "brick " << brickConfigId << " missing, copy request"
00562 << std::endl;
00563 missingList.push_back( brickConfigId );
00564 }
00565 checkedKeys.clear();
00566 }
00567 keyList->load( checkedKeys );
00568
00569 std::vector<int>::const_iterator brickIter = missingList.begin();
00570 std::vector<int>::const_iterator brickIend = missingList.end();
00571 while ( brickIter != brickIend ) {
00572 int brickConfigId = *brickIter++;
00573
00574 coral::AttributeList bindVariableList;
00575 bindVariableList.extend( "brickId", typeid(int) );
00576 bindVariableList["brickId"].data<int>() = brickConfigId;
00577 std::auto_ptr<coral::IQuery>
00578 brickDataQuery( isession.nominalSchema().newQuery() );
00579 brickDataQuery->addToTableList( "CFGRELATIONS" );
00580 brickDataQuery->addToTableList( "CONFIGCMDS" );
00581 std::string
00582 brickCondition = "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
00583 brickCondition += " and CFGRELATIONS.BRKID=:brickId";
00584 brickDataQuery->addToOutputList( "CFGRELATIONS.BRKID" );
00585 brickDataQuery->addToOutputList( "CONFIGCMDS.CONFDATA" );
00586 brickDataQuery->setCondition( brickCondition, bindVariableList );
00587 coral::ICursor& brickDataCursor = brickDataQuery->execute();
00588 brickData = new DTKeyedConfig();
00589 brickData->setId( brickConfigId );
00590 while( brickDataCursor.next() ) {
00591 const coral::AttributeList& row = brickDataCursor.currentRow();
00592 brickData->add( row["CONFIGCMDS.CONFDATA"].data<std::string>() );
00593 }
00594 cond::KeyedElement k( brickData, brickConfigId );
00595 std::cout << "now writing brick: " << brickConfigId << std::endl;
00596 outdb->writeOne( k.m_obj, k.m_key, brickContainer );
00597 }
00598
00599 return;
00600
00601 }
00602
00603
00604 std::string DTKeyedConfigHandler::id() const {
00605 return dataTag;
00606 }
00607
00608
00609 bool DTKeyedConfigHandler::sameConfigList(
00610 const std::vector<DTConfigKey>& cfgl,
00611 const std::vector<DTConfigKey>& cfgr ) {
00612 if ( cfgl.size() != cfgr.size() ) return false;
00613 std::map<int,int> lmap;
00614 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
00615 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
00616 while ( lIter != lIend ) {
00617 const DTConfigKey& entry = *lIter++;
00618 lmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
00619 }
00620 std::map<int,int> rmap;
00621 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
00622 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
00623 while ( rIter != rIend ) {
00624 const DTConfigKey& entry = *rIter++;
00625 rmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
00626 }
00627 std::map<int,int>::const_iterator lmIter = lmap.begin();
00628 std::map<int,int>::const_iterator lmIend = lmap.end();
00629 std::map<int,int>::const_iterator rmIter = rmap.begin();
00630 std::map<int,int>::const_iterator rmIend = rmap.end();
00631 while ( ( lmIter != lmIend ) &&
00632 ( rmIter != rmIend ) ) {
00633 const std::pair<int,int>& lEntry = *lmIter++;
00634 const std::pair<int,int>& rEntry = *rmIter++;
00635 if ( lEntry.first != rEntry.first ) return false;
00636 if ( lEntry.second != rEntry.second ) return false;
00637 }
00638 return true;
00639 }
00640
00641
00642 void DTKeyedConfigHandler::setList( cond::KeyList* list ) {
00643 keyList = list;
00644 }
00645