JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwDataHandlerArray.h
Go to the documentation of this file.
1/*!
2 * \file QwDataHandlerArray.h
3 * \brief Array container for managing multiple data handlers
4 * \author P. M. King
5 * \date 2009-02-04
6 */
7
8#pragma once
9
10#include <vector>
11#include <map>
12#include "Rtypes.h"
13#include "TString.h"
14#include "TDirectory.h"
15#include <TTree.h>
16
17// ROOT headers
18#ifdef HAS_RNTUPLE_SUPPORT
19#include "ROOT/RNTupleModel.hxx"
20#endif // HAS_RNTUPLE_SUPPORT
21
22// Qweak headers
23#include "QwDataHandlerArray.h"
24#include "VQwDataHandler.h"
25#include "QwOptions.h"
26#include "QwHelicityPattern.h"
27#include "MQwPublishable.h"
28
29// Forward declarations
30class QwParityDB;
31class QwPromptSummary;
32
33/**
34 * \class QwDataHandlerArray
35 * \ingroup QwAnalysis
36 *
37 * \brief Virtual base class for the parity handlers
38 *
39 * Virtual base class for the classes containing the
40 * event-based information from each parity handler.
41 * This will define the interfaces used in communicating
42 * with the CODA routines.
43 *
44 */
46 public std::vector<std::shared_ptr<VQwDataHandler> >,
47 public MQwPublishable<QwDataHandlerArray,VQwDataHandler>
48{
49 private:
50 typedef std::vector<std::shared_ptr<VQwDataHandler> > HandlerPtrs;
51 public:
52 using HandlerPtrs::const_iterator;
53 using HandlerPtrs::iterator;
54 using HandlerPtrs::begin;
55 using HandlerPtrs::end;
56 using HandlerPtrs::size;
57 using HandlerPtrs::empty;
58
59 private:
60 /// Private default constructor
61 QwDataHandlerArray(); // not implement, will thrown linker error on use
62
63 public:
64 /// Constructor from helicity pattern with options
65 QwDataHandlerArray(QwOptions& options, QwHelicityPattern& helicitypattern, const TString &run);
66 /// Constructor from subsystem array with options
67 QwDataHandlerArray(QwOptions& options, QwSubsystemArrayParity& detectors, const TString &run);
68 /// Copy constructor by reference
70 /// Default destructor
71 ~QwDataHandlerArray() override;
72
73 /// \brief Define configuration options for global array
74 static void DefineOptions(QwOptions &options);
75 /// \brief Process configuration options for the datahandler array itself
76 void ProcessOptions(QwOptions &options);
77
78 /**
79 * \brief Load data handlers from a parameter file.
80 *
81 * Parses the map file and constructs/initializes handlers, connecting
82 * them to the provided source container.
83 *
84 * @tparam T Source type (QwHelicityPattern or QwSubsystemArrayParity).
85 * @param mapfile Parameter file describing handlers and settings.
86 * @param detectors Source object to connect handlers to.
87 * @param run Run label used for per-run configuration.
88 */
89 template<class T>
90 void LoadDataHandlersFromParameterFile(QwParameterFile& mapfile, T& detectors, const TString &run);
91
92 /// \brief Add the datahandler to this array
93 void push_back(VQwDataHandler* handler);
94 void push_back(std::shared_ptr<VQwDataHandler> handler);
95
96 /// \brief Get the handler with the specified name
97 VQwDataHandler* GetDataHandlerByName(const TString& name);
98
99 std::vector<VQwDataHandler*> GetDataHandlerByType(const std::string& type);
100
102 QwRootFile *treerootfile,
103 const std::string& treeprefix = "",
104 const std::string& branchprefix = "");
105
106 /// \brief Construct a branch and vector for this handler with a prefix
107 void ConstructBranchAndVector(TTree *tree, TString& prefix, QwRootTreeBranchVector &values);
108
109 void FillTreeBranches(QwRootFile *treerootfile);
110 /// \brief Fill the vector for this handler
111 void FillTreeVector(QwRootTreeBranchVector &values) const;
112
113 /// RNTuple methods
115 QwRootFile *treerootfile,
116 const std::string& treeprefix = "",
117 const std::string& branchprefix = "");
118
119 void FillNTupleFields(QwRootFile *treerootfile);
120
121 /// Construct the histograms for this subsystem
123 ConstructHistograms((TDirectory*) NULL);
124 };
125 /// Construct the histograms for this subsystem in a folder
126 void ConstructHistograms(TDirectory *folder) {
127 TString prefix = "";
128 ConstructHistograms(folder, prefix);
129 };
130 /// \brief Construct the histograms in a folder with a prefix
131 void ConstructHistograms(TDirectory *folder, TString &prefix);
132 /// \brief Fill the histograms
133 void FillHistograms();
134
135 /// \brief Fill the database
136 void FillDB(QwParityDB *db, TString type);
137 // void FillErrDB(QwParityDB *db, TString type);
138
139 void ClearEventData();
140 void ProcessEvent();
141
142 void UpdateBurstCounter(Short_t burstcounter)
143 {
144 if (!empty()) {
145 for(iterator handler = begin(); handler != end(); ++handler){
146 (*handler)->UpdateBurstCounter(burstcounter);
147 }
148 }
149 }
150
151 /// \brief Assignment operator
153 /*
154 /// \brief Addition-assignment operator
155 QwDataHandlerArray& operator+= (const QwDataHandlerArray &value);
156 /// \brief Subtraction-assignment operator
157 QwDataHandlerArray& operator-= (const QwDataHandlerArray &value);
158 /// \brief Sum of two handler arrays
159 void Sum(const QwDataHandlerArray &value1, const QwDataHandlerArray &value2);
160 /// \brief Difference of two handler arrays
161 void Difference(const QwDataHandlerArray &value1, const QwDataHandlerArray &value2);
162 /// \brief Scale this handler array
163 void Scale(Double_t factor);
164 */
165
166 /// \brief Update the running sums for devices accumulated for the global error non-zero events/patterns
168
169 /// \brief Update the running sums for devices accumulated for the global error non-zero events/patterns
170 void AccumulateRunningSum(const QwDataHandlerArray& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
171 /// \brief Update the running sums for devices check only the error flags at the channel level. Only used for stability checks
172 void AccumulateAllRunningSum(const QwDataHandlerArray& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF);
173
174 /// \brief Calculate the average for all good events
176
177 /// \brief Report the number of events failed due to HW and event cut failures
178 void PrintErrorCounters() const;
179
180 /// \brief Print value of all channels
181 void PrintValue() const;
182
183
184 void WritePromptSummary(QwPromptSummary *ps, TString type);
185
186
188
189 void FinishDataHandler();
190
191 protected:
192
193 void SetPointer(QwHelicityPattern& helicitypattern) {
194 fHelicityPattern = &helicitypattern;
195 }
197 fSubsystemArray = &detectors;
198 }
199
200 /// Pointer for the original data source
203
204 /// Filename of the global detector map
206
207 Bool_t ScopeMismatch(TString name){
208 name.ToLower();
210 if (name=="event") tmpscope = kEventScope;
211 if (name=="pattern") tmpscope = kPatternScope;
212 return (fArrayScope != tmpscope);
213 }
216
217 std::vector<std::string> fDataHandlersDisabledByName; ///< List of disabled types
218 std::vector<std::string> fDataHandlersDisabledByType; ///< List of disabled names
219
221
222 /// Test whether this handler array can contain a particular handler
223 static Bool_t CanContain(VQwDataHandler* handler) {
224 return (dynamic_cast<VQwDataHandler*>(handler) != 0);
225 };
226
227}; // class QwDataHandlerArray
An options class which parses command line, config file and environment.
Virtual base class for data handlers accessing multiple subsystems.
Array container for managing multiple data handlers.
Helicity pattern analysis and management.
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
A wrapper class for a ROOT file or memory mapped file.
Definition QwRootFile.h:827
Virtual base class for the parity handlers.
void push_back(VQwDataHandler *handler)
Add the datahandler to this array.
void PrintErrorCounters() const
Report the number of events failed due to HW and event cut failures.
std::vector< std::shared_ptr< VQwDataHandler > > HandlerPtrs
void UpdateBurstCounter(Short_t burstcounter)
static void DefineOptions(QwOptions &options)
Define configuration options for global array.
void FillNTupleFields(QwRootFile *treerootfile)
void CalculateRunningAverage()
Calculate the average for all good events.
void ConstructHistograms()
Construct the histograms for this subsystem.
void SetPointer(QwSubsystemArrayParity &detectors)
void FillTreeBranches(QwRootFile *treerootfile)
VQwDataHandler * GetDataHandlerByName(const TString &name)
Get the handler with the specified name.
void FillDB(QwParityDB *db, TString type)
Fill the database.
void SetPointer(QwHelicityPattern &helicitypattern)
Bool_t ScopeMismatch(TString name)
std::vector< std::string > fDataHandlersDisabledByType
List of disabled names.
void ConstructTreeBranches(QwRootFile *treerootfile, const std::string &treeprefix="", const std::string &branchprefix="")
void PrintValue() const
Print value of all channels.
QwSubsystemArrayParity * fSubsystemArray
void AccumulateAllRunningSum(const QwDataHandlerArray &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
Update the running sums for devices check only the error flags at the channel level....
QwHelicityPattern * fHelicityPattern
Pointer for the original data source.
void ConstructHistograms(TDirectory *folder)
Construct the histograms for this subsystem in a folder.
~QwDataHandlerArray() override
Default destructor.
QwDataHandlerArray()
Private default constructor.
void FillTreeVector(QwRootTreeBranchVector &values) const
Fill the vector for this handler.
void WritePromptSummary(QwPromptSummary *ps, TString type)
void ConstructNTupleFields(QwRootFile *treerootfile, const std::string &treeprefix="", const std::string &branchprefix="")
RNTuple methods.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
Construct a branch and vector for this handler with a prefix.
static Bool_t CanContain(VQwDataHandler *handler)
Test whether this handler array can contain a particular handler.
std::string fDataHandlersMapFile
Filename of the global detector map.
std::vector< VQwDataHandler * > GetDataHandlerByType(const std::string &type)
void ProcessOptions(QwOptions &options)
Process configuration options for the datahandler array itself.
QwDataHandlerArray & operator=(const QwDataHandlerArray &value)
Assignment operator.
void AccumulateRunningSum()
Update the running sums for devices accumulated for the global error non-zero events/patterns.
void FillHistograms()
Fill the histograms.
EDataHandlerArrayScope fArrayScope
std::vector< std::string > fDataHandlersDisabledByName
List of disabled types.
void LoadDataHandlersFromParameterFile(QwParameterFile &mapfile, T &detectors, const TString &run)
Load data handlers from a parameter file.
Manages yields/differences/asymmetries for helicity patterns.
Subsystem array container specialized for parity analysis with asymmetry calculations.
Abstract base for handlers that consume multiple subsystems and produce derived outputs.