//-*- Mode: C++ -*- // ***************************************************************************** // * // @Autors: I.Kulakov; M.Pugach; M.Zyzak; I.Kisel * // @e-mail: I.Kulakov@gsi.de; M.Pugach@gsi.de; M.Zyzak@gsi.de; I.Kisel@compeng.uni-frankfurt.de * // * // ***************************************************************************** #ifndef FTSCASTATIONARRAY_H #define FTSCASTATIONARRAY_H #include using std::cout; #include using std::vector; #include "FTSCAHits.h" #include "FTSCATES.h" template< typename T > class FTSCAElementsOnStation: public vector { //* Properties of elements on station public: FTSCAElementsOnStation():fHitsRef(0),fISta(-1),fFirstElementIByHit0(){} FTSCAElementsOnStation( const FTSCAHits* hits ):fHitsRef(hits),fFirstElementIByHit0(){} void SetStation( char s ) { fISta = s; fFirstElementIByHit0.resize((*fHitsRef)[s].size() + 1, -1); } const char& IStation() const { return fISta; } const FTSCAHit& GetHit( int iV, int IH, int i ) const { return (*fHitsRef)[ (*this)[i].IHit(IH)[iV] ]; } const FTSCAHit& GetHit( int IH, int i ) const { return (*fHitsRef)[ (*this)[i].IHit(IH) ]; } int FirstElementIByHit0( int iH ) const { return fFirstElementIByHit0[iH]; } vector& FirstElementIByHit0() { return fFirstElementIByHit0; } const FTSCAHits* HitsRef() const { return fHitsRef; } FTSCAElementsOnStation& operator=( const FTSCAElementsOnStation& a ) { // do not copy fHitsRef vector::operator=( a ); fHitsRef = (a.fHitsRef == 0 ) ? fHitsRef : a.fHitsRef; // copy only of set fISta = (a.fISta == -1 ) ? fISta : a.fISta; fFirstElementIByHit0 = a.fFirstElementIByHit0; return *this; } FTSCAElementsOnStation operator+( const FTSCAElementsOnStation& a ) { if (a.size() <= 0) return *this; FTSCAElementsOnStation r( fHitsRef ); const FTSCAElementsOnStation &b = *this; const vector &bf = fFirstElementIByHit0; assert( a.fFirstElementIByHit0.size() == bf.size() ); r.SetStation(fISta); // find size unsigned int n = 0; for( unsigned int i = 0; i < a.fFirstElementIByHit0.size() - 1; i++ ) { if ( a.fFirstElementIByHit0[i] >= 0 ) for( int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i+1]; e++ ) { n++; } if ( bf[i] >= 0 ) for( int e = bf[i]; e < bf[i+1]; e++ ) { n++; } } const T sample( a[0].N() ); r.resize( (n-1)/float_v::Size + 1, sample ); // copy by hits n = 0; for( unsigned int i = 0; i < a.fFirstElementIByHit0.size()-1; i++ ) { r.fFirstElementIByHit0[i] = n; r.fFirstElementIByHit0[i+1] = n; if ( a.fFirstElementIByHit0[i] >= 0 ) for( int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i+1]; e++ ) { const int nV = e/float_v::Size; const int iV = e%float_v::Size; if ( !a[nV].IsValid()[iV] ) continue; const int nVt = n/float_v::Size; const int iVt = n%float_v::Size; r[nVt].CopyOne( iVt, a[nV], iV ); n++; } if ( bf[i] >= 0 ) for( int e = bf[i]; e < bf[i+1]; e++ ) { const int nV = e/float_v::Size; const int iV = e%float_v::Size; if ( !b[nV].IsValid()[iV] ) continue; const int nVt = n/float_v::Size; const int iVt = n%float_v::Size; r[nVt].CopyOne( iVt, b[nV], iV ); n++; } r.fFirstElementIByHit0[i+1] = n; } return r; } // private: const FTSCAHits* fHitsRef; char fISta; vector fFirstElementIByHit0; }; template< typename T > class FTSCAStationArray { public: FTSCAElementsOnStation& OnStation(char i) { assert((unsigned char)i& OnStation(char i) const { assert((unsigned char)i& operator[](char i) { assert((unsigned char)i& operator[](char i) const { assert((unsigned char)i( hits ) ); for( int i = 0; i < nSta; ++i ) fElement[i].SetStation( i ); } char NStations() const { return fElement.size(); } const FTSCAHits* HitsRef() const { if ( fElement.size() ) return fElement[0].fHitsRef; else return 0; } unsigned int Size() const { unsigned int s = 0; for( int i = 0; i < NStations(); ++i ) s += fElement[i].size(); return s; } T& operator[]( TES i ) { return fElement[i.s][i.e]; } const T& operator[]( TES i ) const { return fElement[i.s][i.e]; } void Add( const T& hit ) { const int iSta = hit.Station(); fElement[iSta].push_back( hit ); } protected: vector< FTSCAElementsOnStation > fElement; // hits on stations }; #endif