CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Attributes

HCALConfigDB Class Reference

Gather config data from online DB. More...

#include <HCALConfigDB.h>

List of all members.

Public Types

typedef
hcal::ConfigurationDatabaseImpl 
ConfigurationDatabaseImpl

Public Member Functions

std::string clobToString (oracle::occi::Clob)
void connect (std::string _accessor1, std::string _accessor2)
void connect (std::string _accessor)
void disconnect (void)
oracle::occi::Connection * getConnection (void)
oracle::occi::Environment * getEnvironment (void)
std::vector< unsigned int > getOnlineLUT (std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt=hcal::ConfigurationDatabase::LinearizerLUT)
std::vector< unsigned int > getOnlineLUT (std::string tag, int crate, int slot, int topbottom, int fiber, int channel, int luttype)
std::vector< unsigned int > getOnlineLUTFromXML (std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt=hcal::ConfigurationDatabase::LinearizerLUT)
 HCALConfigDB ()
 HCALConfigDB (std::string _accessor)
void setAccessor (std::string _accessor)
 ~HCALConfigDB ()

Protected Attributes

std::string accessor
std::string accessor2
ConfigurationDatabaseImpldatabase
ConfigurationDatabaseImpldatabase2

Detailed Description

Gather config data from online DB.

Author:
Gena Kukartsev

Definition at line 21 of file HCALConfigDB.h.


Member Typedef Documentation

typedef hcal::ConfigurationDatabaseImpl HCALConfigDB::ConfigurationDatabaseImpl

Definition at line 23 of file HCALConfigDB.h.


Constructor & Destructor Documentation

HCALConfigDB::HCALConfigDB ( void  )

Definition at line 27 of file HCALConfigDB.cc.

{    
  database = 0;
  database2 = 0;
}
HCALConfigDB::~HCALConfigDB ( void  )

Definition at line 41 of file HCALConfigDB.cc.

{    
  delete database;
  delete database2;
}
HCALConfigDB::HCALConfigDB ( std::string  _accessor)

Definition at line 33 of file HCALConfigDB.cc.

{    
  database = 0;
  database2 = 0;
  accessor = _accessor;
}

Member Function Documentation

string HCALConfigDB::clobToString ( oracle::occi::Clob  clob)

Definition at line 295 of file HCALConfigDB.cc.

References findQualityFiles::size.

                                                    {

                Stream *instream = clob.getStream (1,0);
                unsigned int size = clob.length();
                char *cbuffer = new char[size];
                memset (cbuffer, 0, size);
                instream->readBuffer (cbuffer, size);
                std::string str(cbuffer,size);
                return str;
}
void HCALConfigDB::connect ( std::string  _accessor)

Definition at line 53 of file HCALConfigDB.cc.

References align_tpl::connect, spr::find(), and i.

{

  accessor = _accessor;

  std::string::size_type i = accessor . find( "occi://" );
  if ( i!=std::string::npos )
    {
      database = new ConfigurationDatabaseImplOracle();
      database -> connect( accessor );
    }
  else
    {
      database = new ConfigurationDatabaseImplXMLFile();
      database -> connect( accessor );
    }
}
void HCALConfigDB::connect ( std::string  _accessor1,
std::string  _accessor2 
)

Definition at line 73 of file HCALConfigDB.cc.

References align_tpl::connect, spr::find(), and i.

{

  connect (_accessor1 );

  accessor2 = _accessor2;

  std::string::size_type i = accessor2 . find( "occi://" );
  if ( i!=std::string::npos )
    {
      database2 = new ConfigurationDatabaseImplOracle();
      database2 -> connect( accessor2 );
    }
  else
    {
      database2 = new ConfigurationDatabaseImplXMLFile();
      database2 -> connect( accessor2 );
    }
}
void HCALConfigDB::disconnect ( void  )

Definition at line 96 of file HCALConfigDB.cc.

References NULL.

{
  if ( database != NULL ) database -> disconnect();
  if ( database2 != NULL ) database2 -> disconnect();
}
oracle::occi::Connection * HCALConfigDB::getConnection ( void  )

