CMS 3D CMS Logo

Public Member Functions | Private Attributes

popcon::L1RPCHwConfigSourceHandler Class Reference

#include <L1RPCHwConfigSourceHandler.h>

Inheritance diagram for popcon::L1RPCHwConfigSourceHandler:
popcon::PopConSourceHandler< L1RPCHwConfig >

List of all members.

Public Member Functions

int Compare2Configs (Ref set1, L1RPCHwConfig *set2)
void ConnectOnlineDB (std::string connect, std::string authPath)
void DisconnectOnlineDB ()
void getNewObjects ()
std::string id () const
 L1RPCHwConfigSourceHandler (const edm::ParameterSet &ps)
void readHwConfig1 ()
 ~L1RPCHwConfigSourceHandler ()

Private Attributes

cond::DbConnectionconnection
L1RPCHwConfigdisabledDevs
std::string m_authpath
std::string m_connect
std::vector< int > m_disableCrates
std::vector< int > m_disableTowers
int m_dummy
std::string m_name
int m_validate
cond::DbSessionsession

Detailed Description

Definition at line 36 of file L1RPCHwConfigSourceHandler.h.


Constructor & Destructor Documentation

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

Definition at line 6 of file L1RPCHwConfigSourceHandler.cc.

                                                                                     :
  m_name(ps.getUntrackedParameter<std::string>("name","L1RPCHwConfigSourceHandler")),
  m_dummy(ps.getUntrackedParameter<int>("WriteDummy",0)),
  m_validate(ps.getUntrackedParameter<int>("Validate",0)),
  m_disableCrates(ps.getUntrackedParameter<std::vector<int> >("DisabledCrates")),
  m_disableTowers(ps.getUntrackedParameter<std::vector<int> >("DisabledTowers")),
  m_connect(ps.getUntrackedParameter<std::string>("OnlineConn","")),
  m_authpath(ps.getUntrackedParameter<std::string>("OnlineAuthPath","."))
{
}
popcon::L1RPCHwConfigSourceHandler::~L1RPCHwConfigSourceHandler ( )

Definition at line 17 of file L1RPCHwConfigSourceHandler.cc.

{
}

Member Function Documentation

int popcon::L1RPCHwConfigSourceHandler::Compare2Configs ( Ref  set1,
L1RPCHwConfig set2 
)

Definition at line 229 of file L1RPCHwConfigSourceHandler.cc.

References gather_cfg::cout, L1RPCHwConfig::isActive(), and L1RPCHwConfig::size().

{
  std::cout<<"Size of new object is : "<<std::flush;
  std::cout<<set2->size()<<std::endl;
  std::cout<<"Size of ref object is : "<<std::flush;
  std::cout<<set1->size()<<std::endl;

  if (set1->size() != set2->size()) {
    std::cout<<" Number of disabled devices changed "<<std::endl;
    return 1;
  }
  for (int tower=-16; tower<17; tower++) {
    for (int sector=0; sector<12; sector++) {
      for (int segment=0; segment<12; segment++)
      if (set1->isActive(tower,sector,segment) != set2->isActive(tower,sector,segment)) {
        std::cout<<" Configuration changed for tower "<<tower<<", sector "<<sector<<", segment "<<segment<<std::endl;
        return 1;
      }
    }
  }
  return 0;
}
void popcon::L1RPCHwConfigSourceHandler::ConnectOnlineDB ( std::string  connect,
std::string  authPath 
)

Definition at line 80 of file L1RPCHwConfigSourceHandler.cc.

References gather_cfg::cout, and python::CommonUtils::session.

{
  std::cout << "L1RPCHwConfigSourceHandler: connecting to " << connect << "..." << std::flush;
  connection = new cond::DbConnection() ;
//  session->configuration().setAuthenticationMethod(cond::XML);
  connection->configuration().setAuthenticationPath( authPath ) ;
  connection->configure();
  session = new cond::DbSession(connection->createSession());
  session->open(connect,true) ;
  std::cout << "Done." << std::endl;
}
void popcon::L1RPCHwConfigSourceHandler::DisconnectOnlineDB ( )

Definition at line 92 of file L1RPCHwConfigSourceHandler.cc.

References python::CommonUtils::session.

{
  connection->close() ;
  delete connection ;
  session->close();
  delete session ;
}
void popcon::L1RPCHwConfigSourceHandler::getNewObjects ( ) [virtual]

Implements popcon::PopConSourceHandler< L1RPCHwConfig >.

Definition at line 21 of file L1RPCHwConfigSourceHandler.cc.

References gather_cfg::cout.

