CbmRoot
Loading...
Searching...
No Matches
CbmTrdParSetAsic.cxx
Go to the documentation of this file.
1/* Copyright (C) 2018-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Florian Uhlig [committer], Alexandru Bercuci */
4
5#include "CbmTrdParSetAsic.h"
6
7#include "CbmTrdDigi.h" // for eCbmTrdAsicType
8#include "CbmTrdParAsic.h" // for CbmTrdParAsic
9#include "CbmTrdParFasp.h" // for CbmTrdParFasp, NFASPCH, CbmTrdParFasp...
10#include "CbmTrdParMod.h" // for CbmTrdParMod
11#include "CbmTrdParModAsic.h" // for CbmTrdParModAsic
12#include "CbmTrdParSpadic.h" // for CbmTrdParSpadic, NSPADICCH
13
14#include <FairParamList.h> // for FairParamList
15#include <Logger.h> // for Logger, LOG
16
17#include <TArrayI.h> // for TArrayI
18#include <TGenericClassInfo.h> // for TGenericClassInfo
19#include <TObjArray.h>
20#include <TObjString.h>
21#include <TString.h> // for Form
22#include <TSystem.h>
23
24#include <utility> // for pair
25
26#include <stdint.h> // for size_t
27#include <stdio.h> // for printf
28#include <string.h> // for strcmp
29
30using std::map;
31//_______________________________________________________________________________
32CbmTrdParSetAsic::CbmTrdParSetAsic(const char* name, const char* title, const char* context)
33 : CbmTrdParSet(name, title, context)
34{
35}
36
37//_______________________________________________________________________________
38int CbmTrdParSetAsic::FindModuleByEqId(uint16_t eqid, uint8_t& crob_id, uint8_t& lnk_id) const
39{
40 for (auto mod : fModuleMap) {
41 int crob = ((const CbmTrdParModAsic*) mod.second)->HasEqId(eqid, lnk_id);
42 if (crob < 0) continue;
43 crob_id = crob;
44 return mod.first;
45 }
46 return -1;
47}
48
49//_______________________________________________________________________________
50Bool_t CbmTrdParSetAsic::getParams(FairParamList* l)
51{
52 // LOG(info) << GetName() << "::getParams(FairParamList*)";
53 if (!l) return kFALSE;
54 if (!l->fill("NrOfModules", &fNrOfModules)) return kFALSE;
55 TArrayI moduleId(fNrOfModules);
56 if (!l->fill("ModuleId", &moduleId)) return kFALSE;
57 TArrayI nAsic(fNrOfModules);
58 if (!l->fill("nAsic", &nAsic)) return kFALSE;
59 TArrayI typeAsic(fNrOfModules);
60 if (!l->fill("typeAsic", &typeAsic)) return kFALSE;
61
62 Int_t maxNrAsics {0};
63 for (Int_t imod = 0; imod < fNrOfModules; imod++) {
64 if (nAsic[imod] > maxNrAsics) maxNrAsics = nAsic[imod];
65 }
66 Int_t address(0);
67
68 CbmTrdParModAsic* mod(nullptr);
69 CbmTrdParAsic* asic(nullptr);
70 for (Int_t i = 0; i < fNrOfModules; i++) {
71 mod = new CbmTrdParModAsic(GetName(), Form("%s for Module %d", GetTitle(), moduleId[i]));
72 mod->SetChamberType(typeAsic[i]);
73 mod->SetModuleId(moduleId[i]);
74 // only for FASP
75 if (9 == typeAsic[i]) {
76 TArrayI crobAddress(int(NCROBMOD));
77 if (!l->fill(Form("CrobInfo - Module %d", moduleId[i]), &crobAddress)) continue;
78 mod->SetCrobAddresses(crobAddress.GetArray());
79 Int_t maxValues = maxNrAsics * int(NFASPPARS);
80 TArrayI values(maxValues);
81 if (!l->fill(Form("FaspInfo - Module %d", moduleId[i]), &values)) continue;
82 for (Int_t iasic = 0; iasic < nAsic[i]; iasic++) {
83 Int_t offset = iasic * int(NFASPPARS);
84 address = values[offset++];
85 if (address == moduleId[i] * 1000 + 999) continue;
86 asic = new CbmTrdParFasp(address);
87 static_cast<CbmTrdParFasp*>(asic)->LoadParams(&(values.GetArray()[offset]));
88 mod->SetAsicPar(asic);
89 }
90 }
91 else {
92 Int_t maxValues = maxNrAsics * (5 + NSPADICCH);
93 TArrayI values(maxValues);
94
95 if (!l->fill(Form("SpadicInfo - Module %d", moduleId[i]), &values)) continue;
96 for (Int_t iasic = 0; iasic < nAsic[i]; iasic++) {
97 Int_t offset = iasic * (5 + NSPADICCH);
98 address = values[offset + 0];
99 asic = new CbmTrdParSpadic(address);
100 asic->SetComponentId(static_cast<CbmTrdParSpadic*>(asic)->CreateComponentId(
101 values[offset + 1], values[offset + 2], values[offset + 3], values[offset + 4]));
102 std::vector<Int_t> addresses {};
103 for (Int_t j = offset + 5; j < offset + 5 + NSPADICCH; j++) {
104 addresses.push_back(values[j]);
105 }
106 asic->SetChannelAddresses(addresses);
107 mod->SetAsicPar(asic);
108 }
109 }
110 fModuleMap[moduleId[i]] = mod;
111 }
112 return kTRUE;
113}
114
115//_______________________________________________________________________________
116void CbmTrdParSetAsic::putParams(FairParamList* l)
117{
118 if (!l) return;
119 // LOG(info) << GetName() << "::putParams(FairParamList*)";
120
121 Int_t idx(0);
122 TArrayI moduleId(fNrOfModules), nAsic(fNrOfModules), typeChmb(fNrOfModules);
123 for (auto mod : fModuleMap) {
124 moduleId[idx] = mod.first;
125 nAsic[idx] = ((CbmTrdParModAsic*) mod.second)->GetNofAsics();
126 typeChmb[idx] = ((CbmTrdParModAsic*) mod.second)->GetChamberType();
127 idx++;
128 }
129 l->add("NrOfModules", fNrOfModules);
130 l->add("ModuleId", moduleId);
131 l->add("nAsic", nAsic);
132 l->add("typeAsic", typeChmb);
133
134 idx = 0;
135 for (auto mapEntry : fModuleMap) {
136 Int_t iAsicNr(0);
137 Int_t currentAsicAddress(-1);
138
139 CbmTrdParModAsic* mod = (CbmTrdParModAsic*) mapEntry.second;
141 // Calculate the size of the array to hold all values realted to all
142 // asics of a full detector module
143 // each ASCIC has a maximum of NSPADICCH channels attached + 5 values
144 // for AsicID, CriId, CrobId, CrobNumber and ElinkId
145 Int_t sizePerSpadic = 5 + NSPADICCH;
146 Int_t fullSize = nAsic[idx] * sizePerSpadic;
147 TArrayI asicInfo(fullSize);
148 iAsicNr = 0;
149 for (auto iModuleIt : mod->fModPar) {
150 size_t asicComponentId(100098); // 100098 = undefined
151 currentAsicAddress = iModuleIt.first;
152 asicComponentId = ((CbmTrdParSpadic*) iModuleIt.second)->GetComponentId();
153 int offset = iAsicNr * sizePerSpadic;
154 asicInfo[offset] = currentAsicAddress;
155 asicInfo[offset + 1] = CbmTrdParSpadic::GetCriId(asicComponentId);
156 asicInfo[offset + 2] = CbmTrdParSpadic::GetCrobId(asicComponentId);
157 asicInfo[offset + 3] = CbmTrdParSpadic::GetCrobNumber(asicComponentId);
158 asicInfo[offset + 4] = CbmTrdParSpadic::GetElinkId(asicComponentId, 0);
159
160 if ((((CbmTrdParSpadic*) iModuleIt.second)->GetNchannels()) != NSPADICCH) {
161 LOG(fatal) << "Number of channels found " << ((CbmTrdParSpadic*) iModuleIt.second)->GetNchannels()
162 << " is differnt from the expected " << NSPADICCH;
163 }
164
165 Int_t iAsicChannel(0);
166 for (auto channelAddressIt : ((CbmTrdParSpadic*) iModuleIt.second)->GetChannelAddresses()) {
167 asicInfo[offset + 5 + iAsicChannel] = channelAddressIt;
168 iAsicChannel++;
169 }
170 iAsicNr++;
171 }
172 l->add(Form("SpadicInfo - Module %d", mapEntry.first), asicInfo);
173 }
175 TArrayI crobAddress(int(NCROBMOD));
176 crobAddress.Set(int(NCROBMOD), mod->GetCrobAddresses());
177 l->add(Form("CrobInfo - Module %d", mapEntry.first), crobAddress);
178 int fullSize = nAsic[idx] * int(NFASPPARS);
179 TArrayI asicInfo(fullSize);
180
181 iAsicNr = 0;
182 for (auto iModuleIt : mod->fModPar) {
183 int offset = iAsicNr * int(NFASPPARS);
184 asicInfo[offset++] = iModuleIt.first;
185
186 CbmTrdParFasp* fasp = (CbmTrdParFasp*) iModuleIt.second;
187 asicInfo[offset++] = fasp->GetChannelMask();
188 Int_t ich(0);
189 for (auto chAddress : fasp->GetChannelAddresses()) {
190 const CbmTrdParFaspChannel* ch = fasp->GetChannel(ich);
191 if (!ch) {
192 LOG(info) << "Missing calib for Fasp[" << offset << "] pad " << chAddress;
193 ich++;
194 continue;
195 }
196 asicInfo[offset + ich] = (ch->HasPairingT() ? -1 : 1) * chAddress;
197 asicInfo[offset + (1 * NFASPCH) + ich] = ch->GetPileUpTime();
198 asicInfo[offset + (2 * NFASPCH) + ich] = ch->GetThreshold();
199 asicInfo[offset + (3 * NFASPCH) + ich] = ch->GetMinDelaySignal();
200 ich++;
201 }
202 iAsicNr++;
203 }
204 l->add(Form("FaspInfo - Module %d", mapEntry.first), asicInfo);
205 }
206 idx++;
207 }
208}
209
ClassImp(CbmConverterManager)
#define NFASPPARS
#define NSPADICCH
Definition of ASIC parameters.
virtual std::vector< Int_t > GetChannelAddresses() const
virtual void SetComponentId(size_t id)
virtual void SetChannelAddresses(std::vector< Int_t > addresses)
Definition of FASP channel calibration container.
Int_t GetMinDelaySignal() const
Bool_t HasPairingT() const
Int_t GetPileUpTime() const
Int_t GetThreshold() const
Definition of FASP parameters.
const CbmTrdParFaspChannel * GetChannel(Int_t pad_address, UChar_t pair) const
Query the calibration for one FASP RO channel.
virtual uint32_t GetChannelMask() const
Describe TRD module ASIC settings (electronic gain, delays, etc)
virtual void SetCrobAddresses(int *addresses)
Initialize the CROB addresses as they are used in the DAQ.
std::map< int, CbmTrdParAsic * > fModPar
list of ASIC params for module
virtual void SetChamberType(Int_t t)
virtual CbmTrdDigi::eCbmTrdAsicType GetAsicType() const
Query the type of ASICs in the list.
virtual const int32_t * GetCrobAddresses() const
Query the type of chamber.
virtual void SetAsicPar(CbmTrdParAsic *p)
Initialize the ASIC parameters for DAQ id It applies to the list of ASICs.
virtual void SetModuleId(int m)
Describe TRD module ASIC settings (electronic gain, delays, etc)
CbmTrdParSetAsic(const char *name="CbmTrdParSetAsic", const char *title="TRD ASIC parameters", const char *context="Default")
Bool_t getParams(FairParamList *)
Build the ASICs par for the current module from the info stored in the param file It applies to the l...
void putParams(FairParamList *)
Store the ASICs par info for the current module into the param file It applies to the list of ASICs.
virtual int FindModuleByEqId(uint16_t eqid, uint8_t &rob_id, uint8_t &lnk_id) const
Search for the module in the setup parameters by equipement id.
std::map< Int_t, CbmTrdParMod * > fModuleMap
Int_t fNrOfModules
no of modules in the current run
Definition of SPADIC parameters.
std::uint8_t GetCrobId()
std::uint16_t GetCriId()
std::uint8_t GetCrobNumber()
static std::uint8_t GetElinkId(size_t componentId, Int_t channelId)
eLinkId for the given asicAddress and channelId (in the asic coordinates, i.e. 00....
#define NCROBMOD
#define NFASPCH