QwAnalysis
VQwDataElement.h
Go to the documentation of this file.
1 /*!
2  * \file VQwDataElement.h
3  * \brief Definition of the pure virtual base class of all data elements
4  *
5  * \author P. M. King
6  * \date 2007-05-08 15:40
7  */
8 
9 #ifndef __VQWDATAELEMENT__
10 #define __VQWDATAELEMENT__
11 
12 // System headers
13 #include <vector>
14 #include <iostream>
15 
16 // Root headers
17 #include "Rtypes.h"
18 #include "TString.h"
19 #include "TDirectory.h"
20 
21 // Qweak headers
22 #include "QwLog.h"
23 #include "QwTypes.h"
24 #include "MQwHistograms.h"
25 
26 class QwParameterFile;
27 class VQwHardwareChannel;
28 
29 /**
30  * \class VQwDataElement
31  * \ingroup QwAnalysis
32  * \brief The pure virtual base class of all data elements
33  *
34  * Each stream of data inherits from this virtual base class, which requires
35  * some standard operations on it such as ratios, summing, subtraction. The
36  * specific implementation of those operation is left to be implemented by the
37  * implemented inherited classes, but this class sets up the structure.
38  *
39  * As an example, all individual VQWK channels inherit from this class and
40  * implement the pure virtual functions of VQwDataElement.
41  *
42  * \dot
43  * digraph example {
44  * node [shape=box, fontname=Helvetica, fontsize=10];
45  * VQwDataElement [ label="VQwDataElement" URL="\ref VQwDataElement"];
46  * QwVQWK_Channel [ label="QwVQWK_Channel" URL="\ref QwVQWK_Channel"];
47  * VQwDataElement -> QwVQWK_Channel;
48  * }
49  * \enddot
50  */
52  public:
53  /// Flag to be used to decide which data needs to be histogrammed and
54  /// entered in the tree
55  enum EDataToSave {kRaw = 0, kDerived};
56 
57 
58  public:
59 
60  /// Default constructor
62  : MQwHistograms(),
63  fElementName(""),
65  fGoodEventCount(0),
66  fSubsystemName(""),
67  fModuleType(""),
68  fErrorFlag(0),
70  { };
71  /// Copy constructor
73  : MQwHistograms(value),
78  fModuleType(value.fModuleType),
79  fErrorFlag(value.fErrorFlag),
81  { };
82  /// Virtual destructor
83  virtual ~VQwDataElement() { };
84 
85  /*! \brief Is the name of this element empty? */
86  Bool_t IsNameEmpty() const { return fElementName.IsNull(); }
87  /*! \brief Set the name of this element */
88  void SetElementName(const TString &name) { fElementName = name; }
89  /*! \brief Get the name of this element */
90  virtual const TString& GetElementName() const { return fElementName; }
91 
92  virtual void LoadChannelParameters(QwParameterFile &paramfile){};
93 
94  /*! \brief Clear the event data in this element */
95  virtual void ClearEventData(){
96  fErrorFlag=0;
97  };
98  /*! \brief Process the CODA event buffer for this element */
99  virtual Int_t ProcessEvBuffer(UInt_t* buffer, UInt_t num_words_left, UInt_t subelement=0) = 0;
100 
101  /*! \brief Get the number of data words in this data element */
103 
104  UInt_t GetGoodEventCount() const { return fGoodEventCount; };
105 
106 
107  virtual void AssignValueFrom(const VQwDataElement* valueptr){
108  std::cerr << "Operation AssignValueFrom not defined!" << std::endl;
109  };
110 
111  /*! \brief Addition-assignment operator */
113  { std::cerr << "Operation += not defined!" << std::endl; return *this; }
114  /*! \brief Subtraction-assignment operator */
116  { std::cerr << "Operation -= not defined!" << std::endl; return *this; }
117 
118  /*! \brief Sum operator */
119  virtual void Sum(const VQwDataElement &value1, const VQwDataElement &value2)
120  { std::cerr << "Sum not defined!" << std::endl; }
121  /*! \brief Difference operator */
122  virtual void Difference(const VQwDataElement &value1, const VQwDataElement &value2)
123  { std::cerr << "Difference not defined!" << std::endl; }
124  /*! \brief Ratio operator */
125  virtual void Ratio(const VQwDataElement &numer, const VQwDataElement &denom)
126  { std::cerr << "Ratio not defined!" << std::endl; }
127 
128  /*! \brief Construct the histograms for this data element */
129  virtual void ConstructHistograms(TDirectory *folder, TString &prefix) = 0;
130  /*! \brief Fill the histograms for this data element */
131  virtual void FillHistograms() = 0;
132 
133  /*! \brief Print single line of value and error of this data element */
134  virtual void PrintValue() const { }
135  /*! \brief Print multiple lines of information about this data element */
136  virtual void PrintInfo() const { std::cout << GetElementName() << std::endl; }
137 
138 
139  /*! \brief set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel */
140  virtual void SetSingleEventCuts(UInt_t errorflag,Double_t min, Double_t max, Double_t stability){std::cerr << "SetSingleEventCuts not defined!" << std::endl; };
141  /*! \brief report number of events failed due to HW and event cut failure */
142  virtual void PrintErrorCounters() const {};
143 
144  /*! \brief return the error flag on this channel/device*/
145  virtual UInt_t GetEventcutErrorFlag(){
146  //first condition check for global/local status and second condition check to see non-zero HW error codes
147  if (((fErrorConfigFlag & kGlobalCut) == kGlobalCut) && (fErrorFlag)>0){
148  // we care only about global cuts
149  //std::cout<<"fErrorFlag "<<(fErrorFlag & kGlobalCut)<<std::endl;
150  return fErrorFlag+fErrorConfigFlag;//pass the error codes and configuration codes
151  }
152  return 0;
153  }
154 
155  /// \brief Update the error flag based on the error flags of internally
156  /// contained objects
157  /// Return paramter is the "Eventcut Error Flag".
158  virtual UInt_t UpdateErrorFlag() {return GetEventcutErrorFlag();};
159 
160  // These are related to those hardware channels that need to normalize
161  // to an external clock
162  virtual void SetNeedsExternalClock(Bool_t needed) {}; // Default is No!
163  virtual Bool_t NeedsExternalClock() { return kFALSE; }; // Default is No!
164  virtual std::string GetExternalClockName() { return ""; }; // Default is none
165  virtual void SetExternalClockPtr( const VQwHardwareChannel* clock) {};
166  virtual void SetExternalClockName( const std::string name) {};
167  virtual Double_t GetNormClockValue() { return 1.;}
168 
169 
170 
171  /*! \brief Return the name of the inheriting subsystem name*/
172  TString GetSubsystemName() const {
173  return fSubsystemName;
174  }
175 
176  /*! \brief Set the name of the inheriting subsystem name*/
177  void SetSubsystemName(TString sysname){
178  fSubsystemName=sysname;
179  }
180 
181  /*! \brief Return the type of the beam instrument*/
182  TString GetModuleType() const {
183  return fModuleType;
184  }
185 
186  /*! \brief set the type of the beam instrument*/
187  void SetModuleType(TString ModuleType){
188  fModuleType=ModuleType;
189  }
190 
191  protected:
192  /*! \brief Set the number of data words in this data element */
193  void SetNumberOfDataWords(const UInt_t &numwords) {fNumberOfDataWords = numwords;}
194 
195  /// Arithmetic assignment operator: Should only copy event-based data
196  virtual VQwDataElement& operator=(const VQwDataElement& value) {
197  if(this != &value){
200  fErrorFlag = value.fErrorFlag;
201  }
202  return *this;
203  }
204 
205  // The most basic version of UpdateErrorFlag, which should get hidden
206  // by all the derived class versions.
207  virtual void UpdateErrorFlag(const UInt_t& error){fErrorFlag |= (error);};
208 
209  protected:
210  TString fElementName; ///< Name of this data element
211  UInt_t fNumberOfDataWords; ///< Number of raw data words in this data element
212  Int_t fGoodEventCount; ///< Number of good events accumulated in this element
213 
214 
215  // Name of the inheriting subsystem
216  TString fSubsystemName;
217  // Data module Type
218  TString fModuleType;
219 
220  /*! \name Event error flag */
221  /*! \brief This the standard error code generated for the channel that contains the global/local/stability flags and the Device error code (Unique error code for HW failures)*/
222 // @{
223  UInt_t fErrorFlag;
224  UInt_t fErrorConfigFlag; ///<contains the global/local/stability flags
225 //@}
226 }; // class VQwDataElement
227 
228 #endif // __VQWDATAELEMENT__
virtual UInt_t UpdateErrorFlag()
Update the error flag based on the error flags of internally contained objects Return paramter is the...
virtual Bool_t NeedsExternalClock()
VQwDataElement()
Default constructor.
virtual VQwDataElement & operator+=(const VQwDataElement &value)
Addition-assignment operator.
UInt_t GetGoodEventCount() const
virtual void PrintInfo() const
Print multiple lines of information about this data element.
Bool_t IsNameEmpty() const
Is the name of this element empty?
VQwDataElement(const VQwDataElement &value)
Copy constructor.
virtual void ConstructHistograms(TDirectory *folder, TString &prefix)=0
Construct the histograms for this data element.
virtual void PrintValue() const
Print single line of value and error of this data element.
virtual void Sum(const VQwDataElement &value1, const VQwDataElement &value2)
Sum operator.
virtual void LoadChannelParameters(QwParameterFile &paramfile)
TString GetModuleType() const
Return the type of the beam instrument.
virtual void Ratio(const VQwDataElement &numer, const VQwDataElement &denom)
Ratio operator.
virtual VQwDataElement & operator=(const VQwDataElement &value)
Arithmetic assignment operator: Should only copy event-based data.
The pure virtual base class of all data elements.
virtual UInt_t GetEventcutErrorFlag()
return the error flag on this channel/device
A logfile class, based on an identical class in the Hermes analyzer.
void SetSubsystemName(TString sysname)
Set the name of the inheriting subsystem name.
TString GetSubsystemName() const
Return the name of the inheriting subsystem name.
void SetElementName(const TString &name)
Set the name of this element.
UInt_t fErrorFlag
This the standard error code generated for the channel that contains the global/local/stability flags...
virtual void SetExternalClockName(const std::string name)
virtual std::string GetExternalClockName()
static const double min
Definition: QwUnits.h:76
void SetNumberOfDataWords(const UInt_t &numwords)
Set the number of data words in this data element.
virtual void SetSingleEventCuts(UInt_t errorflag, Double_t min, Double_t max, Double_t stability)
set the upper and lower limits (fULimit and fLLimit), stability % and the error flag on this channel ...
UInt_t fErrorConfigFlag
contains the global/local/stability flags
virtual void SetExternalClockPtr(const VQwHardwareChannel *clock)
UInt_t fNumberOfDataWords
Number of raw data words in this data element.
void SetModuleType(TString ModuleType)
set the type of the beam instrument
virtual void FillHistograms()=0
Fill the histograms for this data element.
static const UInt_t kGlobalCut
Definition: QwTypes.h:176
Int_t fGoodEventCount
Number of good events accumulated in this element.
TString fElementName
Name of this data element.
virtual void Difference(const VQwDataElement &value1, const VQwDataElement &value2)
Difference operator.
virtual const TString & GetElementName() const
Get the name of this element.
virtual void UpdateErrorFlag(const UInt_t &error)
TString fSubsystemName
virtual void SetNeedsExternalClock(Bool_t needed)
virtual void AssignValueFrom(const VQwDataElement *valueptr)
virtual void ClearEventData()
Clear the event data in this element.
virtual Int_t ProcessEvBuffer(UInt_t *buffer, UInt_t num_words_left, UInt_t subelement=0)=0
Process the CODA event buffer for this element.
virtual ~VQwDataElement()
Virtual destructor.
virtual MQwHistograms & operator=(const MQwHistograms &value)
Definition: MQwHistograms.h:34
virtual void PrintErrorCounters() const
report number of events failed due to HW and event cut failure
virtual Double_t GetNormClockValue()
size_t GetNumberOfDataWords()
Get the number of data words in this data element.
virtual VQwDataElement & operator-=(const VQwDataElement &value)
Subtraction-assignment operator.