PandaRoot
PndCAStationArray.h
Go to the documentation of this file.
1 //-*- Mode: C++ -*-
2 // *****************************************************************************
3 // *
4 // @Autors: I.Kulakov; M.Zyzak; I.Kisel *
5 // @e-mail: I.Kulakov@gsi.de; M.Zyzak@gsi.de; I.Kisel@compeng.uni-frankfurt.de *
6 // *
7 // *****************************************************************************
8 
9 #ifndef PNDCASTATIONARRAY_H
10 #define PNDCASTATIONARRAY_H
11 
12 #include <iostream>
13 using std::cout;
14 
15 #include <vector>
16 using std::vector;
17 
18 #include "PndCAHits.h"
19 #include "PndCATES.h"
20 
21 template <typename T>
22 class PndCAElementsOnStation : public vector<T> {
23  public:
24  PndCAElementsOnStation() : fHitsRef(nullptr), fISta(-1) {}
25  PndCAElementsOnStation(const PndCAHits *hits) : fHitsRef(hits) {}
26 
27  void SetStation(char s) { fISta = s; }
28 
29  const char &IStation() const { return fISta; }
30 
31  const PndCAHit &GetHit(int iV, int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)[iV]]; }
32 
33  const PndCAHit &GetHit(int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)]; }
34 
35  const PndCAHits *HitsRef() const { return fHitsRef; }
36 
38  { // do not copy fHitsRef
39  vector<T>::operator=(a);
40  fHitsRef = (a.fHitsRef == 0) ? fHitsRef : a.fHitsRef; // copy only of set
41  fISta = (a.fISta == -1) ? fISta : a.fISta;
42  return *this;
43  }
44 
46  {
48  r.resize(this->size() + a.size());
49  int iR = 0;
50  for (unsigned int i = 0; i < this->size(); ++i) {
51  r[iR++] = (*this)[i];
52  }
53  for (unsigned int i = 0; i < a.size(); ++i) {
54  r[iR++] = a[i];
55  }
56  r.SetStation(fISta);
57  assert(0); // TODO combine fFirstElementIByHit0
58  return r;
59  }
60 
61  // private:
63  char fISta;
64 };
65 
66 template <typename T>
68  public:
70  {
71  assert((unsigned char)i < fElement.size());
72  return fElement[i];
73  }
75  {
76  assert((unsigned char)i < fElement.size());
77  return fElement[i];
78  }
80  {
81  assert((unsigned char)i < fElement.size());
82  return fElement[i];
83  }
85  {
86  assert((unsigned char)i < fElement.size());
87  return fElement[i];
88  }
89 
91 
92  PndCAStationArray(int nSta, const PndCAHits *hits) { Renew(nSta, hits); }
93 
94  void Renew(int nSta, const PndCAHits *hits)
95  {
96  fElement.clear();
97  fElement.resize(nSta, PndCAElementsOnStation<T>(hits));
98  for (int i = 0; i < nSta; ++i)
99  fElement[i].SetStation(i);
100  }
101 
102  char NStations() const { return fElement.size(); }
103 
104  const PndCAHits *HitsRef() const
105  {
106  if (fElement.size())
107  return fElement[0].fHitsRef;
108  else
109  return nullptr;
110  }
111 
112  unsigned int Size() const
113  {
114  unsigned int s = 0;
115  for (int i = 0; i < NStations(); ++i)
116  s += fElement[i].size();
117  return s;
118  }
119 
120  T &operator[](PndCATES i) { return fElement[i.s][i.e]; }
121  const T &operator[](PndCATES i) const { return fElement[i.s][i.e]; }
122 
123  void Add(const T &hit)
124  {
125  const int iSta = hit.Station();
126  fElement[iSta].push_back(hit);
127  }
128 
129  protected:
130  vector<PndCAElementsOnStation<T>> fElement; // hits on stations
131 };
132 
133 #endif
unsigned int Size() const
const PndCAElementsOnStation< T > & operator[](char i) const
PndCAElementsOnStation< T > operator+(const PndCAElementsOnStation< T > &a)
PndCAElementsOnStation< T > & operator=(const PndCAElementsOnStation< T > &a)
char NStations() const
PndCAElementsOnStation< T > & operator[](char i)
const PndCAHit & GetHit(int iV, int IH, int i) const
const PndCAHits * HitsRef() const
void Add(const T &hit)
const char & IStation() const
const T & operator[](PndCATES i) const
const PndCAHits * HitsRef() const
char s
Definition: PndCATES.h:21
unsigned int i
Definition: P4_F32vec4.h:21
const PndCAHits * fHitsRef
PndCAElementsOnStation< T > & OnStation(char i)
void Renew(int nSta, const PndCAHits *hits)
const PndCAElementsOnStation< T > & OnStation(char i) const
T & operator[](PndCATES i)
const PndCAHit & GetHit(int IH, int i) const
PndCAElementsOnStation(const PndCAHits *hits)
PndCAStationArray(int nSta, const PndCAHits *hits)
unsigned int e
Definition: PndCATES.h:22
vector< PndCAElementsOnStation< T > > fElement