{

  std::cout << "L1RPCHwConfigSourceHandler: L1RPCHwConfigSourceHandler::getNewObjects begins\n";
  edm::Service<cond::service::PoolDBOutputService> mydbservice;

//  std::cerr << "------- " << m_name 
//           << " - > getNewObjects" << std::endl;
//  std::cerr<<"Got offlineInfo, tag: "<<std::endl;
//  std::cerr << tagInfo().name << " , last object valid from " 
//          << tagInfo().lastInterval.first << " to "
//            << tagInfo().lastInterval.second << " , token is "
//            << tagInfo().token << " and this is the payload "
//            << tagInfo().lastPayloadToken << std::endl;

// first check what is already there in offline DB
  Ref payload;

  if(m_validate==1) {
    std::cout<<" Validation was requested, so will check present contents"<<std::endl;
    std::cout<<"Name of tag : "<<tagInfo().name << ", tag size : " << tagInfo().size
            << ", last object valid since "
            << tagInfo().lastInterval.first << std::endl;
    payload = lastPayload();
  } else {
    std::cout << "L1RPCHwConfigSourceHandler: no validation requested"<<std::endl;
  }

// now construct new object from online DB
  disabledDevs =  new L1RPCHwConfig();
      if (m_dummy==1) {
        std::vector<int>::iterator crIt = m_disableCrates.begin();
        for (; crIt!=m_disableCrates.end(); ++crIt){
          disabledDevs->enableCrate(*crIt,false);
        }
        std::vector<int>::iterator twIt = m_disableTowers.begin();
        for (; twIt!=m_disableTowers.end(); ++twIt){
          disabledDevs->enableTower(*twIt,false);
        }
      } else {
        ConnectOnlineDB(m_connect,m_authpath);
        readHwConfig1();
        DisconnectOnlineDB();
      }

        cond::Time_t snc=mydbservice->currentTime();

// look for recent changes
        int difference=1;
        if (m_validate==1) difference=Compare2Configs(payload,disabledDevs);
        if (!difference) std::cout<<"No changes - will not write anything!!!"<<std::endl;
        if (difference==1) {
          std::cout<<"Will write new object to offline DB!!!"<<std::endl;
          m_to_transfer.push_back(std::make_pair((L1RPCHwConfig*)disabledDevs,snc+1));
        }

        std::cout << "L1RPCHwConfigSourceHandler: L1RPCHwConfigSourceHandler::getNewObjects ends\n";
}
std::string popcon::L1RPCHwConfigSourceHandler::id ( void  ) const [inline, virtual]

Implements popcon::PopConSourceHandler< L1RPCHwConfig >.

Definition at line 43 of file L1RPCHwConfigSourceHandler.h.

References m_name.

{return m_name;}
void popcon::L1RPCHwConfigSourceHandler::readHwConfig1 ( )

Definition at line 100 of file L1RPCHwConfigSourceHandler.cc.

References gather_cfg::cout, first, prof2calltree::last, python::IdGenerator::schema, python::CommonUtils::session, and AlCaHLTBitMon_QueryRunRegistry::string.

