00001
00002 #include "tmb_tree/TMBCellContainer.hpp"
00003
00004 #include <algorithm>
00005
00006 namespace {
00007
00009 struct compare_cell {
00010 compare_cell(Char_t ieta, UChar_t iphi, UChar_t ilyr)
00011 : _ieta(ieta), _iphi(iphi), _ilyr(ilyr) {}
00012 bool operator()(const TMBCaloCell& other)
00013 {
00014 return
00015 _ieta == other.ieta() &&
00016 _iphi == other.iphi() &&
00017 _ilyr == other.layer();
00018 }
00019 Char_t _ieta;
00020 UChar_t _iphi;
00021 UChar_t _ilyr;
00022 };
00023
00024 }
00025
00026 TMBCellContainer::TMBCellContainer()
00027 {
00028 }
00029
00030 TMBCellContainer::~TMBCellContainer()
00031 {
00032 }
00033
00034 UInt_t TMBCellContainer::NumCells() const
00035 {
00036 return (UInt_t)_cells.size();
00037 }
00038
00039
00040 const TMBCaloCell *TMBCellContainer::GetCell(Index_t index) const
00041 {
00042 return (index < _cells.size()) ? &_cells[index] : 0;
00043 }
00044
00045
00046 const TMBCaloCell *TMBCellContainer::GetCell(Char_t ieta, UChar_t iphi, UChar_t ilayer) const
00047 {
00048 return GetCell(GetIndex(ieta, iphi, ilayer));
00049 }
00050
00051
00052 TMBCellContainer::Index_t TMBCellContainer::GetIndex(Char_t ieta, UChar_t iphi, UChar_t ilayer) const
00053 {
00054 std::vector<TMBCaloCell>::const_iterator it =
00055 std::find_if(_cells.begin(), _cells.end(), compare_cell(ieta, iphi, ilayer));
00056 if(it != _cells.end()) {
00057 return (Index_t) (it - _cells.begin());
00058 } else {
00059 return INVALID_CELL;
00060 }
00061 }
00062
00063 TMBCellContainer::Index_t
00064 TMBCellContainer::AddCell(Char_t ieta, UChar_t iphi, UChar_t ilayer, Float_t energy, UChar_t flags)
00065 {
00066 Index_t index = GetIndex(ieta, iphi, ilayer);
00067 if(index == INVALID_CELL) {
00068 _cells.push_back(TMBCaloCell(ieta, iphi, ilayer, energy, flags));
00069 return (Index_t )(_cells.size() - 1);
00070 } else {
00071
00072
00073 return index;
00074 }
00075 }
00076
00077 void TMBCellContainer::ClearCells()
00078 {
00079 _cells.clear();
00080 }
00081
00082 Bool_t TMBCellContainer::IsFolder() const
00083 {
00084 return kTRUE;
00085 }
00086
00087 ClassImp(TMBCellContainer);