Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
// -*- C++ -*-
//
// Package:     HcalOnlineDb
// Class  :     HcalChannelIterator
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Gena Kukartsev
//         Created:  Mon Jul 13 12:15:33 CEST 2009
//

#include <fstream>
#include "CaloOnlineTools/HcalOnlineDb/interface/HcalChannelIterator.h"
#include "CaloOnlineTools/HcalOnlineDb/interface/RooGKCounter.h"
#include "DataFormats/HcalDetId/interface/HcalDetId.h"

HcalChannelIterator::HcalChannelIterator() {}

HcalChannelIterator::~HcalChannelIterator() {}

int HcalChannelIterator::size(void) { return channel_list.size(); }

int HcalChannelIterator::clearChannelList(void) {
  channel_list.clear();
  return 0;
}

int HcalChannelIterator::addListFromLmapAscii(std::string filename) {
  RooGKCounter lines;
  int _current_size = size();
  std::string _row;
  std::ifstream inFile(filename.c_str(), std::ios::in);
  if (!inFile) {
    std::cout << "Unable to open file with the logical map: " << filename << std::endl;
  } else {
    std::cout << "File with the logical map opened successfully: " << filename << std::endl;
  }
  while (getline(inFile, _row)) {
    //#   side    eta    phi   dphi  depth    det
    int _num, _side, _eta, _phi, _dphi, _depth;
    char subdetbuf[32];

    int _read;
    const char* _format = "%d %d %d %d %d %d %s";
    _read = sscanf(_row.c_str(), _format, &_num, &_side, &_eta, &_phi, &_dphi, &_depth, subdetbuf);
    if (_read == 7) {
      lines.count();

      std::string subdet(subdetbuf);

      HcalSubdetector _det;
      if (subdet.find("HB") != std::string::npos)
        _det = HcalBarrel;
      else if (subdet.find("HE") != std::string::npos)
        _det = HcalEndcap;
      else if (subdet.find("HO") != std::string::npos)
        _det = HcalOuter;
      else if (subdet.find("HF") != std::string::npos)
        _det = HcalForward;
      else
        _det = HcalOther;

      HcalDetId _detid(_det, _side * _eta, _phi, _depth);

      if (_det == HcalBarrel || _det == HcalEndcap || _det == HcalOuter || _det == HcalForward) {
        channel_list.push_back(_detid);
      }
    }
  }
  inFile.close();
  std::cout << "Logical map file: " << lines.getCount() << " lines read" << std::endl;
  std::cout << "Logical map file: " << size() - _current_size << " lines added to the list" << std::endl;
  //
  return 0;
}

int HcalChannelIterator::begin(void) {
  const_iterator = channel_list.begin();
  return 0;
}

int HcalChannelIterator::next(void) {
  const_iterator++;
  return 0;
}

bool HcalChannelIterator::end(void) {
  if (const_iterator == channel_list.end()) {
    return true;
  } else {
    return false;
  }
}

HcalGenericDetId HcalChannelIterator::getHcalGenericDetId(void) {
  if (const_iterator != channel_list.end()) {
    return *const_iterator;
  } else {
    return 0;
  }
}

HcalSubdetector HcalChannelIterator::getHcalSubdetector(void) {
  if (const_iterator != channel_list.end()) {
    HcalDetId _id(*const_iterator);
    return _id.subdet();
  } else
    return HcalOther;
}

int HcalChannelIterator::getIeta(void) {
  if (const_iterator != channel_list.end()) {
    HcalDetId _id(*const_iterator);
    return _id.ieta();
  } else
    return -1000;
}

int HcalChannelIterator::getIphi(void) {
  if (const_iterator != channel_list.end()) {
    HcalDetId _id(*const_iterator);
    return _id.iphi();
  } else
    return -1000;
}

int HcalChannelIterator::getDepth(void) {
  if (const_iterator != channel_list.end()) {
    HcalDetId _id(*const_iterator);
    return _id.depth();
  } else
    return -1000;
}

int HcalChannelIterator::initHBEFListFromLmapAscii(void) {
  clearChannelList();
  addListFromLmapAscii("HCALmapHBEF_Jan.27.2009.txt");
  addListFromLmapAscii("HCALmapHO_Jan.27.2009.txt");
  return channel_list.size();
}

int HcalChannelIterator::init(const std::vector<HcalGenericDetId>& map) {
  channel_list.clear();
  channel_list = map;
  return channel_list.size();
}