CMS 3D CMS Logo

RPCEMapSourceHandler.cc

Go to the documentation of this file.
00001 #include "CondTools/RPC/interface/RPCEMapSourceHandler.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00005 
00006 popcon::RPCEMapSourceHandler::RPCEMapSourceHandler(const edm::ParameterSet& ps) :
00007   m_name(ps.getUntrackedParameter<std::string>("name","RPCEMapSourceHandler")),
00008   m_validate(ps.getUntrackedParameter<int>("Validate",0)),
00009   m_connect(ps.getUntrackedParameter<std::string>("OnlineConn","")),
00010   m_authpath(ps.getUntrackedParameter<std::string>("OnlineAuthPath",".")),
00011   m_host(ps.getUntrackedParameter<std::string>("OnlineDBHost","oracms.cern.ch")),
00012   m_sid(ps.getUntrackedParameter<std::string>("OnlineDBSID","omds")),
00013   m_user(ps.getUntrackedParameter<std::string>("OnlineDBUser","RPC_CONFIGURATION")),
00014   m_pass(ps.getUntrackedParameter<std::string>("OnlineDBPass","blahblah")),
00015   m_port(ps.getUntrackedParameter<int>("OnlineDBPort",10121))
00016 {
00017 }
00018 
00019 popcon::RPCEMapSourceHandler::~RPCEMapSourceHandler()
00020 {
00021 }
00022 
00023 void popcon::RPCEMapSourceHandler::getNewObjects()
00024 {
00025 
00026 //      std::cout << "RPCEMapSourceHandler: RPCEMapSourceHandler::getNewObjects begins\n";
00027 
00028   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00029 
00030 // first check what is already there in offline DB
00031   Ref payload;
00032   if(m_validate==1 && tagInfo().size>0) {
00033     std::cout<<" Validation was requested, so will check present contents"<<std::endl;
00034     std::cout<<"Name of tag : "<<tagInfo().name << ", tag size : " << tagInfo().size 
00035             << ", last object valid since " 
00036             << tagInfo().lastInterval.first << std::endl;  
00037     payload = lastPayload();
00038   }
00039 
00040 // now construct new cabling map from online DB
00041         if (m_connect=="") {
00042           ConnectOnlineDB(m_host,m_sid,m_user,m_pass,m_port);
00043           readEMap0();
00044         } else {
00045           ConnectOnlineDB(m_connect,m_authpath);
00046           readEMap1();
00047         }
00048         DisconnectOnlineDB();
00049 
00050         cond::Time_t snc=mydbservice->currentTime();
00051         
00052 // look for recent changes
00053         int difference=1;
00054         if (m_validate==1) difference=Compare2EMaps(payload,eMap);
00055         if (!difference) cout<<"No changes - will not write anything!!!"<<endl;
00056         if (difference==1) {
00057           cout<<"Will write new object to offline DB!!!"<<endl;
00058           m_to_transfer.push_back(std::make_pair((RPCEMap*)eMap,snc));
00059         }
00060 
00061 //      std::cout << "RPCEMapSourceHandler: RPCEMapSourceHandler::getNewObjects ends\n";
00062 }
00063 
00064 void popcon::RPCEMapSourceHandler::ConnectOnlineDB(string host, string sid, string user, string pass, int port=1521)
00065 {
00066   stringstream ss;
00067   ss << "//" << host << ":" << port << "/" << sid;
00068 
00069   cout << "RPCEMapSourceHandler: connecting to " << host << "..." << flush;
00070   env = Environment::createEnvironment(Environment::OBJECT);
00071   conn = env->createConnection(user, pass, ss.str());
00072   cout << "Done." << endl;
00073 }
00074 
00075 void popcon::RPCEMapSourceHandler::ConnectOnlineDB(string connect, string authPath)
00076 {
00077   cout << "RPCEMapConfigSourceHandler: connecting to " << connect << "..." << flush;
00078   session = new cond::DBSession();
00079   session->configuration().setAuthenticationMethod(cond::XML);
00080   session->configuration().setAuthenticationPath( authPath ) ;
00081   session->open() ;
00082   connection = new cond::Connection( connect ) ;
00083   connection->connect( session ) ;
00084   coralTr = & (connection->coralTransaction()) ;
00085   cout << "Done." << endl;
00086 }
00087 
00088 void popcon::RPCEMapSourceHandler::DisconnectOnlineDB()
00089 {
00090   if (m_connect=="") {
00091     env->terminateConnection(conn);
00092     Environment::terminateEnvironment(env);
00093   } else {
00094     connection->disconnect() ;
00095     delete connection ;
00096     delete session ;
00097   }
00098 }
00099 
00100 void popcon::RPCEMapSourceHandler::readEMap0()
00101 {
00102 
00103   time_t rawtime;
00104   time(&rawtime); //time since January 1, 1970
00105   tm * ptm = gmtime(&rawtime);//GMT time
00106   char buffer[20];
00107   strftime(buffer,20,"%d/%m/%Y_%H:%M:%S",ptm);
00108   string eMap_version=(string)buffer;
00109 
00110   Statement* stmt = conn->createStatement();
00111   string sqlQuery ="";
00112 
00113   cout << endl <<"RPCEMapSourceHandler: start to build RPC e-Map..." << flush << endl << endl;
00114   eMap =  new RPCEMap(eMap_version);
00115 
00116   // Get FEDs
00117   RPCEMap::dccItem thisDcc;
00118   sqlQuery=" SELECT DCCBoardId, FEDNumber FROM DCCBoard WHERE DCCBoardId>0 ORDER BY FEDNumber ";
00119   stmt->setSQL(sqlQuery.c_str());
00120   ResultSet* rset = stmt->executeQuery();
00121   std::pair<int,int> tmp_tbl;
00122   std::vector< std::pair<int,int> > theDAQ;
00123   while (rset->next()) {
00124     tmp_tbl.first=rset->getInt(1);
00125     tmp_tbl.second=rset->getInt(2);
00126     theDAQ.push_back(tmp_tbl);
00127   }
00128   for(unsigned int iFED=0;iFED<theDAQ.size();iFED++) {
00129     thisDcc.theId=theDAQ[iFED].second;
00130     std::vector<std::pair<int,int> > theTB;
00131 // get TBs
00132     RPCEMap::tbItem thisTB;
00133     sqlQuery = " SELECT TriggerBoardId, DCCInputChannelNum FROM TriggerBoard ";
00134     sqlQuery += " WHERE DCCBoard_DCCBoardId= ";
00135     sqlQuery += IntToString(theDAQ[iFED].first);
00136     sqlQuery += " ORDER BY DCCInputChannelNum ";
00137     stmt->setSQL(sqlQuery.c_str());
00138     rset = stmt->executeQuery();
00139     int ntbs=0;
00140     while (rset->next()) {
00141       ntbs++;
00142       tmp_tbl.first=rset->getInt(1);
00143       tmp_tbl.second=rset->getInt(2);
00144       theTB.push_back(tmp_tbl);
00145     }
00146     for(unsigned int iTB=0;iTB<theTB.size();iTB++) {
00147       thisTB.theNum=theTB[iTB].second;
00148       thisTB.theMaskedLinks=0;
00149       std::vector<std::pair<int,int> > theLink;
00150 // get links
00151       RPCEMap::linkItem thisLink;
00152       sqlQuery = " SELECT Board_BoardId, TriggerBoardInputNum FROM LinkConn ";
00153       sqlQuery += " WHERE TB_TriggerBoardId= ";
00154       sqlQuery +=  IntToString(theTB[iTB].first);
00155       sqlQuery += " ORDER BY TriggerBoardInputNum ";
00156       stmt->setSQL(sqlQuery.c_str());
00157       rset = stmt->executeQuery();
00158       int nlinks=0;
00159       while (rset->next()) {
00160         nlinks++;
00161         tmp_tbl.first=rset->getInt(1);
00162         tmp_tbl.second=rset->getInt(2);
00163         theLink.push_back(tmp_tbl);
00164       }
00165       for(unsigned int iLink=0;iLink<theLink.size();iLink++) {
00166         int boardId=theLink[iLink].first;
00167         thisLink.theTriggerBoardInputNumber=theLink[iLink].second;
00168         std::vector<std::pair<int,string> > theLB;
00169         std::pair<int,string> tmpLB;
00170         // Get master LBs first...
00171         RPCEMap::lbItem thisLB;
00172         sqlQuery = " SELECT Name ";
00173         sqlQuery += " FROM Board ";
00174         sqlQuery += " WHERE BoardId= ";
00175         sqlQuery +=  IntToString(theLink[iLink].first);
00176         stmt->setSQL(sqlQuery.c_str());
00177         rset = stmt->executeQuery();
00178         int nlbs=0;
00179         while (rset->next()) {
00180           nlbs++;
00181           tmpLB.first=theLink[iLink].first;
00182           tmpLB.second=rset->getString(1);
00183           theLB.push_back(tmpLB);
00184         }
00185         // then slaves
00186         sqlQuery = " SELECT LinkBoard.LinkBoardId, Board.Name ";
00187         sqlQuery += " FROM LinkBoard, Board ";
00188         sqlQuery += " WHERE LinkBoard.MasterId= ";
00189         sqlQuery +=  IntToString(theLink[iLink].first);
00190         sqlQuery += " AND Board.BoardId=LinkBoard.LinkBoardId";
00191         sqlQuery += " AND LinkBoard.MasterId<>LinkBoard.LinkBoardId";
00192         sqlQuery += " ORDER BY LinkBoard.LinkBoardId ";
00193         stmt->setSQL(sqlQuery.c_str());
00194         rset = stmt->executeQuery();
00195         while (rset->next()) {
00196           nlbs++;
00197           tmpLB.first=rset->getInt(1);
00198           tmpLB.second=rset->getString(2);
00199           theLB.push_back(tmpLB);
00200         }
00201         for(unsigned int iLB=0; iLB<theLB.size(); iLB++) {
00202           thisLB.theLinkBoardNumInLink=atoi(((theLB[iLB].second).substr((theLB[iLB].second).length()-1,1)).c_str());
00203           thisLB.theMaster = (theLB[iLB].first==boardId);
00204           FEBStruct tmpFEB;
00205           std::vector<FEBStruct> theFEB;
00206 // get FEBs
00207           RPCEMap::febItem thisFeb;
00208           sqlQuery = " SELECT FEBLocation.FEBLocationId,";
00209           sqlQuery += "  FEBLocation.CL_ChamberLocationId,";
00210           sqlQuery += "  FEBConnector.FEBConnectorId,";
00211           sqlQuery += "  FEBLocation.FEBLocalEtaPartition,"; 
00212           sqlQuery += "  FEBLocation.PosInLocalEtaPartition,";
00213           sqlQuery += "  FEBLocation.FEBCMSEtaPartition,";
00214           sqlQuery += "  FEBLocation.PosInCMSEtaPartition,";
00215           sqlQuery += "  FEBConnector.LinkBoardInputNum ";
00216           sqlQuery += " FROM FEBLocation, FEBConnector ";
00217           sqlQuery += " WHERE FEBLocation.LB_LinkBoardId= ";
00218           sqlQuery +=  IntToString(theLB[iLB].first);
00219           sqlQuery += "  AND FEBLocation.FEBLocationId=FEBConnector.FL_FEBLocationId";
00220           sqlQuery += " ORDER BY FEBLocation.FEBLocationId, FEBConnector.FEBConnectorId";
00221           stmt->setSQL(sqlQuery.c_str());
00222           rset = stmt->executeQuery();
00223           int nfebs=0;
00224           while (rset->next()) {
00225             nfebs++;
00226             tmpFEB.febId=rset->getInt(1);
00227             tmpFEB.chamberId=rset->getInt(2);
00228             tmpFEB.connectorId=rset->getInt(3);
00229             tmpFEB.localEtaPart=rset->getString(4);
00230             tmpFEB.posInLocalEtaPart=rset->getInt(5);
00231             tmpFEB.cmsEtaPart=rset->getString(6);
00232             tmpFEB.posInCmsEtaPart=rset->getInt(7);
00233             tmpFEB.lbInputNum=rset->getInt(8);
00234             theFEB.push_back(tmpFEB);
00235           }
00236           for(unsigned int iFEB=0; iFEB<theFEB.size(); iFEB++) {
00237             thisFeb.localEtaPartition=theFEB[iFEB].localEtaPart;
00238             thisFeb.positionInLocalEtaPartition=theFEB[iFEB].posInLocalEtaPart;
00239             thisFeb.cmsEtaPartition=theFEB[iFEB].cmsEtaPart;
00240             thisFeb.positionInCmsEtaPartition=theFEB[iFEB].posInCmsEtaPart;
00241             thisFeb.theLinkBoardInputNum=theFEB[iFEB].lbInputNum;
00242             FebLocationSpec febLocation = {theFEB[iFEB].cmsEtaPart,theFEB[iFEB].posInCmsEtaPart,theFEB[iFEB].localEtaPart,theFEB[iFEB].posInLocalEtaPart};
00243             // Get chamber 
00244             sqlQuery = "SELECT DiskOrWheel, Layer, Sector, Subsector,";
00245             sqlQuery += " ChamberLocationName,";
00246             sqlQuery += " FEBZOrnt, FEBRadOrnt, BarrelOrEndcap";
00247             sqlQuery += " FROM ChamberLocation ";
00248             sqlQuery += " WHERE ChamberLocationId= ";
00249             sqlQuery +=  IntToString(theFEB[iFEB].chamberId);
00250             stmt->setSQL(sqlQuery.c_str());
00251             rset = stmt->executeQuery();
00252             while (rset->next()) {
00253               thisFeb.diskOrWheel=rset->getInt(1);
00254               thisFeb.layer=rset->getInt(2);
00255               thisFeb.sector=rset->getInt(3);
00256               thisFeb.subsector=rset->getString(4);
00257               if (thisFeb.subsector=="") thisFeb.subsector="0";
00258               thisFeb.chamberLocationName=rset->getString(5);
00259               thisFeb.febZOrnt=rset->getString(6);
00260               thisFeb.febZRadOrnt=rset->getString(7);
00261               if (thisFeb.febZRadOrnt=="") thisFeb.febZRadOrnt="N/A";
00262               thisFeb.barrelOrEndcap=rset->getString(8);
00263               ChamberLocationSpec chamber = {thisFeb.diskOrWheel,thisFeb.layer,thisFeb.sector,thisFeb.subsector,thisFeb.chamberLocationName,thisFeb.febZOrnt,thisFeb.febZRadOrnt,thisFeb.barrelOrEndcap};
00264               DBSpecToDetUnit toDU;
00265               thisFeb.theRawId=toDU(chamber,febLocation);
00266             }
00267             // Get Strips
00268             RPCEMap::stripItem thisStrip;
00269             sqlQuery = "SELECT CableChannelNum, ChamberStripNumber, CmsStripNumber";
00270             sqlQuery += " FROM ChamberStrip ";
00271             sqlQuery += " WHERE FC_FEBConnectorId= ";
00272             sqlQuery +=  IntToString(theFEB[iFEB].connectorId);
00273             sqlQuery += " ORDER BY CableChannelNum";
00274             stmt->setSQL(sqlQuery.c_str());
00275             rset = stmt->executeQuery();
00276             int nstrips=0;
00277             while (rset->next()) {
00278               thisStrip.cablePinNumber=rset->getInt(1);
00279               thisStrip.chamberStripNumber=rset->getInt(2);
00280               thisStrip.cmsStripNumber=rset->getInt(3);
00281               eMap->theStrips.push_back(thisStrip);
00282               nstrips++;
00283             }
00284             thisFeb.nStrips=nstrips;
00285             eMap->theFebs.push_back(thisFeb);
00286           }
00287           thisLB.nFebs=nfebs;
00288           eMap->theLBs.push_back(thisLB);
00289         }
00290         thisLink.nLBs=nlbs;
00291         eMap->theLinks.push_back(thisLink);
00292       }
00293       thisTB.nLinks=nlinks;
00294       eMap->theTBs.push_back(thisTB);
00295     }
00296     thisDcc.nTBs=ntbs;
00297     std::cout<<"DCC added"<<std::endl;
00298     eMap->theDccs.push_back(thisDcc);
00299   }
00300   cout << endl <<"Building RPC e-Map done!" << flush << endl << endl;
00301 }
00302 
00303 void popcon::RPCEMapSourceHandler::readEMap1()
00304 {
00305   time_t rawtime;
00306   time(&rawtime); //time since January 1, 1970
00307   tm * ptm = gmtime(&rawtime);//GMT time
00308   char buffer[20];
00309   strftime(buffer,20,"%d/%m/%Y_%H:%M:%S",ptm);
00310   string eMap_version=(string)buffer;
00311 
00312   coralTr->start( true );
00313   coral::ISchema& schema = coralTr->nominalSchema();
00314   std::string condition="";
00315   coral::AttributeList conditionData;
00316 
00317   cout << endl <<"RPCEMapSourceHandler: start to build RPC e-Map..." << flush << endl << endl;
00318   eMap =  new RPCEMap(eMap_version);
00319 
00320   // Get FEDs
00321   RPCEMap::dccItem thisDcc;
00322   coral::IQuery* query1 = schema.newQuery();
00323   query1->addToTableList( "DCCBOARD" );
00324   query1->addToOutputList("DCCBOARD.DCCBOARDID","DCCBOARDID");
00325   query1->addToOutputList("DCCBOARD.FEDNUMBER","FEDNUMBER");
00326   query1->addToOrderList("FEDNUMBER");
00327   condition = "DCCBOARD.DCCBOARDID>0";
00328   query1->setCondition( condition, conditionData );
00329   coral::ICursor& cursor1 = query1->execute();
00330   std::pair<int,int> tmp_tbl;
00331   std::vector< std::pair<int,int> > theDAQ;
00332   while ( cursor1.next() ) {
00333 //    cursor1.currentRow().toOutputStream( std::cout ) << std::endl;
00334     const coral::AttributeList& row = cursor1.currentRow();
00335     tmp_tbl.first=row["DCCBOARDID"].data<long long>();
00336     tmp_tbl.second=row["FEDNUMBER"].data<long long>();
00337     theDAQ.push_back(tmp_tbl);
00338   }
00339   delete query1;
00340 
00341   for(unsigned int iFED=0;iFED<theDAQ.size();iFED++) {
00342     thisDcc.theId=theDAQ[iFED].second;
00343     std::vector<std::pair<int,int> > theTB;
00344 // get TBs
00345     RPCEMap::tbItem thisTB;
00346     coral::IQuery* query2 = schema.newQuery();
00347     query2->addToTableList( "TRIGGERBOARD" );
00348     query2->addToOutputList("TRIGGERBOARD.TRIGGERBOARDID","TRIGGERBOARDID");
00349     query2->addToOutputList("TRIGGERBOARD.DCCINPUTCHANNELNUM","DCCCHANNELNUM");
00350     query2->addToOrderList("DCCCHANNELNUM");
00351     condition = "TRIGGERBOARD.DCCBOARD_DCCBOARDID="+IntToString(theDAQ[iFED].first);
00352     query2->setCondition( condition, conditionData );
00353     coral::ICursor& cursor2 = query2->execute();
00354     int ntbs=0;
00355     while ( cursor2.next() ) {
00356       ntbs++;
00357 //      cursor2.currentRow().toOutputStream( std::cout ) << std::endl;
00358       const coral::AttributeList& row = cursor2.currentRow();
00359       tmp_tbl.first=row["TRIGGERBOARDID"].data<long long>();
00360       tmp_tbl.second=row["DCCCHANNELNUM"].data<long long>();
00361       theTB.push_back(tmp_tbl);
00362     }
00363     delete query2;
00364     for(unsigned int iTB=0;iTB<theTB.size();iTB++) {
00365       thisTB.theNum=theTB[iTB].second;
00366       thisTB.theMaskedLinks=0;
00367       std::vector<std::pair<int,int> > theLink;
00368 // get links
00369       RPCEMap::linkItem thisLink;
00370       coral::IQuery* query3 = schema.newQuery();
00371       query3->addToTableList("LINKCONN");
00372       query3->addToOutputList("LINKCONN.BOARD_BOARDID","BOARDID");
00373       query3->addToOutputList("LINKCONN.TRIGGERBOARDINPUTNUM","TBINPUTNUM");
00374       query3->addToOrderList("TBINPUTNUM");
00375       condition = "LINKCONN.TB_TRIGGERBOARDID="+IntToString(theTB[iTB].first);
00376       query3->setCondition( condition, conditionData );
00377       coral::ICursor& cursor3 = query3->execute();
00378       int nlinks=0;
00379       while (cursor3.next()) {
00380         nlinks++;
00381         const coral::AttributeList& row = cursor3.currentRow();
00382         tmp_tbl.first=row["BOARDID"].data<long long>();
00383         tmp_tbl.second=row["TBINPUTNUM"].data<long long>();
00384         theLink.push_back(tmp_tbl);
00385       }
00386       delete query3;
00387       for(unsigned int iLink=0;iLink<theLink.size();iLink++) {
00388         int boardId=theLink[iLink].first;
00389         thisLink.theTriggerBoardInputNumber=theLink[iLink].second;
00390         std::vector<std::pair<int,string> > theLB;
00391         std::pair<int,string> tmpLB;
00392         // Get master LBs first...
00393         RPCEMap::lbItem thisLB;
00394         coral::IQuery* query4 = schema.newQuery();
00395         query4->addToTableList("BOARD");
00396         query4->addToOutputList("BOARD.NAME","NAME");
00397         condition = "BOARD.BOARDID="+IntToString(theLink[iLink].first);
00398         query4->setCondition( condition, conditionData );
00399         coral::ICursor& cursor4 = query4->execute();
00400         int nlbs=0;
00401         while (cursor4.next()) {
00402           nlbs++;
00403           const coral::AttributeList& row = cursor4.currentRow();
00404           tmpLB.first=theLink[iLink].first;
00405           tmpLB.second=row["NAME"].data<std::string>();
00406           theLB.push_back(tmpLB);
00407         }
00408         delete query4;
00409         // then slaves
00410         coral::IQuery* query5 = schema.newQuery();
00411         query5->addToTableList("LINKBOARD");
00412         query5->addToTableList("BOARD");
00413         query5->addToOutputList("LINKBOARD.LINKBOARDID","LINKBOARDID");
00414         query5->addToOutputList("BOARD.NAME","NAME");
00415         query5->addToOrderList("LINKBOARDID");
00416         condition = "LINKBOARD.MASTERID="+IntToString(theLink[iLink].first)+" AND BOARD.BOARDID=LINKBOARD.LINKBOARDID AND LINKBOARD.MASTERID<>LINKBOARD.LINKBOARDID";
00417         query5->setCondition( condition, conditionData );
00418         coral::ICursor& cursor5 = query5->execute();
00419         while (cursor5.next()) {
00420           nlbs++;
00421           const coral::AttributeList& row = cursor5.currentRow();
00422           tmpLB.first=row["LINKBOARDID"].data<long long>();
00423           tmpLB.second=row["NAME"].data<std::string>();
00424           theLB.push_back(tmpLB);
00425         }
00426         delete query5;
00427         for(unsigned int iLB=0; iLB<theLB.size(); iLB++) {
00428           thisLB.theLinkBoardNumInLink=atoi(((theLB[iLB].second).substr((theLB[iLB].second).length()-1,1)).c_str());
00429           thisLB.theMaster = (theLB[iLB].first==boardId);
00430           FEBStruct tmpFEB;
00431           std::vector<FEBStruct> theFEB;
00432 // get FEBs
00433           RPCEMap::febItem thisFeb;
00434           coral::IQuery* query6 = schema.newQuery();
00435           query6->addToTableList("FEBLOCATION");
00436           query6->addToTableList("FEBCONNECTOR");
00437           query6->addToOutputList("FEBLOCATION.FEBLOCATIONID","FEBLOCATIONID");
00438           query6->addToOutputList("FEBLOCATION.CL_CHAMBERLOCATIONID","CHAMBERLOCATIONID");
00439           query6->addToOutputList("FEBCONNECTOR.FEBCONNECTORID","FEBCONNECTORID");
00440           query6->addToOutputList("FEBLOCATION.FEBLOCALETAPARTITION","LOCALETAPART"); 
00441           query6->addToOutputList("FEBLOCATION.POSINLOCALETAPARTITION","POSINLOCALETAPART");
00442           query6->addToOutputList("FEBLOCATION.FEBCMSETAPARTITION","CMSETAPART");
00443           query6->addToOutputList("FEBLOCATION.POSINCMSETAPARTITION","POSINCMSETAPART");
00444           query6->addToOutputList("FEBCONNECTOR.LINKBOARDINPUTNUM","LINKBOARDINPUTNUM");
00445           query6->addToOrderList("FEBLOCATIONID");
00446           query6->addToOrderList("FEBCONNECTORID");
00447           condition = "FEBLOCATION.LB_LINKBOARDID="+IntToString(theLB[iLB].first)+" AND FEBLOCATION.FEBLOCATIONID=FEBCONNECTOR.FL_FEBLOCATIONID";
00448           query6->setCondition( condition, conditionData );
00449           coral::ICursor& cursor6 = query6->execute();
00450           int nfebs=0;
00451           while (cursor6.next()) {
00452             nfebs++;
00453             const coral::AttributeList& row = cursor6.currentRow();
00454             tmpFEB.febId=row["FEBLOCATIONID"].data<long long>();
00455             tmpFEB.chamberId=row["CHAMBERLOCATIONID"].data<long long>();
00456             tmpFEB.connectorId=row["FEBCONNECTORID"].data<long long>();
00457             tmpFEB.localEtaPart=row["LOCALETAPART"].data<std::string>();
00458             tmpFEB.posInLocalEtaPart=row["POSINLOCALETAPART"].data<short>();
00459             tmpFEB.cmsEtaPart=row["CMSETAPART"].data<std::string>();
00460             tmpFEB.posInCmsEtaPart=row["POSINCMSETAPART"].data<short>();
00461             tmpFEB.lbInputNum=row["LINKBOARDINPUTNUM"].data<short>();
00462             theFEB.push_back(tmpFEB);
00463           }
00464           delete query6;
00465           for(unsigned int iFEB=0; iFEB<theFEB.size(); iFEB++) {
00466             thisFeb.localEtaPartition=theFEB[iFEB].localEtaPart;
00467             thisFeb.positionInLocalEtaPartition=theFEB[iFEB].posInLocalEtaPart;
00468             thisFeb.cmsEtaPartition=theFEB[iFEB].cmsEtaPart;
00469             thisFeb.positionInCmsEtaPartition=theFEB[iFEB].posInCmsEtaPart;
00470             thisFeb.theLinkBoardInputNum=theFEB[iFEB].lbInputNum;
00471             FebLocationSpec febLocation = {theFEB[iFEB].cmsEtaPart,theFEB[iFEB].posInCmsEtaPart,theFEB[iFEB].localEtaPart,theFEB[iFEB].posInLocalEtaPart};
00472             // Get chamber 
00473             coral::IQuery* query7 = schema.newQuery();
00474             query7->addToTableList("CHAMBERLOCATION");
00475             query7->addToOutputList("CHAMBERLOCATION.DISKORWHEEL","DISKORWHEEL");
00476             query7->addToOutputList("CHAMBERLOCATION.LAYER","LAYER");
00477             query7->addToOutputList("CHAMBERLOCATION.SECTOR","SECTOR");
00478             query7->addToOutputList("CHAMBERLOCATION.SUBSECTOR","SUBSECTOR");
00479             query7->addToOutputList("CHAMBERLOCATION.CHAMBERLOCATIONNAME","NAME");
00480             query7->addToOutputList("CHAMBERLOCATION.FEBZORNT","FEBZORNT");
00481             query7->addToOutputList("CHAMBERLOCATION.FEBRADORNT","FEBRADORNT");
00482             query7->addToOutputList("CHAMBERLOCATION.BARRELORENDCAP","BARRELORENDCAP");
00483             condition = "CHAMBERLOCATION.CHAMBERLOCATIONID="+IntToString(theFEB[iFEB].chamberId);
00484             query7->setCondition( condition, conditionData );
00485             coral::ICursor& cursor7 = query7->execute();
00486             while (cursor7.next()) {
00487               const coral::AttributeList& row = cursor7.currentRow();
00488               thisFeb.diskOrWheel=row["DISKORWHEEL"].data<short>();
00489               thisFeb.layer=row["LAYER"].data<short>();
00490               thisFeb.sector=row["SECTOR"].data<short>();
00491               thisFeb.subsector=row["SUBSECTOR"].data<std::string>();
00492               if (thisFeb.subsector=="") thisFeb.subsector="0";
00493               thisFeb.chamberLocationName=row["NAME"].data<std::string>();
00494               thisFeb.febZOrnt=row["FEBZORNT"].data<std::string>();
00495               thisFeb.febZRadOrnt=row["FEBRADORNT"].data<std::string>();
00496               if (thisFeb.febZRadOrnt=="") thisFeb.febZRadOrnt="N/A";
00497               thisFeb.barrelOrEndcap=row["BARRELORENDCAP"].data<std::string>();
00498               ChamberLocationSpec chamber = {thisFeb.diskOrWheel,thisFeb.layer,thisFeb.sector,thisFeb.subsector,thisFeb.chamberLocationName,thisFeb.febZOrnt,thisFeb.febZRadOrnt,thisFeb.barrelOrEndcap};
00499               DBSpecToDetUnit toDU;
00500               thisFeb.theRawId=toDU(chamber,febLocation);
00501             }
00502             delete query7;
00503             // Get Strips
00504             RPCEMap::stripItem thisStrip;
00505             coral::IQuery* query8 = schema.newQuery();
00506             query8->addToTableList("CHAMBERSTRIP");
00507             query8->addToOutputList("CHAMBERSTRIP.CABLECHANNELNUM","CABLECHANNELNUM");
00508             query8->addToOutputList("CHAMBERSTRIP.CHAMBERSTRIPNUMBER","CHAMBERSTRIPNUM");
00509             query8->addToOutputList("CHAMBERSTRIP.CMSSTRIPNUMBER","CMSSTRIPNUM");
00510             query8->addToOrderList("CABLECHANNELNUM");
00511             condition = "CHAMBERSTRIP.FC_FEBCONNECTORID="+IntToString(theFEB[iFEB].connectorId);
00512             query8->setCondition( condition, conditionData );
00513             coral::ICursor& cursor8 = query8->execute();
00514             int nstrips=0;
00515             while (cursor8.next()) {
00516               const coral::AttributeList& row = cursor8.currentRow();
00517               thisStrip.cablePinNumber=row["CABLECHANNELNUM"].data<short>();
00518               thisStrip.chamberStripNumber=row["CHAMBERSTRIPNUM"].data<int>();
00519               thisStrip.cmsStripNumber=row["CMSSTRIPNUM"].data<int>();
00520               eMap->theStrips.push_back(thisStrip);
00521               nstrips++;
00522             }
00523             delete query8;
00524             thisFeb.nStrips=nstrips;
00525             eMap->theFebs.push_back(thisFeb);
00526           }
00527           thisLB.nFebs=nfebs;
00528           eMap->theLBs.push_back(thisLB);
00529         }
00530         thisLink.nLBs=nlbs;
00531         eMap->theLinks.push_back(thisLink);
00532       }
00533       thisTB.nLinks=nlinks;
00534       eMap->theTBs.push_back(thisTB);
00535     }
00536     thisDcc.nTBs=ntbs;
00537     std::cout<<"DCC added"<<std::endl;
00538     eMap->theDccs.push_back(thisDcc);
00539   }
00540   coralTr->commit();
00541   cout << endl <<"Building RPC e-Map done!" << flush << endl << endl;
00542 }
00543 
00544 int popcon::RPCEMapSourceHandler::Compare2EMaps(Ref map1, RPCEMap* map2) {
00545   RPCReadOutMapping* oldmap1 = map1->convert();
00546   RPCReadOutMapping* oldmap2 = map2->convert();
00547   vector<const DccSpec *> dccs1 = oldmap1->dccList();
00548   vector<const DccSpec *> dccs2 = oldmap2->dccList();
00549   if(dccs1.size()!=dccs2.size()) {
00550     return 1;
00551   }
00552   pair<int,int> dccRange1 = oldmap1->dccNumberRange();
00553   pair<int,int> dccRange2 = oldmap2->dccNumberRange();
00554   if(dccRange1.first!=dccRange2.first) {
00555     return 1;
00556   }
00557   if(dccRange1.second!=dccRange2.second) {
00558     return 1;
00559   }
00560   typedef vector<const DccSpec *>::const_iterator IDCC;
00561   IDCC idcc2 = dccs2.begin();
00562   for (IDCC idcc1 = dccs1.begin(); idcc1 != dccs1.end(); idcc1++) {
00563     int dccNo = (**idcc1).id();
00564     std::string dccContents = (**idcc1).print(4);
00565     if ((**idcc2).id()!=dccNo) {
00566       return 1;
00567     }
00568     if ((**idcc2).print(4)!=dccContents) {
00569       return 1;
00570     }
00571     idcc2++;
00572   }
00573   return 0;
00574 }

Generated on Tue Jun 9 17:26:56 2009 for CMSSW by  doxygen 1.5.4