diff --git a/core/detectors/trd/CbmTrdParModAsic.cxx b/core/detectors/trd/CbmTrdParModAsic.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0834aa8b16772434e7a347b6f24f129dd05a66c5 --- /dev/null +++ b/core/detectors/trd/CbmTrdParModAsic.cxx @@ -0,0 +1,163 @@ +/* Copyright (C) 2018-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Alexandru Bercuci [committer] */ + +#include "CbmTrdParModAsic.h" + +#include "CbmTrdDigi.h" // for eCbmTrdAsicType +#include "CbmTrdParAsic.h" // for CbmTrdParAsic +#include "CbmTrdParFasp.h" // for CbmTrdParFasp, NFASPCH, CbmTrdParFasp... +#include "CbmTrdParMod.h" // for CbmTrdParMod +#include "CbmTrdParSpadic.h" // for CbmTrdParSpadic, NSPADICCH + +#include <FairParamList.h> // for FairParamList +#include <Logger.h> // for Logger, LOG + +#include <TArrayI.h> // for TArrayI +#include <TGenericClassInfo.h> // for TGenericClassInfo +#include <TObjArray.h> +#include <TObjString.h> +#include <TString.h> // for Form +#include <TSystem.h> + +#include <utility> // for pair + +#include <stdint.h> // for size_t +#include <stdio.h> // for printf +#include <string.h> // for strcmp + +using std::map; +//_______________________________________________________________________________ +CbmTrdParModAsic::CbmTrdParModAsic(const char* name, const char* title) + : CbmTrdParMod(name, title) + , fType(8) + , fCrobAdd() + , fModPar() +{ +} + +//_______________________________________________________________________________ +void CbmTrdParModAsic::clear() +{ + for(auto asic : fModPar) delete asic.second; + fModPar.clear(); +} + +//_______________________________________________________________________________ +Int_t CbmTrdParModAsic::GetAsicAddress(Int_t chAddress) const +{ + /** Query the ASICs in the module set for the specified read-out channel. + * Returns the id of the ASIC within the module or -1 if all returns false. + */ + + for (auto asic : fModPar) { + if (asic.second->QueryChannel(chAddress) >= 0) return asic.first; + } + return -1; +} + +//_______________________________________________________________________________ +void CbmTrdParModAsic::GetAsicAddresses(std::vector<Int_t>* a) const +{ + /** Query the ASICs in the module set for their addresses. + * Returns the list of these addresses in the vector prepared by the user + */ + for (auto asic : fModPar) a->push_back(asic.first); +} + +//_______________________________________________________________________________ +const CbmTrdParAsic* CbmTrdParModAsic::GetAsicPar(Int_t address) const +{ + if (fModPar.find(address) == fModPar.end()) return nullptr; + return fModPar.at(address); +} + +//_______________________________________________________________________________ +CbmTrdParAsic* CbmTrdParModAsic::GetAsicPar(Int_t address) +{ + if (fModPar.find(address) == fModPar.end()) return nullptr; + return fModPar[address]; +} + +//_______________________________________________________________________________ +int CbmTrdParModAsic::GetNofAsics() const +{ + switch (fType) { + case 1: + return 80; + case 3: + return 20; + case 5: + return 180; + case 7: + return 36; + case 8: + return 24; + case 9: + return 180; + default: + LOG(warn) << GetName() << "::GetNofAsics : The chamber type " << fType << " has no mapping to ASICs. Skip."; + } + return 0; +} + +//_______________________________________________________________________________ +CbmTrdDigi::eCbmTrdAsicType CbmTrdParModAsic::GetAsicType() const +{ + switch (fType) { + case 1: + case 3: + case 5: + case 7: + case 8: + return CbmTrdDigi::eCbmTrdAsicType::kSPADIC; + case 9: + return CbmTrdDigi::eCbmTrdAsicType::kFASP; + default: + LOG(warn) << GetName() << "::GetAsicType : The chamber type " << fType << " has no mapping to ASICs. Skip."; + } + return CbmTrdDigi::eCbmTrdAsicType::kNTypes; +} + +//_______________________________________________________________________________ +void CbmTrdParModAsic::Print(Option_t* opt) const +{ + printf(" %s Asics[%d]\n", GetName(), GetNofAsics()); + if (strcmp(opt, "all") == 0) { + for (auto asic : fModPar) asic.second->Print(opt); + } +} + +//_______________________________________________________________________________ +void CbmTrdParModAsic::SetAsicPar(CbmTrdParAsic* p) +{ + int address = p->GetAddress(); + if (fModPar.find(address) != fModPar.end()) { + if (address % 1000 == 999) return; + LOG(warn) << GetName() << "::SetAsicPar : The ASIC @ " << address << " already initialized. Skip."; + return; + } + fModPar[address] = p; +} + +//_______________________________________________________________________________ +void CbmTrdParModAsic::SetCrobAddresses(int* addresses) +{ + switch (fType) { + case 1: + case 3: + case 5: + case 7: + case 8: + fCrobAdd[0] = addresses[0]; + break; + case 9: + for (int i(0); i < NCROBMOD; i++) fCrobAdd[i] = addresses[i]; + break; + default: + LOG(warn) << GetName() << "::SetCrobAddresses : The chamber type " << fType << " has no mapping to CROBs. Skip."; + } +} + + +ClassImp(CbmTrdParModAsic) diff --git a/core/detectors/trd/CbmTrdParModAsic.h b/core/detectors/trd/CbmTrdParModAsic.h new file mode 100644 index 0000000000000000000000000000000000000000..7a8e2cf5ea0ac602973ec059908a2c2f2ac065fd --- /dev/null +++ b/core/detectors/trd/CbmTrdParModAsic.h @@ -0,0 +1,102 @@ +/* Copyright (C) 2018-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Alexandru Bercuci [committer] */ + +#ifndef CBMTRDPARMODASIC_H +#define CBMTRDPARMODASIC_H + +#include "CbmTrdDigi.h" // for CbmTrdDigi::eCbmTrdAsicType +#include "CbmTrdParMod.h" // for CbmTrdParSet + +#include <Rtypes.h> // for THashConsistencyHolder, ClassDef +#include <RtypesCore.h> // for Int_t, Bool_t, Option_t, UChar_t + +#include <map> // for map +#include <vector> // for vector + +class CbmTrdParAsic; +class FairParamList; + +/** + * \brief Describe TRD module ASIC settings (electronic gain, delays, etc) + * + * The following concepts are used : + * - DAQ id : unique id of an ASIC composed of the format modId*1000+asicId. + * - modId : is calculated according to the CbmTrdAddress::GetModuleId(). + * - asicId : uniquely identify the ASICs in one module. + * - chAddress : identify the read-out pad(s) connected to the ASIC. In the case of FASP it distinguish between R and T pairing + **/ +class CbmTrdParModAsic : public CbmTrdParMod { +friend class CbmTrdParSetAsic; +public: + /** Standard constructor **/ + CbmTrdParModAsic(const char* name = "CbmTrdParModAsic", const char* title = "Generic list of ASICs for TRD modules"); + + /** \brief Destructor **/ + virtual ~CbmTrdParModAsic() { clear();} + + /** \brief Reset all parameters **/ + virtual void clear(); + + /** \brief Query the ASICs in the module for their DAQ address. + * It applies to the list of ASICs. + * Returns the list of id of the ASICs within the module. + */ + virtual void GetAsicAddresses(std::vector<Int_t>* a) const; + /** \brief Look for the ASIC which operates on a specific channel + * It applies to the list of ASICs. + *\param chAddress Pad address of the channel + *\return id of the ASIC operating on the channel. -1 in case of failure + */ + virtual Int_t GetAsicAddress(Int_t chAddress) const; + /** \brief Look for the ASIC parameters of a given DAQ id + * It applies to the list of ASICs. + * \param address ASIC address from DAQ + * \return A read-only pointer to the parameters + */ + virtual const CbmTrdParAsic* GetAsicPar(Int_t address) const; + /** \brief Look for the ASIC parameters of a given DAQ id + * It applies to the list of ASICs. + * \param address ASIC address from DAQ + * \return A read-write pointer to the parameters + */ + virtual CbmTrdParAsic* GetAsicPar(Int_t address); + + /** \brief Query the type of ASICs in the list*/ + virtual CbmTrdDigi::eCbmTrdAsicType GetAsicType() const; + + /** \brief Query the type of chamber*/ + virtual Int_t GetChamberType() const { return fType; } + + /** \brief Query the type of chamber*/ + virtual const int* GetCrobAddresses() const { return fCrobAdd.data(); } + + /** \brief Returns the number of INSTALLED ASICs for the current module + * It applies to the list of ASICs. + */ + virtual size_t GetNofAsicsOnModule() const { return fModPar.size(); } + + /** \brief Returns the DEFAULT number of ASICs for the current module + */ + virtual int GetNofAsics() const; + + virtual void Print(Option_t* opt = "") const; + /** \brief Initialize the ASIC parameters for DAQ id + * It applies to the list of ASICs. + */ + virtual void SetAsicPar(CbmTrdParAsic* p); + virtual void SetChamberType(Int_t t) { fType = t; } + /** \brief Initialize the CROB addresses as they are used in the DAQ*/ + virtual void SetCrobAddresses(int* addresses); + +protected: + CbmTrdParModAsic(const CbmTrdParModAsic& ref); + const CbmTrdParModAsic& operator=(const CbmTrdParModAsic& ref); + + uint8_t fType; ///< type of chamber for current module + std::vector<int> fCrobAdd; ///< ordered list of Crobs for current module + std::map<int, CbmTrdParAsic*> fModPar; ///< list of ASIC params for module + ClassDef(CbmTrdParModAsic, + 1); // The set of ASICs for one TRD modules +}; +#endif