JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
VQwDataHandler.h
Go to the documentation of this file.
1/*!
2 * \file VQwDataHandler.h
3 * \brief Virtual base class for data handlers accessing multiple subsystems
4 * \author Michael Vallee
5 * \date 2018-08-01
6 */
7
8#pragma once
9
10// Qweak headers
11#include "QwHelicityPattern.h"
13#include "VQwHardwareChannel.h"
14#include "QwFactory.h"
15#include "MQwPublishable.h"
16
17class QwParameterFile;
18class QwRootFile;
19class QwPromptSummary;
21
22/**
23 * \class VQwDataHandler
24 * \ingroup QwAnalysis
25 * \brief Abstract base for handlers that consume multiple subsystems and produce derived outputs
26 *
27 * A data handler observes one or more subsystem arrays (yields, asymmetries,
28 * differences) and computes derived channels or diagnostics. Typical examples
29 * include linear regression, correlation studies, and alarm/quality handlers.
30 *
31 * Key responsibilities:
32 * - Establish connections to required input channels via ConnectChannels.
33 * - ProcessData once per event to update derived quantities.
34 * - Maintain running sums/averages and optionally publish variables to trees,
35 * histograms, or RNTuples.
36 *
37 * Design notes:
38 * - Uses container-delegation at the system level; underlying arithmetic is
39 * performed by the concrete channel classes.
40 * - Handlers participate in the MQwPublishable pattern for on-demand output
41 * publication, and in cloneable factories for configuration-driven creation.
42 */
43class VQwDataHandler: virtual public VQwDataHandlerCloneable, public MQwPublishable_child<QwDataHandlerArray,VQwDataHandler> {
44
45 public:
46
50
51 typedef std::vector< VQwHardwareChannel* >::iterator Iterator_HdwChan;
52 typedef std::vector< VQwHardwareChannel* >::const_iterator ConstIterator_HdwChan;
53
54 VQwDataHandler(const TString& name);
55 VQwDataHandler(const VQwDataHandler &source);
56
57 virtual void ParseConfigFile(QwParameterFile& file);
58
67
69 return this->ConnectChannels(asym, diff);
70 }
71
72 // Subsystems with support for subsystem arrays should override this
73 virtual Int_t ConnectChannels(QwSubsystemArrayParity& /*detectors*/) { return 0; }
74
75 Int_t ConnectChannels(QwHelicityPattern& helicitypattern) {
76 return this->ConnectChannels(
77 helicitypattern.GetYield(),
78 helicitypattern.GetAsymmetry(),
79 helicitypattern.GetDifference());
80 }
81
82 virtual void ProcessData();
83
84 virtual void UpdateBurstCounter(Short_t burstcounter){fBurstCounter=burstcounter;};
85
86 virtual void FinishDataHandler(){
88 };
89
90 ~VQwDataHandler() override;
91
92 TString GetName(){return fName;}
93
94 virtual void ClearEventData();
95
96 void InitRunningSum();
98 virtual void AccumulateRunningSum(VQwDataHandler &value, Int_t count = 0, Int_t ErrorMask = 0xFFFFFFF);
100 void PrintValue() const;
101
102#ifdef __USE_DATABASE__
103 void FillDB(QwParityDB *db, TString datatype);
104#endif // __USE_DATABASE__
105
106 void WritePromptSummary(QwPromptSummary *ps, TString type);
107
108 virtual void ConstructTreeBranches(
109 QwRootFile *treerootfile,
110 const std::string& treeprefix = "",
111 const std::string& branchprefix = "");
112 virtual void FillTreeBranches(QwRootFile *treerootfile);
113
114 /// \brief RNTuple methods
115 virtual void ConstructNTupleFields(
116 QwRootFile *treerootfile,
117 const std::string& treeprefix = "",
118 const std::string& branchprefix = "");
119 virtual void FillNTupleFields(QwRootFile *treerootfile);
120
121 /// \brief Construct the histograms in a folder with a prefix
122 virtual void ConstructHistograms(TDirectory * /*folder*/, TString & /*prefix*/) { };
123 /// \brief Fill the histograms
124 virtual void FillHistograms() { };
125
126 // Fill the vector for this subsystem
127 void FillTreeVector(QwRootTreeBranchVector &values) const;
128
129 void ConstructBranchAndVector(TTree *tree, TString& prefix, QwRootTreeBranchVector &values);
130#ifdef HAS_RNTUPLE_SUPPORT
131 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs);
132 void FillNTupleVector(std::vector<Double_t>& values) const;
133#endif // HAS_RNTUPLE_SUPPORT
134
135 void SetRunLabel(TString x) {
136 run_label = x;
137 }
138
139 Int_t LoadChannelMap(){return this->LoadChannelMap(fMapFile);}
140 virtual Int_t LoadChannelMap(const std::string& /*mapfile*/){return 0;};
141
142 /// \brief Publish all variables of the subsystem
143 Bool_t PublishInternalValues() const override;
144 /// \brief Try to publish an internal variable matching the submitted name
145 Bool_t PublishByRequest(TString device_name) override;
146
147 protected:
148
150
152
153 void SetEventcutErrorFlagPointer(const UInt_t* errorflagptr) {
154 fErrorFlagPtr = errorflagptr;
155 }
156 UInt_t GetEventcutErrorFlag() const {
157 if (fErrorFlagPtr)
158 return *fErrorFlagPtr;
159 else
160 return -1;
161 };
162
163 std::pair<EQwHandleType,std::string> ParseHandledVariable(const std::string& variable);
164
166 std::vector< const VQwHardwareChannel* > &ivs,
167 std::vector< Double_t > &sens);
168
169 protected:
170 //
171 Int_t fPriority; /// When a datahandler array is processed, handlers with lower priority will be processed before handlers with higher priority
172
174
175 //***************[Variables]***************
176 TString fName;
177 std::string fMapFile;
178 std::string fTreeName;
179 std::string fTreeComment;
180
181 std::string fPrefix;
182
183 TString run_label;
184
185 /// Error flag pointer
186 const UInt_t* fErrorFlagPtr;
187
188 /// Single event pointer
190 /// Helicity pattern pointer
192
193 std::vector< std::string > fDependentFull;
194 std::vector< EQwHandleType > fDependentType;
195 std::vector< std::string > fDependentName;
196
197 std::vector< const VQwHardwareChannel* > fDependentVar;
198 std::vector< Double_t > fDependentValues;
199
200 std::vector< VQwHardwareChannel* > fOutputVar;
201 std::vector< Double_t > fOutputValues;
202
203 std::vector<std::vector<TString> > fPublishList;
204
205 std::string ParseSeparator; // Used as space between tokens in ParseHandledVariable
206
207 protected:
211};
Factory pattern implementation for creating analysis objects.
class VQwCloneable< VQwDataHandler > VQwDataHandlerCloneable
Mix-in factory functionality for datahandlers.
Definition QwFactory.h:247
Subsystem array container for parity analysis with asymmetry calculations.
Helicity pattern analysis and management.
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
Abstract base for concrete hardware channels implementing dual-operator pattern.
Virtual base class for the parity handlers.
Manages yields/differences/asymmetries for helicity patterns.
QwSubsystemArrayParity & GetDifference()
QwSubsystemArrayParity & GetYield()
QwSubsystemArrayParity & GetAsymmetry()
const UInt_t * GetEventcutErrorFlagPointer() const
Subsystem array container specialized for parity analysis with asymmetry calculations.
const UInt_t * GetEventcutErrorFlagPointer() const
Abstract base for handlers that consume multiple subsystems and produce derived outputs.
void CalcOneOutput(const VQwHardwareChannel *dv, VQwHardwareChannel *output, std::vector< const VQwHardwareChannel * > &ivs, std::vector< Double_t > &sens)
virtual void FillHistograms()
Fill the histograms.
virtual void ProcessData()
QwSubsystemArrayParity * fSubsystemArray
Single event pointer.
void FillTreeVector(QwRootTreeBranchVector &values) const
std::vector< std::string > fDependentFull
void AccumulateRunningSum()
virtual Int_t LoadChannelMap(const std::string &)
void SetEventcutErrorFlagPointer(const UInt_t *errorflagptr)
TString GetName()
void WritePromptSummary(QwPromptSummary *ps, TString type)
std::vector< std::vector< TString > > fPublishList
virtual void ConstructHistograms(TDirectory *, TString &)
Construct the histograms in a folder with a prefix.
void PrintValue() const
std::string fPrefix
virtual void UpdateBurstCounter(Short_t burstcounter)
Bool_t PublishInternalValues() const override
Publish all variables of the subsystem.
virtual void ConstructTreeBranches(QwRootFile *treerootfile, const std::string &treeprefix="", const std::string &branchprefix="")
std::vector< Double_t > fDependentValues
virtual void ParseConfigFile(QwParameterFile &file)
virtual void ClearEventData()
std::vector< const VQwHardwareChannel * > fDependentVar
~VQwDataHandler() override
UInt_t GetEventcutErrorFlag() const
void CalculateRunningAverage()
virtual void FillTreeBranches(QwRootFile *treerootfile)
VQwDataHandler(const TString &name)
VQwDataHandler * fRunningsum
const UInt_t * fErrorFlagPtr
Error flag pointer.
virtual void FillNTupleFields(QwRootFile *treerootfile)
std::vector< VQwHardwareChannel * >::const_iterator ConstIterator_HdwChan
std::vector< VQwHardwareChannel * >::iterator Iterator_HdwChan
void SetRunLabel(TString x)
std::string ParseSeparator
virtual void ConstructNTupleFields(QwRootFile *treerootfile, const std::string &treeprefix="", const std::string &branchprefix="")
RNTuple methods.
void SetPointer(QwHelicityPattern *ptr)
Short_t fBurstCounter
When a datahandler array is processed, handlers with lower priority will be processed before handlers...
std::string fTreeComment
std::vector< VQwHardwareChannel * > fOutputVar
std::string fTreeName
void SetPointer(QwSubsystemArrayParity *ptr)
Bool_t PublishByRequest(TString device_name) override
Try to publish an internal variable matching the submitted name.
Int_t ConnectChannels(QwHelicityPattern &helicitypattern)
virtual Int_t ConnectChannels(QwSubsystemArrayParity &)
Bool_t fRunningsumFillsTree
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
std::pair< EQwHandleType, std::string > ParseHandledVariable(const std::string &variable)
std::vector< EQwHandleType > fDependentType
QwHelicityPattern * fHelicityPattern
Helicity pattern pointer.
std::vector< Double_t > fOutputValues
std::vector< std::string > fDependentName
virtual Int_t ConnectChannels(QwSubsystemArrayParity &, QwSubsystemArrayParity &asym, QwSubsystemArrayParity &diff)
std::string fMapFile
virtual void FinishDataHandler()