Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <fstream>
00015 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalChannelIterator.h"
00016 #include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h"
00017 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00018
00019 HcalChannelIterator::HcalChannelIterator()
00020 {
00021 }
00022
00023
00024 HcalChannelIterator::~HcalChannelIterator()
00025 {
00026 }
00027
00028
00029
00030 int HcalChannelIterator::size(void){
00031 return channel_list.size();
00032 }
00033
00034
00035 int HcalChannelIterator::clearChannelList(void){
00036 channel_list.clear();
00037 return 0;
00038 }
00039
00040
00041 int HcalChannelIterator::addListFromLmapAscii(std::string filename){
00042 RooGKCounter lines;
00043 int _current_size = size();
00044 std::string _row;
00045 std::ifstream inFile( filename . c_str(), std::ios::in );
00046 if (!inFile){
00047 std::cout << "Unable to open file with the logical map: " << filename << std::endl;
00048 }
00049 else{
00050 std::cout << "File with the logical map opened successfully: " << filename << std::endl;
00051 }
00052 while ( getline( inFile, _row ) > 0 ){
00053
00054 int _num, _side, _eta, _phi, _dphi, _depth;
00055 char subdetbuf[32];
00056
00057 int _read;
00058 const char * _format = "%d %d %d %d %d %d %s";
00059 _read = sscanf( _row . c_str(), _format,
00060 &_num, &_side, &_eta, &_phi, &_dphi, &_depth,
00061 subdetbuf );
00062 if ( _read == 7 ){
00063 lines . count();
00064
00065 std::string subdet(subdetbuf);
00066
00067 HcalSubdetector _det;
00068 if ( subdet.find("HB")!=std::string::npos ) _det = HcalBarrel;
00069 else if ( subdet.find("HE")!=std::string::npos ) _det = HcalEndcap;
00070 else if ( subdet.find("HO")!=std::string::npos ) _det = HcalOuter;
00071 else if ( subdet.find("HF")!=std::string::npos ) _det = HcalForward;
00072 else _det = HcalOther;
00073
00074 HcalDetId _detid(_det, _side*_eta, _phi, _depth);
00075
00076 if (_det == HcalBarrel || _det == HcalEndcap || _det == HcalOuter || _det == HcalForward){
00077 channel_list . push_back( _detid );
00078 }
00079 }
00080 }
00081 inFile.close();
00082 std::cout << "Logical map file: " << lines . getCount() << " lines read" << std::endl;
00083 std::cout << "Logical map file: " << size() - _current_size << " lines added to the list" << std::endl;
00084
00085 return 0;
00086 }
00087
00088
00089 int HcalChannelIterator::begin(void){
00090 const_iterator = channel_list.begin();
00091 return 0;
00092 }
00093
00094
00095 int HcalChannelIterator::next(void){
00096 const_iterator++;
00097 return 0;
00098 }
00099
00100
00101 bool HcalChannelIterator::end(void){
00102 if (const_iterator==channel_list.end()){
00103 return true;
00104 }
00105 else{
00106 return false;
00107 }
00108 }
00109
00110
00111 HcalGenericDetId HcalChannelIterator::getHcalGenericDetId(void){
00112 if (const_iterator!=channel_list.end()){
00113 return *const_iterator;
00114 }
00115 else{
00116 return 0;
00117 }
00118 }
00119
00120
00121 HcalSubdetector HcalChannelIterator::getHcalSubdetector(void){
00122 if (const_iterator!=channel_list.end()){
00123 HcalDetId _id(*const_iterator);
00124 return _id.subdet();
00125 }
00126 else return HcalOther;
00127 }
00128
00129
00130 int HcalChannelIterator::getIeta(void){
00131 if (const_iterator!=channel_list.end()){
00132 HcalDetId _id(*const_iterator);
00133 return _id.ieta();
00134 }
00135 else return -1000;
00136 }
00137
00138
00139 int HcalChannelIterator::getIphi(void){
00140 if (const_iterator!=channel_list.end()){
00141 HcalDetId _id(*const_iterator);
00142 return _id.iphi();
00143 }
00144 else return -1000;
00145 }
00146
00147
00148 int HcalChannelIterator::getDepth(void){
00149 if (const_iterator!=channel_list.end()){
00150 HcalDetId _id(*const_iterator);
00151 return _id.depth();
00152 }
00153 else return -1000;
00154 }
00155
00156
00157 int HcalChannelIterator::initHBEFListFromLmapAscii(void){
00158 clearChannelList();
00159 addListFromLmapAscii("HCALmapHBEF_Jan.27.2009.txt");
00160 addListFromLmapAscii("HCALmapHO_Jan.27.2009.txt");
00161 return channel_list.size();
00162 }
00163
00164
00165 int HcalChannelIterator::init(std::vector<HcalGenericDetId> map){
00166 channel_list.clear();
00167 channel_list = map;
00168 return channel_list.size();
00169 }
00170