JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwSubsystemArray.h
Go to the documentation of this file.
1/*!
2 * \file QwSubsystemArray.h
3 * \brief Array container for managing multiple subsystems
4 * \author P. M. King, Rakitha Beminiwattha
5 * \date 2008-07-22
6 */
7
8#pragma once
9
10#include <vector>
11#include <map>
12#include <memory>
13
14#include "Rtypes.h"
15#include "TString.h"
16#include "TDirectory.h"
17#include "TTree.h"
18
19// RNTuple headers
20#include "ROOT/RNTupleModel.hxx"
21
22// Qweak headers
23#include "MQwPublishable.h"
24#include "VQwSubsystem.h"
25#include "QwOptions.h"
26
27// Forward declarations
29class QwParameterFile;
31
32/**
33 * \class QwSubsystemArray
34 * \ingroup QwAnalysis
35 * \brief Container for managing multiple subsystems with common operations
36 *
37 * Extends std::vector to provide subsystem-level operations such as
38 * event processing, accumulation, tree/histogram construction, and
39 * publishing. Uses container-delegation pattern to forward arithmetic
40 * operations to individual subsystems while maintaining type safety.
41 */
43 public std::vector<std::shared_ptr<VQwSubsystem>>,
44 public MQwPublishable<QwSubsystemArray, VQwSubsystem> {
45
46 private:
47 typedef std::vector<std::shared_ptr<VQwSubsystem> > SubsysPtrs;
48 public:
49 using SubsysPtrs::const_iterator;
50 using SubsysPtrs::iterator;
51 using SubsysPtrs::begin;
52 using SubsysPtrs::end;
53 using SubsysPtrs::size;
54 using SubsysPtrs::empty;
55
56 typedef Bool_t (*CanContainFn)(VQwSubsystem*);
57
58 private:
59
60 /// Private default constructor
61 QwSubsystemArray(); // not implemented, will throw linker error on use
62
63 public:
64
65 /// \brief Constructor with options
66 QwSubsystemArray(QwOptions& options, CanContainFn myCanContain);
67 /// \brief Copy constructor by reference
69 /// \brief Virtual destructor
70 ~QwSubsystemArray() override { };
71
72 /// \brief Assignment operator
74
75 /// \brief Set the internal record of the CODA run number
76 void SetCodaRunNumber(UInt_t runnum) { fCodaRunNumber = runnum; };
77 /// \brief Set the internal record of the CODA segment number
78 void SetCodaSegmentNumber(UInt_t segnum) { fCodaSegmentNumber = segnum; };
79 /// \brief Set the internal record of the CODA event number
80 void SetCodaEventNumber(UInt_t evtnum) { fCodaEventNumber = evtnum; };
81 /// \brief Set the internal record of the CODA event type
82 void SetCodaEventType(UInt_t evttype) { fCodaEventType = evttype; };
83 /// \brief Get the internal record of the CODA run number
84 UInt_t GetCodaRunNumber() const { return fCodaRunNumber; };
85 /// \brief Get the internal record of the CODA segment number
86 UInt_t GetCodaSegmentNumber() const { return fCodaSegmentNumber; };
87 /// \brief Get the internal record of the CODA event number
88 UInt_t GetCodaEventNumber() const { return fCodaEventNumber; };
89 /// \brief Get the internal record of the CODA event type
90 UInt_t GetCodaEventType() const { return fCodaEventType; };
91
92 /// \brief Set the internal record of the CODA event number
93 void SetCleanParameters(Double_t cleanparameter[3])
94 {
95 fCleanParameter[0] = cleanparameter[0];
96 fCleanParameter[1] = cleanparameter[1];
97 fCleanParameter[2] = cleanparameter[2];
98 };
99
100 /// \brief Set event type mask
101 void SetEventTypeMask(const UInt_t mask) { fEventTypeMask = mask; };
102 /// \brief Get event type mask
103 UInt_t GetEventTypeMask() const { return fEventTypeMask; };
104 /// \brief Update the event type mask from the subsystems
106 for (iterator subsys_iter = begin(); subsys_iter != end(); ++subsys_iter) {
107 VQwSubsystem* subsys = dynamic_cast<VQwSubsystem*>(subsys_iter->get());
108 fEventTypeMask |= subsys->GetEventTypeMask();
109 }
110 return fEventTypeMask;
111 };
112
113
114 /// \brief Set data loaded flag
115 void SetDataLoaded(const Bool_t flag) { fHasDataLoaded = flag; };
116 /// \brief Get data loaded flag
117 Bool_t HasDataLoaded() const { return fHasDataLoaded; };
118
119 /// \brief Define configuration options for global array
120 static void DefineOptions(QwOptions &options);
121 /// \brief Process configuration options for the subsystem array itself
122 void ProcessOptionsToplevel(QwOptions &options);
123 /// \brief Process configuration options for all subsystems in the array
124 void ProcessOptionsSubsystems(QwOptions &options);
125 /// \brief Process configuration options (default behavior)
127 void LoadAllEventRanges(QwOptions &options);
128
129 /// \brief Add the subsystem to this array
130 void push_back(VQwSubsystem* subsys);
131
132 /// \brief Get the subsystem with the specified name
133 virtual VQwSubsystem* GetSubsystemByName(const TString& name);
134
135 /// \brief Get the list of subsystems of the specified type
136 virtual std::vector<VQwSubsystem*> GetSubsystemByType(const std::string& type);
137
138 //each of the methods below will call their counterpart method separately.
139
140 void ClearEventData();
141
142 /// \brief Process the event buffer for configuration events
143 Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id,
144 UInt_t *buffer, UInt_t num_words);
145
146 /// \brief Process the event buffer for events
147 Int_t ProcessEvBuffer(const UInt_t event_type, const ROCID_t roc_id,
148 const BankID_t bank_id, UInt_t *buffer,
149 UInt_t num_words);
150
151 /// \brief Get the ROCID list
152 void GetROCIDList(std::vector<ROCID_t> &list);
153
154 /// \brief Process the decoded data in this event
155 void ProcessEvent();
156
157 /// \brief Perform actions at the end of the event loop
158 void AtEndOfEventLoop();
159
160 public:
161
162
163 /// \brief Print list of parameter files
164 void PrintParamFileList() const;
165
166 /// \brief Get list of parameter files
167 TList* GetParamFileNameList(TString name) const;
168
169 public:
170
171 /// \name Object construction and maintenance
172 // @{
173 /// Construct the objects for this subsystem
175 ConstructObjects((TDirectory*) NULL);
176 };
177 /// Construct the objects for this subsystem in a folder
178 void ConstructObjects(TDirectory *folder) {
179 TString prefix = "";
180 ConstructObjects(folder, prefix);
181 };
182 /// \brief Construct the objects for this subsystem in a folder with a prefix
183 void ConstructObjects(TDirectory *folder, TString &prefix);
184 // @}
185
186
187 /// \name Histogram construction and maintenance
188 // @{
189 /// Construct the histograms for this subsystem
191 ConstructHistograms((TDirectory*) NULL);
192 };
193 /// Construct the histograms for this subsystem in a folder
194 void ConstructHistograms(TDirectory *folder) {
195 TString prefix = "";
196 ConstructHistograms(folder, prefix);
197 };
198 /// \brief Construct the histograms for this subsystem in a folder with a prefix
199 void ConstructHistograms(TDirectory *folder, TString &prefix);
200 /// \brief Fill the histograms for this subsystem
201 void FillHistograms();
202 /// \brief Share the histograms with another subsystem
203 void ShareHistograms(const QwSubsystemArray& source);
204 // @}
205
206
207 /// \name Tree and vector construction and maintenance
208 // @{
209 /// Construct the tree and vector for this subsystem
211 TString tmpstr("");
212 ConstructBranchAndVector(tree,tmpstr,values);
213 };
214 /// \brief Construct a branch and vector for this subsystem with a prefix
215 void ConstructBranchAndVector(TTree *tree, TString& prefix, QwRootTreeBranchVector &values);
216 /// \brief Construct a branch for this subsystem with a prefix
217 void ConstructBranch(TTree *tree, TString& prefix);
218 /// \brief Construct a branch for this subsystem with a prefix after tree leave trimming
219 void ConstructBranch(TTree *tree, TString& prefix, QwParameterFile& trim_file);
220 /// \brief Fill the vector for this subsystem
221 void FillTreeVector(QwRootTreeBranchVector &values) const;
222
223#ifdef HAS_RNTUPLE_SUPPORT
224 /// \brief Construct RNTuple fields and vector for this subsystem
225 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) {
226 TString tmpstr("");
227 ConstructNTupleAndVector(model, tmpstr, values, fieldPtrs);
228 };
229 /// \brief Construct RNTuple fields and vector for this subsystem with a prefix
230 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs);
231 /// \brief Fill the RNTuple vector for this subsystem
232 void FillNTupleVector(std::vector<Double_t>& values) const;
233#endif // HAS_RNTUPLE_SUPPORT
234 // @}
235
236
237 /// \name Tree construction and maintenance
238 /// These functions are not purely virtual, since not every subsystem is
239 /// expected to implement them. They are intended for expert output to
240 /// trees.
241 // @{
242 /// Construct the tree for this subsystem
244 ConstructTree((TDirectory*) NULL);
245 };
246 /// Construct the tree for this subsystem in a folder
247 void ConstructTree(TDirectory *folder) {
248 TString prefix = "";
249 ConstructTree(folder, prefix);
250 };
251 /// \brief Construct the tree for this subsystem in a folder with a prefix
252 void ConstructTree(TDirectory *folder, TString &prefix);
253
254 /// \brief Fill the tree for this subsystem
255 void FillTree();
256 /// \brief Delete the tree for this subsystem
257 void DeleteTree();
258 // @}
259
260
261 /// \brief Print some information about the subsystem
262 void PrintInfo() const;
263
264 void push_back(std::shared_ptr<VQwSubsystem> subsys);
265
266 protected:
268
269 public:
270 void GetMarkerWordList(const ROCID_t roc_id, const BankID_t bank_id, std::vector<UInt_t>& marker) const;
271
272 protected:
273 size_t fTreeArrayIndex; //! Index of this data element in root tree
274
275 protected:
276 UInt_t fCodaRunNumber; ///< CODA run number as provided by QwEventBuffer
277 UInt_t fCodaSegmentNumber; ///< CODA segment number as provided by QwEventBuffer
278 UInt_t fCodaEventNumber; ///< CODA event number as provided by QwEventBuffer
279 UInt_t fCodaEventType; ///< CODA event type as provided by QwEventBuffer
280
281 Double_t fCleanParameter[3];
282 UInt_t fEventTypeMask; ///< Mask of event types
283 Bool_t fHasDataLoaded; ///< Has this array gotten data to be processed?
284
285 protected:
286 /// Function to determine which subsystems we can accept
288
289 /// Test whether this subsystem array can contain a particular subsystem
290 static Bool_t CanContain(VQwSubsystem* subsys) {
291 if (subsys == 0) {
292 QwError << "Zero pointer passed!" << QwLog::endl;
293 }
294 // should never occur
295 return kFALSE;
296 };
297
298 std::vector< std::pair<UInt_t,UInt_t> > fBadEventRange;
299
300 private:
301 /// Filename of the global detector map
303 std::vector<std::string> fSubsystemsDisabledByName; ///< List of disabled types
304 std::vector<std::string> fSubsystemsDisabledByType; ///< List of disabled names
305
306public:
307 // Mock Data Variables
308 /// \brief Randomize the data in this event
309 void RandomizeEventData(int helicity = 0, double time = 0.0);
310
311 /// \brief Encode the data in this event
312 void EncodeEventData(std::vector<UInt_t> &buffer);
313
315
316protected:
318
319
320}; // class QwSubsystemArray
Definition of the pure virtual base class of all subsystems.
An options class which parses command line, config file and environment.
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
ULong64_t BankID_t
Definition QwTypes.h:21
UInt_t ROCID_t
Definition QwTypes.h:20
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Command-line and configuration file options processor.
Definition QwOptions.h:141
Configuration file parser with flexible tokenization and search capabilities.
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:53
Container for managing multiple subsystems with common operations.
void SetCodaRunNumber(UInt_t runnum)
Set the internal record of the CODA run number.
void ConstructObjects(TDirectory *folder)
Construct the objects for this subsystem in a folder.
void SetDataLoaded(const Bool_t flag)
Set data loaded flag.
QwSubsystemArray & operator=(const QwSubsystemArray &value)
Assignment operator.
void SetCleanParameters(Double_t cleanparameter[3])
Set the internal record of the CODA event number.
virtual std::vector< VQwSubsystem * > GetSubsystemByType(const std::string &type)
Get the list of subsystems of the specified type.
void ConstructHistograms()
Construct the histograms for this subsystem.
UInt_t GetEventTypeMask() const
Get event type mask.
void GetMarkerWordList(const ROCID_t roc_id, const BankID_t bank_id, std::vector< UInt_t > &marker) const
void ConstructHistograms(TDirectory *folder)
Construct the histograms for this subsystem in a folder.
void push_back(VQwSubsystem *subsys)
Add the subsystem to this array.
void EncodeEventData(std::vector< UInt_t > &buffer)
Encode the data in this event.
~QwSubsystemArray() override
Virtual destructor.
UInt_t UpdateEventTypeMask()
Update the event type mask from the subsystems.
UInt_t fCodaEventType
CODA event type as provided by QwEventBuffer.
void ConstructObjects()
Construct the objects for this subsystem.
void ProcessEvent()
Process the decoded data in this event.
UInt_t GetCodaEventNumber() const
Get the internal record of the CODA event number.
std::vector< std::string > fSubsystemsDisabledByName
List of disabled types.
void SetCodaSegmentNumber(UInt_t segnum)
Set the internal record of the CODA segment number.
virtual VQwSubsystem * GetSubsystemByName(const TString &name)
Get the subsystem with the specified name.
QwSubsystemArray()
Private default constructor.
UInt_t GetCodaSegmentNumber() const
Get the internal record of the CODA segment number.
void LoadAllEventRanges(QwOptions &options)
void PrintParamFileList() const
Print list of parameter files.
void ConstructBranchAndVector(TTree *tree, QwRootTreeBranchVector &values)
Construct the tree and vector for this subsystem.
TList * GetParamFileNameList(TString name) const
Get list of parameter files.
CanContainFn fnCanContain
Function to determine which subsystems we can accept.
std::vector< std::shared_ptr< VQwSubsystem > > SubsysPtrs
UInt_t GetCodaRunNumber() const
Get the internal record of the CODA run number.
Double_t fCleanParameter[3]
void PrintInfo() const
Print some information about the subsystem.
Bool_t(* CanContainFn)(VQwSubsystem *)
UInt_t GetCodaEventType() const
Get the internal record of the CODA event type.
void SetEventTypeMask(const UInt_t mask)
Set event type mask.
static void DefineOptions(QwOptions &options)
Define configuration options for global array.
void ConstructTree()
Construct the tree for this subsystem.
static Bool_t CanContain(VQwSubsystem *subsys)
Test whether this subsystem array can contain a particular subsystem.
UInt_t fCodaRunNumber
Index of this data element in root tree.
Int_t ProcessEvBuffer(const UInt_t event_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for events.
void ShareHistograms(const QwSubsystemArray &source)
Share the histograms with another subsystem.
void ConstructTree(TDirectory *folder)
Construct the tree for this subsystem in a folder.
void ProcessOptions(QwOptions &options)
Process configuration options (default behavior)
std::string fSubsystemsMapFile
Filename of the global detector map.
void SetCodaEventNumber(UInt_t evtnum)
Set the internal record of the CODA event number.
void FillTree()
Fill the tree for this subsystem.
void RandomizeEventData(int helicity=0, double time=0.0)
Randomize the data in this event.
UInt_t fCodaSegmentNumber
CODA segment number as provided by QwEventBuffer.
std::vector< std::string > fSubsystemsDisabledByType
List of disabled names.
void ConstructBranch(TTree *tree, TString &prefix)
Construct a branch for this subsystem with a prefix.
std::vector< std::pair< UInt_t, UInt_t > > fBadEventRange
void ProcessOptionsToplevel(QwOptions &options)
Process configuration options for the subsystem array itself.
UInt_t fEventTypeMask
Mask of event types.
Bool_t fHasDataLoaded
Has this array gotten data to be processed?
void LoadSubsystemsFromParameterFile(QwParameterFile &detectors)
void SetCodaEventType(UInt_t evttype)
Set the internal record of the CODA event type.
void AtEndOfEventLoop()
Perform actions at the end of the event loop.
void ProcessOptionsSubsystems(QwOptions &options)
Process configuration options for all subsystems in the array.
void FillTreeVector(QwRootTreeBranchVector &values) const
Fill the vector for this subsystem.
Bool_t HasDataLoaded() const
Get data loaded flag.
UInt_t fCodaEventNumber
CODA event number as provided by QwEventBuffer.
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for configuration events.
void GetROCIDList(std::vector< ROCID_t > &list)
Get the ROCID list.
void FillHistograms()
Fill the histograms for this subsystem.
void DeleteTree()
Delete the tree for this subsystem.
Abstract base for concrete hardware channels implementing dual-operator pattern.
Base class for subsystems implementing container-delegation pattern.
UInt_t GetEventTypeMask() const
Get event type mask.