00001
00002
00003
00004
00005
00006
00007
00008 #include "QwBCM.h"
00009
00010
00011 #include <stdexcept>
00012
00013
00014 #include "QwDBInterface.h"
00015
00016
00017 #include "QwVQWK_Channel.h"
00018 #include "QwScaler_Channel.h"
00019
00020
00021 template<typename T>
00022 void QwBCM<T>::SetPedestal(Double_t pedestal)
00023 {
00024 fBeamCurrent.SetPedestal(pedestal);
00025 }
00026
00027 template<typename T>
00028 void QwBCM<T>::SetCalibrationFactor(Double_t calibration)
00029 {
00030 fBeamCurrent.SetCalibrationFactor(calibration);
00031 }
00032
00033 template<typename T>
00034 void QwBCM<T>::InitializeChannel(TString name, TString datatosave)
00035 {
00036 SetPedestal(0.);
00037 SetCalibrationFactor(1.);
00038 fBeamCurrent.InitializeChannel(name,datatosave);
00039 this->SetElementName(name);
00040 }
00041
00042 template<typename T>
00043 void QwBCM<T>::InitializeChannel(TString subsystem, TString name, TString datatosave){
00044 SetPedestal(0.);
00045 SetCalibrationFactor(1.);
00046 fBeamCurrent.InitializeChannel(subsystem, "QwBCM", name, datatosave);
00047 SetElementName(name);
00048 }
00049
00050 template<typename T>
00051 void QwBCM<T>::InitializeChannel(TString subsystem, TString name, TString type,
00052 TString datatosave){
00053 SetPedestal(0.);
00054 SetCalibrationFactor(1.);
00055 SetModuleType(type);
00056 fBeamCurrent.InitializeChannel(subsystem, "QwBCM", name, datatosave);
00057 SetElementName(name);
00058 }
00059
00060
00061 template<typename T>
00062 void QwBCM<T>::ClearEventData()
00063 {
00064 fBeamCurrent.ClearEventData();
00065 }
00066
00067
00068 template<typename T>
00069 void QwBCM<T>::UseExternalRandomVariable()
00070 {
00071 fBeamCurrent.UseExternalRandomVariable();
00072 }
00073
00074 template<typename T>
00075 void QwBCM<T>::SetExternalRandomVariable(double random_variable)
00076 {
00077 fBeamCurrent.SetExternalRandomVariable(random_variable);
00078 }
00079
00080 template<typename T>
00081 void QwBCM<T>::SetRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
00082 {
00083 fBeamCurrent.SetRandomEventDriftParameters(amplitude, phase, frequency);
00084 }
00085
00086 template<typename T>
00087 void QwBCM<T>::AddRandomEventDriftParameters(Double_t amplitude, Double_t phase, Double_t frequency)
00088 {
00089 fBeamCurrent.AddRandomEventDriftParameters(amplitude, phase, frequency);
00090 }
00091
00092 template<typename T>
00093 void QwBCM<T>::SetRandomEventParameters(Double_t mean, Double_t sigma)
00094 {
00095 fBeamCurrent.SetRandomEventParameters(mean, sigma);
00096 }
00097
00098 template<typename T>
00099 void QwBCM<T>::SetRandomEventAsymmetry(Double_t asymmetry)
00100 {
00101 fBeamCurrent.SetRandomEventAsymmetry(asymmetry);
00102 }
00103
00104 template<typename T>
00105 void QwBCM<T>::RandomizeEventData(int helicity, double time)
00106 {
00107 fBeamCurrent.RandomizeEventData(helicity, time);
00108 }
00109
00110 template<typename T>
00111 void QwBCM<T>::EncodeEventData(std::vector<UInt_t> &buffer)
00112 {
00113 fBeamCurrent.EncodeEventData(buffer);
00114 }
00115
00116 template<typename T>
00117 void QwBCM<T>::ProcessEvent()
00118 {
00119 this->ApplyHWChecks();
00120 fBeamCurrent.ProcessEvent();
00121 }
00122
00123 template<typename T>
00124 Bool_t QwBCM<T>::ApplyHWChecks()
00125 {
00126 Bool_t eventokay=kTRUE;
00127
00128 UInt_t deviceerror=fBeamCurrent.ApplyHWChecks();
00129 eventokay=(deviceerror & 0x0);
00130
00131 return eventokay;
00132 }
00133
00134
00135 template<typename T>
00136 Int_t QwBCM<T>::SetSingleEventCuts(Double_t LL=0, Double_t UL=0){
00137 fBeamCurrent.SetSingleEventCuts(LL,UL);
00138 return 1;
00139 }
00140
00141 template<typename T>
00142 void QwBCM<T>::SetSingleEventCuts(UInt_t errorflag, Double_t LL=0, Double_t UL=0, Double_t stability=0){
00143
00144 errorflag|=kBCMErrorFlag;
00145 QwMessage<<"QwBCM Error Code passing to QwVQWK_Ch "<<errorflag<<" "<<stability<<QwLog::endl;
00146 fBeamCurrent.SetSingleEventCuts(errorflag,LL,UL,stability);
00147
00148 }
00149
00150 template<typename T>
00151 void QwBCM<T>::SetDefaultSampleSize(Int_t sample_size){
00152 fBeamCurrent.SetDefaultSampleSize((size_t)sample_size);
00153 }
00154
00155
00156
00157 template<typename T>
00158 Bool_t QwBCM<T>::ApplySingleEventCuts()
00159 {
00160
00161 Bool_t status = kTRUE;
00162
00163 if (fBeamCurrent.ApplySingleEventCuts()) {
00164 status = kTRUE;
00165 } else {
00166 status &= kFALSE;
00167 }
00168 return status;
00169 }
00170
00171
00172
00173 template<typename T>
00174 void QwBCM<T>::IncrementErrorCounters()
00175 {
00176 fBeamCurrent.IncrementErrorCounters();
00177 }
00178
00179 template<typename T>
00180 void QwBCM<T>::PrintErrorCounters() const
00181 {
00182 fBeamCurrent.PrintErrorCounters();
00183 }
00184
00185
00186 template<typename T>
00187 void QwBCM<T>::UpdateErrorFlag(const VQwBCM *ev_error){
00188 try {
00189 if(typeid(*ev_error)==typeid(*this)) {
00190
00191 if (this->GetElementName()!="") {
00192 const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(ev_error);
00193 fBeamCurrent.UpdateErrorFlag(value_bcm->fBeamCurrent);
00194 }
00195 } else {
00196 TString loc="Standard exception from QwBCM::UpdateErrorFlag :"+
00197 ev_error->GetElementName()+" "+this->GetElementName()+" are not of the "
00198 +"same type";
00199 throw std::invalid_argument(loc.Data());
00200 }
00201 } catch (std::exception& e) {
00202 std::cerr<< e.what()<<std::endl;
00203 }
00204 };
00205
00206
00207
00208 template<typename T>
00209 Int_t QwBCM<T>::ProcessEvBuffer(UInt_t* buffer, UInt_t word_position_in_buffer, UInt_t subelement)
00210 {
00211 fBeamCurrent.ProcessEvBuffer(buffer,word_position_in_buffer);
00212
00213 return word_position_in_buffer;
00214 }
00215
00216 template<typename T>
00217 QwBCM<T>& QwBCM<T>::operator= (const QwBCM<T> &value)
00218 {
00219
00220 if (this->GetElementName()!="")
00221 {
00222 this->fBeamCurrent=value.fBeamCurrent;
00223 }
00224
00225
00226
00227
00228
00229 return *this;
00230 }
00231
00232 template<typename T>
00233 VQwBCM& QwBCM<T>::operator= (const VQwBCM &value)
00234 {
00235 try {
00236 if(typeid(value)==typeid(*this)) {
00237
00238 if (this->GetElementName()!="") {
00239 const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
00240 QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
00241 this_cast->fBeamCurrent= value_bcm->fBeamCurrent;
00242 }
00243 } else {
00244 TString loc="Standard exception from QwBCM::operato= :"+
00245 value.GetElementName()+" "+this->GetElementName()+" are not of the "
00246 +"same type";
00247 throw std::invalid_argument(loc.Data());
00248 }
00249 } catch (std::exception& e) {
00250 std::cerr<< e.what()<<std::endl;
00251 }
00252
00253
00254
00255
00256
00257 return *this;
00258 }
00259
00260 template<typename T>
00261 QwBCM<T>& QwBCM<T>::operator+= (const QwBCM<T> &value)
00262 {
00263 if (this->GetElementName()!="")
00264 {
00265 this->fBeamCurrent+=value.fBeamCurrent;
00266 }
00267 return *this;
00268 }
00269
00270 template<typename T>
00271 VQwBCM& QwBCM<T>::operator+= (const VQwBCM &value)
00272 {
00273 try {
00274 if(typeid(value)==typeid(*this)) {
00275
00276 if (this->GetElementName()!="") {
00277 const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
00278 QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
00279 this_cast->fBeamCurrent+=value_bcm->fBeamCurrent;
00280 }
00281 } else {
00282 TString loc="Standard exception from QwBCM::operator+= :"+
00283 value.GetElementName()+" "+this->GetElementName()+" are not of the "
00284 +"same type";
00285 throw std::invalid_argument(loc.Data());
00286 }
00287 } catch (std::exception& e) {
00288 std::cerr<< e.what()<<std::endl;
00289 }
00290
00291 return *this;
00292 }
00293
00294 template<typename T>
00295 VQwBCM& QwBCM<T>::operator-= (const VQwBCM &value)
00296 {
00297 if (this->GetElementName()!="")
00298 {
00299 const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
00300 QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
00301 this_cast->fBeamCurrent-=value_bcm->fBeamCurrent;
00302 }
00303 return *this;
00304 }
00305
00306 template<typename T>
00307 QwBCM<T>& QwBCM<T>::operator-= (const QwBCM<T> &value)
00308 {
00309 try {
00310 if(typeid(value)==typeid(*this)) {
00311
00312 if (this->GetElementName()!="") {
00313 const QwBCM<T>* value_bcm = dynamic_cast<const QwBCM<T>* >(&value);
00314 QwBCM<T>* this_cast = dynamic_cast<QwBCM<T>* >(this);
00315 this_cast->fBeamCurrent-=value_bcm->fBeamCurrent;
00316 }
00317 } else {
00318 TString loc="Standard exception from QwBCM::operator-= :"+
00319 value.GetElementName()+" "+this->GetElementName()+" are not of the "
00320 +"same type";
00321 throw std::invalid_argument(loc.Data());
00322 }
00323 } catch (std::exception& e) {
00324 std::cerr<< e.what()<<std::endl;
00325 }
00326 return *this;
00327 }
00328
00329
00330 template<typename T>
00331 void QwBCM<T>::Sum(QwBCM<T> &value1, QwBCM<T> &value2){
00332 *this = value1;
00333 *this += value2;
00334 }
00335
00336 template<typename T>
00337 void QwBCM<T>::Difference(QwBCM<T> &value1, QwBCM<T> &value2){
00338 *this = value1;
00339 *this -= value2;
00340 }
00341
00342 template<typename T>
00343 void QwBCM<T>::Ratio(const VQwBCM &numer, const VQwBCM &denom)
00344 {
00345 Ratio(*dynamic_cast<const QwBCM<T>* >(&numer),
00346 *dynamic_cast<const QwBCM<T>* >(&denom));
00347 }
00348
00349 template<typename T>
00350 void QwBCM<T>::Ratio(const QwBCM<T> &numer, const QwBCM<T> &denom)
00351 {
00352
00353 if (this->GetElementName()!="")
00354 {
00355
00356 this->fBeamCurrent.Ratio(numer.fBeamCurrent,denom.fBeamCurrent);
00357 }
00358 }
00359
00360 template<typename T>
00361 void QwBCM<T>::Scale(Double_t factor)
00362 {
00363 fBeamCurrent.Scale(factor);
00364 }
00365
00366 template<typename T>
00367 void QwBCM<T>::CalculateRunningAverage()
00368 {
00369 fBeamCurrent.CalculateRunningAverage();
00370 }
00371
00372 template<typename T>
00373 void QwBCM<T>::AccumulateRunningSum(const VQwBCM& value) {
00374 fBeamCurrent.AccumulateRunningSum(
00375 dynamic_cast<const QwBCM<T>* >(&value)->fBeamCurrent);
00376 }
00377
00378 template<typename T>
00379 void QwBCM<T>::DeaccumulateRunningSum(VQwBCM& value) {
00380 fBeamCurrent.DeaccumulateRunningSum(dynamic_cast<QwBCM<T>* >(&value)->fBeamCurrent);
00381 }
00382 template<typename T>
00383 void QwBCM<T>::PrintValue() const
00384 {
00385 fBeamCurrent.PrintValue();
00386 }
00387
00388 template<typename T>
00389 void QwBCM<T>::PrintInfo() const
00390 {
00391 std::cout << "QwVQWK_Channel Info " << std::endl;
00392 fBeamCurrent.PrintInfo();
00393 }
00394
00395
00396 template<typename T>
00397 void QwBCM<T>::ConstructHistograms(TDirectory *folder, TString &prefix)
00398 {
00399 if (this->GetElementName()=="")
00400 {
00401
00402 }
00403 else
00404 {
00405 fBeamCurrent.ConstructHistograms(folder, prefix);
00406 }
00407 }
00408
00409 template<typename T>
00410 void QwBCM<T>::FillHistograms()
00411 {
00412 if (this->GetElementName()=="")
00413 {
00414
00415 }
00416 else
00417 {
00418 fBeamCurrent.FillHistograms();
00419 }
00420 }
00421
00422 template<typename T>
00423 void QwBCM<T>::ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector<Double_t> &values)
00424 {
00425 if (this->GetElementName()==""){
00426
00427 } else
00428 {
00429 fBeamCurrent.ConstructBranchAndVector(tree, prefix,values);
00430 }
00431 }
00432
00433 template<typename T>
00434 void QwBCM<T>::ConstructBranch(TTree *tree, TString &prefix)
00435 {
00436 if (GetElementName()==""){
00437
00438 } else
00439 {
00440 fBeamCurrent.ConstructBranch(tree, prefix);
00441
00442 }
00443 }
00444
00445 template<typename T>
00446 void QwBCM<T>::ConstructBranch(TTree *tree, TString &prefix, QwParameterFile& modulelist)
00447 {
00448 TString devicename;
00449
00450 devicename=GetElementName();
00451 devicename.ToLower();
00452 if (GetElementName()==""){
00453
00454 } else
00455 {
00456
00457
00458 if (modulelist.HasValue(devicename)){
00459 fBeamCurrent.ConstructBranch(tree, prefix);
00460 QwMessage <<" Tree leave added to "<<devicename<<QwLog::endl;
00461 }
00462
00463 }
00464 }
00465
00466 template<typename T>
00467 void QwBCM<T>::FillTreeVector(std::vector<Double_t> &values) const
00468 {
00469 if (this->GetElementName()==""){
00470
00471 } else
00472 {
00473 fBeamCurrent.FillTreeVector(values);
00474
00475 }
00476 }
00477
00478 template<typename T>
00479 std::vector<QwDBInterface> QwBCM<T>::GetDBEntry()
00480 {
00481 std::vector <QwDBInterface> row_list;
00482 fBeamCurrent.AddEntriesToList(row_list);
00483 return row_list;
00484 }
00485
00486
00487
00488 template<typename T>
00489 std::vector<QwErrDBInterface> QwBCM<T>::GetErrDBEntry()
00490 {
00491 std::vector <QwErrDBInterface> row_list;
00492 fBeamCurrent.AddErrEntriesToList(row_list);
00493 return row_list;
00494 }
00495
00496
00497 template<typename T>
00498 Double_t QwBCM<T>::GetValue()
00499 {
00500 return fBeamCurrent.GetValue();
00501 }
00502
00503
00504 template<typename T>
00505 Double_t QwBCM<T>::GetValueError()
00506 {
00507 return fBeamCurrent.GetValueError();
00508 }
00509
00510 template<typename T>
00511 Double_t QwBCM<T>::GetValueWidth()
00512 {
00513 return fBeamCurrent.GetValueWidth();
00514 }
00515
00516 template class QwBCM<QwVQWK_Channel>;
00517 template class QwBCM<QwSIS3801_Channel>;
00518 template class QwBCM<QwSIS3801D24_Channel>;