CMS 3D CMS Logo

popcon::RPCReadOutMappingSourceHandler Class Reference

#include <CondTools/RPC/interface/RPCReadOutMappingSourceHandler.h>

Inheritance diagram for popcon::RPCReadOutMappingSourceHandler:

popcon::PopConSourceHandler< RPCReadOutMapping >

List of all members.

Public Member Functions

int Compare2Cablings (const RPCReadOutMapping *map1, RPCReadOutMapping *map2)
void ConnectOnlineDB (string host, string sid, string user, string pass, int port)
void DisconnectOnlineDB ()
void getNewObjects ()
std::string id () const
void readCablingMap ()
 RPCReadOutMappingSourceHandler (const edm::ParameterSet &ps)
 ~RPCReadOutMappingSourceHandler ()

Private Member Functions

string IntToString (int num)

Private Attributes

RPCReadOutMappingcabling
Connectionconn
Environment * env
std::string m_host
std::string m_name
std::string m_pass
int m_port
std::string m_sid
std::string m_user
int m_validate

Classes

struct  FEBStruct


Detailed Description

Definition at line 36 of file RPCReadOutMappingSourceHandler.h.


Constructor & Destructor Documentation

popcon::RPCReadOutMappingSourceHandler::RPCReadOutMappingSourceHandler ( const edm::ParameterSet ps  ) 

Definition at line 6 of file RPCReadOutMappingSourceHandler.cc.

00006                                                                                              :
00007   m_name(ps.getUntrackedParameter<std::string>("name","RPCReadOutMappingSourceHandler")),
00008   m_validate(ps.getUntrackedParameter<int>("Validate",0)),
00009   m_host(ps.getUntrackedParameter<std::string>("OnlineDBHost","lxplus.cern.ch")),
00010   m_sid(ps.getUntrackedParameter<std::string>("OnlineDBSID","blah")),
00011   m_user(ps.getUntrackedParameter<std::string>("OnlineDBUser","blaah")),
00012   m_pass(ps.getUntrackedParameter<std::string>("OnlineDBPass","blaaah")),
00013   m_port(ps.getUntrackedParameter<int>("OnlineDBPort",1521))
00014 {
00015 }

popcon::RPCReadOutMappingSourceHandler::~RPCReadOutMappingSourceHandler (  ) 

Definition at line 17 of file RPCReadOutMappingSourceHandler.cc.

00018 {
00019 }


Member Function Documentation

int popcon::RPCReadOutMappingSourceHandler::Compare2Cablings ( const RPCReadOutMapping map1,
RPCReadOutMapping map2 
)

Definition at line 244 of file RPCReadOutMappingSourceHandler.cc.

References RPCReadOutMapping::dccList(), and RPCReadOutMapping::dccNumberRange().

Referenced by getNewObjects().

00244                                                                                                                  {
00245   vector<const DccSpec *> dccs1 = map1->dccList();
00246   vector<const DccSpec *> dccs2 = map2->dccList();
00247   if(dccs1.size()!=dccs2.size()) {
00248 //    std::cout<<"Compare2Cablings: map sizes do not match :"<<dccs1.size()<<" "<<dccs2.size()<<std::endl;
00249     return 1;
00250   }
00251   pair<int,int> dccRange1 = map1->dccNumberRange();
00252   pair<int,int> dccRange2 = map2->dccNumberRange();
00253   if(dccRange1.first!=dccRange2.first) {
00254 //    std::cout<<"Compare2Cablings: DCC range begins do not match :"<<dccRange1.first<<" "<<dccRange2.first<<std::endl;
00255     return 1;
00256   }
00257   if(dccRange1.second!=dccRange2.second) {
00258 //    std::cout<<"Compare2Cablings: DCC range ends do not match :"<<dccRange1.second<<" "<<dccRange2.second<<std::endl;
00259     return 1;
00260   }
00261   typedef vector<const DccSpec *>::const_iterator IDCC;
00262   IDCC idcc2 = dccs2.begin();
00263   for (IDCC idcc1 = dccs1.begin(); idcc1 != dccs1.end(); idcc1++) {
00264     int dccNo = (**idcc1).id();
00265     std::string dccContents = (**idcc1).print(4);
00266     if ((**idcc2).id()!=dccNo) {
00267 //      std::cout<<"Compare2Cablings: DCC numbers do not match :"<<dccNo<<" "<<(**idcc2).id()<<std::endl;
00268       return 1;
00269     }
00270     if ((**idcc2).print(4)!=dccContents) {
00271 //      std::cout<<"Compare2Cablings: DCC contents do not match for DCC "<<dccNo<<std::endl;
00272       return 1;
00273     }
00274     idcc2++;
00275   }
00276   return 0;
00277 }

