JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwClock.cc
Go to the documentation of this file.
1/*!
2 * \file QwClock.cc
3 * \brief Clock channel template class implementation
4 * \author Juan Carlos Cornejo
5 * \date 2011-06-16
6 */
7
8#include "QwClock.h"
9
10// System headers
11#include <stdexcept>
12
13// ROOT headers
14#include "ROOT/RNTupleModel.hxx"
15#include "ROOT/RField.hxx"
16
17// Qweak database headers
18#ifdef __USE_DATABASE__
19#include "QwDBInterface.h"
20#endif // __USE_DATABASE__
21
22// Qweak types that we want to use in this template
23#include "QwVQWK_Channel.h"
24#include "QwScaler_Channel.h"
25
26/********************************************************/
27template<typename T>
28void QwClock<T>::SetPedestal(Double_t pedestal)
29{
30 fPedestal=pedestal;
31 fClock.SetPedestal(fPedestal);
32}
33
34template<typename T>
36{
37 fCalibration=calib;
38 fClock.SetCalibrationFactor(fCalibration);
39}
40/********************************************************/
41template<typename T>
42void QwClock<T>::InitializeChannel(TString subsystem, TString name, TString datatosave, TString type){
43 SetPedestal(0.);
45 if (type.Length() > 0)
46 SetModuleType(type);
47 fClock.InitializeChannel(subsystem, "QwClock", name, datatosave);
48 fClock.SetNeedsExternalClock(kFALSE);
49 SetElementName(name);
50 //set default limits to event cuts
51 fLLimit=0;//init two timits
52 fULimit=0;//init two timits
53}
54/********************************************************/
55template<typename T>
57{
58 fClock.ClearEventData();
59 return;
60}
61/********************************************************/
62//template<typename T>
63// void QwClock<T>::SetEventData(Double_t* block, UInt_t sequencenumber)
64// {
65// fClock.SetEventData(block, sequencenumber);
66// return;
67// }
68/********************************************************/
69// template<typename T>
70// void QwClock<T>::SetEventNumber(int event)
71// {
72// fClock.SetEventNumber(event);
73// return;
74// };
75/********************************************************/
76template<typename T>
77void QwClock<T>::EncodeEventData(std::vector<UInt_t> &buffer)
78{
79 fClock.EncodeEventData(buffer);
80}
81/********************************************************/
82template<typename T>
84{
85 return;
86}
87/********************************************************/
88template<typename T>
90{
91 Bool_t eventokay=kTRUE;
92
93 UInt_t deviceerror=fClock.ApplyHWChecks();//will check for HW consistency and return the error code (=0 is HW good)
94 eventokay=(deviceerror & 0x0);//if no HW error return true
95
96 return eventokay;
97}
98/********************************************************/
99
100template<typename T>
101void QwClock<T>::SetSingleEventCuts(UInt_t errorflag, Double_t LL, Double_t UL, Double_t stability, Double_t burplevel){
102 //set the unique tag to identify device type (bcm,bpm & etc)
103 errorflag|=kBCMErrorFlag;
104 QwMessage<<"QwClock Error Code passing to QwVQWK_Ch "<<errorflag<<QwLog::endl;
105 fClock.SetSingleEventCuts(errorflag,LL,UL,stability,burplevel);
106
107}
108
109template<typename T>
110void QwClock<T>::SetDefaultSampleSize(Int_t sample_size){
111 fClock.SetDefaultSampleSize((size_t)sample_size);
112}
113
114
115/********************************************************/
116template<typename T>
118 //std::cout<<" QwClock::SingleEventCuts() "<<std::endl;
119 Bool_t status=kTRUE;
120
121 if (fClock.ApplySingleEventCuts()){
122 status=kTRUE;
123 }
124 else{
125
126 if (bDEBUG) std::cout<<" evnt cut failed:-> set limit "<<fULimit<<" hardware sum "<<fClock.GetValue();
127 status&=kFALSE;
128 }
129 return status;
130}
131
132/********************************************************/
133
134template<typename T>
135void QwClock<T>::PrintErrorCounters() const{// report number of events failed due to HW and event cut failure
136 fClock.PrintErrorCounters();
137}
138
139
140
141template<typename T>
142Int_t QwClock<T>::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement)
143{
144 UInt_t words_read = fClock.ProcessEvBuffer(buffer,word_position_in_buffer);
145 this->ApplyHWChecks();
146 return words_read;
147}
148/********************************************************/
149template<typename T>
151{
152// std::cout<<" Here in QwClock::operator= \n";
153 if (this->GetElementName()!="")
154 {
155 this->fClock=value.fClock;
156 this->fPedestal=value.fPedestal;
157 this->fCalibration=value.fCalibration;
158 }
159// std::cout<<" to be copied \n";
160// value.Print();
161// std::cout<<" copied \n";
162// this->Print();
163
164 return *this;
165}
166
167template<typename T>
169{
170 try {
171 if(typeid(value)==typeid(*this)) {
172 // std::cout<<" Here in QwClock::operator= \n";
173 if (this->GetElementName()!="") {
174 const QwClock<T>* value_bcm = dynamic_cast<const QwClock<T>* >(&value);
175 QwClock<T>* this_cast = dynamic_cast<QwClock<T>* >(this);
176 this_cast->fClock= value_bcm->fClock;
177 this_cast->fPedestal=value_bcm->fPedestal;
178 this_cast->fCalibration=value_bcm->fCalibration;
179 }
180 } else {
181 TString loc="Standard exception from QwClock::operator= :"+
182 value.GetElementName()+" "+this->GetElementName()+" are not of the "
183 +"same type";
184 throw std::invalid_argument(loc.Data());
185 }
186 } catch (std::exception& e) {
187 std::cerr<< e.what()<<std::endl;
188 }
189// std::cout<<" to be copied \n";
190// value.Print();
191// std::cout<<" copied \n";
192// this->Print();
193
194 return *this;
195
196}
197
198template<typename T>
200{
201 if (this->GetElementName()!="")
202 {
203 this->fClock+=value.fClock;
204 this->fPedestal+=value.fPedestal;
205 this->fCalibration=0;
206 }
207 return *this;
208}
209
210template<typename T>
212{
213 try {
214 if(typeid(value)==typeid(*this)) {
215 // std::cout<<" Here in QwClock::operator+= \n";
216 if (this->GetElementName()!="") {
217 const QwClock<T>* value_bcm = dynamic_cast<const QwClock<T>* >(&value);
218 QwClock<T>* this_cast = dynamic_cast<QwClock<T>* >(this);
219 this_cast->fClock+=value_bcm->fClock;
220 this_cast->fPedestal+=value_bcm->fPedestal;
221 this_cast->fCalibration=0;
222 }
223 } else {
224 TString loc="Standard exception from QwClock::operator+= :"+
225 value.GetElementName()+" "+this->GetElementName()+" are not of the "
226 +"same type";
227 throw std::invalid_argument(loc.Data());
228 }
229 } catch (std::exception& e) {
230 std::cerr<< e.what()<<std::endl;
231 }
232
233 return *this;
234}
235
236template<typename T>
238{
239 if (this->GetElementName()!="")
240 {
241 const QwClock<T>* value_bcm = dynamic_cast<const QwClock<T>* >(&value);
242 QwClock<T>* this_cast = dynamic_cast<QwClock<T>* >(this);
243 this_cast->fClock-=value_bcm->fClock;
244 this_cast->fPedestal-=value_bcm->fPedestal;
245 this_cast->fCalibration=0;
246 }
247 return *this;
248}
249
250template<typename T>
252{
253 try {
254 if(typeid(value)==typeid(*this)) {
255 // std::cout<<" Here in QwClock::operator-= \n";
256 if (this->GetElementName()!="") {
257 const QwClock<T>* value_bcm = dynamic_cast<const QwClock<T>* >(&value);
258 QwClock<T>* this_cast = dynamic_cast<QwClock<T>* >(this);
259 this_cast->fClock-=value_bcm->fClock;
260 this_cast->fPedestal-=value_bcm->fPedestal;
261 this_cast->fCalibration=0;
262 }
263 } else {
264 TString loc="Standard exception from QwClock::operator-= :"+
265 value.GetElementName()+" "+this->GetElementName()+" are not of the "
266 +"same type";
267 throw std::invalid_argument(loc.Data());
268 }
269 } catch (std::exception& e) {
270 std::cerr<< e.what()<<std::endl;
271 }
272 return *this;
273}
274
275template<typename T>
276void QwClock<T>::Ratio(const VQwClock &numer, const VQwClock &denom)
277{
278 Ratio(*dynamic_cast<const QwClock<T>* >(&numer),
279 *dynamic_cast<const QwClock<T>* >(&denom));
280}
281
282template<typename T>
283void QwClock<T>::Ratio(const QwClock<T> &numer, const QwClock<T> &denom)
284{
285 // std::cout<<"QwClock::Ratio element name ="<<GetElementName()<<" \n";
286 if (this->GetElementName()!="")
287 {
288 // std::cout<<"here in \n";
289 this->fClock.Ratio(numer.fClock,denom.fClock);
290 this->fPedestal=0;
291 this->fCalibration=0;
292 }
293 return;
294}
295
296template<typename T>
297void QwClock<T>::Scale(Double_t factor)
298{
299 fClock.Scale(factor);
300 return;
301}
302
303template<typename T>
305 fClock.CalculateRunningAverage();
306}
307
308template<typename T>
309void QwClock<T>::AccumulateRunningSum(const VQwClock& value, Int_t count, Int_t ErrorMask) {
310 fClock.AccumulateRunningSum(
311 dynamic_cast<const QwClock<T>* >(&value)->fClock, count, ErrorMask);
312}
313
314template<typename T>
315void QwClock<T>::DeaccumulateRunningSum(VQwClock& value, Int_t ErrorMask) {
316 fClock.DeaccumulateRunningSum(
317 dynamic_cast<const QwClock<T>* >(&value)->fClock, ErrorMask);
318}
319
320template<typename T>
322{
323 fClock.PrintValue();
324}
325
326template<typename T>
328{
329 std::cout << "QwVQWK_Channel Info " << std::endl;
330 fClock.PrintInfo();
331}
332
333/********************************************************/
334template<typename T>
335void QwClock<T>::ConstructHistograms(TDirectory *folder, TString &prefix)
336{
337 if (this->GetElementName()=="")
338 {
339 // This channel is not used, so skip filling the histograms.
340 }
341 else
342 {
343 fClock.ConstructHistograms(folder, prefix);
344 }
345 return;
346}
347
348template<typename T>
350{
351 if (this->GetElementName()=="")
352 {
353 // This channel is not used, so skip filling the histograms.
354 }
355 else
356 {
357 fClock.FillHistograms();
358 }
359
360
361 return;
362}
363
364template<typename T>
365void QwClock<T>::ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values)
366{
367 if (this->GetElementName()==""){
368 // This channel is not used, so skip
369 } else
370 {
371 fClock.ConstructBranchAndVector(tree, prefix,values);
372 }
373 return;
374}
375
376template<typename T>
377void QwClock<T>::ConstructBranch(TTree *tree, TString &prefix)
378{
379 if (GetElementName()==""){
380 // This channel is not used, so skip filling the histograms.
381 } else
382 {
383 fClock.ConstructBranch(tree, prefix);
384 // this functions doesn't do anything yet
385 }
386 return;
387}
388
389template<typename T>
390void QwClock<T>::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist)
391{
392 TString devicename;
393
394 devicename=GetElementName();
395 devicename.ToLower();
396 if (GetElementName()==""){
397 // This channel is not used, so skip filling the histograms.
398 } else
399 {
400
401 //QwMessage <<" QwClock "<<devicename<<QwLog::endl;
402 if (modulelist.HasValue(devicename)){
403 fClock.ConstructBranch(tree, prefix);
404 QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
405 }
406 // this functions doesn't do anything yet
407 }
408 return;
409}
410
411template<typename T>
413{
414 if (this->GetElementName()==""){
415 // This channel is not used, so skip filling the histograms.
416 } else
417 {
418 fClock.FillTreeVector(values);
419 // this functions doesn't do anything yet
420 }
421 return;
422}
423
424#ifdef HAS_RNTUPLE_SUPPORT
425template<typename T>
426void QwClock<T>::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
427{
428 if (this->GetElementName()==""){
429 // This channel is not used, so skip RNTuple construction
430 } else
431 {
432 fClock.ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
433 }
434}
435
436template<typename T>
437void QwClock<T>::FillNTupleVector(std::vector<Double_t>& values) const
438{
439 if (this->GetElementName()==""){
440 // This channel is not used, so skip filling the RNTuple.
441 } else
442 {
443 fClock.FillNTupleVector(values);
444 // this functions doesn't do anything yet
445 }
446}
447#endif // HAS_RNTUPLE_SUPPORT
448
449#ifdef __USE_DATABASE__
450/********************************************************/
451template<typename T>
452std::vector<QwDBInterface> QwClock<T>::GetDBEntry()
453{
454 std::vector <QwDBInterface> row_list;
455 fClock.AddEntriesToList(row_list);
456 return row_list;
457}
458#endif // __USE_DATABASE__
459
460template class QwClock<QwVQWK_Channel>;
461template class QwClock<QwSIS3801_Channel>;
462template class QwClock<QwSIS3801D24_Channel>;
Base and derived classes for scaler channel data handling.
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
Decoding and management for VQWK ADC channels (6x32-bit datawords)
static const UInt_t kBCMErrorFlag
Definition QwTypes.h:168
Database interface for QwIntegrationPMT and subsystems.
Clock channel implementation for normalization and timing.
const TString QwBPMStripline< T >::subelement[4]
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
virtual const TString & GetElementName() const
Get the name of this element.
void SetElementName(const TString &name)
Set the name of this element.
void SetModuleType(TString ModuleType)
set the type of the beam instrument
Standard clock channel with calibration representing frequency.
Definition QwClock.h:42
Double_t fCalibration
Definition QwClock.h:172
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
void ClearEventData() override
Clear the event data in this element.
Definition QwClock.cc:56
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
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 fPedestal
Definition QwClock.h:171
void ConstructBranchAndVector(TTree *tree, TString &prefix, QwRootTreeBranchVector &values) override
Definition QwClock.cc:365
void SetDefaultSampleSize(Int_t sample_size)
Definition QwClock.cc:110
void Ratio(const VQwClock &numer, const VQwClock &denom) override
Definition QwClock.cc:276
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
VQwClock & operator-=(const VQwClock &value) override
Definition QwClock.cc:237
QwClock()
Definition QwClock.h:45
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
VQwClock()
Definition VQwClock.h:56