{
  session->transaction().start( true );
  coral::ISchema& schema = session->nominalSchema();
  std::string condition="";
  coral::AttributeList conditionData;
  std::cout << std::endl <<"L1RPCHwConfigSourceHandler: start to build L1RPC Hw Config..." << std::flush << std::endl << std::endl;

// get disabled crates and translate into towers/sectors/segments
  coral::IQuery* query1 = schema.newQuery();
  query1->addToTableList( "CRATEDISABLED" );
  query1->addToTableList( "CRATE" );
  query1->addToTableList( "BOARD" );
  query1->addToTableList( "TRIGGERBOARD" );
  query1->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
  query1->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
  query1->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
  query1->addToOrderList( "TOWERTO" );
  query1->addToOrderList( "SECTOR" );
  condition = "CRATE.CRATEID=CRATEDISABLED.CRATE_CRATEID AND BOARD.CRATE_CRATEID=CRATE.CRATEID AND BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID AND CRATE.TYPE='TRIGGERCRATE'";
  query1->setCondition( condition, conditionData );
  coral::ICursor& cursor1 = query1->execute();
  while ( cursor1.next() ) {
//    cursor1.currentRow().toOutputStream( std::cout ) << std::endl;
    const coral::AttributeList& row = cursor1.currentRow();
    int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
    int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
    int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
    for (int iTower=first; iTower<=last; iTower++) {
      for (int jSegment=0; jSegment<12; jSegment++) {
        disabledDevs->enablePAC(iTower,sector,jSegment,false);
      }
    }
  }
  delete query1;

// get disabled triggerboards and translate into towers/sectors/segments
  coral::IQuery* query2 = schema.newQuery();
  query2->addToTableList( "BOARDDISABLED" );
  query2->addToTableList( "BOARD" );
  query2->addToTableList( "TRIGGERBOARD" );
  query2->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
  query2->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
  query2->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
  query2->addToOrderList( "TOWERTO" );
  query2->addToOrderList( "SECTOR" );
  condition = "BOARD.BOARDID=BOARDDISABLED.BOARD_BOARDID AND BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID";
  query2->setCondition( condition, conditionData );
  coral::ICursor& cursor2 = query2->execute();
  while ( cursor2.next() ) {
//    cursor2.currentRow().toOutputStream( std::cout ) << std::endl;
    const coral::AttributeList& row = cursor2.currentRow();
    int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
    int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
    int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
    for (int iTower=first; iTower<=last; iTower++) {
      for (int jSegment=0; jSegment<12; jSegment++) {
        disabledDevs->enablePAC(iTower,sector,jSegment,false);
      }
    }
  }
  delete query2;

// get disabled links - this is not usable here
/*
  coral::IQuery* query3 = schema.newQuery();
  query3->addToTableList( "LINKDISABLED" );
  query3->addToTableList( "LINKCONN" );
  query3->addToTableList( "TRIGGERBOARD" );
  query3->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
  query3->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
  query3->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
  query3->addToOutputList("LINKCONN.TRIGGERBOARDINPUTNUM","TBINPUTNUM");
  query3->addToOrderList( "TOWERTO" );
  query3->addToOrderList( "SECTOR" );
  query3->addToOrderList( "TBINPUTNUM" );
  condition = "LINKCONN.LINKCONNID=LINKDISABLED.LINK_LINKCONNID AND LINKCONN.TB_TRIGGERBOARDID=TRIGGERBOARD.TRIGGERBOARDID";
  query3->setCondition( condition, conditionData );
  coral::ICursor& cursor3 = query3->execute();
  while ( cursor3.next() ) {
//    cursor3.currentRow().toOutputStream( std::cout ) << std::endl;
    const coral::AttributeList& row = cursor3.currentRow();
    int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
    int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
    int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
    for (int iTower=first; iTower<=last; iTower++) {
      for (int jSegment=0; jSegment<12; jSegment++) {
        disabledDevs->enablePAC(iTower,sector,jSegment,false);
      }
    }
  }
  delete query3;*/

// get disabled chips and translate into towers/sectors
// for the moment assume that chip position 8 corresponds to lowest tower number
// and so on, ignoring bogus chip at position 11 if given TB operates 3 towers.
  coral::IQuery* query4 = schema.newQuery();
  query4->addToTableList( "CHIPDISABLED" );
  query4->addToTableList( "CHIP" );
  query4->addToTableList( "BOARD" );
  query4->addToTableList( "TRIGGERBOARD" );
  query4->addToOutputList("TRIGGERBOARD.TOWERTO","TOWERTO");
  query4->addToOutputList("TRIGGERBOARD.TOWERFROM","TOWERFROM");
  query4->addToOutputList("TRIGGERBOARD.SECTOR","SECTOR");
  query4->addToOutputList("CHIP.POSITION","POSITION");
  query4->addToOrderList( "TOWERTO" );
  query4->addToOrderList( "SECTOR" );
  query4->addToOrderList( "POSITION" );
  condition = "CHIP.CHIPID=CHIPDISABLED.CHIP_CHIPID AND CHIP.BOARD_BOARDID=BOARD.BOARDID AND BOARD.BOARDID=TRIGGERBOARD.TRIGGERBOARDID AND CHIP.TYPE='PAC'";
  query4->setCondition( condition, conditionData );
  coral::ICursor& cursor4 = query4->execute();
  while ( cursor4.next() ) {
//    cursor4.currentRow().toOutputStream( std::cout ) << std::endl;
    const coral::AttributeList& row = cursor4.currentRow();
    int sector = atoi((row["SECTOR"].data<std::string>()).c_str());
    int first = atoi((row["TOWERTO"].data<std::string>()).c_str());
    int last = atoi((row["TOWERFROM"].data<std::string>()).c_str());
    int chipPos=row["POSITION"].data<short>();
    int tower=first+chipPos-8;
    if (tower<=last) {
      for (int jSegment=0; jSegment<12; jSegment++) {
        disabledDevs->enablePAC(tower,sector,jSegment,false);
      }
    }
  }
  delete query4;

}

Member Data Documentation

Definition at line 52 of file L1RPCHwConfigSourceHandler.h.

Definition at line 50 of file L1RPCHwConfigSourceHandler.h.

Definition at line 59 of file L1RPCHwConfigSourceHandler.h.

Definition at line 58 of file L1RPCHwConfigSourceHandler.h.

Definition at line 56 of file L1RPCHwConfigSourceHandler.h.

Definition at line 57 of file L1RPCHwConfigSourceHandler.h.

Definition at line 54 of file L1RPCHwConfigSourceHandler.h.

Definition at line 53 of file L1RPCHwConfigSourceHandler.h.

Referenced by id().

Definition at line 55 of file L1RPCHwConfigSourceHandler.h.

Definition at line 51 of file L1RPCHwConfigSourceHandler.h.