JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwClock.h
Go to the documentation of this file.
1/*!
2 * \file QwClock.h
3 * \brief Clock channel implementation for normalization and timing
4 *
5 * \author Juan Carlos Cornejo <cornejo@jlab.org>
6 * \date 2011-06-16
7 */
8
9#pragma once
10
11// System headers
12#include <vector>
13
14// ROOT headers
15#include <TTree.h>
16#ifdef HAS_RNTUPLE_SUPPORT
17#include "ROOT/RNTupleModel.hxx"
18#endif // HAS_RNTUPLE_SUPPORT
19
20#include "QwParameterFile.h"
21#include <stdexcept>
22#include "VQwDataElement.h"
23#include "VQwHardwareChannel.h"
24#include "VQwClock.h"
25
26// Forward declarations
27#ifdef __USE_DATABASE__
28class QwDBInterface;
29#endif // __USE_DATABASE__
30
31/**
32 * \class QwClock
33 * \ingroup QwAnalysis_BL
34 * \brief Standard clock channel with calibration representing frequency
35 *
36 * Provides timing and normalization support for subsystems that need an
37 * external clock. The calibration factor encodes the clock frequency.
38 * Implements specialized polymorphic dispatch for burp-failure checks
39 * via the VQwClock base as per the dual-operator pattern.
40 */
41template<typename T>
42class QwClock : public VQwClock {
43/////
44 public:
45 QwClock() { };
46 QwClock(TString subsystemname, TString name, TString type = ""){
47 SetSubsystemName(subsystemname);
48 InitializeChannel(subsystemname, name, "raw", type);
49 };
50 QwClock(const QwClock& source)
51 : VQwClock(source),
53 fULimit(source.fULimit),fLLimit(source.fLLimit),
54 fClock(source.fClock),
56 { }
57 ~QwClock() override { };
58
59 void LoadChannelParameters(QwParameterFile &paramfile) override{
60 fClock.LoadChannelParameters(paramfile);
61 };
62
63 Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override;
64
65 void InitializeChannel(TString subsystem, TString name, TString datatosave, TString type = "") override;
66 void ClearEventData() override;
67
68
69 void EncodeEventData(std::vector<UInt_t> &buffer);
70
71 void ProcessEvent() override;
72 Bool_t ApplyHWChecks();//Check for hardware errors in the devices
73 Bool_t ApplySingleEventCuts() override;//Check for good events by setting limits on the devices readings
74 void IncrementErrorCounters() override{fClock.IncrementErrorCounters();}
75
76 Bool_t CheckForBurpFail(const QwClock *ev_error){
77 return fClock.CheckForBurpFail(&(ev_error->fClock));
78 }
79
80 // Override the pure virtual from VQwClock to enable polymorphic dispatch via VQwClock*
81 Bool_t CheckForBurpFail(const VQwClock* ev_error) override {
82 auto rhs = dynamic_cast<const QwClock*>(ev_error);
83 if (!rhs) {
84 throw std::invalid_argument("Type mismatch in QwClock::CheckForBurpFail(VQwClock*)");
85 }
86 return CheckForBurpFail(rhs);
87 }
88
89 // Polymorphic delegator: match VQwDataElement signature so calls via VQwClock* hit this path
90 Bool_t CheckForBurpFail(const VQwDataElement* ev_error){
91 auto rhs = dynamic_cast<const QwClock*>(ev_error);
92 if (!rhs) {
93 throw std::invalid_argument("Type mismatch in QwClock::CheckForBurpFail");
94 }
95 return CheckForBurpFail(rhs);
96 }
97
98
99 void PrintErrorCounters() const override;// report number of events failed due to HW and event cut failure
100 UInt_t GetEventcutErrorFlag() override{//return the error flag
101 return fClock.GetEventcutErrorFlag();
102 }
103 UInt_t UpdateErrorFlag() override {return GetEventcutErrorFlag();};
104 void UpdateErrorFlag(const QwClock *ev_error){
105 fClock.UpdateErrorFlag(ev_error->fClock);
106 }
107
108 /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
109 void SetSingleEventCuts(UInt_t errorflag, Double_t min = 0, Double_t max = 0, Double_t stability = 0, Double_t burplevel = 0) override;
110
111 void SetDefaultSampleSize(Int_t sample_size);
112 void SetEventCutMode(Int_t bcuts) override{
113 bEVENTCUTMODE=bcuts;
114 fClock.SetEventCutMode(bcuts);
115 }
116
117 void PrintValue() const override;
118 void PrintInfo() const override;
119
120 // Implementation of Parent class's virtual operators
121 VQwClock& operator= (const VQwClock &value) override;
122 VQwClock& operator+= (const VQwClock &value) override;
123 VQwClock& operator-= (const VQwClock &value) override;
124
125 // This class specific operators
126 QwClock& operator= (const QwClock &value);
127 QwClock& operator+= (const QwClock &value);
128 QwClock& operator-= (const QwClock &value);
129 void Ratio(const VQwClock &numer, const VQwClock &denom) override;
130 void Ratio(const QwClock &numer, const QwClock &denom);
131 void Scale(Double_t factor) override;
132
133 void AccumulateRunningSum(const VQwClock& value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override;
134 void DeaccumulateRunningSum(VQwClock& value, Int_t ErrorMask=0xFFFFFFF) override;
135 void CalculateRunningAverage() override;
136
137 void SetPedestal(Double_t ped) override;
138 void SetCalibrationFactor(Double_t calib) override;
139
140 void ConstructHistograms(TDirectory *folder, TString &prefix) override;
141 void FillHistograms() override;
142
143 void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override;
144 void ConstructBranch(TTree *tree, TString &prefix) override;
145 void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist) override;
146 void FillTreeVector(QwRootTreeBranchVector &values) const override;
147#ifdef HAS_RNTUPLE_SUPPORT
148 void ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs) override;
149 void FillNTupleVector(std::vector<Double_t>& values) const override;
150#endif // HAS_RNTUPLE_SUPPORT
151
152#ifdef __USE_DATABASE__
153 std::vector<QwDBInterface> GetDBEntry();
154#endif // __USE_DATABASE__
155
156 // These are related to those hardware channels that need to normalize
157 // to an external clock
158 Double_t GetNormClockValue() override { return fNormalizationValue;};
159 Double_t GetStandardClockValue() override { return fCalibration; };
160
161 const VQwHardwareChannel* GetTime() const override {
162 return &fClock;
163 };
164
165
166/////
167 protected:
168
169/////
170 private:
171 Double_t fPedestal;
172 Double_t fCalibration;
173 Double_t fULimit, fLLimit;
174
176
177 Int_t fDeviceErrorCode;//keep the device HW status using a unique code from the QwVQWK_Channel::fDeviceErrorCode
178
179 const static Bool_t bDEBUG=kFALSE;//debugging display purposes
180 Bool_t bEVENTCUTMODE;//If this set to kFALSE then Event cuts do not depend on HW checks. This is set externally through the qweak_beamline_eventcuts.map
181
183
184};
Parameter file parsing and management.
Definition of the pure virtual base class of all data elements.
const TString QwBPMStripline< T >::subelement[4]
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
VQwDataElement()
Default constructor.
void SetSubsystemName(TString sysname)
Set the name of the inheriting subsystem name.
Abstract base for concrete hardware channels implementing dual-operator pattern.
Standard clock channel with calibration representing frequency.
Definition QwClock.h:42
Double_t fCalibration
Definition QwClock.h:172
void SetEventCutMode(Int_t bcuts) override
Definition QwClock.h:112
VQwClock & operator+=(const VQwClock &value) override
Definition QwClock.cc:211
void SetSingleEventCuts(UInt_t errorflag, Double_t min=0, Double_t max=0, Double_t stability=0, Double_t burplevel=0) override
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit),...
Definition QwClock.cc:101
T fClock
Definition QwClock.h:175
void AccumulateRunningSum(const VQwClock &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Definition QwClock.cc:309
VQwClock & operator=(const VQwClock &value) override
Definition QwClock.cc:168
void ConstructBranch(TTree *tree, TString &prefix) override
Definition QwClock.cc:377
void InitializeChannel(TString subsystem, TString name, TString datatosave, TString type="") override
Definition QwClock.cc:42
Bool_t CheckForBurpFail(const VQwClock *ev_error) override
Definition QwClock.h:81
UInt_t UpdateErrorFlag() override
Update the error flag based on the error flags of internally contained objects Return parameter is th...
Definition QwClock.h:103
QwClock(TString subsystemname, TString name, TString type="")
Definition QwClock.h:46
void ClearEventData() override
Clear the event data in this element.
Definition QwClock.cc:56
Int_t fDeviceErrorCode
Definition QwClock.h:177
void PrintErrorCounters() const override
report number of events failed due to HW and event cut failure
Definition QwClock.cc:135
Bool_t ApplySingleEventCuts() override
Definition QwClock.cc:117
~QwClock() override
Definition QwClock.h:57
Bool_t bEVENTCUTMODE
Definition QwClock.h:180
Double_t fULimit
Definition QwClock.h:173
void CalculateRunningAverage() override
Definition QwClock.cc:304
void DeaccumulateRunningSum(VQwClock &value, Int_t ErrorMask=0xFFFFFFF) override
Definition QwClock.cc:315
Double_t fNormalizationValue
Definition QwClock.h:182
Double_t fPedestal
Definition QwClock.h:171
void IncrementErrorCounters() override
Definition QwClock.h:74
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Definition QwClock.cc:365
UInt_t GetEventcutErrorFlag() override
return the error flag on this channel/device
Definition QwClock.h:100
Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Definition QwClock.h:90
QwClock(const QwClock &source)
Definition QwClock.h:50
void SetDefaultSampleSize(Int_t sample_size)
Definition QwClock.cc:110
void Ratio(const VQwClock &numer, const VQwClock &denom) override
Definition QwClock.cc:276
const VQwHardwareChannel * GetTime() const override
Definition QwClock.h:161
void EncodeEventData(std::vector< UInt_t > &buffer)
Definition QwClock.cc:77
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0) override
Process the CODA event buffer for this element.
Definition QwClock.cc:142
void FillTreeVector(QwRootTreeBranchVector &values) const override
Definition QwClock.cc:412
Double_t fLLimit
Definition QwClock.h:173
void PrintValue() const override
Print single line of value and error of this data element.
Definition QwClock.cc:321
void ProcessEvent() override
Definition QwClock.cc:83
void UpdateErrorFlag(const QwClock *ev_error)
Definition QwClock.h:104
Double_t GetStandardClockValue() override
Definition QwClock.h:159
Bool_t CheckForBurpFail(const QwClock *ev_error)
Definition QwClock.h:76
void LoadChannelParameters(QwParameterFile &paramfile) override
Definition QwClock.h:59
VQwClock & operator-=(const VQwClock &value) override
Definition QwClock.cc:237
QwClock()
Definition QwClock.h:45
Double_t GetNormClockValue() override
Definition QwClock.h:158
void PrintInfo() const override
Print multiple lines of information about this data element.
Definition QwClock.cc:327
static const Bool_t bDEBUG
Definition QwClock.h:179
Bool_t ApplyHWChecks()
Definition QwClock.cc:89
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Construct the histograms for this data element.
Definition QwClock.cc:335
void SetPedestal(Double_t ped) override
Definition QwClock.cc:28
void SetCalibrationFactor(Double_t calib) override
Definition QwClock.cc:35
void FillHistograms() override
Fill the histograms for this data element.
Definition QwClock.cc:349
void Scale(Double_t factor) override
Definition QwClock.cc:297
Abstract base for beam clocks used to normalize rates and yields.
Definition VQwClock.h:47
VQwClock()
Definition VQwClock.h:56