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 ( activeCCBCfgMap.find( fullCCBCfgId ) ==
00495 activeCCBCfgMap.end() )
00496 activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId, true ) );
00497 }
00498
00499
00500 std::map<int,bool> activeCfgBrkMap;
00501 coral::ITable& ccbConfBrkTable =
00502 isession.nominalSchema().tableHandle( "CFG2BRKREL" );
00503 std::auto_ptr<coral::IQuery>
00504 ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
00505 ccbConfBrickQuery->addToOutputList( "CONFID" );
00506 ccbConfBrickQuery->addToOutputList( "BRKID" );
00507 coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
00508 while( ccbConfBrickCursor.next() ) {
00509 const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
00510 int fullCCBCfgId = row["CONFID"].data<int>();
00511 int ccbConfBrkId = row["BRKID" ].data<int>();
00512
00513
00514 std::map<int,bool>::const_iterator ccbIter;
00515 if ( ( ccbIter = activeCCBCfgMap.find( fullCCBCfgId ) )
00516 == activeCCBCfgMap.end() ) continue;
00517 if ( !( ccbIter->second ) ) continue;
00518 if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
00519 activeCfgBrkMap.end() )
00520 activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId, true ) );
00521 }
00522
00523
00524
00525 coral::ITable& brickConfigTable =
00526 isession.nominalSchema().tableHandle( "CFGBRICKS" );
00527 std::auto_ptr<coral::IQuery>
00528 brickConfigQuery( brickConfigTable.newQuery() );
00529 brickConfigQuery->addToOutputList( "BRKID" );
00530 brickConfigQuery->addToOutputList( "BRKNAME" );
00531 coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
00532 DTKeyedConfig* brickData = 0;
00533 std::vector<int> missingList;
00534 std::vector<unsigned long long> checkedKeys;
00535 while( brickConfigCursor.next() ) {
00536 const coral::AttributeList& row = brickConfigCursor.currentRow();
00537 int brickConfigId = row["BRKID"].data<int>();
00538 if ( brickConfigId < minBrickId ) continue;
00539 if ( brickConfigId > maxBrickId ) continue;
00540
00541
00542 std::map<int,bool>::const_iterator brkIter;
00543 if ( ( brkIter = activeCfgBrkMap.find( brickConfigId ) )
00544 == activeCfgBrkMap.end() ) continue;
00545 if ( !( brkIter->second ) ) continue;
00546 std::string brickConfigName = row["BRKNAME"].data<std::string>();
00547 std::cout << "brick " << brickConfigId
00548 << " : " << brickConfigName << std::endl;
00549 checkedKeys.push_back( brickConfigId );
00550 bool brickFound = false;
00551 try {
00552 keyList->load( checkedKeys );
00553 const DTKeyedConfig* brickCheck = keyList->get<DTKeyedConfig>( 0 );
00554 if ( brickCheck != 0 ) brickFound =
00555 ( brickCheck->getId() == brickConfigId );
00556 }
00557 catch ( std::exception e ) {
00558 }
00559 if ( !brickFound ) {
00560 std::cout << "brick " << brickConfigId << " missing, copy request"
00561 << std::endl;
00562 missingList.push_back( brickConfigId );
00563 }
00564 checkedKeys.clear();
00565 }
00566 keyList->load( checkedKeys );
00567
00568 std::vector<int>::const_iterator brickIter = missingList.begin();
00569 std::vector<int>::const_iterator brickIend = missingList.end();
00570 while ( brickIter != brickIend ) {
00571 int brickConfigId = *brickIter++;
00572
00573 coral::AttributeList bindVariableList;
00574 bindVariableList.extend( "brickId", typeid(int) );
00575 bindVariableList["brickId"].data<int>() = brickConfigId;
00576 std::auto_ptr<coral::IQuery>
00577 brickDataQuery( isession.nominalSchema().newQuery() );
00578 brickDataQuery->addToTableList( "CFGRELATIONS" );
00579 brickDataQuery->addToTableList( "CONFIGCMDS" );
00580 std::string
00581 brickCondition = "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
00582 brickCondition += " and CFGRELATIONS.BRKID=:brickId";
00583 brickDataQuery->addToOutputList( "CFGRELATIONS.BRKID" );
00584 brickDataQuery->addToOutputList( "CONFIGCMDS.CONFDATA" );
00585 brickDataQuery->setCondition( brickCondition, bindVariableList );
00586 coral::ICursor& brickDataCursor = brickDataQuery->execute();
00587 brickData = new DTKeyedConfig();
00588 brickData->setId( brickConfigId );
00589 while( brickDataCursor.next() ) {
00590 const coral::AttributeList& row = brickDataCursor.currentRow();
00591 brickData->add( row["CONFIGCMDS.CONFDATA"].data<std::string>() );
00592 }
00593 cond::KeyedElement k( brickData, brickConfigId );
00594 std::cout << "now writing brick: " << brickConfigId << std::endl;
00595 outdb->writeOne( k.m_obj, 0, k.m_key, brickContainer );
00596 }
00597
00598 return;
00599
00600 }
00601
00602
00603 std::string DTKeyedConfigHandler::id() const {
00604 return dataTag;
00605 }
00606
00607
00608 bool DTKeyedConfigHandler::sameConfigList(
00609 const std::vector<DTConfigKey>& cfgl,
00610 const std::vector<DTConfigKey>& cfgr ) {
00611 if ( cfgl.size() != cfgr.size() ) return false;
00612 std::map<int,int> lmap;
00613 std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
00614 std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
00615 while ( lIter != lIend ) {
00616 const DTConfigKey& entry = *lIter++;
00617 lmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
00618 }
00619 std::map<int,int> rmap;
00620 std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
00621 std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
00622 while ( rIter != rIend ) {
00623 const DTConfigKey& entry = *rIter++;
00624 rmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
00625 }
00626 std::map<int,int>::const_iterator lmIter = lmap.begin();
00627 std::map<int,int>::const_iterator lmIend = lmap.end();
00628 std::map<int,int>::const_iterator rmIter = rmap.begin();
00629 std::map<int,int>::const_iterator rmIend = rmap.end();
00630 while ( ( lmIter != lmIend ) &&
00631 ( rmIter != rmIend ) ) {
00632 const std::pair<int,int>& lEntry = *lmIter++;
00633 const std::pair<int,int>& rEntry = *rmIter++;
00634 if ( lEntry.first != rEntry.first ) return false;
00635 if ( lEntry.second != rEntry.second ) return false;
00636 }
00637 return true;
00638 }
00639
00640
00641 void DTKeyedConfigHandler::setList( cond::KeyList* list ) {
00642 keyList = list;
00643 }
00644