Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:15:08

0001 // -*- C++ -*-
0002 //
0003 // Package:     HcalOnlineDb
0004 // Class  :     HcalChannelIterator
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Gena Kukartsev
0010 //         Created:  Mon Jul 13 12:15:33 CEST 2009
0011 //
0012 
0013 #include <fstream>
0014 #include "CaloOnlineTools/HcalOnlineDb/interface/HcalChannelIterator.h"
0015 #include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h"
0016 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0017 
0018 HcalChannelIterator::HcalChannelIterator() {}
0019 
0020 HcalChannelIterator::~HcalChannelIterator() {}
0021 
0022 int HcalChannelIterator::size(void) { return channel_list.size(); }
0023 
0024 int HcalChannelIterator::clearChannelList(void) {
0025   channel_list.clear();
0026   return 0;
0027 }
0028 
0029 int HcalChannelIterator::addListFromLmapAscii(std::string filename) {
0030   RooGKCounter lines;
0031   int _current_size = size();
0032   std::string _row;
0033   std::ifstream inFile(filename.c_str(), std::ios::in);
0034   if (!inFile) {
0035     std::cout << "Unable to open file with the logical map: " << filename << std::endl;
0036   } else {
0037     std::cout << "File with the logical map opened successfully: " << filename << std::endl;
0038   }
0039   while (getline(inFile, _row)) {
0040     //#   side    eta    phi   dphi  depth    det
0041     int _num, _side, _eta, _phi, _dphi, _depth;
0042     char subdetbuf[32];
0043 
0044     int _read;
0045     const char* _format = "%d %d %d %d %d %d %s";
0046     _read = sscanf(_row.c_str(), _format, &_num, &_side, &_eta, &_phi, &_dphi, &_depth, subdetbuf);
0047     if (_read == 7) {
0048       lines.count();
0049 
0050       std::string subdet(subdetbuf);
0051 
0052       HcalSubdetector _det;
0053       if (subdet.find("HB") != std::string::npos)
0054         _det = HcalBarrel;
0055       else if (subdet.find("HE") != std::string::npos)
0056         _det = HcalEndcap;
0057       else if (subdet.find("HO") != std::string::npos)
0058         _det = HcalOuter;
0059       else if (subdet.find("HF") != std::string::npos)
0060         _det = HcalForward;
0061       else
0062         _det = HcalOther;
0063 
0064       HcalDetId _detid(_det, _side * _eta, _phi, _depth);
0065 
0066       if (_det == HcalBarrel || _det == HcalEndcap || _det == HcalOuter || _det == HcalForward) {
0067         channel_list.push_back(_detid);
0068       }
0069     }
0070   }
0071   inFile.close();
0072   std::cout << "Logical map file: " << lines.getCount() << " lines read" << std::endl;
0073   std::cout << "Logical map file: " << size() - _current_size << " lines added to the list" << std::endl;
0074   //
0075   return 0;
0076 }
0077 
0078 int HcalChannelIterator::begin(void) {
0079   const_iterator = channel_list.begin();
0080   return 0;
0081 }
0082 
0083 int HcalChannelIterator::next(void) {
0084   const_iterator++;
0085   return 0;
0086 }
0087 
0088 bool HcalChannelIterator::end(void) {
0089   if (const_iterator == channel_list.end()) {
0090     return true;
0091   } else {
0092     return false;
0093   }
0094 }
0095 
0096 HcalGenericDetId HcalChannelIterator::getHcalGenericDetId(void) {
0097   if (const_iterator != channel_list.end()) {
0098     return *const_iterator;
0099   } else {
0100     return 0;
0101   }
0102 }
0103 
0104 HcalSubdetector HcalChannelIterator::getHcalSubdetector(void) {
0105   if (const_iterator != channel_list.end()) {
0106     HcalDetId _id(*const_iterator);
0107     return _id.subdet();
0108   } else
0109     return HcalOther;
0110 }
0111 
0112 int HcalChannelIterator::getIeta(void) {
0113   if (const_iterator != channel_list.end()) {
0114     HcalDetId _id(*const_iterator);
0115     return _id.ieta();
0116   } else
0117     return -1000;
0118 }
0119 
0120 int HcalChannelIterator::getIphi(void) {
0121   if (const_iterator != channel_list.end()) {
0122     HcalDetId _id(*const_iterator);
0123     return _id.iphi();
0124   } else
0125     return -1000;
0126 }
0127 
0128 int HcalChannelIterator::getDepth(void) {
0129   if (const_iterator != channel_list.end()) {
0130     HcalDetId _id(*const_iterator);
0131     return _id.depth();
0132   } else
0133     return -1000;
0134 }
0135 
0136 int HcalChannelIterator::initHBEFListFromLmapAscii(void) {
0137   clearChannelList();
0138   addListFromLmapAscii("HCALmapHBEF_Jan.27.2009.txt");
0139   addListFromLmapAscii("HCALmapHO_Jan.27.2009.txt");
0140   return channel_list.size();
0141 }
0142 
0143 int HcalChannelIterator::init(const std::vector<HcalGenericDetId>& map) {
0144   channel_list.clear();
0145   channel_list = map;
0146   return channel_list.size();
0147 }