QwAnalysis
QwClock.h
Go to the documentation of this file.
1 /********************************************************\
2 * File: QwClock.h *
3 * *
4 * Author: Juan Carlos Cornejo <cornejo@jlab.org> *
5 * Time-stamp: <2011-06-16> *
6 \********************************************************/
7 
8 #ifndef __QWCLOCK__
9 #define __QWCLOCK__
10 
11 // System headers
12 #include <vector>
13 
14 // ROOT headers
15 #include <TTree.h>
16 
17 #include "QwParameterFile.h"
18 #include "VQwDataElement.h"
19 #include "VQwHardwareChannel.h"
20 #include "VQwClock.h"
21 
22 // Forward declarations
23 class QwDBInterface;
24 
25 /*****************************************************************
26 * Class:
27 * \brief QwClock is a standard clock with the calibration factor
28 * representing the frequency of this clock.
29 *
30 * Other channels may use this clock to normalize their units with
31 * time. Initially designed for Scalers, but could be used by
32 * other hardware elements.
33 ******************************************************************/
34 template<typename T>
35 class QwClock : public VQwClock {
36 /////
37  public:
38  QwClock() { };
39  QwClock(TString subsystemname, TString name, TString type = ""){
40  SetSubsystemName(subsystemname);
41  InitializeChannel(subsystemname, name, "raw", type);
42  };
43  QwClock(const QwClock& source)
44  : VQwClock(source),
46  fULimit(source.fULimit),fLLimit(source.fLLimit),
47  fClock(source.fClock),
49  { }
50  virtual ~QwClock() { };
51 
53  fClock.LoadChannelParameters(paramfile);
54  };
55 
56  Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement=0);
57 
58  void InitializeChannel(TString subsystem, TString name, TString datatosave, TString type = "");
59  void ClearEventData();
60 
61 
62  void EncodeEventData(std::vector<UInt_t> &buffer);
63 
64  void ProcessEvent();
65  Bool_t ApplyHWChecks();//Check for harware errors in the devices
66  Bool_t ApplySingleEventCuts();//Check for good events by stting limits on the devices readings
67  void IncrementErrorCounters(){fClock.IncrementErrorCounters();}
68  void PrintErrorCounters() const;// report number of events failed due to HW and event cut faliure
69  UInt_t GetEventcutErrorFlag(){//return the error flag
70  return fClock.GetEventcutErrorFlag();
71  }
72  UInt_t UpdateErrorFlag() {return GetEventcutErrorFlag();};
73  void UpdateErrorFlag(const QwClock *ev_error){
74  fClock.UpdateErrorFlag(ev_error->fClock);
75  }
76 
77  /*! \brief Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
78  void SetSingleEventCuts(UInt_t errorflag, Double_t min = 0, Double_t max = 0, Double_t stability = 0);
79 
80  void SetDefaultSampleSize(Int_t sample_size);
81  void SetEventCutMode(Int_t bcuts){
82  bEVENTCUTMODE=bcuts;
83  fClock.SetEventCutMode(bcuts);
84  }
85 
86  void PrintValue() const;
87  void PrintInfo() const;
88 
89  // Implementation of Parent class's virtual operators
90  VQwClock& operator= (const VQwClock &value);
91  VQwClock& operator+= (const VQwClock &value);
92  VQwClock& operator-= (const VQwClock &value);
93 
94  // This class specific operators
95  QwClock& operator= (const QwClock &value);
96  QwClock& operator+= (const QwClock &value);
97  QwClock& operator-= (const QwClock &value);
98  void Sum(QwClock &value1, QwClock &value2);
99  void Difference(QwClock &value1, QwClock &value2);
100  void Ratio(const VQwClock &numer, const VQwClock &denom);
101  void Ratio(const QwClock &numer, const QwClock &denom);
102  void Scale(Double_t factor);
103 
104  void AccumulateRunningSum(const VQwClock& value);
106 
107  void SetPedestal(Double_t ped);
108  void SetCalibrationFactor(Double_t calib);
109 
110  void ConstructHistograms(TDirectory *folder, TString &prefix);
111  void FillHistograms();
112 
113  void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values);
114  void ConstructBranch(TTree *tree, TString &prefix);
115  void ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist);
116  void FillTreeVector(std::vector<Double_t> &values) const;
117 
118  std::vector<QwDBInterface> GetDBEntry();
119 
120 
121  // These are related to those hardware channels that need to normalize
122  // to an external clock
123  Double_t GetNormClockValue() { return fNormalizationValue;};
124  Double_t GetStandardClockValue() { return fCalibration; };
125 
126  const VQwHardwareChannel* GetTime() const {
127  return &fClock;
128  };
129 
130 
131 /////
132  protected:
133 
134 /////
135  private:
136  Double_t fPedestal;
137  Double_t fCalibration;
138  Double_t fULimit, fLLimit;
139 
141 
142  Int_t fDeviceErrorCode;//keep the device HW status using a unique code from the QwVQWK_Channel::fDeviceErrorCode
143 
144  const static Bool_t bDEBUG=kFALSE;//debugging display purposes
145  Bool_t bEVENTCUTMODE;//If this set to kFALSE then Event cuts do not depend on HW ckecks. This is set externally through the qweak_beamline_eventcuts.map
146 
148 
149 };
150 
151 #endif // __QWCLOCK__
QwClock()
Definition: QwClock.h:38
void Sum(QwClock &value1, QwClock &value2)
Definition: QwClock.cc:271
void LoadChannelParameters(QwParameterFile &paramfile)
Definition: QwClock.h:52
void InitializeChannel(TString subsystem, TString name, TString datatosave, TString type="")
Definition: QwClock.cc:36
QwClock(const QwClock &source)
Definition: QwClock.h:43
const VQwHardwareChannel * GetTime() const
Definition: QwClock.h:126
void PrintValue() const
Print single line of value and error of this data element.
Definition: QwClock.cc:322
void FillTreeVector(std::vector< Double_t > &values) const
Definition: QwClock.cc:413
void SetSingleEventCuts(UInt_t errorflag, Double_t min=0, Double_t max=0, Double_t stability=0)
Inherited from VQwDataElement to set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel.
Definition: QwClock.cc:95
T fClock
Definition: QwClock.h:140
void AccumulateRunningSum(const VQwClock &value)
Definition: QwClock.cc:316
Double_t GetNormClockValue()
Definition: QwClock.h:123
VQwClock & operator+=(const VQwClock &value)
Definition: QwClock.cc:205
Bool_t ApplyHWChecks()
Definition: QwClock.cc:83
void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
Definition: QwClock.cc:129
Double_t fULimit
Definition: QwClock.h:138
void ConstructBranch(TTree *tree, TString &prefix)
Definition: QwClock.cc:378
Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t word_position_in_buffer, UInt_t subelement=0)
Process the CODA event buffer for this element.
Definition: QwClock.cc:136
void SetPedestal(Double_t ped)
Definition: QwClock.cc:22
void ProcessEvent()
Definition: QwClock.cc:77
void Difference(QwClock &value1, QwClock &value2)
Definition: QwClock.cc:277
VQwClock & operator=(const VQwClock &value)
Definition: QwClock.cc:162
Definition of the pure virtual base class of all data elements.
std::vector< QwDBInterface > GetDBEntry()
Definition: QwClock.cc:427
void SetSubsystemName(TString sysname)
Set the name of the inheriting subsystem name.
void PrintInfo() const
Print multiple lines of information about this data element.
Definition: QwClock.cc:328
Bool_t bEVENTCUTMODE
Definition: QwClock.h:145
Double_t fNormalizationValue
Definition: QwClock.h:147
void SetEventCutMode(Int_t bcuts)
Definition: QwClock.h:81
void UpdateErrorFlag(const QwClock *ev_error)
Definition: QwClock.h:73
virtual ~QwClock()
Definition: QwClock.h:50
void CalculateRunningAverage()
Definition: QwClock.cc:311
Double_t GetStandardClockValue()
Definition: QwClock.h:124
void IncrementErrorCounters()
Definition: QwClock.h:67
void ConstructHistograms(TDirectory *folder, TString &prefix)
Construct the histograms for this data element.
Definition: QwClock.cc:336
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
void ClearEventData()
Clear the event data in this element.
Definition: QwClock.cc:50
QwClock(TString subsystemname, TString name, TString type="")
Definition: QwClock.h:39
static const double min
Definition: QwUnits.h:76
UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
Definition: QwClock.h:69
void SetDefaultSampleSize(Int_t sample_size)
Definition: QwClock.cc:104
VQwClock & operator-=(const VQwClock &value)
Definition: QwClock.cc:231
void Scale(Double_t factor)
Definition: QwClock.cc:304
void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)
Definition: QwClock.cc:366
Double_t fCalibration
Definition: QwClock.h:137
void EncodeEventData(std::vector< UInt_t > &buffer)
Definition: QwClock.cc:71
Double_t fLLimit
Definition: QwClock.h:138
Double_t fPedestal
Definition: QwClock.h:128
Bool_t ApplySingleEventCuts()
Definition: QwClock.cc:111
void Ratio(const VQwClock &numer, const VQwClock &denom)
Definition: QwClock.cc:283
void FillHistograms()
Fill the histograms for this data element.
Definition: QwClock.cc:350
UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
Definition: QwClock.h:72
void SetCalibrationFactor(Double_t calib)
Definition: QwClock.cc:29
Int_t fDeviceErrorCode
Definition: QwClock.h:142
static const Bool_t bDEBUG
Definition: QwClock.h:144