#include #include #include "TSystem.h" #include "TString.h" #include "TATOFparMap.h" /*! \class TATOFparMapAddr TATOFparMap.h "TATOFparMap.h" \brief Hardware address mapping info for the ALADiN ToF-Wall. ** */ ClassImp(TATOFparMapAddr); //------------------------------------------+----------------------------------- //! Destructor. TATOFparMapAddr::~TATOFparMapAddr() {} //############################################################################## /*! \class TATparMapSlat TATOFparMap.h "TATOFparMap.h" \brief Hardware slat info for the ALADiN ToF-Wall. ** */ ClassImp(TATOFparMapSlat); //------------------------------------------+----------------------------------- //! Destructor. TATOFparMapSlat::~TATOFparMapSlat() {} //############################################################################## /*! \class TATOFparMap TATOFparMap.h "TATOFparMap.h" \brief Map and Geometry parameters for the ALADiN ToF-Wall. ** */ ClassImp(TATOFparMap); //------------------------------------------+----------------------------------- //! Default constructor. TATOFparMap::TATOFparMap() {} //TATOFparMap::TATOFparMap() // : fAddrInfo(dim_addr), // fSlatInfo(dim_slat) //{} //------------------------------------------+----------------------------------- //! Destructor. TATOFparMap::~TATOFparMap() {} //------------------------------------------+----------------------------------- //! Setup mapping data for a single slat. Bool_t TATOFparMap::SetupSlat(Int_t i_slat, Int_t i_type, Int_t i_packid, Int_t i_slatid, Int_t i_adct_g, Int_t i_adct_c, Int_t i_adcb_g, Int_t i_adcb_c, Int_t i_tdct_g, Int_t i_tdct_c, Int_t i_tdcb_g, Int_t i_tdcb_c, Int_t i_thisleft, Int_t i_thisright, Int_t i_otherleft, Int_t i_otherright) { if (CheckSlat(i_slat) || CheckSlat(i_thisleft) || CheckSlat(i_thisright) || CheckSlat(i_otherleft) || CheckSlat(i_otherright) || CheckAddr(i_adct_g, i_adct_c) || CheckAddr(i_adcb_g, i_adcb_c) || CheckAddr(i_tdct_g, i_tdct_c) || CheckAddr(i_tdcb_g, i_tdcb_c)) return kTRUE; Int_t i_adct = PackAddress(i_adct_g, i_adct_c); Int_t i_adcb = PackAddress(i_adcb_g, i_adcb_c); Int_t i_tdct = PackAddress(i_tdct_g, i_tdct_c); Int_t i_tdcb = PackAddress(i_tdcb_g, i_tdcb_c); if (CheckMap(i_adct, i_slat) || CheckMap(i_adcb, i_slat) || CheckMap(i_tdct, i_slat) || CheckMap(i_tdcb, i_slat)) return kTRUE; fAddrInfo[i_adct].SetData(i_slat, 1); fAddrInfo[i_adcb].SetData(i_slat, 2); fAddrInfo[i_tdct].SetData(i_slat, 3); fAddrInfo[i_tdcb].SetData(i_slat, 4); fSlatInfo[i_slat].SetData(i_type, i_packid, i_slatid, i_adct, i_adcb, i_tdct, i_tdcb, i_thisleft, i_thisright, i_otherleft, i_otherright); return kFALSE; } //------------------------------------------+----------------------------------- //! Read mapping data from file \a name . Bool_t TATOFparMap::FromFile(const TString& name) { Clear(); TString name_exp = name; gSystem->ExpandPathName(name_exp); ifstream ifs; ifs.open(name_exp.Data()); if (!ifs) { Error("FromFile()", "failed to open file '%s'", name_exp.Data()); return kTRUE; } char buf[1024]; Int_t i_nline = 0; while (ifs.good()) { Int_t i_slat, i_type; Int_t i_packid, i_slatid; Int_t i_adct_g, i_adct_c; Int_t i_adcb_g, i_adcb_c; Int_t i_tdct_g, i_tdct_c; Int_t i_tdcb_g, i_tdcb_c; Int_t i_thisleft, i_thisright; Int_t i_otherleft, i_otherright; ifs.getline(buf, 1024); Int_t i_len = strlen(buf); if (i_len > 0 && buf[i_len-1] == '\n') { buf[i_len-1] = 0; i_len -= 1; } i_nline += 1; if (i_len == 0 && ifs.good()) continue; if (i_len == 0) continue; if (buf[0] == '#') continue; Int_t i_nv = sscanf(buf, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &i_slat, &i_type, &i_packid, &i_slatid, &i_adct_g, &i_adct_c, &i_adcb_g, &i_adcb_c, &i_tdct_g, &i_tdct_c, &i_tdcb_g, &i_tdcb_c, &i_thisleft, &i_thisright, &i_otherleft, &i_otherright); if (i_nv != 16) { Error("FromFile()", "conversion error in line %d\n`%s'", i_nline, buf); continue; } if (SetupSlat(i_slat, i_type, i_packid, i_slatid, i_adct_g, i_adct_c, i_adcb_g, i_adcb_c, i_tdct_g, i_tdct_c, i_tdcb_g, i_tdcb_c, i_thisleft, i_thisright, i_otherleft, i_otherright)) { Error("FromFile()", "data error in line %d\n`%s'", i_nline, buf); continue; } } return kFALSE; } //------------------------------------------+----------------------------------- //! Clear event. void TATOFparMap::Clear(Option_t*) { TATOFpara::Clear(); fAddrInfo.clear(); fAddrInfo.resize(dim_addr); fSlatInfo.clear(); fSlatInfo.resize(dim_slat); return; } /*------------------------------------------+---------------------------------*/ //! ostream insertion. void TATOFparMap::ToStream(ostream& os, Option_t* option) const { os << "TATparMap " << GetName() << endl; os << "slat typ pack adct adcb tdct tdcb Neighbour's " << endl; os << " p s g c g c g c g c l r pl pr" << endl; for (Int_t i = 0; i < MaxSlat(); i++) { const TATOFparMapSlat& slatinfo = SlatInfo(i); if (slatinfo.Type() == 0) continue; os << Form("%4d", i) << Form(" %2d", slatinfo.Type()) << Form(" %2d %1d", slatinfo.PackId(), slatinfo.SlatId()) << Form(" %2d %2d", GeoFromAddress(slatinfo.AddressAdct()), ChaFromAddress(slatinfo.AddressAdct())) << Form(" %2d %2d", GeoFromAddress(slatinfo.AddressAdcb()), ChaFromAddress(slatinfo.AddressAdcb())) << Form(" %2d %2d", GeoFromAddress(slatinfo.AddressTdct()), ChaFromAddress(slatinfo.AddressTdct())) << Form(" %2d %2d", GeoFromAddress(slatinfo.AddressTdcb()), ChaFromAddress(slatinfo.AddressTdcb())) << Form(" %3d", slatinfo.NeighborThisLeft()) << Form(" %3d", slatinfo.NeighborThisRight()) << Form(" %3d", slatinfo.NeighborOtherLeft()) << Form(" %3d", slatinfo.NeighborOtherRight()) << endl; } return; } /*------------------------------------------+---------------------------------*/ //! Returns \c true if slat number \a i_slat is out of range Bool_t TATOFparMap::CheckSlat(Int_t i_slat) const { if (i_slat >= 0 && i_slat < dim_slat) return kFALSE; Error("CheckSlat()", "slat number %d out of range", i_slat); return kTRUE; } /*------------------------------------------+---------------------------------*/ //! Returns \c true if slat number \a i_slat is out of range Bool_t TATOFparMap::CheckAddr(Int_t i_g, Int_t i_c) const { if (i_g >= 0 && i_g < dim_geo && i_c >= 0 && i_c < dim_cha ) return kFALSE; Error("CheckAddr()", "FastBus address (g,c) = (%d,%d) out of range", i_g,i_c); return kTRUE; } /*------------------------------------------+---------------------------------*/ //! Returns \c true if map for address \a i_addr is already occupied. Bool_t TATOFparMap::CheckMap(Int_t i_addr, Int_t i_slat) const { if (fAddrInfo[i_addr].Slat() == 0) return kFALSE; Int_t i_g = GeoFromAddress(i_addr); Int_t i_c = ChaFromAddress(i_addr); Error("CheckMap()", "Map conflict - slat %d overwrites mapping for" " (g,c) = (%d,%d) to slat %d", i_slat, i_g, i_c, fAddrInfo[i_addr].Slat()); return kTRUE; } /*------------------------------------------+---------------------------------*/ //! Returns \c true if map for address \a i_addr is actually occupied - ALF Bool_t TATOFparMap::CheckMap2(Int_t i_addr) const { //printf("TEST HERE0, i_addr=%d\n",i_addr); if (fAddrInfo[i_addr].Slat() == 0) { //printf("TEST HERE\n"); return kFALSE; } return kTRUE; } //! Returns the slat number related to i_addr - ALF, 01/2013 Int_t TATOFparMap::SlatFromAddress(Int_t i_addr) const { return fAddrInfo[i_addr].Slat(); } //! Returns the info type related to i_addr - ALF, 01/2013 Int_t TATOFparMap::TypeFromAddress(Int_t i_addr) const { return fAddrInfo[i_addr].Type(); } //! Returns the info type (front or rear wall) related to i_slat - ALF, 01/2013 Int_t TATOFparMap::TypeFromSlat(Int_t i_slat) const { return fSlatInfo[i_slat].Type(); } //! Returns the left neighbor slat related to i_slat - ALF, 01/2013 Int_t TATOFparMap::NeighborThisLeftFromSlat(Int_t i_slat) const { return fSlatInfo[i_slat].NeighborThisLeft(); } //! Returns the right neighbor slat related to i_slat - ALF, 01/2013 Int_t TATOFparMap::NeighborThisRightFromSlat(Int_t i_slat) const { return fSlatInfo[i_slat].NeighborThisRight(); } //! Returns the left neighbor slat of the other wall related to i_slat - ALF, 01/2013 Int_t TATOFparMap::NeighborOtherLeftFromSlat(Int_t i_slat) const { return fSlatInfo[i_slat].NeighborOtherLeft(); } //! Returns the right neighbor slat of the other wall related to i_slat - ALF, 01/2013 Int_t TATOFparMap::NeighborOtherRightFromSlat(Int_t i_slat) const { return fSlatInfo[i_slat].NeighborOtherRight(); }