void popcon::RPCReadOutMappingSourceHandler::ConnectOnlineDB ( string  host,
string  sid,
string  user,
string  pass,
int  port = 1521 
)

Definition at line 54 of file RPCReadOutMappingSourceHandler.cc.

References conn, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), env, flush(), python_dbs::port, and ss.

Referenced by getNewObjects().

00055 {
00056   stringstream ss;
00057   ss << "//" << host << ":" << port << "/" << sid;
00058 
00059   cout << "RPCReadOutMappingSourceHandler: connecting to " << host << "..." << flush;
00060   env = Environment::createEnvironment(Environment::OBJECT);
00061   conn = env->createConnection(user, pass, ss.str());
00062   cout << "Done." << endl;
00063 }

void popcon::RPCReadOutMappingSourceHandler::DisconnectOnlineDB (  ) 

Definition at line 65 of file RPCReadOutMappingSourceHandler.cc.

References conn, and env.

Referenced by getNewObjects().

00066 {
00067   env->terminateConnection(conn);
00068   Environment::terminateEnvironment(env);
00069 }

void popcon::RPCReadOutMappingSourceHandler::getNewObjects (  )  [virtual]

Implements popcon::PopConSourceHandler< RPCReadOutMapping >.

Definition at line 21 of file RPCReadOutMappingSourceHandler.cc.

References cabling, Compare2Cablings(), ConnectOnlineDB(), GenMuonPlsPt100GeV_cfg::cout, DisconnectOnlineDB(), lat::endl(), m_host, m_pass, m_port, m_sid, popcon::PopConSourceHandler< RPCReadOutMapping >::m_to_transfer, m_user, m_validate, and readCablingMap().

00022 {
00023 
00024 //      std::cout << "RPCReadOutMappingSourceHandler: RPCReadOutMappingSourceHandler::getNewObjects begins\n";
00025 
00026         edm::Service<cond::service::PoolDBOutputService> mydbservice;
00027 
00028 // first check what is already there in offline DB
00029         const RPCReadOutMapping* cabling_prev;
00030         if(m_validate==1) {
00031 //          std::cout<<" Validation was requested, so will check present contents"<<std::endl;
00032           std::cout<<" Sorry, validation not available for the moment..."<<std::endl;
00033         }
00034 
00035 // now construct new cabling map from online DB
00036         ConnectOnlineDB(m_host,m_sid,m_user,m_pass,m_port);
00037         readCablingMap();
00038         DisconnectOnlineDB();
00039 
00040         cond::Time_t snc=mydbservice->currentTime();
00041 
00042 // look for recent changes
00043         int difference=1;
00044         if (m_validate==1) difference=Compare2Cablings(cabling_prev,cabling);
00045         if (!difference) cout<<"No changes - will not write anything!!!"<<endl;
00046         if (difference==1) {
00047           cout<<"Will write new object to offline DB!!!"<<endl;
00048           m_to_transfer.push_back(std::make_pair((RPCReadOutMapping*)cabling,snc));
00049         }
00050 
00051         std::cout << "RPCReadOutMappingSourceHandler: RPCReadOutMappingSourceHandler::getNewObjects ends\n";
00052 }

std::string popcon::RPCReadOutMappingSourceHandler::id ( void   )  const [inline, virtual]

Implements popcon::PopConSourceHandler< RPCReadOutMapping >.

Definition at line 43 of file RPCReadOutMappingSourceHandler.h.

References m_name.

00043 {return m_name;}

string popcon::RPCReadOutMappingSourceHandler::IntToString ( int  num  )  [inline, private]

Definition at line 62 of file RPCReadOutMappingSourceHandler.h.

References flush().

Referenced by readCablingMap().

00063     {
00064       stringstream snum;
00065       snum << num << flush;
00066       return(snum.str());
00067     }

void popcon::RPCReadOutMappingSourceHandler::readCablingMap (  ) 

Definition at line 71 of file RPCReadOutMappingSourceHandler.cc.

