JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwHaloMonitor.cc
Go to the documentation of this file.
1/**
2 * \file QwHaloMonitor.cc
3 * \brief Implementation of the halo monitor data element.
4 */
5/**********************************************************\
6* File: QwHaloMonitor.cc *
7* *
8* Author:B. Waidyawansa *
9* Time-stamp:24-june-2010 *
10\**********************************************************/
11
12#include "QwHaloMonitor.h"
13
14// System headers
15#include <stdexcept>
16
17// ROOT headers for RNTuple support
18#ifdef HAS_RNTUPLE_SUPPORT
19#include <ROOT/RNTupleModel.hxx>
20#include <ROOT/RNTupleWriter.hxx>
21#endif // HAS_RNTUPLE_SUPPORT
22
23// Qweak headers
24#ifdef __USE_DATABASE__
25#include "QwDBInterface.h"
26#endif // __USE_DATABASE__
27
28/**
29 * \brief Initialize the halo monitor with subsystem and name.
30 * \param subsystem Subsystem identifier.
31 * \param name Detector name used for branches and histograms.
32 */
33void QwHaloMonitor::InitializeChannel(TString subsystem, TString name){
34 fHalo_Counter.InitializeChannel(name);
35 SetElementName(name);
36}
37
38/**
39 * \brief Initialize the halo monitor with a detector name.
40 * \param name Detector name used for branches and histograms.
41 */
43 fHalo_Counter.InitializeChannel(name);
44 SetElementName(name);
45}
46
47/** \brief Clear event-scoped data in the underlying counter. */
49{
50 fHalo_Counter.ClearEventData();
51}
52
53/** \brief Process event (delegated to the underlying counter). */
55{
56 // no processing required for the halos as they are just counters(?).
57 fHalo_Counter.ProcessEvent();
58}
59
60/** \brief Decode the raw event buffer into the underlying counter. */
61Int_t QwHaloMonitor::ProcessEvBuffer(UInt_t* buffer, UInt_t num_words_left,UInt_t index)
62{
63 return fHalo_Counter.ProcessEvBuffer(buffer,num_words_left);
64}
65
66
67/** \brief Apply hardware checks (no hardware errors for simple counters). */
69{
70 Bool_t eventokay=kTRUE;
71 return eventokay;
72}
73
74
75/** \brief Apply single-event cuts on the underlying counter. */
77{
78 return fHalo_Counter.ApplySingleEventCuts();
79}
80
81
82/** \brief Print accumulated error counters for this monitor. */
84{
85 fHalo_Counter.PrintErrorCounters();
86}
87
88
89/** \brief Copy-assign from another halo monitor. */
91{
92 if (GetElementName()!=""){
93 this->fHalo_Counter=value.fHalo_Counter;
94 }
95 return *this;
96}
97
98/** \brief Add-assign from another halo monitor (sum counters). */
100{
101 if (GetElementName()!=""){
102 this->fHalo_Counter+=value.fHalo_Counter;
103 }
104 return *this;
105}
106
107/** \brief Subtract-assign from another halo monitor (difference counters). */
109{
110 if (GetElementName()!=""){
111 this->fHalo_Counter-=value.fHalo_Counter;
112 }
113 return *this;
114}
115
116
117/** \brief Sum two halo monitors into this instance. */
119 *this = value1;
120 *this += value2;
121}
122
123/** \brief Compute the difference of two halo monitors into this instance. */
125 *this = value1;
126 *this -= value2;
127}
128
129/** \brief Form the ratio of two halo monitors into this instance. */
131{
132 if (GetElementName()!=""){
133 this->fHalo_Counter.Ratio(numer.fHalo_Counter,denom.fHalo_Counter);
134 }
135 return;
136}
137
138/** \brief Scale the underlying counter by a constant factor. */
139void QwHaloMonitor::Scale(Double_t factor)
140{
141 fHalo_Counter.Scale(factor);
142}
143
144/** \brief Accumulate running sums from another monitor into this one. */
145void QwHaloMonitor::AccumulateRunningSum(const QwHaloMonitor& value, Int_t count, Int_t ErrorMask) {
146 fHalo_Counter.AccumulateRunningSum(value.fHalo_Counter, count, ErrorMask);
147}
148
149/** \brief Remove a single entry from the running sums using a source value. */
151 fHalo_Counter.DeaccumulateRunningSum(value.fHalo_Counter, ErrorMask);
152}
153
154/** \brief Update running averages for the underlying counter. */
156 fHalo_Counter.CalculateRunningAverage();
157}
158
159
160/** \brief Print a compact value summary for this monitor. */
162{
163 fHalo_Counter.PrintValue();
164}
165
166/** \brief Print detailed information for this monitor. */
168{
169 std::cout << "QwVQWK_Channel Info " << std::endl;
170 fHalo_Counter.PrintInfo();
171}
172
173/**
174 * \brief Check for burp failures by delegating to the underlying counter.
175 * \param ev_error Reference halo monitor to compare against.
176 * \return kTRUE if a burp failure was detected; otherwise kFALSE.
177 */
179 Bool_t burpstatus = kFALSE;
180 try {
181 if(typeid(*ev_error)==typeid(*this)) {
182 //std::cout<<" Here in QwHaloMonitor::CheckForBurpFail \n";
183 if (this->GetElementName()!="") {
184 const QwHaloMonitor* value_halo = dynamic_cast<const QwHaloMonitor* >(ev_error);
185 burpstatus |= fHalo_Counter.CheckForBurpFail(&(value_halo->fHalo_Counter));
186 }
187 } else {
188 TString loc="Standard exception from QwHaloMonitor::CheckForBurpFail :"+
189 ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
190 +"same type";
191 throw std::invalid_argument(loc.Data());
192 }
193 } catch (std::exception& e) {
194 std::cerr<< e.what()<<std::endl;
195 }
196 return burpstatus;
197}
198
199/**
200 * \brief Define histograms for this monitor (delegated to underlying counter).
201 * \param folder ROOT folder to contain histograms.
202 * \param prefix Histogram name prefix.
203 */
204void QwHaloMonitor::ConstructHistograms(TDirectory *folder, TString &prefix)
205{
206 if (GetElementName()==""){
207 // This channel is not used, so skip filling the histograms.
208 }
209 else{
210 fHalo_Counter.ConstructHistograms(folder, prefix);
211 }
212}
213
214/** \brief Fill histograms for this monitor if enabled. */
216{
217 if (GetElementName()==""){
218 // This channel is not used, so skip filling the histograms.
219 }
220 else{
221 fHalo_Counter.FillHistograms();
222 }
223}
224
225/**
226 * \brief Construct ROOT branches and value vector entries.
227 * \param tree Output tree.
228 * \param prefix Branch name prefix.
229 * \param values Output value vector to be appended.
230 */
231void QwHaloMonitor::ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
232{
233 if (GetElementName()==""){
234 // This channel is not used, so skip filling the histograms.
235 }
236 else{
237 fHalo_Counter.ConstructBranchAndVector(tree, prefix,values);
238 // this functions doesn't do anything yet
239 }
240}
241
242void QwHaloMonitor::ConstructBranch(TTree *tree, TString &prefix)
243{
244 if (GetElementName()==""){
245 // This channel is not used, so skip filling the histograms.
246 }
247 else{
248 fHalo_Counter.ConstructBranch(tree, prefix);
249 // this functions doesn't do anything yet
250 }
251}
252
253
254
255void QwHaloMonitor::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist)
256{
257 TString devicename;
258
259 devicename=GetElementName();
260 devicename.ToLower();
261 if (GetElementName()==""){
262 // This channel is not used, so skip filling the histograms.
263 } else {
264
265 //QwMessage <<" QwHaloMonitor "<<devicename<<QwLog::endl;
266 if (modulelist.HasValue(devicename)){
267 fHalo_Counter.ConstructBranch(tree, prefix);
268 QwMessage <<" Tree leaf added to "<<devicename<<QwLog::endl;
269 }
270 // this functions doesn't do anything yet
271 }
272}
273
274
275
276
278{
279 if (GetElementName()==""){
280 // This channel is not used, so skip filling the histograms.
281 }
282 else{
283 fHalo_Counter.FillTreeVector(values);
284 // this functions doesn't do anything yet
285 }
286}
287
288#ifdef HAS_RNTUPLE_SUPPORT
289void QwHaloMonitor::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
290{
291 if (GetElementName()==""){
292 // This channel is not used, so skip construction.
293 }
294 else{
295 fHalo_Counter.ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
296 }
297}
298
299void QwHaloMonitor::FillNTupleVector(std::vector<Double_t>& values) const
300{
301 if (GetElementName()==""){
302 // This channel is not used, so skip filling.
303 }
304 else{
305 fHalo_Counter.FillNTupleVector(values);
306 }
307}
308#endif // HAS_RNTUPLE_SUPPORT
309
310#ifdef __USE_DATABASE__
311std::vector<QwDBInterface> QwHaloMonitor::GetDBEntry()
312{
313 std::vector <QwDBInterface> row_list;
314 row_list.clear();
315 fHalo_Counter.AddEntriesToList(row_list);
316 return row_list;
317}
318
319
320std::vector<QwErrDBInterface> QwHaloMonitor::GetErrDBEntry()
321{
322 std::vector <QwErrDBInterface> row_list;
323 row_list.clear();
324 fHalo_Counter.AddErrEntriesToList(row_list);
325 return row_list;
326}
327#endif // __USE_DATABASE__
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
Database interface for QwIntegrationPMT and subsystems.
Halo monitor using scaler channels for beam monitoring.
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Configuration file parser with flexible tokenization and search capabilities.
Bool_t HasValue(TString &vname)
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:53
VQwDataElement()
Default constructor.
virtual const TString & GetElementName() const
Get the name of this element.
void SetElementName(const TString &name)
Set the name of this element.
void ProcessEvent()
Process event (delegated to the underlying counter).
void ConstructBranch(TTree *tree, TString &prefix)
void PrintValue() const override
Print a compact value summary for this monitor.
QwHaloMonitor & operator=(const QwHaloMonitor &value)
Copy-assign from another halo monitor.
QwSIS3801D24_Channel fHalo_Counter
void ClearEventData() override
Clear event-scoped data in the underlying counter.
void ConstructHistograms(TDirectory *folder, TString &prefix) override
Define histograms for this monitor (delegated to underlying counter).
void PrintErrorCounters()
void Sum(QwHaloMonitor &value1, QwHaloMonitor &value2)
Sum two halo monitors into this instance.
void InitializeChannel(TString name)
Initialize the halo monitor with a detector name.
void AccumulateRunningSum(const QwHaloMonitor &value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF)
Accumulate running sums from another monitor into this one.
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
Construct ROOT branches and value vector entries.
void Difference(QwHaloMonitor &value1, QwHaloMonitor &value2)
Compute the difference of two halo monitors into this instance.
QwHaloMonitor & operator-=(const QwHaloMonitor &value)
Subtract-assign from another halo monitor (difference counters).
void FillHistograms() override
Fill histograms for this monitor if enabled.
Bool_t ApplyHWChecks()
Apply hardware checks (no hardware errors for simple counters).
QwHaloMonitor & operator+=(const QwHaloMonitor &value)
Add-assign from another halo monitor (sum counters).
Bool_t CheckForBurpFail(const VQwDataElement *ev_error)
Check for burp failures by delegating to the underlying counter.
void FillTreeVector(QwRootTreeBranchVector &values) const
void Ratio(QwHaloMonitor &numer, QwHaloMonitor &denom)
Form the ratio of two halo monitors into this instance.
void DeaccumulateRunningSum(QwHaloMonitor &value, Int_t ErrorMask=0xFFFFFFF)
Remove a single entry from the running sums using a source value.
void CalculateRunningAverage()
Update running averages for the underlying counter.
void Scale(Double_t Offset)
Scale the underlying counter by a constant factor.
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t index=0) override
Decode the raw event buffer into the underlying counter.
void PrintInfo() const override
Print detailed information for this monitor.
Bool_t ApplySingleEventCuts()
Apply single-event cuts on the underlying counter.