#ifndef _CALDATA_HH_ #define _CALDATA_HH_ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Component: CalData.hh // Purpose: This is the container class for calorimeter towers (C++ // equivalent of TOWE bank). See also CalTower class. // // Created: 09/04/99 Pierre Savard (adapted from J. Lamoureux's // towe_bank_driver) // History: 17/04/99 Marc Paterno // Modified to deal with new CalTower // 04/05/99 Pierre Savard Added createTower and setEnergy methods // 13/09/99 Pierre Savard // Make this class a storable object // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include "Edm/StorableObject.hh" #include "Edm/ConstHandle.hh" #include "Edm/Handle.hh" #include "CalorGeometry/CalConstants.hh" #include "CalorGeometry/TowerKey.hh" #include "CalorGeometry/Locations.hh" #include "CalorObjects/CalTower.hh" #include "CalorObjects/CalDataCalib.hh" #include "CalorObjects/createTower.hh" //ROOT headers #include "TBuffer.h" // namespace calor { class Calib; class Locations; class CalData; class CalDataNtuplizer; typedef Handle CalData_h; typedef ConstHandle CalData_ch; class CalData : public StorableObject { public: enum Error{ERROR,OK}; typedef CalTower* TowerData[TOWER_NETA][TOWER_MAX_NPHI]; // Forward declarations template class TowerDescription; class TowerType0; class TowerType1; class TowerType2; class TowerType3; class TowerType4; class TowerType5; class TowerType6; class TowerType7; class TowerType8; friend class TypeIter; // iterates over tower types friend class HighLevelIter; // iterates over towers using predicate // // Memory management // // Default constructor. Creates towers of the correct types in the // correct (iEta, iPhi) locations, using default constructor for each // tower type. CalData(); // Copy constructor CalData(const CalData& rhs):StorableObject() { UChar_t iEta; UChar_t iPhi; _paramVersion = rhs._paramVersion; _isPuffed = rhs._isPuffed; _calibrations = rhs._calibrations; _locs = 0; if (rhs._locs) _locs = new Locations(*rhs._locs); for (iEta = 0; iEta < TOWER_NETA; ++iEta){ for (iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi){ if(rhs._data[iEta][iPhi] == 0){ _data[iEta][iPhi] = 0; } else{ _data[iEta][iPhi] = rhs._data[iEta][iPhi]->clone(); } } } } // The swap method is used to make sure we (eventually) have safe exception handling void swap(CalData& copy) { UChar_t iEta; UChar_t iPhi; _paramVersion = copy._paramVersion; _isPuffed = copy._isPuffed; _calibrations = copy._calibrations; for (iEta = 0; iEta < TOWER_NETA; ++iEta) for (iPhi = 0; iPhi < TOWER_MAX_NPHI; ++iPhi) std::swap(_data[iEta][iPhi], copy._data[iEta][iPhi]); } // Assignment operator (uses swap above); CalData& operator=(const CalData& rhs) { CalData temp(rhs); swap(temp); return *this; } // protected destructor (EDM requirement) protected: ~CalData(); public: virtual void destroy(void) ; virtual void deallocate(void) ; virtual std::string class_name(void) const ; virtual Version_t class_version(void) const ; virtual void print(std::ostream& os) const ; virtual bool postread(EventRecord* p_record) ; virtual bool prewrite(EventRecord* p_record) ; virtual bool activate(EventRecord* p_record); virtual bool deactivate(EventRecord* p_record); // These methods will fetch a CalData object from the event // the version below will grab the first CalData object in the // event. It will use AbsEnv::theEvent() to get the event pointer. static Error find(CalData_ch&); // The versions below will be implemented when needed. // static CalData::Error find(CalData_ch,Selector sel); // static CalData::Error find(CalData_ch,Selector sel,AbsEvent* anEvent); // // Manipulation and access // // Give read access to a specific tower const CalTower* tower(UChar_t iEta, UChar_t iPhi) const; const CalTower* tower(TowerKey tKey) const; // Give read and write access to a specific tower CalTower* tower(UChar_t iEta, UChar_t iPhi); CalTower* tower(TowerKey tKey); // Give read and write access to a specific tower // This method will create the tower if it does not // exist. It is used in CalDataMaker. CalTower* towerMake(CellKey& cKey); CalTower* towerMake(TowerKey& tKey); // this fills CalTower data members e.g. emenergy and // hadenergy, hadphi, emphi (called after CalDataMaker is done). void cleanup(int skcut, float etmin); // skcut is spike killing cut, etmin is minimum Et required in Tower TowerData* getData() {return &_data;} // Some utilities void totalEnergies(float& emSum, float& hadSum) const; void storeCalibrations(Calib& dbCalib); CalDataCalib* getCalibrations(){return &_calibrations;} bool puff() const; bool isPuffed() const; void setParamVersion(int version); int paramVersion(); // // Printing // int size() const; // returns number of towers with energy // void print() const; void printSummary() const; //friend std::ostream& operator<<(std::ostream& os, const CalData& c); // ntuplizer methods virtual void ntuplize() const; static void attach_ntuplizer(CalDataNtuplizer* p_ntuplizer); static CalDataNtuplizer* _p_ntuplizer; private: // When a CalData is constructed, these CalTower* will actually point to // instances of the correct subclasses. TowerData _data; CalDataCalib _calibrations; mutable bool _isPuffed; Locations* _locs; int _paramVersion; #ifndef __CINT__ public: // // Iterators // // These iterators will return the next non-null pointer to a CalTower // The begin() and end() methods of CalData will find the first and // last non-null pointer // The constant iterator class ConstIterator { public: ConstIterator(); ConstIterator(const TowerData& td,UChar_t iEta, UChar_t iPhi) ; ConstIterator(const ConstIterator& rhs); UChar_t iEta(); UChar_t iPhi(); CalTower* tower() const; ConstIterator& operator++(); ConstIterator& operator--(); CalTower* operator->() const; CalTower& operator*() const; bool operator==(const ConstIterator& it) const; bool operator!=(const ConstIterator& it) const; ConstIterator& operator=(const ConstIterator& iter); private: UChar_t _iEta; UChar_t _iPhi; const TowerData* _dataptr; }; ConstIterator begin() const; ConstIterator end() const; typedef ConstIterator const_iterator; // The non-const Iterator class Iterator { public: Iterator(); Iterator(TowerData& td,UChar_t iEta, UChar_t iPhi); Iterator(const Iterator& rhs); UChar_t iEta(); UChar_t iPhi(); CalTower* tower(); Iterator& operator++(); Iterator& operator--(); CalTower* operator->(); CalTower& operator*(); bool operator==(const Iterator& it) const; bool operator!=(const Iterator& it) const; Iterator& operator=(const Iterator& iter); private: UChar_t _iEta; UChar_t _iPhi; TowerData* _dataptr; }; Iterator begin(); Iterator end(); typedef Iterator iterator; #endif // CINT // EDM stuff ClassDef(CalData, 12) }; #ifndef __CINT__ // inline implementation inline CalData::ConstIterator::ConstIterator( const ConstIterator& rhs ){ _iEta = rhs._iEta; _iPhi = rhs._iPhi; _dataptr = rhs._dataptr; } inline CalData::ConstIterator CalData::begin() const{ ConstIterator iter(_data,0,0); while(iter.tower() == 0 && !(iter.iEta()==51 && iter.iPhi() ==47)) ++iter; return iter;} inline CalData::ConstIterator CalData::end() const{ ConstIterator iter(_data,TOWER_NETA-1,TOWER_MAX_NPHI-1); // while(iter.tower() == 0 && !(iter.iEta()==0 && iter.iPhi() ==0)) --iter; return iter;} inline UChar_t CalData::ConstIterator::iEta() { return _iEta; } inline UChar_t CalData::ConstIterator::iPhi() { return _iPhi; } inline CalTower* CalData::ConstIterator::tower() const { return (*_dataptr)[_iEta][_iPhi];} inline CalData::Iterator::Iterator( const Iterator& rhs ){ _iEta = rhs._iEta; _iPhi = rhs._iPhi; _dataptr = rhs._dataptr; } inline CalData::Iterator CalData::begin(){ Iterator iter(_data,0,0); while(iter.tower() == 0 && !(iter.iEta()==51 && iter.iPhi() ==47)) ++iter; return iter;} inline CalData::Iterator CalData::end(){ Iterator iter(_data,TOWER_NETA-1,TOWER_MAX_NPHI-1); // while(iter.tower() == 0 && !(iter.iEta()==0 && iter.iPhi() ==0)) --iter; return iter;} inline UChar_t CalData::Iterator::iEta() { return _iEta; } inline UChar_t CalData::Iterator::iPhi() { return _iPhi; } inline CalTower* CalData::Iterator::tower() { return (*_dataptr)[_iEta][_iPhi]; } inline bool CalData::isPuffed() const { return _isPuffed; } inline void CalData::setParamVersion(int version) {_paramVersion=version; } inline int CalData::paramVersion() {return _paramVersion;} #endif // CINT // } // namespace calor #endif // _CALDATA_HH_