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