CMS 3D CMS Logo

HCALConfigDB.cc

Go to the documentation of this file.
00001 
00002 //
00003 // Gena Kukartsev (Brown), Feb 1, 2008
00004 // $Id:
00005 //
00006 
00007 #include <iostream>
00008 #include <string.h>
00009 
00010 #include "xgi/Utils.h"
00011 #include "toolbox/string.h"
00012 
00013 #include "occi.h"
00014 
00015 #include "CaloOnlineTools/HcalOnlineDb/interface/HCALConfigDB.h"
00016 #include "CaloOnlineTools/HcalOnlineDb/interface/XMLProcessor.h"
00017 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabase.hh"
00018 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplOracle.hh"
00019 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseImplXMLFile.hh"
00020 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationItemNotFoundException.hh"
00021 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00022 
00023 using namespace std;
00024 using namespace oracle::occi;
00025 using namespace hcal;
00026 
00027 HCALConfigDB::HCALConfigDB( void )
00028 {    
00029   database = NULL;
00030   database2 = NULL;
00031 }
00032 
00033 HCALConfigDB::HCALConfigDB( string _accessor )
00034 {    
00035   database = NULL;
00036   database2 = NULL;
00037   accessor = _accessor;
00038 }
00039 
00040 
00041 HCALConfigDB::~HCALConfigDB( void )
00042 {    
00043   if ( database != NULL ) delete database;
00044   if ( database2 != NULL ) delete database2;
00045 }
00046 
00047 
00048 void HCALConfigDB::setAccessor( string _accessor )
00049 {      
00050   accessor = _accessor;
00051 }
00052 
00053 void HCALConfigDB::connect( string _accessor )
00054 {
00055 
00056   accessor = _accessor;
00057 
00058   std::string::size_type i = accessor . find( "occi://" );
00059   if ( i!=std::string::npos )
00060     {
00061       database = new ConfigurationDatabaseImplOracle();
00062       database -> connect( accessor );
00063     }
00064   else
00065     {
00066       database = new ConfigurationDatabaseImplXMLFile();
00067       database -> connect( accessor );
00068     }
00069 }
00070 
00071 
00072 
00073 void HCALConfigDB::connect( string _accessor1, string _accessor2 )
00074 {
00075 
00076   connect (_accessor1 );
00077 
00078   accessor2 = _accessor2;
00079 
00080   std::string::size_type i = accessor2 . find( "occi://" );
00081   if ( i!=std::string::npos )
00082     {
00083       database2 = new ConfigurationDatabaseImplOracle();
00084       database2 -> connect( accessor2 );
00085     }
00086   else
00087     {
00088       database2 = new ConfigurationDatabaseImplXMLFile();
00089       database2 -> connect( accessor2 );
00090     }
00091 }
00092 
00093 
00094 
00095 
00096 void HCALConfigDB::disconnect( void )
00097 {
00098   if ( database != NULL ) database -> disconnect();
00099   if ( database2 != NULL ) database2 -> disconnect();
00100 }
00101 
00102 
00103 
00104 std::vector<unsigned int> HCALConfigDB::getOnlineLUT( string tag, int crate, int slot, int topbottom, int fiber, int channel, int luttype )
00105 {
00106 
00107   //connect( accessor );
00108 
00109   std::vector<unsigned int> result;
00110 
00111   hcal::ConfigurationDatabase::FPGASelection _fpga;
00112   if ( topbottom == 0 ) _fpga = hcal::ConfigurationDatabase::Bottom;
00113   else if ( topbottom == 1 ) _fpga = hcal::ConfigurationDatabase::Top;
00114   else
00115     {
00116       cout << "topbottom out of range" << endl;
00117       exit(-1);
00118     }
00119 
00120   hcal::ConfigurationDatabase::LUTType _lt;
00121   if ( luttype == 1 ) _lt = hcal::ConfigurationDatabase::LinearizerLUT;
00122   else if ( luttype == 2 ) _lt = hcal::ConfigurationDatabase::CompressionLUT;
00123   else
00124     {
00125       cout << "LUT type out of range" << endl;
00126       exit(-1);
00127     }
00128 
00129   hcal::ConfigurationDatabase::LUTId _lutid( crate, slot, _fpga, fiber, channel, _lt );
00130   std::map<hcal::ConfigurationDatabase::LUTId, hcal::ConfigurationDatabase::LUT> testLUTs;
00131 
00132   XMLProcessor * theProcessor = XMLProcessor::getInstance();
00133 
00134   try {
00135     database -> getLUTs(tag, crate, slot, testLUTs);
00136   } catch (hcal::exception::ConfigurationItemNotFoundException& e) {
00137     cout << "Found nothing!" << endl;
00138   } catch (hcal::exception::Exception& e2) {
00139     cout << "Exception: " << e2.what() << endl;
00140   }
00141 
00142   result = testLUTs[_lutid];
00143 
00144   //database -> disconnect();
00145 
00146   return result;
00147 }
00148 
00149 std::vector<unsigned int> HCALConfigDB::getOnlineLUT( string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt )
00150 {
00151   HcalDetId _id( _rawid );
00152 
00153   double _condition_data_set_id;
00154   unsigned int _crate, _slot, _fiber, _channel;
00155   hcal::ConfigurationDatabase::FPGASelection _fpga;
00156 
00157   int side   = _id . zside();
00158   int etaAbs = _id . ietaAbs();
00159   int phi    = _id . iphi();
00160   int depth  = _id . depth();
00161   string subdetector;
00162   if ( _id . subdet() == HcalBarrel) subdetector = "HB";
00163   else if ( _id . subdet() == HcalEndcap) subdetector = "HE";
00164   else if ( _id . subdet() == HcalOuter) subdetector = "HO";
00165   else if ( _id . subdet() == HcalForward) subdetector = "HF";
00166 
00167   oracle::occi::Connection * _connection = database -> getConnection();
00168 
00169   try {
00170     Statement* stmt = _connection -> createStatement();
00171     std::string query = ("SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
00172     query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
00173     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() );
00174     
00175     //SELECT
00176     ResultSet *rs = stmt->executeQuery(query.c_str());
00177 
00178     _condition_data_set_id = 0.0;
00179 
00180     while (rs->next()) {
00181       double _cdsi = rs -> getDouble(1);
00182       if ( _condition_data_set_id < _cdsi )
00183         {
00184           _condition_data_set_id = _cdsi;
00185           _crate    = rs -> getInt(2);
00186           _slot     = rs -> getInt(3);
00187           std::string fpga_ = rs -> getString(4);
00188           if ( fpga_ == "top" ) _fpga = hcal::ConfigurationDatabase::Top;
00189           else _fpga  = hcal::ConfigurationDatabase::Bottom;
00190           _fiber    = rs -> getInt(5);
00191           _channel  = rs -> getInt(6);
00192           
00193           //cout << _cdsi << "   " << _crate << "   " << _slot << "   " << _fiber << "   " << _channel << endl;
00194         }
00195     }
00196     //Always terminate statement
00197     _connection -> terminateStatement(stmt);
00198   } catch (SQLException& e) {
00199     XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle  exception : %s",e.getMessage().c_str()));
00200   }
00201 
00202   int topbottom, luttype;
00203   if ( _fpga == hcal::ConfigurationDatabase::Top ) topbottom = 1;
00204   else topbottom = 0;
00205   if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
00206   else luttype = 2;
00207   
00208   std::vector<unsigned int> result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
00209   
00210   return result;
00211 }
00212 
00213 
00214 std::vector<unsigned int> HCALConfigDB::getOnlineLUTFromXML( string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt ){
00215 
00216   std::vector<unsigned int> result;
00217 
00218   if ( database && database2 ){
00219     
00220     HcalDetId _id( _rawid );
00221     
00222     double _condition_data_set_id;
00223     unsigned int _crate, _slot, _fiber, _channel;
00224     hcal::ConfigurationDatabase::FPGASelection _fpga;
00225     
00226     int side   = _id . zside();
00227     int etaAbs = _id . ietaAbs();
00228     int phi    = _id . iphi();
00229     int depth  = _id . depth();
00230     string subdetector;
00231     if ( _id . subdet() == HcalBarrel) subdetector = "HB";
00232     else if ( _id . subdet() == HcalEndcap) subdetector = "HE";
00233     else if ( _id . subdet() == HcalOuter) subdetector = "HO";
00234     else if ( _id . subdet() == HcalForward) subdetector = "HF";
00235     
00236     oracle::occi::Connection * _connection = database2 -> getConnection();
00237     
00238     try {
00239       Statement* stmt = _connection -> createStatement();
00240       std::string query = ("SELECT RECORD_ID, CRATE, HTR_SLOT, HTR_FPGA, HTR_FIBER, FIBER_CHANNEL ");
00241       query += " FROM CMS_HCL_HCAL_CONDITION_OWNER.HCAL_HARDWARE_LOGICAL_MAPS_V3 ";
00242       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() );
00243       
00244       //SELECT
00245       ResultSet *rs = stmt->executeQuery(query.c_str());
00246       
00247       _condition_data_set_id = 0.0;
00248       
00249       while (rs->next()) {
00250         double _cdsi = rs -> getDouble(1);
00251         if ( _condition_data_set_id < _cdsi )
00252           {
00253             _condition_data_set_id = _cdsi;
00254             _crate    = rs -> getInt(2);
00255             _slot     = rs -> getInt(3);
00256             std::string fpga_ = rs -> getString(4);
00257             if ( fpga_ == "top" ) _fpga = hcal::ConfigurationDatabase::Top;
00258             else _fpga  = hcal::ConfigurationDatabase::Bottom;
00259             _fiber    = rs -> getInt(5);
00260             _channel  = rs -> getInt(6);
00261             
00262             //cout << _cdsi << "   " << _crate << "   " << _slot << "   " << _fiber << "   " << _channel << endl;
00263           }
00264       }
00265       //Always terminate statement
00266       _connection -> terminateStatement(stmt);
00267     } catch (SQLException& e) {
00268       XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle  exception : %s",e.getMessage().c_str()));
00269     }
00270     
00271     int topbottom, luttype;
00272     if ( _fpga == hcal::ConfigurationDatabase::Top ) topbottom = 1;
00273     else topbottom = 0;
00274     if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
00275     else luttype = 2;
00276     
00277     result = getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
00278     
00279   }
00280   else{
00281     cout << "Either the XML file with LUTs or the database with LMap are not defined" << endl;
00282   }
00283 
00284   return result;
00285 }
00286 
00287 
00288 oracle::occi::Connection * HCALConfigDB::getConnection( void ){
00289   return database -> getConnection();
00290 }
00291 
00292 oracle::occi::Environment * HCALConfigDB::getEnvironment( void ){
00293   return database -> getEnvironment();
00294 }
00295 
00296 
00297 

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