PandaRoot
FTSCAStationArray.h
Go to the documentation of this file.
1 //-*- Mode: C++ -*-
2 // *****************************************************************************
3 // *
4 // @Autors: I.Kulakov; M.Pugach; M.Zyzak; I.Kisel *
5 // @e-mail: I.Kulakov@gsi.de; M.Pugach@gsi.de; M.Zyzak@gsi.de; I.Kisel@compeng.uni-frankfurt.de *
6 // *
7 // *****************************************************************************
8 
9 #ifndef FTSCASTATIONARRAY_H
10 #define FTSCASTATIONARRAY_H
11 
12 #include <iostream>
13 using std::cout;
14 
15 #include <vector>
16 using std::vector;
17 
18 #include "FTSCAHits.h"
19 #include "FTSCATES.h"
20 
21 template <typename T>
22 class FTSCAElementsOnStation : public vector<T> {
23 
24  //* Properties of elements on station
25 
26  public:
29 
30  void SetStation(char s)
31  {
32  fISta = s;
33  fFirstElementIByHit0.resize((*fHitsRef)[s].size() + 1, -1);
34  }
35 
36  const char &IStation() const { return fISta; }
37 
38  const FTSCAHit &GetHit(int iV, int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)[iV]]; }
39 
40  const FTSCAHit &GetHit(int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)]; }
41 
42  int FirstElementIByHit0(int iH) const { return fFirstElementIByHit0[iH]; }
43  vector<int> &FirstElementIByHit0() { return fFirstElementIByHit0; }
44 
45  const FTSCAHits *HitsRef() const { return fHitsRef; }
46 
48  { // do not copy fHitsRef
49  vector<T>::operator=(a);
50  fHitsRef = (a.fHitsRef == 0) ? fHitsRef : a.fHitsRef; // copy only of set
51  fISta = (a.fISta == -1) ? fISta : a.fISta;
53  return *this;
54  }
55 
57  {
58  if (a.size() <= 0)
59  return *this;
61  const FTSCAElementsOnStation<T> &b = *this;
62  const vector<int> &bf = fFirstElementIByHit0;
63 
64  assert(a.fFirstElementIByHit0.size() == bf.size());
65  r.SetStation(fISta);
66 
67  // find size
68  unsigned int n = 0;
69  for (unsigned int i = 0; i < a.fFirstElementIByHit0.size() - 1; i++) {
70  if (a.fFirstElementIByHit0[i] >= 0)
71  for (int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i + 1]; e++) {
72  n++;
73  }
74  if (bf[i] >= 0)
75  for (int e = bf[i]; e < bf[i + 1]; e++) {
76  n++;
77  }
78  }
79  const T sample(a[0].N());
80  r.resize((n - 1) / float_v::Size + 1, sample);
81 
82  // copy by hits
83  n = 0;
84  for (unsigned int i = 0; i < a.fFirstElementIByHit0.size() - 1; i++) {
85  r.fFirstElementIByHit0[i] = n;
86  r.fFirstElementIByHit0[i + 1] = n;
87  if (a.fFirstElementIByHit0[i] >= 0)
88  for (int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i + 1]; e++) {
89  const int nV = e / float_v::Size;
90  const int iV = e % float_v::Size;
91  if (!a[nV].IsValid()[iV])
92  continue;
93 
94  const int nVt = n / float_v::Size;
95  const int iVt = n % float_v::Size;
96  r[nVt].CopyOne(iVt, a[nV], iV);
97  n++;
98  }
99  if (bf[i] >= 0)
100  for (int e = bf[i]; e < bf[i + 1]; e++) {
101  const int nV = e / float_v::Size;
102  const int iV = e % float_v::Size;
103  if (!b[nV].IsValid()[iV])
104  continue;
105 
106  const int nVt = n / float_v::Size;
107  const int iVt = n % float_v::Size;
108  r[nVt].CopyOne(iVt, b[nV], iV);
109  n++;
110  }
111  r.fFirstElementIByHit0[i + 1] = n;
112  }
113 
114  return r;
115  }
116 
117  // private:
119  char fISta;
120  vector<int> fFirstElementIByHit0;
121 };
122 
123 template <typename T>
125  public:
127  {
128  assert((unsigned char)i < fElement.size());
129  return fElement[i];
130  }
132  {
133  assert((unsigned char)i < fElement.size());
134  return fElement[i];
135  }
137  {
138  assert((unsigned char)i < fElement.size());
139  return fElement[i];
140  }
142  {
143  assert((unsigned char)i < fElement.size());
144  return fElement[i];
145  }
146 
148 
149  FTSCAStationArray(int nSta, const FTSCAHits *hits) { Renew(nSta, hits); }
150 
151  void Renew(int nSta, const FTSCAHits *hits)
152  {
153  fElement.clear();
154  fElement.resize(nSta, FTSCAElementsOnStation<T>(hits));
155  for (int i = 0; i < nSta; ++i)
156  fElement[i].SetStation(i);
157  }
158 
159  char NStations() const { return fElement.size(); }
160 
161  const FTSCAHits *HitsRef() const
162  {
163  if (fElement.size())
164  return fElement[0].fHitsRef;
165  else
166  return nullptr;
167  }
168 
169  unsigned int Size() const
170  {
171  unsigned int s = 0;
172  for (int i = 0; i < NStations(); ++i)
173  s += fElement[i].size();
174  return s;
175  }
176 
177  T &operator[](TES i) { return fElement[i.s][i.e]; }
178  const T &operator[](TES i) const { return fElement[i.s][i.e]; }
179 
180  void Add(const T &hit)
181  {
182  const int iSta = hit.Station();
183  fElement[iSta].push_back(hit);
184  }
185 
186  protected:
187  vector<FTSCAElementsOnStation<T>> fElement; // hits on stations
188 };
189 
190 #endif
char NStations() const
void Add(const T &hit)
const FTSCAHit & GetHit(int iV, int IH, int i) const
FTSCAElementsOnStation< T > & operator[](char i)
const T & operator[](TES i) const
const char & IStation() const
const FTSCAHits * HitsRef() const
const FTSCAHit & GetHit(int IH, int i) const
FTSCAElementsOnStation< T > operator+(const FTSCAElementsOnStation< T > &a)
unsigned int i
Definition: P4_F32vec4.h:21
int FirstElementIByHit0(int iH) const
const FTSCAElementsOnStation< T > & operator[](char i) const
unsigned int Size() const
vector< int > & FirstElementIByHit0()
FTSCAElementsOnStation< T > & OnStation(char i)
FTSCAStationArray(int nSta, const FTSCAHits *hits)
char s
Definition: FTSCATES.h:21
FTSCAElementsOnStation< T > & operator=(const FTSCAElementsOnStation< T > &a)
vector< int > fFirstElementIByHit0
void Renew(int nSta, const FTSCAHits *hits)
FTSCAElementsOnStation(const FTSCAHits *hits)
const FTSCAHits * HitsRef() const
vector< FTSCAElementsOnStation< T > > fElement
const FTSCAElementsOnStation< T > & OnStation(char i) const
unsigned int e
Definition: FTSCATES.h:22
const FTSCAHits * fHitsRef
Definition: FTSCATES.h:12