References TriggerBoardSpec::add(), LinkBoardSpec::add(), LinkConnSpec::add(), FebConnectorSpec::add(), DccSpec::add(), RPCReadOutMapping::add(), ChamberLocationSpec::barrelOrEndcap, cabling, popcon::RPCReadOutMappingSourceHandler::FEBStruct::chamberId, ChamberLocationSpec::chamberLocationName, popcon::RPCReadOutMappingSourceHandler::FEBStruct::cmsEtaPart, conn, popcon::RPCReadOutMappingSourceHandler::FEBStruct::connectorId, GenMuonPlsPt100GeV_cfg::cout, ChamberLocationSpec::diskOrWheel, lat::endl(), popcon::RPCReadOutMappingSourceHandler::FEBStruct::febId, ChamberLocationSpec::febZOrnt, ChamberLocationSpec::febZRadOrnt, first, flush(), IntToString(), ChamberLocationSpec::layer, popcon::RPCReadOutMappingSourceHandler::FEBStruct::lbInputNum, popcon::RPCReadOutMappingSourceHandler::FEBStruct::localEtaPart, funct::master(), popcon::RPCReadOutMappingSourceHandler::FEBStruct::posInCmsEtaPart, popcon::RPCReadOutMappingSourceHandler::FEBStruct::posInLocalEtaPart, edm::second(), ChamberLocationSpec::sector, strip(), and ChamberLocationSpec::subsector.

Referenced by getNewObjects().

