Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:46

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author Paolo Ronchese INFN Padova
0005  *
0006  */
0007 
0008 //-----------------------
0009 // This Class' Header --
0010 //-----------------------
0011 #include "CondTools/DT/interface/DTKeyedConfigHandler.h"
0012 
0013 //-------------------------------
0014 // Collaborating Class Headers --
0015 //-------------------------------
0016 #include "CondFormats/DTObjects/interface/DTCCBConfig.h"
0017 #include "CondFormats/DTObjects/interface/DTKeyedConfig.h"
0018 
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0021 #include "CondCore/DBOutputService/interface/KeyedElement.h"
0022 #include "CondCore/CondDB/interface/KeyList.h"
0023 
0024 #include "RelationalAccess/ISessionProxy.h"
0025 #include "RelationalAccess/ITransaction.h"
0026 #include "RelationalAccess/ISchema.h"
0027 #include "RelationalAccess/ITable.h"
0028 #include "RelationalAccess/ICursor.h"
0029 #include "RelationalAccess/IQuery.h"
0030 #include "CoralBase/AttributeList.h"
0031 #include "CoralBase/AttributeSpecification.h"
0032 #include "CoralBase/Attribute.h"
0033 
0034 //---------------
0035 // C++ Headers --
0036 //---------------
0037 
0038 #include <iostream>
0039 #include <memory>
0040 
0041 //-------------------
0042 // Initializations --
0043 //-------------------
0044 
0045 //----------------
0046 // Constructors --
0047 //----------------
0048 DTKeyedConfigHandler::DTKeyedConfigHandler(const edm::ParameterSet& ps)
0049     : copyData(ps.getUntrackedParameter<bool>("copyData", true)),
0050       minBrickId(ps.getUntrackedParameter<int>("minBrick", 0)),
0051       maxBrickId(ps.getUntrackedParameter<int>("maxBrick", 999999999)),
0052       minRunId(ps.getUntrackedParameter<int>("minRun", 0)),
0053       maxRunId(ps.getUntrackedParameter<int>("maxRun", 999999999)),
0054       dataTag(ps.getParameter<std::string>("tag")),
0055       onlineConnect(ps.getParameter<std::string>("onlineDB")),
0056       onlineAuthentication(ps.getParameter<std::string>("onlineAuthentication")),
0057       onlineAuthSys(ps.getUntrackedParameter<int>("onlineAuthSys", 1)),
0058       brickContainer(ps.getParameter<std::string>("container")),
0059       connection(),
0060       isession() {
0061   std::cout << " PopCon application for DT configuration export " << onlineAuthentication << std::endl;
0062 }
0063 
0064 //--------------
0065 // Destructor --
0066 //--------------
0067 DTKeyedConfigHandler::~DTKeyedConfigHandler() {}
0068 
0069 //--------------
0070 // Operations --
0071 //--------------
0072 void DTKeyedConfigHandler::getNewObjects() {
0073   //to access the information on the tag inside the offline database:
0074   cond::TagInfo_t const& ti = tagInfo();
0075   cond::Time_t last = ti.lastInterval.since;
0076   std::cout << "last configuration key already copied for run: " << last << std::endl;
0077 
0078   std::vector<DTConfigKey> lastKey;
0079   std::cout << "check for last " << std::endl;
0080   if (last == 0) {
0081     DTCCBConfig* dummyConf = new DTCCBConfig(dataTag);
0082     dummyConf->setStamp(0);
0083     dummyConf->setFullKey(lastKey);
0084     cond::Time_t snc = 1;
0085     std::cout << "write dummy " << std::endl;
0086     m_to_transfer.push_back(std::make_pair(dummyConf, snc));
0087   } else {
0088     std::cout << "get last payload" << std::endl;
0089     Ref payload = lastPayload();
0090     std::cout << "get last full key" << std::endl;
0091     lastKey = payload->fullKey();
0092     std::cout << "last key: " << std::endl;
0093     std::vector<DTConfigKey>::const_iterator keyIter = lastKey.begin();
0094     std::vector<DTConfigKey>::const_iterator keyIend = lastKey.end();
0095     while (keyIter != keyIend) {
0096       const DTConfigKey& cfgKeyList = *keyIter++;
0097       std::cout << cfgKeyList.confType << " : " << cfgKeyList.confKey << std::endl;
0098     }
0099   }
0100 
0101   //to access the information on last successful log entry for this tag:
0102   //  cond::LogDBEntry const & lde = logDBEntry();
0103 
0104   //to access the lastest payload (Ref is a smart pointer)
0105   //  Ref payload = lastPayload();
0106 
0107   if (!copyData)
0108     return;
0109 
0110   unsigned lastRun = last;
0111   std::cout << "check for new runs since " << lastRun << std::endl;
0112 
0113   std::cout << "configure DbConnection" << std::endl;
0114   //  conn->configure( cond::CmsDefaults );
0115   connection.setAuthenticationPath(onlineAuthentication);
0116   connection.setAuthenticationSystem(onlineAuthSys);
0117   connection.configure();
0118   std::cout << "create/open DbSession" << std::endl;
0119   isession = connection.createCoralSession(onlineConnect);
0120   std::cout << "start transaction" << std::endl;
0121   isession->transaction().start(true);
0122 
0123   // =========== Update configuration data
0124   chkConfigList();
0125   // =========== Find latest runs
0126   std::cout << "get run config..." << std::endl;
0127   std::map<int, std::vector<int>*> runMap;
0128   std::map<int, std::vector<DTConfigKey>*> rhcMap;
0129   coral::ITable& runHistoryTable = isession->nominalSchema().tableHandle("RUNHISTORY");
0130   std::unique_ptr<coral::IQuery> runHistoryQuery(runHistoryTable.newQuery());
0131   runHistoryQuery->addToOutputList("RUN");
0132   runHistoryQuery->addToOutputList("RHID");
0133   coral::ICursor& runHistoryCursor = runHistoryQuery->execute();
0134   while (runHistoryCursor.next()) {
0135     const coral::AttributeList& row = runHistoryCursor.currentRow();
0136     int runId = row["RUN"].data<int>();
0137     int rhcId = static_cast<int>(row["RHID"].data<int>());
0138     // ----------- ignore already copied runs
0139     if (static_cast<unsigned>(runId) <= lastRun)
0140       continue;
0141     // ----------- ignore runs outside required range
0142     if (runId < minRunId)
0143       continue;
0144     if (runId > maxRunId)
0145       continue;
0146     std::cout << "schedule config key copy for run " << runId << " ---> RHID " << rhcId << std::endl;
0147     // ----------- retrieve or create RH relation list for this run
0148     std::vector<int>* rhlPtr = nullptr;
0149     std::map<int, std::vector<int>*>::const_iterator runIter;
0150     if ((runIter = runMap.find(runId)) != runMap.end())
0151       rhlPtr = runIter->second;
0152     else
0153       runMap.insert(std::pair<int, std::vector<int>*>(runId, rhlPtr = new std::vector<int>));
0154     // ----------- append RH relation to the list
0155     rhlPtr->push_back(rhcId);
0156     // ----------- create key list for this RH relation
0157     if (rhcMap.find(rhcId) == rhcMap.end())
0158       rhcMap.insert(std::pair<int, std::vector<DTConfigKey>*>(rhcId, new std::vector<DTConfigKey>));
0159   }
0160   if (runMap.empty())
0161     std::cout << "no new run found" << std::endl;
0162 
0163   // =========== get ccb identifiers map
0164   std::cout << "retrieve CCB map" << std::endl;
0165   std::map<int, DTCCBId> ccbMap;
0166   coral::ITable& ccbMapTable = isession->nominalSchema().tableHandle("CCBMAP");
0167   std::unique_ptr<coral::IQuery> ccbMapQuery(ccbMapTable.newQuery());
0168   ccbMapQuery->addToOutputList("CCBID");
0169   ccbMapQuery->addToOutputList("WHEEL");
0170   ccbMapQuery->addToOutputList("SECTOR");
0171   ccbMapQuery->addToOutputList("STATION");
0172   coral::ICursor& ccbMapCursor = ccbMapQuery->execute();
0173   while (ccbMapCursor.next()) {
0174     const coral::AttributeList& row = ccbMapCursor.currentRow();
0175     int ccb = row["CCBID"].data<int>();
0176     int wheel = row["WHEEL"].data<int>();
0177     int sector = row["SECTOR"].data<int>();
0178     int station = row["STATION"].data<int>();
0179     DTCCBId ccbId;
0180     ccbId.wheelId = wheel;
0181     ccbId.stationId = station;
0182     ccbId.sectorId = sector;
0183     ccbMap.insert(std::pair<int, DTCCBId>(ccb, ccbId));
0184   }
0185 
0186   // =========== get brick types
0187   std::cout << "retrieve brick types" << std::endl;
0188   std::map<int, int> bktMap;
0189   coral::AttributeList emptyBindVariableList;
0190   std::unique_ptr<coral::IQuery> brickTypeQuery(isession->nominalSchema().newQuery());
0191   brickTypeQuery->addToTableList("CFGBRICKS");
0192   brickTypeQuery->addToTableList("BRKT2CSETT");
0193   // ----------- join brick type (1-11) to subsystem part (1-6)
0194   std::string bTypeCondition = "CFGBRICKS.BRKTYPE=BRKT2CSETT.BRKTYPE";
0195   brickTypeQuery->addToOutputList("CFGBRICKS.BRKID");
0196   brickTypeQuery->addToOutputList("BRKT2CSETT.CSETTYPE");
0197   brickTypeQuery->setCondition(bTypeCondition, emptyBindVariableList);
0198   coral::ICursor& brickTypeCursor = brickTypeQuery->execute();
0199   while (brickTypeCursor.next()) {
0200     const coral::AttributeList& row = brickTypeCursor.currentRow();
0201     int id = row["CFGBRICKS.BRKID"].data<int>();
0202     int bt = row["BRKT2CSETT.CSETTYPE"].data<short>();
0203     //    std::cout << "brick " << id << " type " << bt << std::endl;
0204     // @@FIX - TEMPORARY PATCH
0205     //    if ( bt > 3 ) bt = 3;
0206     bktMap.insert(std::pair<int, int>(id, bt));
0207   }
0208 
0209   // =========== get RH relations
0210   std::cout << "retrieve RH relations" << std::endl;
0211   std::map<int, int> cfgMap;
0212   coral::ITable& rhcRelTable = isession->nominalSchema().tableHandle("RHRELATIONS");
0213   std::unique_ptr<coral::IQuery> rhcRelQuery(rhcRelTable.newQuery());
0214   rhcRelQuery->addToOutputList("RHID");
0215   rhcRelQuery->addToOutputList("CONFKEY");
0216   rhcRelQuery->addToOutputList("CSETTYPEID");
0217   coral::ICursor& rhcRelCursor = rhcRelQuery->execute();
0218   while (rhcRelCursor.next()) {
0219     const coral::AttributeList& row = rhcRelCursor.currentRow();
0220     int rhc = row["RHID"].data<int>();
0221     int key = row["CONFKEY"].data<int>();
0222     int cfg = row["CSETTYPEID"].data<int>();
0223     // ----------- check for used RH relations, skip unused
0224     std::map<int, std::vector<DTConfigKey>*>::iterator rhcIter = rhcMap.find(rhc);
0225     std::map<int, std::vector<DTConfigKey>*>::iterator rhcIend = rhcMap.end();
0226     if (rhcIter == rhcIend)
0227       continue;
0228     std::vector<DTConfigKey>* keyPtr = rhcIter->second;
0229     DTConfigKey confList;
0230     confList.confType = cfg;
0231     confList.confKey = key;
0232     keyPtr->push_back(confList);
0233     // ----------- flag config key as used
0234     if (cfgMap.find(cfg) == cfgMap.end())
0235       cfgMap.insert(std::pair<int, int>(key, rhc));
0236   }
0237 
0238   // =========== get ccb config keys
0239   std::cout << "retrieve CCB configuration keys" << std::endl;
0240   std::map<int, std::map<int, int>*> keyMap;
0241   std::map<int, int> cckMap;
0242   coral::ITable& ccbRelTable = isession->nominalSchema().tableHandle("CCBRELATIONS");
0243   std::unique_ptr<coral::IQuery> ccbRelQuery(ccbRelTable.newQuery());
0244   ccbRelQuery->addToOutputList("CONFKEY");
0245   ccbRelQuery->addToOutputList("CCBID");
0246   ccbRelQuery->addToOutputList("CONFCCBKEY");
0247   coral::ICursor& ccbRelCursor = ccbRelQuery->execute();
0248   while (ccbRelCursor.next()) {
0249     const coral::AttributeList& row = ccbRelCursor.currentRow();
0250     int cfg = row["CONFKEY"].data<int>();
0251     int ccb = row["CCBID"].data<int>();
0252     int key = row["CONFCCBKEY"].data<int>();
0253     // ----------- check for used configurations, skip unused
0254     if (cfgMap.find(cfg) == cfgMap.end())
0255       continue;
0256     // ----------- retrieve or create ccb id-key map for this configuration
0257     std::map<int, int>* mapPtr = nullptr;
0258     std::map<int, std::map<int, int>*>::const_iterator keyIter;
0259     if ((keyIter = keyMap.find(cfg)) != keyMap.end())
0260       mapPtr = keyIter->second;
0261     else
0262       keyMap.insert(std::pair<int, std::map<int, int>*>(cfg, mapPtr = new std::map<int, int>));
0263     //    std::map<int,std::map<int,int>*>::const_iterator keyIter =
0264     //                                                     keyMap.find( cfg );
0265     //    std::map<int,std::map<int,int>*>::const_iterator keyIend =
0266     //                                                     keyMap.end();
0267     //    if ( keyIter != keyIend ) mapPtr = keyIter->second;
0268     //    else                      keyMap.insert(
0269     //                              std::pair<int,std::map<int,int>*>( cfg,
0270     //                              mapPtr = new std::map<int,int> ) );
0271     // ----------- store config key for this ccb
0272     std::map<int, int>& mapRef(*mapPtr);
0273     mapRef.insert(std::pair<int, int>(ccb, key));
0274     // ----------- flag ccb config key as used
0275     if (cckMap.find(key) == cckMap.end())
0276       cckMap.insert(std::pair<int, int>(key, ccb));
0277   }
0278 
0279   // =========== get brick keys
0280   std::cout << "retrieve CCB configuration bricks" << std::endl;
0281   std::map<int, std::vector<int>*> brkMap;
0282   coral::ITable& confBrickTable = isession->nominalSchema().tableHandle("CFG2BRKREL");
0283   std::unique_ptr<coral::IQuery> confBrickQuery(confBrickTable.newQuery());
0284   confBrickQuery->addToOutputList("CONFID");
0285   confBrickQuery->addToOutputList("BRKID");
0286   coral::ICursor& confBrickCursor = confBrickQuery->execute();
0287   while (confBrickCursor.next()) {
0288     const coral::AttributeList& row = confBrickCursor.currentRow();
0289     int key = row["CONFID"].data<int>();
0290     int brk = row["BRKID"].data<int>();
0291     // ----------- check for used ccb config key, skip unused
0292     if (cckMap.find(key) == cckMap.end())
0293       continue;
0294     //    std::map<int,std::vector<int>*>::const_iterator brkIter =
0295     //                                                    brkMap.find( key );
0296     //    std::map<int,std::vector<int>*>::const_iterator brkIend =
0297     //                                                    brkMap.end();
0298     // ----------- retrieve or create brick list for this ccb config
0299     std::vector<int>* brkPtr = nullptr;
0300     std::map<int, std::vector<int>*>::const_iterator brkIter;
0301     //check for new ccb config key
0302     if ((brkIter = brkMap.find(key)) != brkMap.end())
0303       brkPtr = brkIter->second;
0304     else
0305       brkMap.insert(std::pair<int, std::vector<int>*>(key, brkPtr = new std::vector<int>));
0306     //    if ( brkIter != brkIend ) brkPtr = brkIter->second;
0307     //    else                      brkMap.insert(
0308     //                              std::pair<int,std::vector<int>*>( key,
0309     //                              brkPtr = new std::vector<int> ) );
0310     // ----------- store brick key
0311     brkPtr->push_back(brk);
0312   }
0313 
0314   // =========== loop over new runs
0315   std::map<int, std::vector<int>*>::const_iterator runIter = runMap.begin();
0316   std::map<int, std::vector<int>*>::const_iterator runIend = runMap.end();
0317   while (runIter != runIend) {
0318     const std::pair<int, std::vector<int>*>& runEntry = *runIter++;
0319     // ----------- get full configuration
0320     int run = runEntry.first;
0321     std::vector<DTConfigKey> cfl;
0322     // ----------- get RH relation list
0323     std::vector<int>* rhlPtr = runEntry.second;
0324     std::vector<int>::const_iterator rhlIter = rhlPtr->begin();
0325     std::vector<int>::const_iterator rhlIend = rhlPtr->end();
0326     // ----------- loop over RH relations
0327     while (rhlIter != rhlIend) {
0328       int rhc = *rhlIter++;
0329       std::cout << "retrieve configuration bricks for run " << run << " ---> RH " << rhc << std::endl;
0330       //      std::map<int,std::vector<DTConfigKey>*>::const_iterator
0331       //               rhcIter = rhcMap.find( rhc );
0332       //      std::map<int,std::vector<DTConfigKey>*>::const_iterator
0333       //               rhcIend = rhcMap.end();
0334       std::map<int, std::vector<DTConfigKey>*>::const_iterator rhcIter;
0335       // ----------- redundant check
0336       if ((rhcIter = rhcMap.find(rhc)) == rhcMap.end())
0337         continue;
0338       std::vector<DTConfigKey>* listPtr = rhcIter->second;
0339       // ----------- redundant check
0340       if (listPtr == nullptr)
0341         continue;
0342       std::vector<DTConfigKey>::const_iterator bkiIter = listPtr->begin();
0343       std::vector<DTConfigKey>::const_iterator bkiIend = listPtr->end();
0344       while (bkiIter != bkiIend)
0345         cfl.push_back(*bkiIter++);
0346     }
0347     if (sameConfigList(cfl, lastKey))
0348       continue;
0349     lastKey = cfl;
0350     DTCCBConfig* fullConf = new DTCCBConfig(dataTag);
0351     // set run and full configuration in payload
0352     fullConf->setStamp(run);
0353     fullConf->setFullKey(cfl);
0354 
0355     std::vector<DTConfigKey>::const_iterator cfgIter = cfl.begin();
0356     std::vector<DTConfigKey>::const_iterator cfgIend = cfl.end();
0357     while (cfgIter != cfgIend) {
0358       const DTConfigKey& cfgEntry = *cfgIter++;
0359       int cft = cfgEntry.confType;
0360       int cfg = cfgEntry.confKey;
0361 
0362       // =========== retrieve ccb config map
0363       //    std::map<int,std::map<int,int>*>::const_iterator keyIter =
0364       //                                                     keyMap.find( cfg );
0365       //    std::map<int,std::map<int,int>*>::const_iterator keyIend =
0366       //                                                     keyMap.end();
0367       std::map<int, int>* mapPtr = nullptr;
0368       std::map<int, std::map<int, int>*>::const_iterator keyIter;
0369       // ----------- redundant check
0370       //      if ( keyIter != keyIend )
0371       if ((keyIter = keyMap.find(cfg)) != keyMap.end())
0372         mapPtr = keyIter->second;
0373       if (mapPtr == nullptr)
0374         continue;
0375       std::map<int, int>::const_iterator ccmIter = mapPtr->begin();
0376       std::map<int, int>::const_iterator ccmIend = mapPtr->end();
0377       while (ccmIter != ccmIend) {
0378         const std::pair<int, int>& ccmEntry = *ccmIter++;
0379         // ----------- get ccb config key
0380         int ccb = ccmEntry.first;
0381         int key = ccmEntry.second;
0382         // retrieve chamber id
0383         //        std::map<int,DTCCBId>::const_iterator ccbIter = ccbMap.find( ccb );
0384         //        std::map<int,DTCCBId>::const_iterator ccbIend = ccbMap.end();
0385         std::map<int, DTCCBId>::const_iterator ccbIter;
0386         // ----------- redundant check
0387         //        if ( ccbIter == ccbIend ) continue;
0388         if ((ccbIter = ccbMap.find(ccb)) == ccbMap.end())
0389           continue;
0390         const DTCCBId& chaId = ccbIter->second;
0391         // ----------- retrieve brick id list
0392         //        std::map<int,std::vector<int>*>::const_iterator brkIter =
0393         //                                                        brkMap.find( key );
0394         //        std::map<int,std::vector<int>*>::const_iterator brkIend =
0395         //                                                        brkMap.end();
0396         //        if ( brkIter == brkIend ) continue;
0397         std::map<int, std::vector<int>*>::const_iterator brkIter;
0398         if ((brkIter = brkMap.find(key)) == brkMap.end())
0399           continue;
0400         std::vector<int>* brkPtr = brkIter->second;
0401         // ----------- redundant check
0402         if (brkPtr == nullptr)
0403           continue;
0404         // ----------- set brick id lists in payload
0405         std::vector<int> bkList;
0406         bkList.reserve(20);
0407         //        std::map<int,int>::const_iterator bktIter = bktMap.begin();
0408         //        std::map<int,int>::const_iterator bktIend = bktMap.end();
0409         std::map<int, int>::const_iterator bktIter;
0410         std::vector<int>::const_iterator bkiIter = brkPtr->begin();
0411         std::vector<int>::const_iterator bkiIend = brkPtr->end();
0412         while (bkiIter != bkiIend) {
0413           int brickId = *bkiIter++;
0414           //          bktIter = bktMap.find( brickId );
0415           // ----------- redundant check
0416           if ((bktIter = bktMap.find(brickId)) == bktMap.end())
0417             continue;
0418           if (bktIter->second == cft)
0419             bkList.push_back(brickId);
0420         }
0421         fullConf->appendConfigKey(chaId.wheelId, chaId.stationId, chaId.sectorId, bkList);
0422       }
0423     }
0424     cond::Time_t snc = runEntry.first;
0425     m_to_transfer.push_back(std::make_pair(fullConf, snc));
0426     std::cout << "writing payload : " << sizeof(*fullConf) << " ( " << (fullConf->end() - fullConf->begin()) << " ) "
0427               << std::endl;
0428   }
0429 
0430   isession->transaction().commit();
0431 
0432   return;
0433 }
0434 
0435 void DTKeyedConfigHandler::chkConfigList() {
0436   std::cout << "open POOL out db " << std::endl;
0437   edm::Service<cond::service::PoolDBOutputService> outdb;
0438 
0439   std::cout << "start queries " << std::endl;
0440   std::map<int, bool> activeConfigMap;
0441   coral::ITable& fullConfigTable = isession->nominalSchema().tableHandle("CONFIGSETS");
0442   std::unique_ptr<coral::IQuery> fullConfigQuery(fullConfigTable.newQuery());
0443   fullConfigQuery->addToOutputList("CONFKEY");
0444   fullConfigQuery->addToOutputList("NAME");
0445   fullConfigQuery->addToOutputList("RUN");
0446   coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
0447   while (fullConfigCursor.next()) {
0448     const coral::AttributeList& row = fullConfigCursor.currentRow();
0449     int fullConfigId = row["CONFKEY"].data<int>();
0450     int fullConfigRN = row["RUN"].data<int>();
0451     if (fullConfigRN)
0452       activeConfigMap.insert(std::pair<int, bool>(fullConfigId, true));
0453     else
0454       activeConfigMap.insert(std::pair<int, bool>(fullConfigId, false));
0455     std::string fullConfigName = row["NAME"].data<std::string>();
0456   }
0457 
0458   //  std::cout << " =============== CCB config list" << std::endl;
0459   std::map<int, bool> activeCCBCfgMap;
0460   coral::ITable& fullCCBCfgTable = isession->nominalSchema().tableHandle("CCBRELATIONS");
0461   std::unique_ptr<coral::IQuery> fullCCBCfgQuery(fullCCBCfgTable.newQuery());
0462   fullCCBCfgQuery->addToOutputList("CONFKEY");
0463   fullCCBCfgQuery->addToOutputList("CONFCCBKEY");
0464   coral::ICursor& fullCCBCfgCursor = fullCCBCfgQuery->execute();
0465   while (fullCCBCfgCursor.next()) {
0466     const coral::AttributeList& row = fullCCBCfgCursor.currentRow();
0467     int fullConfigId = row["CONFKEY"].data<int>();
0468     int fullCCBCfgId = row["CONFCCBKEY"].data<int>();
0469     //    std::map<int,bool>::const_iterator cfgIter =
0470     //                                       activeConfigMap.find( fullConfigId );
0471     std::map<int, bool>::const_iterator cfgIter;
0472     if ((cfgIter = activeConfigMap.find(fullConfigId)) == activeConfigMap.end())
0473       continue;
0474     if (!(cfgIter->second))
0475       continue;
0476     if (activeCCBCfgMap.find(fullCCBCfgId) == activeCCBCfgMap.end())
0477       activeCCBCfgMap.insert(std::pair<int, bool>(fullCCBCfgId, true));
0478   }
0479 
0480   //  std::cout << " =============== config brick list" << std::endl;
0481   std::map<int, bool> activeCfgBrkMap;
0482   coral::ITable& ccbConfBrkTable = isession->nominalSchema().tableHandle("CFG2BRKREL");
0483   std::unique_ptr<coral::IQuery> ccbConfBrickQuery(ccbConfBrkTable.newQuery());
0484   ccbConfBrickQuery->addToOutputList("CONFID");
0485   ccbConfBrickQuery->addToOutputList("BRKID");
0486   coral::ICursor& ccbConfBrickCursor = ccbConfBrickQuery->execute();
0487   while (ccbConfBrickCursor.next()) {
0488     const coral::AttributeList& row = ccbConfBrickCursor.currentRow();
0489     int fullCCBCfgId = row["CONFID"].data<int>();
0490     int ccbConfBrkId = row["BRKID"].data<int>();
0491     //    std::map<int,bool>::const_iterator ccbIter =
0492     //                                       activeCCBCfgMap.find( fullCCBCfgId );
0493     std::map<int, bool>::const_iterator ccbIter;
0494     if ((ccbIter = activeCCBCfgMap.find(fullCCBCfgId)) == activeCCBCfgMap.end())
0495       continue;
0496     if (!(ccbIter->second))
0497       continue;
0498     if (activeCfgBrkMap.find(ccbConfBrkId) == activeCfgBrkMap.end())
0499       activeCfgBrkMap.insert(std::pair<int, bool>(ccbConfBrkId, true));
0500   }
0501 
0502   //  std::cout << " ===============" << std::endl;
0503 
0504   coral::ITable& brickConfigTable = isession->nominalSchema().tableHandle("CFGBRICKS");
0505   std::unique_ptr<coral::IQuery> brickConfigQuery(brickConfigTable.newQuery());
0506   brickConfigQuery->addToOutputList("BRKID");
0507   brickConfigQuery->addToOutputList("BRKNAME");
0508   coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
0509   std::vector<int> missingList;
0510   while (brickConfigCursor.next()) {
0511     const coral::AttributeList& row = brickConfigCursor.currentRow();
0512     int brickConfigId = row["BRKID"].data<int>();
0513     if (brickConfigId < minBrickId)
0514       continue;
0515     if (brickConfigId > maxBrickId)
0516       continue;
0517     //    std::map<int,bool>::const_iterator brkIter =
0518     //                                       activeCfgBrkMap.find( brickConfigId );
0519     std::map<int, bool>::const_iterator brkIter;
0520     if ((brkIter = activeCfgBrkMap.find(brickConfigId)) == activeCfgBrkMap.end())
0521       continue;
0522     if (!(brkIter->second))
0523       continue;
0524     std::string brickConfigName = row["BRKNAME"].data<std::string>();
0525     std::cout << "brick " << brickConfigId << " : " << brickConfigName << std::endl;
0526     bool brickFound = false;
0527     try {
0528       std::shared_ptr<DTKeyedConfig> brickCheck = keyList->getUsingKey<DTKeyedConfig>(brickConfigId);
0529       if (brickCheck.get())
0530         brickFound = (brickCheck->getId() == brickConfigId);
0531     } catch (std::exception const&) {
0532     }
0533     if (!brickFound) {
0534       std::cout << "brick " << brickConfigId << " missing, copy request" << std::endl;
0535       missingList.push_back(brickConfigId);
0536     }
0537   }
0538 
0539   std::vector<int>::const_iterator brickIter = missingList.begin();
0540   std::vector<int>::const_iterator brickIend = missingList.end();
0541   while (brickIter != brickIend) {
0542     int brickConfigId = *brickIter++;
0543     //    std::cout << "get data for brick: " << brickConfigId << std::endl;
0544     coral::AttributeList bindVariableList;
0545     bindVariableList.extend("brickId", typeid(int));
0546     bindVariableList["brickId"].data<int>() = brickConfigId;
0547     std::unique_ptr<coral::IQuery> brickDataQuery(isession->nominalSchema().newQuery());
0548     brickDataQuery->addToTableList("CFGRELATIONS");
0549     brickDataQuery->addToTableList("CONFIGCMDS");
0550     std::string brickCondition = "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
0551     brickCondition += " and CFGRELATIONS.BRKID=:brickId";
0552     brickDataQuery->addToOutputList("CFGRELATIONS.BRKID");
0553     brickDataQuery->addToOutputList("CONFIGCMDS.CONFDATA");
0554     brickDataQuery->setCondition(brickCondition, bindVariableList);
0555     coral::ICursor& brickDataCursor = brickDataQuery->execute();
0556     DTKeyedConfig brickData;
0557     brickData.setId(brickConfigId);
0558     while (brickDataCursor.next()) {
0559       const coral::AttributeList& row = brickDataCursor.currentRow();
0560       brickData.add(row["CONFIGCMDS.CONFDATA"].data<std::string>());
0561     }
0562     cond::KeyedElement k(&brickData, brickConfigId);
0563     std::cout << "now writing brick: " << brickConfigId << std::endl;
0564     outdb->writeOneIOV(*(k.m_obj), k.m_key, brickContainer);
0565   }
0566 
0567   return;
0568 }
0569 
0570 std::string DTKeyedConfigHandler::id() const { return dataTag; }
0571 
0572 bool DTKeyedConfigHandler::sameConfigList(const std::vector<DTConfigKey>& cfgl, const std::vector<DTConfigKey>& cfgr) {
0573   if (cfgl.size() != cfgr.size())
0574     return false;
0575   std::map<int, int> lmap;
0576   std::vector<DTConfigKey>::const_iterator lIter = cfgl.begin();
0577   std::vector<DTConfigKey>::const_iterator lIend = cfgl.end();
0578   while (lIter != lIend) {
0579     const DTConfigKey& entry = *lIter++;
0580     lmap.insert(std::pair<int, int>(entry.confType, entry.confKey));
0581   }
0582   std::map<int, int> rmap;
0583   std::vector<DTConfigKey>::const_iterator rIter = cfgr.begin();
0584   std::vector<DTConfigKey>::const_iterator rIend = cfgr.end();
0585   while (rIter != rIend) {
0586     const DTConfigKey& entry = *rIter++;
0587     rmap.insert(std::pair<int, int>(entry.confType, entry.confKey));
0588   }
0589   std::map<int, int>::const_iterator lmIter = lmap.begin();
0590   std::map<int, int>::const_iterator lmIend = lmap.end();
0591   std::map<int, int>::const_iterator rmIter = rmap.begin();
0592   std::map<int, int>::const_iterator rmIend = rmap.end();
0593   while ((lmIter != lmIend) && (rmIter != rmIend)) {
0594     const std::pair<int, int>& lEntry = *lmIter++;
0595     const std::pair<int, int>& rEntry = *rmIter++;
0596     if (lEntry.first != rEntry.first)
0597       return false;
0598     if (lEntry.second != rEntry.second)
0599       return false;
0600   }
0601   return true;
0602 }
0603 
0604 void DTKeyedConfigHandler::setList(const cond::persistency::KeyList* list) { keyList = list; }