#ifdef USE_CDFEDM2 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Component: PhysicsTowerData.cc // Purpose: Implementation of the PhysicsTowerData class. // // Created: 16/04/99 Marc Paterno // History: 02/05/99 Pierre Savard: Added Iterator and changed constructor // 12/09/99 Pierre Savard: Port to new EDM // 17/05/01 Matthias Toennesmann: Modified find(..., PhysicsTowerParams* , ...) methods. // Now also the parameters are compared. // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include using namespace std; #include "BaBar/Cdf.hh" #include "ErrorLogger_i/gERRLOG.hh" #include "Edm/EventRecord.hh" #include "CalorObjects/PhysicsTowerData.hh" #include "EdmUtilities/CdfClassImp.hh" // namespace calor { // // Memory management // PhysicsTowerData::PhysicsTowerData(): StorableObject(){ // Fill some default parameters for now: // first entry 0 = CalData is the input source // second entry 0 = StanardCalculator is the tower calculator // third entry 0.1 = Et Threshold on towers // last entry 0.0 : z vertex // use memset here instead? size_t iEta; size_t iPhi; for (iEta = 0; iEta < TOWER_NETA; ++iEta) for (iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi) _data[iEta][iPhi] = 0; } PhysicsTowerData::PhysicsTowerData(PhysicsTowerParams& params): StorableObject(), _towerParams(params){ size_t iEta; size_t iPhi; // use memset here instead? for (iEta = 0; iEta < TOWER_NETA; ++iEta) for (iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi) _data[iEta][iPhi] = 0; } PhysicsTowerData::~PhysicsTowerData(){} void PhysicsTowerData::destroy(void) { PhysicsTowerData::deallocate() ; delete this ; } void PhysicsTowerData::deallocate(void) { for (size_t iEta = 0; iEta < TOWER_NETA; ++iEta) { for (size_t iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi) { PhysicsTower* p_temp = _data[iEta][iPhi]; if (p_temp != 0) delete p_temp ; } } StorableObject::deallocate() ; } std::string PhysicsTowerData::class_name(void) const { return(PhysicsTowerData::Class_Name()) ; } Version_t PhysicsTowerData::class_version( void) const { return(PhysicsTowerData::Class_Version()) ; } //============================================================================= // Iostream //============================================================================= void PhysicsTowerData::print(std::ostream& os) const { StorableObject::print(os) ; os << "List of calorimeter towers with energy: " << std::endl; int intow = 0; PhysicsTowerData::ConstIterator end = this->end(); for(PhysicsTowerData::ConstIterator iter= this->begin(); iter != end; ++iter){ PhysicsTower* t = iter.tower(); t->print(); intow++; } os << std::endl; os << "Number of towers with energy: " << intow << std::endl; } //============================================================================= // Edm input/output //============================================================================= bool PhysicsTowerData::postread(EventRecord* p_record) { bool status = StorableObject::postread(p_record) ; return(status) ; } bool PhysicsTowerData::prewrite(EventRecord* p_record) { bool status = StorableObject::prewrite(p_record) ; return(status) ; } bool PhysicsTowerData::deactivate(EventRecord* p_record) { bool status = StorableObject::deactivate(p_record) ; return(status) ; } bool PhysicsTowerData::activate(EventRecord* p_record) { bool status = StorableObject::activate(p_record) ; return(status) ; } void PhysicsTowerData::Streamer(TBuffer& iobuffer){ unsigned int start = 0 ; unsigned int byte_count = 0 ; if (iobuffer.IsReading()){ Version_t original_version = iobuffer.ReadVersion(&start, &byte_count) ; if (original_version != 2){ ERRLOG(ELerror,"PhysicsTowerData: ") "Unsupported PhysicsTowerData class version cannot be treated" << endmsg; } else{ StorableObject::Streamer(iobuffer); iobuffer.CheckByteCount(start, byte_count, PhysicsTowerData::IsA()) ; } } else if (iobuffer.IsWriting()){ byte_count = iobuffer.WriteVersion(PhysicsTowerData::IsA(), kTRUE) ; Version_t current_version = class_version() ; if (current_version != 2){ ERRLOG(ELerror,"PhysicsTowerData: ") "Unsupported PhysicsTowerData class version cannot be treated" << endmsg; } StorableObject::Streamer(iobuffer); iobuffer.SetByteCount(byte_count, kTRUE) ; } else{ ERRLOG(ELerror,"PhysicsTowerData: ") << " (): NOTHING DONE" << endmsg; } } // // Access and manipulation // int PhysicsTowerData::size() const{ ConstIterator iter(_data,0,0); int nTowers = 0; while(!(iter.iEta()==51 && iter.iPhi() ==47)) { if(iter.tower() != 0) nTowers++; ++iter; } return nTowers; } bool PhysicsTowerData::add(PhysicsTower* pTower) { if(_data[pTower->iEta()][pTower->iPhi()]) return false; _data[pTower->iEta()][pTower->iPhi()] = pTower; return true; } bool PhysicsTowerData::destroyTower(PhysicsTower* pTower){ int ieta = pTower->iEta(); int iphi = pTower->iPhi(); if(_data[ieta][iphi] == 0){ return false; } else{ PhysicsTower* p_temp =_data[ieta][iphi] ; if (p_temp != 0) { delete p_temp ; _data[ieta][iphi] = 0; } return true;} } PhysicsTower * PhysicsTowerData::tower(size_t iEta, size_t iPhi){ assert (iEta < TOWER_NETA); assert (iPhi < TOWER_MAX_NPHI); return _data[iEta][iPhi]; } PhysicsTower * PhysicsTowerData::tower(int iEta, int iPhi){ assert (iEta < TOWER_NETA); assert (iPhi < TOWER_MAX_NPHI); return _data[iEta][iPhi]; } PhysicsTower * PhysicsTowerData::tower(TowerKey tKey){ int iEta = tKey.iEta(); int iPhi = tKey.iPhi(); assert (iEta < TOWER_NETA); assert (iPhi < TOWER_MAX_NPHI); return _data[iEta][iPhi]; } PhysicsTower * PhysicsTowerData::towerMake(TowerKey& tKey){ int iEta = tKey.iEta(); int iPhi = tKey.iPhi(); assert (iEta < TOWER_NETA); assert (iPhi < TOWER_MAX_NPHI); if(_data[iEta][iPhi]==0) _data[iEta][iPhi] = new PhysicsTower(); return _data[iEta][iPhi]; } // // ConstIterator implementation (should probably inline most of this) // PhysicsTowerData::ConstIterator::ConstIterator():_iEta(0),_iPhi(0),_dataptr(0) { } PhysicsTowerData::ConstIterator::ConstIterator(const TowerData& td,size_t iEta=0, size_t iPhi=0):_iEta(iEta),_iPhi(iPhi),_dataptr(&td) { } PhysicsTowerData::ConstIterator& PhysicsTowerData::ConstIterator::operator++(){ bool first = true; while(((*_dataptr)[_iEta][_iPhi] == 0 || first) && !(_iPhi ==47 && _iEta ==51)){ first = false; ++_iPhi; if(_iPhi == TOWER_MAX_NPHI){ ++_iEta; _iPhi=0; } } return *this; } PhysicsTowerData::ConstIterator& PhysicsTowerData::ConstIterator::operator--(){ bool first = true; while(((*_dataptr)[_iEta][_iPhi] == 0 || first) && !(_iPhi ==0 && _iEta ==0)){ first = false; if(_iPhi== 0) { --_iEta; _iPhi = TOWER_MAX_NPHI;} --_iPhi; } return *this; } PhysicsTower* PhysicsTowerData::ConstIterator::operator->() const{ return (*_dataptr)[_iEta][_iPhi]; } PhysicsTower& PhysicsTowerData::ConstIterator::operator*() const { return *operator->(); } bool PhysicsTowerData::ConstIterator::operator==(const ConstIterator& rhs) const{ if (this == &rhs) return true; return (_iEta == rhs._iEta && _iPhi == rhs._iPhi && _dataptr == rhs._dataptr); } bool PhysicsTowerData::ConstIterator::operator!=(const ConstIterator& it) const { return !operator==(it); } PhysicsTowerData::ConstIterator& PhysicsTowerData::ConstIterator::operator=(const ConstIterator& iter) { _iEta=iter._iEta; _iPhi=iter._iPhi; _dataptr=iter._dataptr; return *this; } // The non-const Iterator implementation PhysicsTowerData::Iterator::Iterator():_iEta(0),_iPhi(0),_dataptr(0) { } PhysicsTowerData::Iterator::Iterator(TowerData& td,size_t iEta=0, size_t iPhi=0):_iEta(iEta),_iPhi(iPhi),_dataptr(&td) { } PhysicsTowerData::Iterator& PhysicsTowerData::Iterator::operator++(){ bool first = true; while(((*_dataptr)[_iEta][_iPhi] == 0 || first) && !(_iPhi ==47 && _iEta ==51)){ first = false; ++_iPhi; if(_iPhi == TOWER_MAX_NPHI){ ++_iEta; _iPhi=0; } } return *this; } PhysicsTowerData::Iterator& PhysicsTowerData::Iterator::operator--(){ bool first = true; while(((*_dataptr)[_iEta][_iPhi] == 0 || first) && !(_iPhi ==0 && _iEta ==0)){ first = false; if(_iPhi== 0) { --_iEta; _iPhi = TOWER_MAX_NPHI;} --_iPhi; } return *this; } PhysicsTower* PhysicsTowerData::Iterator::operator->() { return (*_dataptr)[_iEta][_iPhi]; } PhysicsTower& PhysicsTowerData::Iterator::operator*() { return *operator->(); } bool PhysicsTowerData::Iterator::operator==(const Iterator& rhs) const { if (this == &rhs) return true; return (_iEta == rhs._iEta && _iPhi == rhs._iPhi && _dataptr == rhs._dataptr); } bool PhysicsTowerData::Iterator::operator!=(const Iterator& it) const { return !operator==(it); } PhysicsTowerData::Iterator& PhysicsTowerData::Iterator::operator=(const Iterator& iter) { _iEta=iter._iEta; _iPhi=iter._iPhi; _dataptr=iter._dataptr; return *this; } PhysicsTowerData::Error PhysicsTowerData::find(PhysicsTowerData_ch& theHandle){ AbsEvent* theEvent = AbsEnv::theEvent(); EventRecord::ConstIterator iter(theEvent,"PhysicsTowerData" ); if(iter.is_invalid()) return ERROR; theHandle = PhysicsTowerData_ch(iter); return OK; } PhysicsTowerData::Error PhysicsTowerData::find(PhysicsTowerData_ch& theHandle, const std::string& description){ AbsEvent* theEvent = AbsEnv::theEvent(); StorableObject::SelectByDescription selector( description ); StorableObject::SelectByClassName classSel( "PhysicsTowerData" ); EventRecord::ConstIterator iter( theEvent, selector && classSel ); if(iter.is_invalid())return ERROR; theHandle = PhysicsTowerData_ch(iter); return OK; } PhysicsTowerData::Error PhysicsTowerData::find(PhysicsTowerData_ch& theHandle, const std::string& description, AbsEvent* theEvent){ StorableObject::SelectByDescription selector( description ); StorableObject::SelectByClassName classSel( "PhysicsTowerData" ); EventRecord::ConstIterator iter( theEvent, selector && classSel ); if(iter.is_invalid())return ERROR; theHandle = PhysicsTowerData_ch(iter); return OK; } PhysicsTowerData::Error PhysicsTowerData::find(PhysicsTowerData_ch& theHandle, PhysicsTowerParams* params, const std::string& description){ // Returns the first PhysicsTowerData object in the event with a given description and a given parameter set. AbsEvent* theEvent = AbsEnv::theEvent(); StorableObject::SelectByDescription selector( description ); StorableObject::SelectByClassName classSel( "PhysicsTowerData" ); EventRecord::ConstIterator iter( theEvent, selector && classSel ); PhysicsTowerData_ch hndl; while(iter.is_valid()){ hndl = PhysicsTowerData_ch(iter); if(hndl->parameters() == *params) break; iter++; } if(iter.is_invalid()) return ERROR; theHandle = hndl; return OK; } PhysicsTowerData::Error PhysicsTowerData::find(PhysicsTowerData_ch& theHandle, PhysicsTowerParams* params, const std::string& description, AbsEvent* theEvent){ // Returns the first PhysicsTowerData object in the event with a given description and a given parameter set. StorableObject::SelectByDescription selector( description ); StorableObject::SelectByClassName classSel( "PhysicsTowerData" ); EventRecord::ConstIterator iter( theEvent, selector && classSel ); PhysicsTowerData_ch hndl; while(iter.is_valid()){ hndl = PhysicsTowerData_ch(iter); if(hndl->parameters() == *params) break; iter++; } if(iter.is_invalid()) return ERROR; theHandle = hndl; return OK; } CdfClassImp(PhysicsTowerData) // } // namespace calor #endif // USE_CDFEDM2