Definition at line 284 of file HCALConfigDB.cc.

                                                        {
  return database -> getConnection();
}
oracle::occi::Environment * HCALConfigDB::getEnvironment ( void  )

Definition at line 288 of file HCALConfigDB.cc.

                                                          {
  return database -> getEnvironment();
}
std::vector< unsigned int > HCALConfigDB::getOnlineLUT ( std::string  tag,
int  crate,
int  slot,
int  topbottom,
int  fiber,
int  channel,
int  luttype 
)

Definition at line 104 of file HCALConfigDB.cc.

References gather_cfg::cout, Exception, cmsRelvalreport::exit, XMLProcessor::getInstance(), query::result, and TtFullHadDaughter::Top.

{

  //connect( accessor );

  std::vector<unsigned int> result;

  hcal::ConfigurationDatabase::FPGASelection _fpga;
  if ( topbottom == 0 ) _fpga = hcal::ConfigurationDatabase::Bottom;
  else if ( topbottom == 1 ) _fpga = hcal::ConfigurationDatabase::Top;
  else
    {
      std::cout << "topbottom out of range" << std::endl;
      exit(-1);
    }

  hcal::ConfigurationDatabase::LUTType _lt;
  if ( luttype == 1 ) _lt = hcal::ConfigurationDatabase::LinearizerLUT;
  else if ( luttype == 2 ) _lt = hcal::ConfigurationDatabase::CompressionLUT;
  else
    {
      std::cout << "LUT type out of range" << std::endl;
      exit(-1);
    }

  hcal::ConfigurationDatabase::LUTId _lutid( crate, slot, _fpga, fiber, channel, _lt );
  std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT> testLUTs;

  XMLProcessor::getInstance();

  try {
    database -> getLUTs(tag, crate, slot, testLUTs);
  } catch (hcal::exception::ConfigurationItemNotFoundException& e) {
    std::cout << "Found nothing!" << std::endl;
  } catch (hcal::exception::Exception& e2) {
    std::cout << "Exception: " << e2.what() << std::endl;
  }

  result = testLUTs[_lutid];

  //database -> disconnect();

  return result;
}
std::vector< unsigned int > HCALConfigDB::getOnlineLUT ( std::string  tag,
uint32_t  _rawid,
hcal::ConfigurationDatabase::LUTType  _lt = hcal::ConfigurationDatabase::LinearizerLUT 
)

Definition at line 149 of file HCALConfigDB.cc.

References getInt(), HcalBarrel, HcalEndcap, HcalForward, HcalOuter, phi, o2o::query, query::result, TtFullHadDaughter::Top, and toString().

