CMS 3D CMS Logo

HcalQIEManager.cc

Go to the documentation of this file.
00001 //
00002 // Gena Kukartsev (Brown), Feb 23, 2008
00003 // $Id:
00004 
00005 #include <fstream>
00006 
00007 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalQIEManager.h"
00008 
00009 using namespace std;
00010 using namespace oracle::occi;
00011 using namespace hcal;
00012 
00013 HcalQIEManager::HcalQIEManager( void )
00014 {    
00015 
00016 }
00017 
00018 
00019 
00020 HcalQIEManager::~HcalQIEManager( void )
00021 {    
00022 
00023 }
00024 
00025 
00026 
00027 bool HcalChannelId::operator<( const HcalChannelId & other) const{
00028   bool result=false;
00029   long long int _res_this, _res_other;
00030   int _sub_this, _sub_other;
00031 
00032   if (this->subdetector == "HE") _sub_this=1;
00033   else if (this->subdetector == "HF") _sub_this=2;
00034   else if (this->subdetector == "HO") _sub_this=3;
00035   else  _sub_this=4;
00036   
00037   if (other.subdetector == "HE") _sub_other=1;
00038   else if (other.subdetector == "HF") _sub_other=2;
00039   else if (other.subdetector == "HO") _sub_other=3;
00040   else  _sub_other=4;
00041   
00042 
00043   _res_this = 100+eta + (phi+100)*1000 + (depth+10)*1000000 + _sub_this*1000000000;
00044   _res_other = 100+other.eta + (other.phi+100)*1000 + (other.depth+10)*1000000 + _sub_other*1000000000;
00045 
00046   return _res_this < _res_other;
00047 }
00048 
00049 std::map<HcalChannelId,HcalQIECaps> & HcalQIEManager::getQIETableFromFile( std::string _filename )
00050 {
00051   std::map<HcalChannelId,HcalQIECaps> * result_sup = new std::map<HcalChannelId,HcalQIECaps>;
00052   std::map<HcalChannelId,HcalQIECaps> & result = (*result_sup);
00053 
00054   ifstream infile( _filename . c_str() );
00055   std::string buf;
00056 
00057   if ( infile . is_open() ){
00058     cout << "File is open" << endl;
00059     while ( getline( infile, buf ) > 0 ){
00060       vector<string> _line = splitString( buf );
00061 
00062       HcalChannelId _id;
00063       sscanf(_line[0].c_str(), "%d", &_id . eta);
00064       sscanf(_line[1].c_str(), "%d", &_id . phi);
00065       sscanf(_line[2].c_str(), "%d", &_id . depth);
00066       _id . subdetector = _line[3];
00067 
00068       HcalQIECaps _adc;
00069       int _columns = _line . size();
00070       for(int i = 4; i != _columns; i++){
00071         sscanf(_line[i].c_str(), "%lf", &_adc . caps[i-4]);
00072       }
00073       
00074       result[_id]=_adc;
00075 
00076       //cout << result.size() << endl;
00077 
00078       //cout << _id.eta << "    " << _id . subdetector << "     " << _adc.caps[7] << endl;
00079     }
00080   }
00081   return result;
00082 }
00083 
00084 
00085 
00086 // courtesy of Fedor Ratnikov
00087 std::vector <std::string> HcalQIEManager::splitString (const std::string& fLine) {
00088   std::vector <std::string> result;
00089   int start = 0;
00090   bool empty = true;
00091   for (unsigned i = 0; i <= fLine.size (); i++) {
00092     if (fLine [i] == ' ' || fLine [i] == '      ' || i == fLine.size ()) {
00093       if (!empty) {
00094         std::string item (fLine, start, i-start);
00095         result.push_back (item);
00096         empty = true;
00097       }
00098       start = i+1;
00099     }
00100     else {
00101       if (empty) empty = false;
00102     }
00103   }
00104   return result;
00105 }

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