00072 {
00073 
00074 //  string cabling_version = "test";
00075   time_t rawtime;
00076   time(&rawtime); //time since January 1, 1970
00077   tm * ptm = gmtime(&rawtime);//GMT time
00078   char buffer[20];
00079   strftime(buffer,20,"%d/%m/%Y_%H:%M:%S",ptm);
00080   string cabling_version=(string)buffer;
00081 
00082   Statement* stmt = conn->createStatement();
00083   string sqlQuery ="";
00084 
00085   cout << endl <<"RPCReadOutMappingSourceHandler: start to build RPC cabling..." << flush << endl << endl;
00086   cabling =  new RPCReadOutMapping(cabling_version);
00087 
00088   // Get FEDs
00089   sqlQuery=" SELECT DCCBoardId, FEDNumber FROM DCCBoard WHERE DCCBoardId>0 ORDER BY FEDNumber ";
00090   stmt->setSQL(sqlQuery.c_str());
00091   ResultSet* rset = stmt->executeQuery();
00092   std::pair<int,int> tmp_tbl;
00093   std::vector< std::pair<int,int> > theDAQ;
00094   while (rset->next()) {
00095     tmp_tbl.first=rset->getInt(1);
00096     tmp_tbl.second=rset->getInt(2);
00097     theDAQ.push_back(tmp_tbl);
00098   }
00099   for(unsigned int iFED=0;iFED<theDAQ.size();iFED++) {
00100     std::vector<std::pair<int,int> > theTB;
00101     DccSpec dcc(theDAQ[iFED].second);
00102     sqlQuery = " SELECT TriggerBoardId, DCCInputChannelNum FROM TriggerBoard ";
00103     sqlQuery += " WHERE DCCBoard_DCCBoardId= ";
00104     sqlQuery += IntToString(theDAQ[iFED].first);
00105     sqlQuery += " ORDER BY DCCInputChannelNum ";
00106     stmt->setSQL(sqlQuery.c_str());
00107     rset = stmt->executeQuery();
00108     while (rset->next()) {
00109       tmp_tbl.first=rset->getInt(1);
00110       tmp_tbl.second=rset->getInt(2);
00111       theTB.push_back(tmp_tbl);
00112     }
00113     for(unsigned int iTB=0;iTB<theTB.size();iTB++) {
00114       std::vector<std::pair<int,int> > theLink;
00115       TriggerBoardSpec tb(theTB[iTB].second);
00116       sqlQuery = " SELECT Board_BoardId, TriggerBoardInputNum FROM LinkConn ";
00117       sqlQuery += " WHERE TB_TriggerBoardId= ";
00118       sqlQuery +=  IntToString(theTB[iTB].first);
00119       sqlQuery += " ORDER BY TriggerBoardInputNum ";
00120       stmt->setSQL(sqlQuery.c_str());
00121       rset = stmt->executeQuery();
00122       while (rset->next()) {
00123         tmp_tbl.first=rset->getInt(1);
00124         tmp_tbl.second=rset->getInt(2);
00125         theLink.push_back(tmp_tbl);
00126       }
00127       for(unsigned int iLink=0;iLink<theLink.size();iLink++) {
00128         std::vector<std::pair<int,string> > theLB;
00129         std::pair<int,string> tmpLB;
00130         // Get master first...
00131         sqlQuery = " SELECT Name ";
00132         sqlQuery += " FROM Board ";
00133         sqlQuery += " WHERE BoardId= ";
00134         sqlQuery +=  IntToString(theLink[iLink].first);
00135         stmt->setSQL(sqlQuery.c_str());
00136         rset = stmt->executeQuery();
00137         while (rset->next()) {
00138           tmpLB.first=theLink[iLink].first;
00139           tmpLB.second=rset->getString(1);
00140           theLB.push_back(tmpLB);
00141         }
00142         // then slaves
00143         sqlQuery = " SELECT LinkBoard.LinkBoardId, Board.Name ";
00144         sqlQuery += " FROM LinkBoard, Board ";
00145         sqlQuery += " WHERE LinkBoard.MasterId= ";
00146         sqlQuery +=  IntToString(theLink[iLink].first);
00147         sqlQuery += " AND Board.BoardId=LinkBoard.LinkBoardId";
00148         sqlQuery += " AND LinkBoard.MasterId<>LinkBoard.LinkBoardId";
00149         sqlQuery += " ORDER BY LinkBoard.LinkBoardId ";
00150         stmt->setSQL(sqlQuery.c_str());
00151         rset = stmt->executeQuery();
00152         while (rset->next()) {
00153           tmpLB.first=rset->getInt(1);
00154           tmpLB.second=rset->getString(2);
00155           theLB.push_back(tmpLB);
00156         }
00157         LinkConnSpec  lc(theLink[iLink].second);
00158         int linkChannel;
00159         for(unsigned int iLB=0; iLB<theLB.size(); iLB++) {
00160           linkChannel=atoi(((theLB[iLB].second).substr((theLB[iLB].second).length()-1,1)).c_str());
00161           bool master = (theLB[iLB].first==theLink[iLink].first);
00162           LinkBoardSpec lb(master,linkChannel);
00163           FEBStruct tmpFEB;
00164           std::vector<FEBStruct> theFEB;
00165           sqlQuery = " SELECT FEBLocation.FEBLocationId,";
00166           sqlQuery += "  FEBLocation.CL_ChamberLocationId,";
00167           sqlQuery += "  FEBConnector.FEBConnectorId,";
00168           sqlQuery += "  FEBLocation.FEBLocalEtaPartition,"; 
00169           sqlQuery += "  FEBLocation.PosInLocalEtaPartition,";
00170           sqlQuery += "  FEBLocation.FEBCMSEtaPartition,";
00171           sqlQuery += "  FEBLocation.PosInCMSEtaPartition,";
00172           sqlQuery += "  FEBConnector.LinkBoardInputNum ";
00173           sqlQuery += " FROM FEBLocation, FEBConnector ";
00174           sqlQuery += " WHERE FEBLocation.LB_LinkBoardId= ";
00175           sqlQuery +=  IntToString(theLB[iLB].first);
00176           sqlQuery += "  AND FEBLocation.FEBLocationId=FEBConnector.FL_FEBLocationId";
00177           sqlQuery += " ORDER BY FEBLocation.FEBLocationId, FEBConnector.FEBConnectorId";
00178           stmt->setSQL(sqlQuery.c_str());
00179           rset = stmt->executeQuery();
00180           while (rset->next()) {
00181             tmpFEB.febId=rset->getInt(1);
00182             tmpFEB.chamberId=rset->getInt(2);
00183             tmpFEB.connectorId=rset->getInt(3);
00184             tmpFEB.localEtaPart=rset->getString(4);
00185             tmpFEB.posInLocalEtaPart=rset->getInt(5);
00186             tmpFEB.cmsEtaPart=rset->getString(6);
00187             tmpFEB.posInCmsEtaPart=rset->getInt(7);
00188             tmpFEB.lbInputNum=rset->getInt(8);
00189             theFEB.push_back(tmpFEB);
00190 }
00191           for(unsigned int iFEB=0; iFEB<theFEB.size(); iFEB++) {
00192             FebLocationSpec febLocation = {theFEB[iFEB].cmsEtaPart,theFEB[iFEB].posInCmsEtaPart,theFEB[iFEB].localEtaPart,theFEB[iFEB].posInLocalEtaPart};
00193 // Get chamber 
00194             ChamberLocationSpec chamber;
00195             sqlQuery = "SELECT DiskOrWheel, Layer, Sector, Subsector,";
00196             sqlQuery += " ChamberLocationName,";
00197             sqlQuery += " FEBZOrnt, FEBRadOrnt, BarrelOrEndcap";
00198             sqlQuery += " FROM ChamberLocation ";
00199             sqlQuery += " WHERE ChamberLocationId= ";
00200             sqlQuery +=  IntToString(theFEB[iFEB].chamberId);
00201             stmt->setSQL(sqlQuery.c_str());
00202             rset = stmt->executeQuery();
00203             while (rset->next()) {
00204               chamber.diskOrWheel=rset->getInt(1);
00205               chamber.layer=rset->getInt(2);
00206               chamber.sector=rset->getInt(3);
00207               chamber.subsector=rset->getString(4);
00208               if (chamber.subsector=="") chamber.subsector="0";
00209               chamber.chamberLocationName=rset->getString(5);
00210               chamber.febZOrnt=rset->getString(6);
00211               chamber.febZRadOrnt=rset->getString(7);
00212               if (chamber.febZRadOrnt=="") chamber.febZRadOrnt="N/A";
00213               chamber.barrelOrEndcap=rset->getString(8);
00214             }
00215             FebConnectorSpec febConnector(theFEB[iFEB].lbInputNum,chamber,febLocation);
00216             // Get Strips
00217             sqlQuery = "SELECT CableChannelNum, ChamberStripNumber, CmsStripNumber";
00218             sqlQuery += " FROM ChamberStrip ";
00219             sqlQuery += " WHERE FC_FEBConnectorId= ";
00220             sqlQuery +=  IntToString(theFEB[iFEB].connectorId);
00221             sqlQuery += " ORDER BY CableChannelNum";
00222             stmt->setSQL(sqlQuery.c_str());
00223             rset = stmt->executeQuery();
00224             unsigned int iStripEntry=0;
00225             while (rset->next()) {
00226               ChamberStripSpec strip = {rset->getInt(1),rset->getInt(2),rset->getInt(3)};
00227               febConnector.add(strip);
00228               iStripEntry++;
00229             }
00230             lb.add(febConnector); 
00231           }
00232           lc.add(lb);
00233         }
00234         tb.add(lc);
00235       }
00236       dcc.add(tb);
00237     }
00238     std::cout<<"--> Adding DCC"<<std::endl;
00239     cabling->add(dcc);
00240   }
00241   cout << endl <<"Building RPC Cabling done!" << flush << endl << endl;
00242 }