{
  std::vector<unsigned int> result;
  HcalDetId _id( _rawid );

  double _condition_data_set_id;
  unsigned int _crate, _slot, _fiber, _channel;
  hcal::ConfigurationDatabase::FPGASelection _fpga;

  int side   = _id . zside();
  int etaAbs = _id . ietaAbs();
  int phi    = _id . iphi();
  int depth  = _id . depth();
  std::string subdetector;
  if ( _id . subdet() == HcalBarrel) subdetector = "HB";
  else if ( _id . subdet() == HcalEndcap) subdetector = "HE";
  else if ( _id . subdet() == HcalOuter) subdetector = "HO";
  else if ( _id . subdet() == HcalForward) subdetector = "HF";

  oracle::occi::Connection * _connection = database -> getConnection();

  try {
    Statement* stmt = _connection -> createStatement();
    std::string query = ("SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
    query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
    query += toolbox::toString(" WHERE SIDE=%d AND ETA=%d AND PHI=%d AND DEPTH=%d AND SUBDETECTOR='%s'", side, etaAbs, phi, depth, subdetector . c_str() );
    
    //SELECT
    ResultSet *rs = stmt->executeQuery(query.c_str());

    _condition_data_set_id = 0.0;

    while (rs->next()) {
      double _cdsi = rs -> getDouble(1);
      if ( _condition_data_set_id < _cdsi )
        {
          _condition_data_set_id = _cdsi;
          _crate    = rs -> getInt(2);
          _slot     = rs -> getInt(3);
          std::string fpga_ = rs -> getString(4);
          if ( fpga_ == "top" ) _fpga = hcal::ConfigurationDatabase::Top;
          else _fpga  = hcal::ConfigurationDatabase::Bottom;
          _fiber    = rs -> getInt(5);
          _channel  = rs -> getInt(6);
          
          int topbottom, luttype;
          if ( _fpga == hcal::ConfigurationDatabase::Top ) topbottom = 1;
          else topbottom = 0;
          if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
          else luttype = 2;
          
          result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
        }
    }
    //Always terminate statement
    _connection -> terminateStatement(stmt);
  } catch (SQLException& e) {
    XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle  exception : %s",e.getMessage().c_str()));
  }
  return result;
}
std::vector< unsigned int > HCALConfigDB::getOnlineLUTFromXML ( std::string  tag,
uint32_t  _rawid,
hcal::ConfigurationDatabase::LUTType  _lt = hcal::ConfigurationDatabase::LinearizerLUT 
)

Definition at line 212 of file HCALConfigDB.cc.

References gather_cfg::cout, getInt(), HcalBarrel, HcalEndcap, HcalForward, HcalOuter, phi, o2o::query, query::result, TtFullHadDaughter::Top, and toString().

                                                                                                                               {

  std::vector<unsigned int> result;

  if ( database && database2 ){
    
    HcalDetId _id( _rawid );
    
    double _condition_data_set_id;
    unsigned int _crate, _slot, _fiber, _channel;
    hcal::ConfigurationDatabase::FPGASelection _fpga;
    
    int side   = _id . zside();
    int etaAbs = _id . ietaAbs();
    int phi    = _id . iphi();
    int depth  = _id . depth();
    std::string subdetector;
    if ( _id . subdet() == HcalBarrel) subdetector = "HB";
    else if ( _id . subdet() == HcalEndcap) subdetector = "HE";
    else if ( _id . subdet() == HcalOuter) subdetector = "HO";
    else if ( _id . subdet() == HcalForward) subdetector = "HF";
    
    oracle::occi::Connection * _connection = database2 -> getConnection();
    
    try {
      Statement* stmt = _connection -> createStatement();
      std::string query = ("SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
      query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
      query += toolbox::toString(" WHERE SIDE=%d AND ETA=%d AND PHI=%d AND DEPTH=%d AND SUBDETECTOR='%s'", side, etaAbs, phi, depth, subdetector . c_str() );
      
      //SELECT
      ResultSet *rs = stmt->executeQuery(query.c_str());
      
      _condition_data_set_id = 0.0;
      
      while (rs->next()) {
        double _cdsi = rs -> getDouble(1);
        if ( _condition_data_set_id < _cdsi )
          {
            _condition_data_set_id = _cdsi;
            _crate    = rs -> getInt(2);
            _slot     = rs -> getInt(3);
            std::string fpga_ = rs -> getString(4);
            if ( fpga_ == "top" ) _fpga = hcal::ConfigurationDatabase::Top;
            else _fpga  = hcal::ConfigurationDatabase::Bottom;
            _fiber    = rs -> getInt(5);
            _channel  = rs -> getInt(6);
            
            //
            int topbottom, luttype;
            if ( _fpga == hcal::ConfigurationDatabase::Top ) topbottom = 1;
            else topbottom = 0;
            if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
            else luttype = 2;
            result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
          }
      }
      //Always terminate statement
      _connection -> terminateStatement(stmt);

    } catch (SQLException& e) {
      XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle  exception : %s",e.getMessage().c_str()));
    }
  }
  else{
    std::cout << "Either the XML file with LUTs or the database with LMap are not defined" << std::endl;
  }

  return result;
}
void HCALConfigDB::setAccessor ( std::string  _accessor)

Definition at line 48 of file HCALConfigDB.cc.

{      
  accessor = _accessor;
}

Member Data Documentation

std::string HCALConfigDB::accessor [protected]

Definition at line 43 of file HCALConfigDB.h.

std::string HCALConfigDB::accessor2 [protected]

Definition at line 50 of file HCALConfigDB.h.

Definition at line 44 of file HCALConfigDB.h.

Definition at line 51 of file HCALConfigDB.h.