/*! \file \version $Id: TAGparFbusCal.cxx,v 1.2 2003/07/11 18:18:08 mueller Exp $ \brief Implementation of TATOFparFbusCal. */ #include "TSystem.h" #include "TString.h" #include "TATOFconfigFile.h" #include "TATOFdatFbus.h" #include "TATOFparFbusCal.h" /*! \class TATOFparFbusCalInfo TATOFparFbusCal.h "TATOFparFbusCal.h" \brief FastBus ADC/TDC high/low range calibration info for one channel. ** */ ClassImp(TATOFparFbusCalInfo); //------------------------------------------+----------------------------------- //! Calibrate FastBus converter values. Float_t TATOFparFbusCalInfo::Calibrate(Int_t i_combo) const { Int_t i_val = i_combo & 0x0fff; Bool_t b_ran = i_combo & 0x1000; return (b_ran) ? ffFactorHigh*(i_val+ffOffsetHigh) : ffFactorLow*(i_val+ffOffsetLow); } //############################################################################## /*! \class TATOFparFbusCal TATOFparFbusCal.hxx "TATOFparFbusCal.hxx" \brief FastBus ADC/TDC high/low range calibration. ** */ ClassImp(TATOFparFbusCal); //------------------------------------------+----------------------------------- //! Default constructor. TATOFparFbusCal::TATOFparFbusCal() {} //------------------------------------------+----------------------------------- //! Destructor. TATOFparFbusCal::~TATOFparFbusCal() {} //------------------------------------------+----------------------------------- //! Setup default calibration for one ADC module. void TATOFparFbusCal::AddDefaultAdc(Int_t i_geo) { for (Int_t i_cha = 0; i_cha < 96; i_cha++) AddInfo(TATOFdatFbus::PackAddress(i_geo, i_cha), 0., 1., 0., 8.); return; } //------------------------------------------+----------------------------------- //! Setup default calibration for one TDC module. void TATOFparFbusCal::AddDefaultTdc(Int_t i_geo) { for (Int_t i_cha = 0; i_cha < 64; i_cha++) AddInfo(TATOFdatFbus::PackAddress(i_geo, i_cha), -4096., -0.025, -4096., -0.200); return; } //------------------------------------------+----------------------------------- //! Setup calibration for one module. void TATOFparFbusCal::AddInfo(Int_t i_addr, Float_t f_offlow, Float_t f_faclow, Float_t f_offhigh, Float_t f_fachigh) { fInfo[i_addr] = TATOFparFbusCalInfo(f_offlow, f_faclow, f_offhigh, f_fachigh); return; } //------------------------------------------+----------------------------------- //! Add calibration infos from file \a name . Bool_t TATOFparFbusCal::AddFile(const TString& name) { TATOFconfigFile cf; if (cf.Open(name)) return kTRUE; while(cf.NextLine()) { Int_t i_geo, i_cha; Float_t f_offl, f_facl, f_offh, f_fach; Int_t i_n = sscanf(cf.CurrentLine().Data(), "%d %d %f %f %f %f", &i_geo, &i_cha, &f_offl, &f_facl, &f_offh, &f_fach); if (i_n == 6) { AddInfo(TATOFdatFbus::PackAddress(i_geo, i_cha), f_offl, f_facl, f_offh, f_fach); } else { Warning("AddFile()", "Conversion error in line:\n '%s'", cf.CurrentLine().Data()); } } return kFALSE; } //------------------------------------------+----------------------------------- //! Find calibration info for packed address \a i_addr. const TATOFparFbusCalInfo* TATOFparFbusCal::Find(Int_t i_addr) const { citer_t p_info = fInfo.find(i_addr); return (p_info != fInfo.end()) ? &(p_info->second) : 0; } //------------------------------------------+----------------------------------- //! Clear event. void TATOFparFbusCal::Clear(Option_t*) { TATOFpara::Clear(); fInfo.clear(); return; } /*------------------------------------------+---------------------------------*/ //! ostream insertion. void TATOFparFbusCal::ToStream(ostream& os, Option_t* option) const { os << "TATOFparFbusCal " << GetName() << endl; if (fInfo.size() == 0) return; os << "gei cha offlow faclow offhigh fachigh" << endl; for (citer_t p = fInfo.begin(); p != fInfo.end(); ++p) { os << Form("%3d %3d", TATOFdatFbus::GeoFromAddress(p->first), TATOFdatFbus::ChaFromAddress(p->first)) << Form(" %8.1f %8.5f", p->second.OffsetLow(), p->second.FactorLow()) << Form(" %8.1f %8.5f", p->second.OffsetHigh(), p->second.FactorHigh()) << endl; } return; }