PandaRoot
PndCAStationArray.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.Zyzak; I.Kisel *
17 // @e-mail: I.Kulakov@gsi.de; M.Zyzak@gsi.de; I.Kisel@compeng.uni-frankfurt.de *
18 // *
19 // *****************************************************************************
20 
21 #ifndef PNDCASTATIONARRAY_H
22 #define PNDCASTATIONARRAY_H
23 
24 #include <iostream>
25 using std::cout;
26 
27 #include <vector>
28 using std::vector;
29 
30 #include "PndCAHits.h"
31 #include "PndCATES.h"
32 
33 template <typename T>
34 class PndCAElementsOnStation : public vector<T> {
35  public:
36  PndCAElementsOnStation() : fHitsRef(nullptr), fISta(-1) {}
37  PndCAElementsOnStation(const PndCAHits *hits) : fHitsRef(hits) {}
38 
39  void SetStation(char s) { fISta = s; }
40 
41  const char &IStation() const { return fISta; }
42 
43  const PndCAHit &GetHit(int iV, int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)[iV]]; }
44 
45  const PndCAHit &GetHit(int IH, int i) const { return (*fHitsRef)[(*this)[i].IHit(IH)]; }
46 
47  const PndCAHits *HitsRef() const { return fHitsRef; }
48 
50  { // do not copy fHitsRef
51  vector<T>::operator=(a);
52  fHitsRef = (a.fHitsRef == 0) ? fHitsRef : a.fHitsRef; // copy only of set
53  fISta = (a.fISta == -1) ? fISta : a.fISta;
54  return *this;
55  }
56 
58  {
60  r.resize(this->size() + a.size());
61  int iR = 0;
62  for (unsigned int i = 0; i < this->size(); ++i) {
63  r[iR++] = (*this)[i];
64  }
65  for (unsigned int i = 0; i < a.size(); ++i) {
66  r[iR++] = a[i];
67  }
68  r.SetStation(fISta);
69  assert(0); // TODO combine fFirstElementIByHit0
70  return r;
71  }
72 
73  // private:
75  char fISta;
76 };
77 
78 template <typename T>
80  public:
82  {
83  assert((unsigned char)i < fElement.size());
84  return fElement[i];
85  }
87  {
88  assert((unsigned char)i < fElement.size());
89  return fElement[i];
90  }
92  {
93  assert((unsigned char)i < fElement.size());
94  return fElement[i];
95  }
97  {
98  assert((unsigned char)i < fElement.size());
99  return fElement[i];
100  }
101 
103 
104  PndCAStationArray(int nSta, const PndCAHits *hits) { Renew(nSta, hits); }
105 
106  void Renew(int nSta, const PndCAHits *hits)
107  {
108  fElement.clear();
109  fElement.resize(nSta, PndCAElementsOnStation<T>(hits));
110  for (int i = 0; i < nSta; ++i)
111  fElement[i].SetStation(i);
112  }
113 
114  char NStations() const { return fElement.size(); }
115 
116  const PndCAHits *HitsRef() const
117  {
118  if (fElement.size())
119  return fElement[0].fHitsRef;
120  else
121  return nullptr;
122  }
123 
124  unsigned int Size() const
125  {
126  unsigned int s = 0;
127  for (int i = 0; i < NStations(); ++i)
128  s += fElement[i].size();
129  return s;
130  }
131 
132  T &operator[](PndCATES i) { return fElement[i.s][i.e]; }
133  const T &operator[](PndCATES i) const { return fElement[i.s][i.e]; }
134 
135  void Add(const T &hit)
136  {
137  const int iSta = hit.Station();
138  fElement[iSta].push_back(hit);
139  }
140 
141  protected:
142  vector<PndCAElementsOnStation<T>> fElement; // hits on stations
143 };
144 
145 #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:33
unsigned int i
Definition: P4_F32vec4.h:33
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:34
vector< PndCAElementsOnStation< T > > fElement