PandaRoot
FTSCAStationArray.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 //-*- Mode: C++ -*-
14 // *****************************************************************************
15 // *
16 // @Autors: I.Kulakov; M.Pugach; M.Zyzak; I.Kisel *
17 // @e-mail: I.Kulakov@gsi.de; M.Pugach@gsi.de; M.Zyzak@gsi.de; I.Kisel@compeng.uni-frankfurt.de *
18 // *
19 // *****************************************************************************
20 
21 #ifndef FTSCASTATIONARRAY_H
22 #define FTSCASTATIONARRAY_H
23 
24 #include <iostream>
25 using std::cout;
26 
27 #include <vector>
28 using std::vector;
29 
30 #include "FTSCAHits.h"
31 #include "FTSCATES.h"
32 
33 template <typename T>
34 class FTSCAElementsOnStation : public vector<T> {
35 
36  //* Properties of elements on station
37 
38  public:
41 
42  void SetStation(char s)
43  {
44  fISta = s;
45  fFirstElementIByHit0.resize((*fHitsRef)[s].size() + 1, -1);
46  }
47 
48  const char &IStation() const { return fISta; }
49 
50  const FTSCAHit &GetHit(int iV, int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)[iV]]; }
51 
52  const FTSCAHit &GetHit(int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)]; }
53 
54  int FirstElementIByHit0(int iH) const { return fFirstElementIByHit0[iH]; }
55  vector<int> &FirstElementIByHit0() { return fFirstElementIByHit0; }
56 
57  const FTSCAHits *HitsRef() const { return fHitsRef; }
58 
60  { // do not copy fHitsRef
61  vector<T>::operator=(a);
62  fHitsRef = (a.fHitsRef == 0) ? fHitsRef : a.fHitsRef; // copy only of set
63  fISta = (a.fISta == -1) ? fISta : a.fISta;
65  return *this;
66  }
67 
69  {
70  if (a.size() <= 0)
71  return *this;
73  const FTSCAElementsOnStation<T> &b = *this;
74  const vector<int> &bf = fFirstElementIByHit0;
75 
76  assert(a.fFirstElementIByHit0.size() == bf.size());
77  r.SetStation(fISta);
78 
79  // find size
80  unsigned int n = 0;
81  for (unsigned int i = 0; i < a.fFirstElementIByHit0.size() - 1; i++) {
82  if (a.fFirstElementIByHit0[i] >= 0)
83  for (int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i + 1]; e++) {
84  n++;
85  }
86  if (bf[i] >= 0)
87  for (int e = bf[i]; e < bf[i + 1]; e++) {
88  n++;
89  }
90  }
91  const T sample(a[0].N());
92  r.resize((n - 1) / float_v::Size + 1, sample);
93 
94  // copy by hits
95  n = 0;
96  for (unsigned int i = 0; i < a.fFirstElementIByHit0.size() - 1; i++) {
97  r.fFirstElementIByHit0[i] = n;
98  r.fFirstElementIByHit0[i + 1] = n;
99  if (a.fFirstElementIByHit0[i] >= 0)
100  for (int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i + 1]; e++) {
101  const int nV = e / float_v::Size;
102  const int iV = e % float_v::Size;
103  if (!a[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, a[nV], iV);
109  n++;
110  }
111  if (bf[i] >= 0)
112  for (int e = bf[i]; e < bf[i + 1]; e++) {
113  const int nV = e / float_v::Size;
114  const int iV = e % float_v::Size;
115  if (!b[nV].IsValid()[iV])
116  continue;
117 
118  const int nVt = n / float_v::Size;
119  const int iVt = n % float_v::Size;
120  r[nVt].CopyOne(iVt, b[nV], iV);
121  n++;
122  }
123  r.fFirstElementIByHit0[i + 1] = n;
124  }
125 
126  return r;
127  }
128 
129  // private:
131  char fISta;
132  vector<int> fFirstElementIByHit0;
133 };
134 
135 template <typename T>
137  public:
139  {
140  assert((unsigned char)i < fElement.size());
141  return fElement[i];
142  }
144  {
145  assert((unsigned char)i < fElement.size());
146  return fElement[i];
147  }
149  {
150  assert((unsigned char)i < fElement.size());
151  return fElement[i];
152  }
154  {
155  assert((unsigned char)i < fElement.size());
156  return fElement[i];
157  }
158 
160 
161  FTSCAStationArray(int nSta, const FTSCAHits *hits) { Renew(nSta, hits); }
162 
163  void Renew(int nSta, const FTSCAHits *hits)
164  {
165  fElement.clear();
166  fElement.resize(nSta, FTSCAElementsOnStation<T>(hits));
167  for (int i = 0; i < nSta; ++i)
168  fElement[i].SetStation(i);
169  }
170 
171  char NStations() const { return fElement.size(); }
172 
173  const FTSCAHits *HitsRef() const
174  {
175  if (fElement.size())
176  return fElement[0].fHitsRef;
177  else
178  return nullptr;
179  }
180 
181  unsigned int Size() const
182  {
183  unsigned int s = 0;
184  for (int i = 0; i < NStations(); ++i)
185  s += fElement[i].size();
186  return s;
187  }
188 
189  T &operator[](TES i) { return fElement[i.s][i.e]; }
190  const T &operator[](TES i) const { return fElement[i.s][i.e]; }
191 
192  void Add(const T &hit)
193  {
194  const int iSta = hit.Station();
195  fElement[iSta].push_back(hit);
196  }
197 
198  protected:
199  vector<FTSCAElementsOnStation<T>> fElement; // hits on stations
200 };
201 
202 #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:33
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:33
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:34
const FTSCAHits * fHitsRef
Definition: FTSCATES.h:24