CbmRoot
CbmTrdParSetAsic.cxx
Go to the documentation of this file.
1 #include "CbmTrdParSetAsic.h"
2 
3 #include "CbmTrdParAsic.h" // for CbmTrdParAsic
4 #include "CbmTrdParFasp.h" // for CbmTrdParFasp, NFASPCH, CbmTrdParFasp...
5 #include "CbmTrdParMod.h" // for CbmTrdParMod
6 #include "CbmTrdParSpadic.h" // for CbmTrdParSpadic, NSPADICCH
7 
8 #include <FairLogger.h> // for Logger, LOG
9 #include <FairParamList.h> // for FairParamList
10 
11 #include <TArrayI.h> // for TArrayI
12 #include <TGenericClassInfo.h> // for TGenericClassInfo
13 #include <TString.h> // for Form
14 
15 #include <stdint.h> // for uint64_t
16 #include <stdio.h> // for printf
17 #include <string.h> // for strcmp
18 #include <utility> // for pair
19 
20 using std::map;
21 //_______________________________________________________________________________
23  const char* title,
24  const char* context)
25  : CbmTrdParSet(name, title, context), fType(8), fModPar() {}
26 
27 //_______________________________________________________________________________
29  if (fNrOfModules) {
30  // std::map<Int_t, CbmTrdParSetAsic*>::iterator it=fModPar.begin();
31  // while(it!=fModPar.end()){
32  // if(it->second) delete it->second;
33  // it++;
34  // }
35  fModPar.clear();
36  }
37 }
38 //_______________________________________________________________________________
39 Bool_t CbmTrdParSetAsic::getParams(FairParamList* l) {
40  if (!l) return kFALSE;
41  if (!l->fill("NrOfModules", &fNrOfModules)) return kFALSE;
42  TArrayI moduleId(fNrOfModules);
43  if (!l->fill("ModuleId", &moduleId)) return kFALSE;
44  TArrayI nAsic(fNrOfModules);
45  if (!l->fill("nAsic", &nAsic)) return kFALSE;
46  TArrayI typeAsic(fNrOfModules);
47  if (!l->fill("typeAsic", &typeAsic)) return kFALSE;
48 
49  Int_t maxNrAsics {0};
50  for (Int_t imod = 0; imod < fNrOfModules; imod++) {
51  if (nAsic[imod] > maxNrAsics) maxNrAsics = nAsic[imod];
52  }
53  Int_t address(0);
54 
55  CbmTrdParAsic* asic(nullptr);
56  for (Int_t i = 0; i < fNrOfModules; i++) {
57  fModPar[moduleId[i]] = new CbmTrdParSetAsic(
58  GetName(),
59  Form("%s for Module %d", GetTitle(), moduleId[i]) /*, GetContext()*/);
60  // only for FASP
61  if (9 == typeAsic[i]) {
62  Int_t sizePerFasp = 1 + NFASPCH * 4;
63  Int_t maxValues = maxNrAsics * (sizePerFasp);
64  TArrayI values(maxValues);
65  if (!l->fill(Form("FaspInfo - Module %d", moduleId[i]), &values))
66  continue;
67  for (Int_t iasic = 0; iasic < nAsic[i]; iasic++) {
68  Int_t offset = iasic * (sizePerFasp);
69  address = values[offset + 0];
70  asic = new CbmTrdParFasp(address);
71  static_cast<CbmTrdParFasp*>(asic)->LoadParams(values, iasic);
72  fModPar[moduleId[i]]->SetAsicPar(address, asic);
73  }
74  } else {
75  Int_t maxValues = maxNrAsics * (5 + NSPADICCH);
76  TArrayI values(maxValues);
77 
78  if (!l->fill(Form("SpadicInfo - Module %d", moduleId[i]), &values))
79  continue;
80  for (Int_t iasic = 0; iasic < nAsic[i]; iasic++) {
81  Int_t offset = iasic * (5 + NSPADICCH);
82  address = values[offset + 0];
83  asic = new CbmTrdParSpadic(address);
84  asic->SetComponentId(
85  static_cast<CbmTrdParSpadic*>(asic)->CreateComponentId(
86  values[offset + 1],
87  values[offset + 2],
88  values[offset + 3],
89  values[offset + 4]));
90  std::vector<Int_t> addresses {};
91  for (Int_t j = offset + 5; j < offset + 5 + NSPADICCH; j++) {
92  addresses.push_back(values[j]);
93  }
94  asic->SetChannelAddresses(addresses);
95  fModPar[moduleId[i]]->SetAsicPar(address, asic);
96  }
97  }
98  }
99  return kTRUE;
100 }
101 
102 //_______________________________________________________________________________
103 void CbmTrdParSetAsic::putParams(FairParamList* l) {
104  if (!l) return;
105  LOG(info) << GetName() << "::putParams(FairParamList*)";
106 
107  Int_t idx(0);
108  TArrayI moduleId(fNrOfModules), nAsic(fNrOfModules), typeAsic(fNrOfModules);
109  for (std::map<Int_t, CbmTrdParSetAsic*>::iterator imod = fModPar.begin();
110  imod != fModPar.end();
111  imod++) {
112  moduleId[idx] = imod->first;
113  nAsic[idx] = imod->second->GetNofAsics();
114  typeAsic[idx++] = imod->second->GetAsicType();
115  }
116  l->add("NrOfModules", fNrOfModules);
117  l->add("ModuleId", moduleId);
118  l->add("nAsic", nAsic);
119  l->add("typeAsic", typeAsic);
120 
121  CbmTrdParSetAsic* mod(nullptr);
122  for (Int_t i = 0; i < fNrOfModules; i++) {
123  mod = (CbmTrdParSetAsic*) fModPar[moduleId[i]];
124 
125  Int_t iAsicNr(0);
126  Int_t currentAsicAddress(-1);
127 
128  if (mod->fModuleMap.begin()->second->IsA() == CbmTrdParSpadic::Class()) {
129  // Calculate the size of the array to hold all values realted to all
130  // asics of a full detector module
131  // each ASCIC has a maximum of NSPADICCH channels attached + 5 values
132  // for AsicID, CriId, CrobId, CrobNumber and ElinkId
133  Int_t sizePerSpadic = 5 + NSPADICCH;
134  Int_t fullSize = nAsic[i] * sizePerSpadic;
135  TArrayI asicInfo(fullSize);
136  iAsicNr = 0;
137  for (auto iModuleIt : mod->fModuleMap) {
138  std::uint64_t asicComponentId(100098); // 100098 = undefined
139  currentAsicAddress = iModuleIt.first;
140  asicComponentId =
141  ((CbmTrdParSpadic*) iModuleIt.second)->GetComponentId();
142  int offset = iAsicNr * sizePerSpadic;
143  asicInfo[offset] = currentAsicAddress;
144  asicInfo[offset + 1] = CbmTrdParSpadic::GetCriId(asicComponentId);
145  asicInfo[offset + 2] = CbmTrdParSpadic::GetCrobId(asicComponentId);
146  asicInfo[offset + 3] = CbmTrdParSpadic::GetCrobNumber(asicComponentId);
147  asicInfo[offset + 4] = CbmTrdParSpadic::GetElinkId(asicComponentId, 0);
148 
149  if ((((CbmTrdParSpadic*) iModuleIt.second)->GetNchannels())
150  != NSPADICCH) {
151  LOG(fatal) << "Number of channels found "
152  << ((CbmTrdParSpadic*) iModuleIt.second)->GetNchannels()
153  << " is differnt from the expected " << NSPADICCH;
154  }
155 
156  Int_t iAsicChannel(0);
157  for (auto channelAddressIt :
158  ((CbmTrdParSpadic*) iModuleIt.second)->GetChannelAddresses()) {
159  asicInfo[offset + 5 + iAsicChannel] = channelAddressIt;
160  iAsicChannel++;
161  }
162  iAsicNr++;
163  }
164  l->add(Form("SpadicInfo - Module %d", moduleId[i]), asicInfo);
165  }
166  if (mod->fModuleMap.begin()->second->IsA() == CbmTrdParFasp::Class()) {
167 
168  Int_t sizePerFasp = 1 + NFASPCH * 4;
169  Int_t fullSize = nAsic[i] * sizePerFasp;
170  TArrayI asicInfo(fullSize);
171 
172  iAsicNr = 0;
173  for (auto iModuleIt : mod->fModuleMap) {
174  int offset = iAsicNr * sizePerFasp;
175  asicInfo[offset] = iModuleIt.first;
176  Int_t nchannels(((CbmTrdParAsic*) iModuleIt.second)->GetNchannels());
177  CbmTrdParFasp* fasp = (CbmTrdParFasp*) iModuleIt.second;
178 
179  for (Int_t ich(0); ich < nchannels; ich += 2) {
180  for (Int_t ipair(0); ipair < 2; ipair++) {
181  Int_t faspAddress = fasp->GetChannelAddress(ich);
182  const CbmTrdParFaspChannel* ch =
183  fasp->GetChannel(faspAddress, ipair);
184  asicInfo[offset + 1 + ich + ipair] = faspAddress;
185  asicInfo[offset + 1 + (1 * NFASPCH) + ich + ipair] =
186  ch->GetPileUpTime();
187  asicInfo[offset + 1 + (2 * NFASPCH) + ich + ipair] =
188  ch->GetThreshold();
189  asicInfo[offset + 1 + (3 * NFASPCH) + ich + ipair] =
190  ch->GetMinDelaySignal();
191  }
192  }
193  iAsicNr++;
194  }
195  l->add(Form("FaspInfo - Module %d", moduleId[i]), asicInfo);
196  }
197  }
198 }
199 
200 //_______________________________________________________________________________
202  //printf("CbmTrdParSetAsic::addParam() :\n");
203 
204  fModPar[mod->fModuleMap.begin()->first / 1000] = mod;
205  fNrOfModules++;
206 }
207 
208 //_______________________________________________________________________________
209 Int_t CbmTrdParSetAsic::GetAsicAddress(Int_t chAddress) const {
213  std::map<Int_t, CbmTrdParMod*>::const_iterator it = fModuleMap.begin();
214  CbmTrdParAsic* asic(nullptr);
215  while (it != fModuleMap.end()) {
216  asic = (CbmTrdParAsic*) it->second;
217  if (asic->QueryChannel(chAddress) >= 0) return it->first;
218  it++;
219  }
220  return -1;
221 }
222 
223 //_______________________________________________________________________________
224 void CbmTrdParSetAsic::GetAsicAddresses(std::vector<Int_t>* a) const {
228  std::map<Int_t, CbmTrdParMod*>::const_iterator it = fModuleMap.begin();
229  CbmTrdParAsic* asic(nullptr);
230  while (it != fModuleMap.end()) {
231  asic = (CbmTrdParAsic*) it->second;
232  a->push_back(asic->GetAddress());
233  it++;
234  }
235 }
236 
237 //_______________________________________________________________________________
238 const CbmTrdParSet* CbmTrdParSetAsic::GetModuleSet(Int_t detId) const {
242  map<Int_t, CbmTrdParSetAsic*>::const_iterator imod = fModPar.find(detId);
243  if (imod == fModPar.end()) return nullptr;
244  return imod->second;
245 }
246 
247 //_______________________________________________________________________________
248 void CbmTrdParSetAsic::Print(Option_t* opt) const {
249  if (fModPar.size()) {
250  printf(" %s Modules[%d]\n", GetName(), fNrOfModules);
251  map<Int_t, CbmTrdParSetAsic*>::const_iterator imod = fModPar.begin();
252  while (imod != fModPar.end()) {
253  printf(" %d %s(%s)\n",
254  imod->first,
255  imod->second->GetName(),
256  imod->second->GetTitle());
257  imod->second->Print(opt);
258  imod++;
259  }
260  } else if (fModuleMap.size()) {
261  printf(" %s Asics[%d]\n", GetName(), GetNofAsics());
262  if (strcmp(opt, "all") == 0) {
263  map<Int_t, CbmTrdParMod*>::const_iterator iasic = fModuleMap.begin();
264  while (iasic != fModuleMap.end()) {
265  iasic->second->Print(opt);
266  iasic++;
267  }
268  }
269  }
270 }
271 
272 //_______________________________________________________________________________
274  std::map<Int_t, CbmTrdParMod*>::iterator it = fModuleMap.find(address);
275  if (it != fModuleMap.end()) {
276  LOG(warn) << GetName() << "::SetAsicPar : The ASIC @ " << address
277  << " already initialized. Skip.";
278  return;
279  }
280  fModuleMap[address] = p;
281  fNrOfModules++;
282 }
283 
CbmTrdParAsic::SetChannelAddresses
virtual void SetChannelAddresses(std::vector< Int_t > addresses)
Definition: CbmTrdParAsic.cxx:51
CbmTrdParAsic::GetAddress
virtual Int_t GetAddress() const
Definition: CbmTrdParAsic.h:41
CbmTrdParSetAsic::GetModuleSet
virtual const CbmTrdParSet * GetModuleSet(Int_t detId) const
Definition: CbmTrdParSetAsic.cxx:238
CbmTrdParSet::fModuleMap
std::map< Int_t, CbmTrdParMod * > fModuleMap
Definition: CbmTrdParSet.h:43
CbmTrdParSetAsic::Print
virtual void Print(Option_t *opt="") const
Definition: CbmTrdParSetAsic.cxx:248
CbmTrdParFaspChannel::GetThreshold
Int_t GetThreshold() const
Definition: CbmTrdParFasp.h:38
CbmTrdParAsic
Definition of ASIC parameters.
Definition: CbmTrdParAsic.h:15
CbmTrdParSpadic::GetCriId
std::uint16_t GetCriId()
Definition: CbmTrdParSpadic.cxx:80
CbmTrdParSetAsic::GetNofAsics
virtual Int_t GetNofAsics() const
Definition: CbmTrdParSetAsic.h:48
CbmTrdParSetAsic::putParams
void putParams(FairParamList *)
Definition: CbmTrdParSetAsic.cxx:103
NFASPCH
#define NFASPCH
Definition: CbmTrdParFasp.h:4
CbmTrdParAsic::SetComponentId
virtual void SetComponentId(std::uint64_t id)
Definition: CbmTrdParAsic.h:66
CbmTrdParSetAsic::CbmTrdParSetAsic
CbmTrdParSetAsic(const char *name="CbmTrdParSetAsic", const char *title="TRD ASIC parameters", const char *context="Default")
Definition: CbmTrdParSetAsic.cxx:22
CbmTrdParSpadic::GetElinkId
static std::uint8_t GetElinkId(std::uint64_t componentId, Int_t channelId)
eLinkId for the given asicAddress and channelId (in the asic coordinates, i.e. 00....
Definition: CbmTrdParSpadic.cxx:119
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmTrdParFasp::GetChannel
const CbmTrdParFaspChannel * GetChannel(Int_t pad_address, UChar_t pair) const
Definition: CbmTrdParFasp.cxx:27
CbmTrdParSetAsic
Describe TRD module ASIC settings (electronic gain, delays, etc)
Definition: CbmTrdParSetAsic.h:18
CbmTrdParSetAsic::GetAsicAddress
virtual Int_t GetAsicAddress(Int_t chAddress) const
Look for the ASIC which operates on a specific channel.
Definition: CbmTrdParSetAsic.cxx:209
CbmTrdParFaspChannel
Definition of FASP channel calibration container.
Definition: CbmTrdParFasp.h:18
CbmTrdParSpadic.h
CbmTrdParAsic.h
CbmTrdParSetAsic::~CbmTrdParSetAsic
virtual ~CbmTrdParSetAsic()
Destructor.
Definition: CbmTrdParSetAsic.cxx:28
CbmTrdParSetAsic.h
CbmTrdParSet
Definition: CbmTrdParSet.h:19
CbmTrdParSet::fNrOfModules
Int_t fNrOfModules
no of modules in the current run
Definition: CbmTrdParSet.h:41
CbmTrdParFasp.h
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmTrdParFasp
Definition of FASP parameters.
Definition: CbmTrdParFasp.h:74
CbmTrdParAsic::QueryChannel
virtual Int_t QueryChannel(Int_t ch) const
Query ASIC for specific pad address.
Definition: CbmTrdParAsic.cxx:30
CbmTrdParSetAsic::AddParameters
void AddParameters(CbmTrdParSetAsic *)
Definition: CbmTrdParSetAsic.cxx:201
NSPADICCH
#define NSPADICCH
Definition: CbmTrdParSpadic.h:4
CbmTrdParFaspChannel::GetPileUpTime
Int_t GetPileUpTime() const
Definition: CbmTrdParFasp.h:37
CbmTrdParSetAsic::fModPar
std::map< Int_t, CbmTrdParSetAsic * > fModPar
module wise list of ASIC sets
Definition: CbmTrdParSetAsic.h:59
CbmTrdParSetAsic::getParams
Bool_t getParams(FairParamList *)
Definition: CbmTrdParSetAsic.cxx:39
CbmTrdParSetAsic::SetAsicPar
virtual void SetAsicPar(Int_t address, CbmTrdParAsic *p)
Definition: CbmTrdParSetAsic.cxx:273
CbmTrdParFasp::GetChannelAddress
Int_t GetChannelAddress(Int_t ich) const
Definition: CbmTrdParFasp.h:85
CbmTrdParSpadic::GetCrobId
std::uint8_t GetCrobId()
Definition: CbmTrdParSpadic.cxx:90
CbmTrdParMod.h
CbmTrdParSetAsic::GetAsicAddresses
virtual void GetAsicAddresses(std::vector< Int_t > *a) const
Definition: CbmTrdParSetAsic.cxx:224
CbmTrdParSpadic
Definition of SPADIC parameters.
Definition: CbmTrdParSpadic.h:16
CbmTrdParSpadic::GetCrobNumber
std::uint8_t GetCrobNumber()
Definition: CbmTrdParSpadic.cxx:101
CbmTrdParFaspChannel::GetMinDelaySignal
Int_t GetMinDelaySignal() const
Definition: CbmTrdParFasp.h:35