CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CondTools/DT/src/DTKeyedConfigHandler.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/07/21 16:06:53 $
00005  *  $Revision: 1.5 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //-----------------------
00011 // This Class' Header --
00012 //-----------------------
00013 #include "CondTools/DT/interface/DTKeyedConfigHandler.h"
00014 
00015 //-------------------------------
00016 // Collaborating Class Headers --
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 // C++ Headers --
00039 //---------------
00040 
00041 
00042 //-------------------
00043 // Initializations --
00044 //-------------------
00045 cond::KeyList* DTKeyedConfigHandler::keyList = 0;
00046 
00047 //----------------
00048 // Constructors --
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 // Destructor --
00069 //--------------
00070 DTKeyedConfigHandler::~DTKeyedConfigHandler() {
00071 }
00072 
00073 //--------------
00074 // Operations --
00075 //--------------
00076 void DTKeyedConfigHandler::getNewObjects() {
00077 
00078   //to access the information on the tag inside the offline database:
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   //to access the information on last successful log entry for this tag:
00110 //  cond::LogDBEntry const & lde = logDBEntry();     
00111 
00112   //to access the lastest payload (Ref is a smart pointer)
00113 //  Ref payload = lastPayload();
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   //  conn->configure( cond::CmsDefaults );
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   chkConfigList();
00132   std::cout << "get run config..." << std::endl;
00133 
00134   // Find latest runs
00135   std::map<int,int> runMap;
00136   std::map<int,std::vector<DTConfigKey>*> rhcMap;
00137   coral::ITable& runHistoryTable =
00138     isession.nominalSchema().tableHandle( "RUNHISTORY" );
00139   std::auto_ptr<coral::IQuery>
00140     runHistoryQuery( runHistoryTable.newQuery() );
00141   runHistoryQuery->addToOutputList( "RUN" );
00142   runHistoryQuery->addToOutputList( "RHID" );
00143   coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
00144   while( runHistoryCursor.next() ) {
00145     const coral::AttributeList& row = runHistoryCursor.currentRow();
00146     int runId = row[    "RUN"].data<int>();
00147     int rhcId = static_cast<int>( row["RHID"].data<int>() );
00148     if ( static_cast<unsigned>( runId ) <= lastRun ) continue;
00149     if ( runId < minRunId ) continue;
00150     if ( runId > maxRunId ) continue;
00151     std::cout << "schedule config key copy for run "
00152               << runId << " ---> RHID " << rhcId << std::endl;
00153     if ( runMap.find( runId ) == runMap.end() )
00154          runMap.insert( std::pair<int,int>( runId, rhcId ) );
00155     if ( rhcMap.find( rhcId ) == rhcMap.end() )
00156          rhcMap.insert( std::pair<int,std::vector<DTConfigKey>*>(
00157                                             rhcId,
00158                                             new std::vector<DTConfigKey> ) );
00159 //         rhcMap.insert( std::pair<int,std::vector<DTConfigKey>*>( rhcId, 0 ) );
00160   }
00161   if ( !runMap.size() ) std::cout << "no new run found" << std::endl;
00162 
00163   // get ccb identifiers map
00164   std::cout << "retrieve CCB map" << std::endl;
00165   std::map<int,DTCCBId> ccbMap;
00166   coral::ITable& ccbMapTable =
00167     isession.nominalSchema().tableHandle( "CCBMAP" );
00168   std::auto_ptr<coral::IQuery>
00169     ccbMapQuery( ccbMapTable.newQuery() );
00170   ccbMapQuery->addToOutputList( "CCBID" );
00171   ccbMapQuery->addToOutputList( "WHEEL" );
00172   ccbMapQuery->addToOutputList( "SECTOR" );
00173   ccbMapQuery->addToOutputList( "STATION" );
00174   coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
00175   while( ccbMapCursor.next() ) {
00176     const coral::AttributeList& row = ccbMapCursor.currentRow();
00177     int ccb     = row["CCBID"  ].data<int>();
00178     int wheel   = row["WHEEL"  ].data<int>();
00179     int sector  = row["SECTOR" ].data<int>();
00180     int station = row["STATION"].data<int>();
00181     DTCCBId ccbId;
00182     ccbId.  wheelId =   wheel;
00183     ccbId.stationId = station;
00184     ccbId. sectorId =  sector;
00185     ccbMap.insert( std::pair<int,DTCCBId>( ccb, ccbId ) );
00186   }
00187 
00188   // get brick types
00189   std::cout << "retrieve brick types" << std::endl;
00190   std::map<int,int> bktMap;
00191   coral::AttributeList emptyBindVariableList;
00192   std::auto_ptr<coral::IQuery>
00193          brickTypeQuery( isession.nominalSchema().newQuery() );
00194   brickTypeQuery->addToTableList( "CFGBRICKS" );
00195   brickTypeQuery->addToTableList( "BRKT2CSETT" );
00196   std::string bTypeCondition = "CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
00197   brickTypeQuery->addToOutputList( "CFGBRICKS.BRKID" );
00198   brickTypeQuery->addToOutputList( "BRKT2CSETT.CSETTYPE" );
00199   brickTypeQuery->setCondition( bTypeCondition, emptyBindVariableList );
00200   coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
00201   while( brickTypeCursor.next() ) {
00202     const coral::AttributeList& row = brickTypeCursor.currentRow();
00203     int id = row["CFGBRICKS.BRKID"    ].data<int>();
00204     int bt = row["BRKT2CSETT.CSETTYPE"].data<short>();
00205 //    std::cout << "brick " << id << " type " << bt << std::endl;
00206 // @@FIX - TEMPORARY PATCH
00207 //    if ( bt > 3 ) bt = 3;
00208     bktMap.insert( std::pair<int,int>( id, bt ) );
00209   }
00210 
00211   // get RH relations
00212   std::cout << "retrieve RH relations" << std::endl;
00213   std::map<int,int> cfgMap;
00214   coral::ITable& rhcRelTable =
00215     isession.nominalSchema().tableHandle( "RHRELATIONS" );
00216   std::auto_ptr<coral::IQuery>
00217     rhcRelQuery( rhcRelTable.newQuery() );
00218   rhcRelQuery->addToOutputList( "RHID" );
00219   rhcRelQuery->addToOutputList( "CONFKEY" );
00220   rhcRelQuery->addToOutputList( "CSETTYPEID" );
00221   coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
00222   // loop over all RH relations
00223   while( rhcRelCursor.next() ) {
00224     const coral::AttributeList& row = rhcRelCursor.currentRow();
00225     int rhc     = row["RHID"      ].data<int>();
00226     int key     = row["CONFKEY"   ].data<int>();
00227     int cfg     = row["CSETTYPEID"].data<int>();
00228     // check for used configurations
00229     std::map<int,std::vector<DTConfigKey>*>::iterator rhcIter =
00230                                                       rhcMap.find( rhc );
00231     std::map<int,std::vector<DTConfigKey>*>::iterator rhcIend =
00232                                                       rhcMap.end();
00233     if ( rhcIter == rhcIend ) continue;
00234     std::vector<DTConfigKey>* keyPtr = rhcIter->second;
00235 //    if ( keyPtr == 0 ) rhcIter->second = keyPtr = new std::vector<DTConfigKey>;
00236     DTConfigKey confList;
00237     confList.confType = cfg;
00238     confList.confKey  = key;
00239     keyPtr->push_back( confList );
00240     if ( cfgMap.find( cfg ) == cfgMap.end() )
00241          cfgMap.insert( std::pair<int,int>( key, rhc ) );
00242   }
00243 
00244   // get ccb config keys
00245   std::cout << "retrieve CCB configuration keys" << std::endl;
00246   std::map<int,std::map<int,int>*> keyMap;
00247   std::map<int,int> cckMap;
00248   coral::ITable& ccbRelTable =
00249     isession.nominalSchema().tableHandle( "CCBRELATIONS" );
00250   std::auto_ptr<coral::IQuery>
00251     ccbRelQuery( ccbRelTable.newQuery() );
00252   ccbRelQuery->addToOutputList( "CONFKEY" );
00253   ccbRelQuery->addToOutputList( "CCBID" );
00254   ccbRelQuery->addToOutputList( "CONFCCBKEY" );
00255   coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
00256   // loop over all full configurations
00257   while( ccbRelCursor.next() ) {
00258     const coral::AttributeList& row = ccbRelCursor.currentRow();
00259     int cfg     = row["CONFKEY"   ].data<int>();
00260     int ccb     = row["CCBID"     ].data<int>();
00261     int key     = row["CONFCCBKEY"].data<int>();
00262     // check for used configurations
00263     if ( cfgMap.find( cfg ) == cfgMap.end() ) continue;
00264     std::map<int,std::map<int,int>*>::const_iterator keyIter =
00265                                                      keyMap.find( cfg );
00266     std::map<int,std::map<int,int>*>::const_iterator keyIend =
00267                                                      keyMap.end();
00268     std::map<int,int>* mapPtr = 0;
00269     // check for new full configuration
00270     if ( keyIter != keyIend ) mapPtr = keyIter->second;
00271     else                      keyMap.insert(
00272                               std::pair<int,std::map<int,int>*>( cfg,
00273                               mapPtr = new std::map<int,int> ) );
00274     // store ccb config key
00275     std::map<int,int>& mapRef( *mapPtr );
00276     mapRef.insert( std::pair<int,int>( ccb, key ) );
00277     // check for new ccb config key
00278     if ( cckMap.find( key ) == cckMap.end() )
00279          cckMap.insert( std::pair<int,int>( key, ccb ) );
00280   }
00281 
00282   // get brick keys
00283   std::cout << "retrieve CCB configuration bricks" << std::endl;
00284   std::map<int,std::vector<int>*> brkMap;
00285   coral::ITable& confBrickTable =
00286     isession.nominalSchema().tableHandle( "CFG2BRKREL" );
00287   std::auto_ptr<coral::IQuery>
00288     confBrickQuery( confBrickTable.newQuery() );
00289   confBrickQuery->addToOutputList( "CONFID" );
00290   confBrickQuery->addToOutputList( "BRKID"  );
00291   coral::ICursor& confBrickCursor = confBrickQuery->execute();
00292   // loop over all brick keys
00293   while( confBrickCursor.next() ) {
00294     const coral::AttributeList& row = confBrickCursor.currentRow();
00295     int key = row["CONFID"].data<int>();
00296     int brk = row["BRKID" ].data<int>();
00297     // check for used ccb config key
00298     if ( cckMap.find( key ) == cckMap.end() ) continue;
00299     std::map<int,std::vector<int>*>::const_iterator brkIter =
00300                                                     brkMap.find( key );
00301     std::map<int,std::vector<int>*>::const_iterator brkIend =
00302                                                     brkMap.end();
00303     // check for new ccb config key
00304     std::vector<int>* brkPtr = 0;
00305     if ( brkIter != brkIend ) brkPtr = brkIter->second;
00306     else                      brkMap.insert(
00307                               std::pair<int,std::vector<int>*>( key,
00308                               brkPtr = new std::vector<int> ) );
00309     // store brick key
00310     brkPtr->push_back( brk );
00311   }
00312 
00313   // loop over new runs
00314   std::map<int,int>::const_iterator runIter = runMap.begin();
00315   std::map<int,int>::const_iterator runIend = runMap.end();
00316   while ( runIter != runIend ) {
00317     const std::pair<int,int>& runEntry = *runIter++;
00318     // get full configuration
00319     int run = runEntry.first;
00320     int rhc = runEntry.second;
00321     std::map<int,std::vector<DTConfigKey>*>::const_iterator
00322              rhcIter = rhcMap.find( rhc );
00323     std::map<int,std::vector<DTConfigKey>*>::const_iterator
00324              rhcIend = rhcMap.end();
00325     if ( rhcIter == rhcIend ) continue;
00326     if ( rhcIter->second == 0 ) {
00327       std::cout << "RHC not found for run: " << run << std::endl;
00328       continue;
00329     }
00330     if ( rhcIter->second->size() == 0 ) 
00331       std::cout << "empty RHC for run: " << run << std::endl;
00332     std::vector<DTConfigKey>& cfl = *( rhcIter->second );
00333     if ( sameConfigList( cfl, lastKey ) ) continue;
00334     lastKey = cfl;
00335     std::cout << "retrieve configuration bricks for run " << run
00336               << " ---> RH " << rhc << std::endl;
00337     DTCCBConfig* fullConf = new DTCCBConfig( dataTag );
00338     // set run and full configuration in payload
00339     fullConf->setStamp(   run );
00340     fullConf->setFullKey( cfl );
00341 
00342     std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
00343     std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
00344     while ( cfgIter != cfgIend ) {
00345     const DTConfigKey& cfgEntry = *cfgIter++;
00346     int cft = cfgEntry.confType;
00347     int cfg = cfgEntry.confKey;
00348 
00349     // retrieve ccb config map
00350     std::map<int,std::map<int,int>*>::const_iterator keyIter =
00351                                                      keyMap.find( cfg );
00352     std::map<int,std::map<int,int>*>::const_iterator keyIend =
00353                                                      keyMap.end();
00354     std::map<int,int>* mapPtr = 0;
00355     if ( keyIter != keyIend ) mapPtr = keyIter->second;
00356     if ( mapPtr == 0 ) continue;
00357     // loop over ccb
00358     std::map<int,int>::const_iterator ccbIter = mapPtr->begin();
00359     std::map<int,int>::const_iterator ccbIend = mapPtr->end();
00360     while ( ccbIter != ccbIend ) {
00361       const std::pair<int,int>& ccbEntry = *ccbIter++;
00362       // get ccb config key
00363       int ccb = ccbEntry.first;
00364       int key = ccbEntry.second;
00365       // retrieve chamber id
00366       std::map<int,DTCCBId>::const_iterator ccbIter = ccbMap.find( ccb );
00367       std::map<int,DTCCBId>::const_iterator ccbIend = ccbMap.end();
00368       if ( ccbIter == ccbIend ) continue;
00369       const DTCCBId& chaId = ccbIter->second;
00370       // retrieve brick id list
00371       std::map<int,std::vector<int>*>::const_iterator brkIter =
00372                                                       brkMap.find( key );
00373       std::map<int,std::vector<int>*>::const_iterator brkIend =
00374                                                       brkMap.end();
00375       if ( brkIter == brkIend ) continue;
00376       std::vector<int>* brkPtr = brkIter->second;
00377       if ( brkPtr == 0 ) continue;
00378       // brick id lists in payload
00379       std::vector<int> bkList;
00380       bkList.reserve( 20 );
00381       std::map<int,int>::const_iterator bktIter = bktMap.begin();
00382       std::map<int,int>::const_iterator bktIend = bktMap.end();
00383       std::vector<int>::const_iterator bkiIter = brkPtr->begin();
00384       std::vector<int>::const_iterator bkiIend = brkPtr->end();
00385       while ( bkiIter != bkiIend ) {
00386         int brickId = *bkiIter++;
00387         bktIter = bktMap.find( brickId );
00388         if ( bktIter == bktIend ) continue;
00389         if ( bktIter->second == cft ) bkList.push_back( brickId );
00390       }
00391       fullConf->appendConfigKey( chaId.wheelId,
00392                                  chaId.stationId,
00393                                  chaId.sectorId,
00394                                  bkList );
00395     }
00396     }
00397     cond::Time_t snc = runEntry.first;
00398     m_to_transfer.push_back( std::make_pair( fullConf, snc ) );
00399     std::cout << "writing payload : " << sizeof( *fullConf ) 
00400               << " ( " << ( fullConf->end() - fullConf->begin() )
00401               << " ) " << std::endl;
00402   }
00403 
00404   isession.transaction().commit();
00405   isession.close();
00406 
00407   return;
00408 
00409 }
00410 
00411 
00412 void DTKeyedConfigHandler::chkConfigList() {
00413 
00414   std::cout << "open POOL out db " << std::endl;
00415   edm::Service<cond::service::PoolDBOutputService> outdb;
00416 
00417   std::cout << "start queries " << std::endl;
00418   std::map<int,bool> activeConfigMap;
00419   coral::ITable& fullConfigTable =
00420     isession.nominalSchema().tableHandle( "CONFIGSETS" );
00421   std::auto_ptr<coral::IQuery>
00422     fullConfigQuery( fullConfigTable.newQuery() );
00423   fullConfigQuery->addToOutputList( "CONFKEY" );
00424   fullConfigQuery->addToOutputList( "NAME" );
00425   fullConfigQuery->addToOutputList( "RUN" );
00426   coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
00427   while( fullConfigCursor.next() ) {
00428     const coral::AttributeList& row = fullConfigCursor.currentRow();
00429     int fullConfigId = row["CONFKEY"].data<int>();
00430     int fullConfigRN = row["RUN"    ].data<int>();
00431     if ( fullConfigRN ) activeConfigMap.insert(
00432                         std::pair<int,bool>( fullConfigId, true ) );
00433     else                activeConfigMap.insert(
00434                         std::pair<int,bool>( fullConfigId, false ) );
00435     std::string fullConfigName = row["NAME"].data<std::string>();
00436   }
00437 
00438 //  std::cout << " =============== CCB config list" << std::endl;
00439   std::map<int,bool> activeCCBCfgMap;
00440   coral::ITable& fullCCBCfgTable =
00441     isession.nominalSchema().tableHandle( "CCBRELATIONS" );
00442   std::auto_ptr<coral::IQuery>
00443     fullCCBCfgQuery( fullCCBCfgTable.newQuery() );
00444   fullCCBCfgQuery->addToOutputList( "CONFKEY" );
00445   fullCCBCfgQuery->addToOutputList( "CONFCCBKEY" );
00446   coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
00447   while( fullCCBCfgCursor.next() ) {
00448     const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
00449     int fullConfigId = row["CONFKEY"   ].data<int>();
00450     int fullCCBCfgId = row["CONFCCBKEY"].data<int>();
00451     std::map<int,bool>::const_iterator cfgIter =
00452                                        activeConfigMap.find( fullConfigId );
00453     if ( cfgIter == activeConfigMap.end() ) continue;
00454     if ( activeCCBCfgMap.find( fullCCBCfgId ) ==
00455          activeCCBCfgMap.end() ) 
00456          activeCCBCfgMap.insert( std::pair<int,bool>( fullCCBCfgId, true ) );
00457   }
00458 
00459 //  std::cout << " =============== config brick list" << std::endl;
00460   std::map<int,bool> activeCfgBrkMap;
00461   coral::ITable& ccbConfBrkTable =
00462     isession.nominalSchema().tableHandle( "CFG2BRKREL" );
00463   std::auto_ptr<coral::IQuery>
00464     ccbConfBrickQuery( ccbConfBrkTable.newQuery() );
00465   ccbConfBrickQuery->addToOutputList( "CONFID" );
00466   ccbConfBrickQuery->addToOutputList( "BRKID" );
00467   coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
00468   while( ccbConfBrickCursor.next() ) {
00469     const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
00470     int fullCCBCfgId = row["CONFID"].data<int>();
00471     int ccbConfBrkId = row["BRKID" ].data<int>();
00472     std::map<int,bool>::const_iterator ccbIter =
00473                                        activeCCBCfgMap.find( fullCCBCfgId );
00474     if ( ccbIter == activeCCBCfgMap.end() ) continue;
00475     if ( !( ccbIter->second ) ) continue;
00476     if ( activeCfgBrkMap.find( ccbConfBrkId ) ==
00477          activeCfgBrkMap.end() )
00478          activeCfgBrkMap.insert( std::pair<int,bool>( ccbConfBrkId, true ) );
00479   }
00480 
00481 //  std::cout << " ===============" << std::endl;
00482 
00483   coral::ITable& brickConfigTable =
00484     isession.nominalSchema().tableHandle( "CFGBRICKS" );
00485   std::auto_ptr<coral::IQuery>
00486     brickConfigQuery( brickConfigTable.newQuery() );
00487   brickConfigQuery->addToOutputList( "BRKID" );
00488   brickConfigQuery->addToOutputList( "BRKNAME" );
00489   coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
00490   DTKeyedConfig* brickData = 0;
00491   std::vector<int> missingList;
00492   std::vector<unsigned long long> checkedKeys;
00493   while( brickConfigCursor.next() ) {
00494     const coral::AttributeList& row = brickConfigCursor.currentRow();
00495     int brickConfigId = row["BRKID"].data<int>();
00496     if ( brickConfigId < minBrickId ) continue;
00497     if ( brickConfigId > maxBrickId ) continue;
00498     std::map<int,bool>::const_iterator brkIter =
00499                                        activeCfgBrkMap.find( brickConfigId );
00500     if ( brkIter == activeCfgBrkMap.end() ) continue;
00501     if ( !( brkIter->second ) ) continue;
00502     std::string brickConfigName = row["BRKNAME"].data<std::string>();
00503     std::cout << "brick " << brickConfigId
00504               << " : "    << brickConfigName << std::endl;
00505     checkedKeys.push_back( brickConfigId );
00506     bool brickFound = false;
00507     try {
00508       keyList->load( checkedKeys );
00509       const DTKeyedConfig* brickCheck = keyList->get<DTKeyedConfig>( 0 );
00510       if ( brickCheck != 0 ) brickFound =
00511                              ( brickCheck->getId() == brickConfigId );
00512     }
00513     catch ( std::exception e ) {
00514     }
00515     if ( !brickFound ) {
00516       std::cout << "brick " << brickConfigId << " missing, copy request"
00517                 << std::endl;
00518       missingList.push_back( brickConfigId );
00519     }
00520     checkedKeys.clear();
00521   }
00522   keyList->load( checkedKeys );
00523 
00524   std::vector<int>::const_iterator brickIter = missingList.begin();
00525   std::vector<int>::const_iterator brickIend = missingList.end();
00526   while ( brickIter != brickIend ) {
00527     int brickConfigId = *brickIter++;
00528 //    std::cout << "get data for brick: " << brickConfigId << std::endl;
00529     coral::AttributeList bindVariableList;
00530     bindVariableList.extend( "brickId", typeid(int) );
00531     bindVariableList["brickId"].data<int>() = brickConfigId;
00532     std::auto_ptr<coral::IQuery>
00533            brickDataQuery( isession.nominalSchema().newQuery() );
00534     brickDataQuery->addToTableList( "CFGRELATIONS" );
00535     brickDataQuery->addToTableList( "CONFIGCMDS" );
00536     std::string
00537     brickCondition  =      "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
00538     brickCondition += " and CFGRELATIONS.BRKID=:brickId";
00539     brickDataQuery->addToOutputList( "CFGRELATIONS.BRKID" );
00540     brickDataQuery->addToOutputList( "CONFIGCMDS.CONFDATA" );
00541     brickDataQuery->setCondition( brickCondition, bindVariableList );
00542     coral::ICursor& brickDataCursor = brickDataQuery->execute();
00543     brickData = new DTKeyedConfig();
00544     brickData->setId( brickConfigId );
00545     while( brickDataCursor.next() ) {
00546       const coral::AttributeList& row = brickDataCursor.currentRow();
00547       brickData->add( row["CONFIGCMDS.CONFDATA"].data<std::string>() );
00548     }
00549     cond::KeyedElement k( brickData, brickConfigId );
00550     std::cout << "now writing brick: " << brickConfigId << std::endl;
00551     outdb->writeOne( k.m_obj, 0, k.m_key, brickContainer );
00552   }
00553 
00554   return;
00555 
00556 }
00557 
00558 
00559 std::string DTKeyedConfigHandler::id() const {
00560   return dataTag;
00561 }
00562 
00563 
00564 bool DTKeyedConfigHandler::sameConfigList(
00565                            const std::vector<DTConfigKey>& cfgl,
00566                            const std::vector<DTConfigKey>& cfgr ) {
00567   if ( cfgl.size() != cfgr.size() ) return false;
00568   std::map<int,int> lmap;
00569   std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
00570   std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
00571   while ( lIter != lIend ) {
00572     const DTConfigKey& entry = *lIter++;
00573     lmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
00574  }
00575   std::map<int,int> rmap;
00576   std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
00577   std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
00578   while ( rIter != rIend ) {
00579     const DTConfigKey& entry = *rIter++;
00580     rmap.insert( std::pair<int,int>( entry.confType, entry.confKey ) );
00581   }
00582   std::map<int,int>::const_iterator lmIter = lmap.begin();
00583   std::map<int,int>::const_iterator lmIend = lmap.end();
00584   std::map<int,int>::const_iterator rmIter = rmap.begin();
00585   std::map<int,int>::const_iterator rmIend = rmap.end();
00586   while ( ( lmIter != lmIend ) &&
00587           ( rmIter != rmIend ) ) {
00588     const std::pair<int,int>& lEntry = *lmIter++;
00589     const std::pair<int,int>& rEntry = *rmIter++;
00590     if ( lEntry.first  != rEntry.first  ) return false;
00591     if ( lEntry.second != rEntry.second ) return false;
00592   }
00593   return true;
00594 }
00595 
00596 
00597 void DTKeyedConfigHandler::setList( cond::KeyList* list ) {
00598   keyList = list;
00599 }
00600