CbmRoot
Loading...
Searching...
No Matches
CbmDigiVector.h
Go to the documentation of this file.
1/* Copyright (C) 2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
11#ifndef CBMDIGIVECTOR_H
12#define CBMDIGIVECTOR_H 1
13
14
15#include "CbmDigiContainer.h"
16#include "CbmMatch.h"
17
18#include <Logger.h>
19
20#include <vector>
21
27template<class Digi>
29
30public:
34 CbmDigiVector(bool hasMatches = false) : fHasMatches(hasMatches)
35 {
36 TString name = Digi::GetClassName();
37 name += "_vector";
38 SetName(name.Data());
39 }
40
41
43 virtual ~CbmDigiVector() {}
44
45
53 virtual void AddDigi(boost::any digi, const CbmMatch* match = nullptr)
54 {
55 if (fIsLocked) {
56 LOG(fatal) << GetName() << "::AddDigi: Vector is locked.";
57 return;
58 }
59 const Digi* thisDigi = boost::any_cast<const Digi*>(digi);
60 if (!thisDigi) {
61 LOG(fatal) << GetName() << "::AddDigi: Wrong argument type"
62 << " (should be " << Digi::GetClassName() << "*) !";
63 return;
64 } //? Any_cast successful
65 fDigis.push_back(*thisDigi);
66 if (fHasMatches) {
67 if (match == nullptr) {
68 LOG(fatal) << GetName() << "::AddDigi: Valid match object required!";
69 return;
70 }
71 fMatches.push_back(*match);
72 } //? Has matches
73 }
74
75
80 virtual bool ConnectToTree()
81 {
82 LOG(fatal) << "Digi vector cannot be connected to a TTree!";
83 return false;
84 }
85
86
93 virtual boost::any GetDigi(uint32_t index)
94 {
95 fIsLocked = true;
96 const Digi* result = nullptr;
97 if (index < fDigis.size()) result = &(fDigis[index]);
98 return boost::any(result);
99 }
100
101
109 virtual const CbmMatch* GetDigiMatch(uint32_t index)
110 {
111 fIsLocked = true;
112 const CbmMatch* result = nullptr;
113 if (fHasMatches && index < fMatches.size()) result = &(fMatches[index]);
114 return result;
115 }
116
117
121 virtual bool HasMatches() const { return fHasMatches; }
122
123
127 virtual uint64_t GetNofDigis() const
128 {
129 if (fHasMatches) assert(fMatches.size() == fDigis.size());
130 return static_cast<uint64_t>(fDigis.size());
131 }
132
133
137 virtual std::string ToString() const
138 {
139 std::stringstream ss;
140 ss << GetName() << ", size " << fDigis.size();
141 if (HasMatches()) ss << ", matches present";
142 return ss.str();
143 }
144
145
146private:
147 std::vector<Digi> fDigis {};
148 std::vector<CbmMatch> fMatches {};
149 bool fHasMatches = false;
150 bool fIsLocked = false;
151
152
154};
155
156#endif /* CBMDIGIVECTOR_H */
Abstract container for digis in CBM.
virtual const char * GetName() const
Name of container.
std::vector implementation of CbmDigiContainer
std::vector< Digi > fDigis
virtual bool HasMatches() const
Presence of match objects.
std::vector< CbmMatch > fMatches
virtual ~CbmDigiVector()
Destructor.
ClassDef(CbmDigiVector, 1)
virtual std::string ToString() const
String output.
virtual uint64_t GetNofDigis() const
Number of digis in the vector.
CbmDigiVector(bool hasMatches=false)
Constructor.
virtual const CbmMatch * GetDigiMatch(uint32_t index)
Get digi match object.
virtual void AddDigi(boost::any digi, const CbmMatch *match=nullptr)
Add a digi (and match) to the vector.
virtual bool ConnectToTree()
Connect to a ROOT TTree.
virtual boost::any GetDigi(uint32_t index)
Get digi object.