Member Data Documentation

RPCReadOutMapping* popcon::RPCReadOutMappingSourceHandler::cabling [private]

Definition at line 50 of file RPCReadOutMappingSourceHandler.h.

Referenced by getNewObjects(), and readCablingMap().

Connection* popcon::RPCReadOutMappingSourceHandler::conn [private]

Definition at line 52 of file RPCReadOutMappingSourceHandler.h.

Referenced by ConnectOnlineDB(), DisconnectOnlineDB(), and readCablingMap().

Environment* popcon::RPCReadOutMappingSourceHandler::env [private]

Definition at line 51 of file RPCReadOutMappingSourceHandler.h.

Referenced by ConnectOnlineDB(), and DisconnectOnlineDB().

std::string popcon::RPCReadOutMappingSourceHandler::m_host [private]

Definition at line 55 of file RPCReadOutMappingSourceHandler.h.

Referenced by getNewObjects().

std::string popcon::RPCReadOutMappingSourceHandler::m_name [private]

Definition at line 53 of file RPCReadOutMappingSourceHandler.h.

Referenced by id().

std::string popcon::RPCReadOutMappingSourceHandler::m_pass [private]

Definition at line 58 of file RPCReadOutMappingSourceHandler.h.

Referenced by getNewObjects().

int popcon::RPCReadOutMappingSourceHandler::m_port [private]

Definition at line 59 of file RPCReadOutMappingSourceHandler.h.

Referenced by getNewObjects().

std::string popcon::RPCReadOutMappingSourceHandler::m_sid [private]

Definition at line 56 of file RPCReadOutMappingSourceHandler.h.

Referenced by getNewObjects().

std::string popcon::RPCReadOutMappingSourceHandler::m_user [private]

Definition at line 57 of file RPCReadOutMappingSourceHandler.h.

Referenced by getNewObjects().

int popcon::RPCReadOutMappingSourceHandler::m_validate [private]

Definition at line 54 of file RPCReadOutMappingSourceHandler.h.

Referenced by getNewObjects().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:50:32 2009 for CMSSW by  doxygen 1.5.4