Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:15

0001 #include "CondTools/RPC/interface/L1RPCHwConfigSourceHandler.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 #include "CondCore/CondDB/interface/ConnectionPool.h"
0005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0006 
0007 popcon::L1RPCHwConfigSourceHandler::L1RPCHwConfigSourceHandler(const edm::ParameterSet& ps)
0008     : m_name(ps.getUntrackedParameter<std::string>("name", "L1RPCHwConfigSourceHandler")),
0009       m_dummy(ps.getUntrackedParameter<int>("WriteDummy", 0)),
0010       m_validate(ps.getUntrackedParameter<int>("Validate", 0)),
0011       m_disableCrates(ps.getUntrackedParameter<std::vector<int> >("DisabledCrates")),
0012       m_disableTowers(ps.getUntrackedParameter<std::vector<int> >("DisabledTowers")),
0013       m_connect(ps.getUntrackedParameter<std::string>("OnlineConn", "")),
0014       m_authpath(ps.getUntrackedParameter<std::string>("OnlineAuthPath", ".")) {}
0015 
0016 popcon::L1RPCHwConfigSourceHandler::~L1RPCHwConfigSourceHandler() {}
0017 
0018 void popcon::L1RPCHwConfigSourceHandler::getNewObjects() {
0019   std::cout << "L1RPCHwConfigSourceHandler: L1RPCHwConfigSourceHandler::getNewObjects begins\n";
0020   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0021 
0022   //  std::cerr << "------- " << m_name
0023   //           << " - > getNewObjects" << std::endl;
0024   //  std::cerr<<"Got offlineInfo, tag: "<<std::endl;
0025   //  std::cerr << tagInfo().name << " , last object valid from "
0026   //          << tagInfo().lastInterval.first << " to "
0027   //            << tagInfo().lastInterval.second << " , token is "
0028   //            << tagInfo().token << " and this is the payload "
0029   //            << tagInfo().lastPayloadToken << std::endl;
0030 
0031   // first check what is already there in offline DB
0032   Ref payload;
0033 
0034   if (m_validate == 1) {
0035     std::cout << " Validation was requested, so will check present contents" << std::endl;
0036     std::cout << "Name of tag : " << tagInfo().name << ", tag size : " << tagInfo().size << ", last object valid since "
0037               << tagInfo().lastInterval.since << std::endl;
0038     payload = lastPayload();
0039   } else {
0040     std::cout << "L1RPCHwConfigSourceHandler: no validation requested" << std::endl;
0041   }
0042 
0043   // now construct new object from online DB
0044   disabledDevs = new L1RPCHwConfig();
0045   if (m_dummy == 1) {
0046     std::vector<int>::iterator crIt = m_disableCrates.begin();
0047     for (; crIt != m_disableCrates.end(); ++crIt) {
0048       disabledDevs->enableCrate(*crIt, false);
0049     }
0050     std::vector<int>::iterator twIt = m_disableTowers.begin();
0051     for (; twIt != m_disableTowers.end(); ++twIt) {
0052       disabledDevs->enableTower(*twIt, false);
0053     }
0054   } else {
0055     ConnectOnlineDB(m_connect, m_authpath);
0056     readHwConfig1();
0057     DisconnectOnlineDB();
0058   }
0059 
0060   cond::Time_t snc = mydbservice->currentTime();
0061 
0062   // look for recent changes
0063   int difference = 1;
0064   if (m_validate == 1)
0065     difference = Compare2Configs(payload, disabledDevs);
0066   if (!difference)
0067     std::cout << "No changes - will not write anything!!!" << std::endl;
0068   if (difference == 1) {
0069     std::cout << "Will write new object to offline DB!!!" << std::endl;
0070     m_to_transfer.push_back(std::make_pair((L1RPCHwConfig*)disabledDevs, snc + 1));
0071   }
0072 
0073   std::cout << "L1RPCHwConfigSourceHandler: L1RPCHwConfigSourceHandler::getNewObjects ends\n";
0074 }
0075 
0076 void popcon::L1RPCHwConfigSourceHandler::ConnectOnlineDB(std::string connect, std::string authPath) {
0077   std::cout << "L1RPCHwConfigSourceHandler: connecting to " << connect << "..." << std::flush;
0078   cond::persistency::ConnectionPool connection;
0079   //  session->configuration().setAuthenticationMethod(cond::XML);
0080   connection.setAuthenticationPath(authPath);
0081   connection.configure();
0082   session = connection.createSession(connect, true);
0083   std::cout << "Done." << std::endl;
0084 }
0085 
0086 void popcon::L1RPCHwConfigSourceHandler::DisconnectOnlineDB() { session.close(); }
0087 
0088 void popcon::L1RPCHwConfigSourceHandler::readHwConfig1() {
0089   session.transaction().start(true);
0090   coral::ISchema& schema = session.nominalSchema();
0091   std::string condition = "";
0092   coral::AttributeList conditionData;
0093   std::cout << std::endl
0094             << "L1RPCHwConfigSourceHandler: start to build L1RPC Hw Config..." << std::flush << std::endl
0095             << std::endl;
0096 
0097   // get disabled crates and translate into towers/sectors/segments
0098   coral::IQuery* query1 = schema.newQuery();
0099   query1->addToTableList("CRATEDISABLED");
0100   query1->addToTableList("CRATE");
0101   query1->addToTableList("BOARD");
0102   query1->addToTableList("TRIGGERBOARD");
0103   query1->addToOutputList("TRIGGERBOARD.TOWERTO", "TOWERTO");
0104   query1->addToOutputList("TRIGGERBOARD.TOWERFROM", "TOWERFROM");
0105   query1->addToOutputList("TRIGGERBOARD.SECTOR", "SECTOR");
0106   query1->addToOrderList("TOWERTO");
0107   query1->addToOrderList("SECTOR");
0108   condition =
0109       "CRATE.CRATEID=CRATEDISABLED.CRATE_CRATEID AND BOARD.CRATE_CRATEID=CRATE.CRATEID AND "
0110       "BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID AND CRATE.TYPE='TRIGGERCRATE'";
0111   query1->setCondition(condition, conditionData);
0112   coral::ICursor& cursor1 = query1->execute();
0113   while (cursor1.next()) {
0114     //    cursor1.currentRow().toOutputStream( std::cout ) << std::endl;
0115     const coral::AttributeList& row = cursor1.currentRow();
0116     int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
0117     int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
0118     int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
0119     for (int iTower = first; iTower <= last; iTower++) {
0120       for (int jSegment = 0; jSegment < 12; jSegment++) {
0121         disabledDevs->enablePAC(iTower, sector, jSegment, false);
0122       }
0123     }
0124   }
0125   delete query1;
0126 
0127   // get disabled triggerboards and translate into towers/sectors/segments
0128   coral::IQuery* query2 = schema.newQuery();
0129   query2->addToTableList("BOARDDISABLED");
0130   query2->addToTableList("BOARD");
0131   query2->addToTableList("TRIGGERBOARD");
0132   query2->addToOutputList("TRIGGERBOARD.TOWERTO", "TOWERTO");
0133   query2->addToOutputList("TRIGGERBOARD.TOWERFROM", "TOWERFROM");
0134   query2->addToOutputList("TRIGGERBOARD.SECTOR", "SECTOR");
0135   query2->addToOrderList("TOWERTO");
0136   query2->addToOrderList("SECTOR");
0137   condition = "BOARD.BOARDID=BOARDDISABLED.BOARD_BOARDID AND BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID";
0138   query2->setCondition(condition, conditionData);
0139   coral::ICursor& cursor2 = query2->execute();
0140   while (cursor2.next()) {
0141     //    cursor2.currentRow().toOutputStream( std::cout ) << std::endl;
0142     const coral::AttributeList& row = cursor2.currentRow();
0143     int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
0144     int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
0145     int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
0146     for (int iTower = first; iTower <= last; iTower++) {
0147       for (int jSegment = 0; jSegment < 12; jSegment++) {
0148         disabledDevs->enablePAC(iTower, sector, jSegment, false);
0149       }
0150     }
0151   }
0152   delete query2;
0153 
0154   // get disabled links - this is not usable here
0155   /*
0156   coral::IQuery* query3 = schema.newQuery();
0157   query3->addToTableList( "LINKDISABLED" );
0158   query3->addToTableList( "LINKCONN" );
0159   query3->addToTableList( "TRIGGERBOARD" );
0160   query3->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
0161   query3->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
0162   query3->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
0163   query3->addToOutputList("LINKCONN.TRIGGERBOARDINPUTNUM","TBINPUTNUM");
0164   query3->addToOrderList( "TOWERTO" );
0165   query3->addToOrderList( "SECTOR" );
0166   query3->addToOrderList( "TBINPUTNUM" );
0167   condition = "LINKCONN.LINKCONNID=LINKDISABLED.LINK_LINKCONNID AND LINKCONN.TB_TRIGGERBOARDID=TRIGGERBOARD.TRIGGERBOARDID";
0168   query3->setCondition( condition, conditionData );
0169   coral::ICursor& cursor3 = query3->execute();
0170   while ( cursor3.next() ) {
0171 //    cursor3.currentRow().toOutputStream( std::cout ) << std::endl;
0172     const coral::AttributeList& row = cursor3.currentRow();
0173     int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
0174     int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
0175     int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
0176     for (int iTower=first; iTower<=last; iTower++) {
0177       for (int jSegment=0; jSegment<12; jSegment++) {
0178         disabledDevs->enablePAC(iTower,sector,jSegment,false);
0179       }
0180     }
0181   }
0182   delete query3;*/
0183 
0184   // get disabled chips and translate into towers/sectors
0185   // for the moment assume that chip position 8 corresponds to lowest tower number
0186   // and so on, ignoring bogus chip at position 11 if given TB operates 3 towers.
0187   coral::IQuery* query4 = schema.newQuery();
0188   query4->addToTableList("CHIPDISABLED");
0189   query4->addToTableList("CHIP");
0190   query4->addToTableList("BOARD");
0191   query4->addToTableList("TRIGGERBOARD");
0192   query4->addToOutputList("TRIGGERBOARD.TOWERTO", "TOWERTO");
0193   query4->addToOutputList("TRIGGERBOARD.TOWERFROM", "TOWERFROM");
0194   query4->addToOutputList("TRIGGERBOARD.SECTOR", "SECTOR");
0195   query4->addToOutputList("CHIP.POSITION", "POSITION");
0196   query4->addToOrderList("TOWERTO");
0197   query4->addToOrderList("SECTOR");
0198   query4->addToOrderList("POSITION");
0199   condition =
0200       "CHIP.CHIPID=CHIPDISABLED.CHIP_CHIPID AND CHIP.BOARD_BOARDID=BOARD.BOARDID AND "
0201       "BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID AND CHIP.TYPE='PAC'";
0202   query4->setCondition(condition, conditionData);
0203   coral::ICursor& cursor4 = query4->execute();
0204   while (cursor4.next()) {
0205     //    cursor4.currentRow().toOutputStream( std::cout ) << std::endl;
0206     const coral::AttributeList& row = cursor4.currentRow();
0207     int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
0208     int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
0209     int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
0210     int chipPos = row["POSITION"].data<short>();
0211     int tower = first + chipPos - 8;
0212     if (tower <= last) {
0213       for (int jSegment = 0; jSegment < 12; jSegment++) {
0214         disabledDevs->enablePAC(tower, sector, jSegment, false);
0215       }
0216     }
0217   }
0218   delete query4;
0219 }
0220 
0221 int popcon::L1RPCHwConfigSourceHandler::Compare2Configs(const Ref& _set1, L1RPCHwConfig* set2) {
0222   const Ref& set1 = _set1;
0223   std::cout << "Size of new object is : " << std::flush;
0224   std::cout << set2->size() << std::endl;
0225   std::cout << "Size of ref object is : " << std::flush;
0226   std::cout << set1->size() << std::endl;
0227 
0228   if (set1->size() != set2->size()) {
0229     std::cout << " Number of disabled devices changed " << std::endl;
0230     return 1;
0231   }
0232   for (int tower = -16; tower < 17; tower++) {
0233     for (int sector = 0; sector < 12; sector++) {
0234       for (int segment = 0; segment < 12; segment++)
0235         if (set1->isActive(tower, sector, segment) != set2->isActive(tower, sector, segment)) {
0236           std::cout << " Configuration changed for tower " << tower << ", sector " << sector << ", segment " << segment
0237                     << std::endl;
0238           return 1;
0239         }
0240     }
0241   }
0242   return 0;
0243 }