Project
Loading...
Searching...
No Matches
HelperMethods.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef ALICEO2_TRD_HELPERMETHODS_HH
13#define ALICEO2_TRD_HELPERMETHODS_HH
14
16#include <iostream>
17#include <string>
18#include <fmt/format.h>
19
20namespace o2
21{
22namespace trd
23{
24
26 static int getROBfromPad(int irow, int icol)
27 {
28 return (irow / constants::NMCMROBINROW) * 2 + getColSide(icol);
29 }
30
31 static int getMCMfromPad(int irow, int icol)
32 {
33 if (irow < 0 || icol < 0 || irow > constants::NROWC1 || icol > constants::NCOLUMN) {
34 return -1;
35 }
37 }
38
39 static int getColSide(int icol)
40 {
41 if (icol < 0 || icol >= constants::NCOLUMN) {
42 return -1;
43 }
44
45 return icol / (constants::NCOLUMN / 2);
46 }
47
48 static int getPadRowFromMCM(int irob, int imcm)
49 {
50 return constants::NMCMROBINROW * (irob / 2) + imcm / constants::NMCMROBINCOL;
51 }
52
53 static void printSectorStackLayer(int det)
54 {
55 // for a given chamber number prints SECTOR_STACK_LAYER
56 printf("%02i_%i_%i\n", det / constants::NCHAMBERPERSEC, (det % constants::NCHAMBERPERSEC) / constants::NLAYER, det % constants::NLAYER);
57 }
58
59 static std::string getSectorStackLayerSide(int hcid)
60 {
61 int det = hcid / 2;
62 std::string side = (hcid % 2 == 0) ? "A" : "B";
63 return fmt::format("{}_{}_{}{}", getSector(det), getStack(det), getLayer(det), side);
64 }
65
66 static void printSectorStackLayerSide(int hcid)
67 {
68 // for a given half-chamber number prints SECTOR_STACK_LAYER_side
69 printf("%s\n", getSectorStackLayerSide(hcid).c_str());
70 }
71
72 static int getPadColFromADC(int irob, int imcm, int iadc)
73 {
74 if (iadc < 0 || iadc > constants::NADCMCM) {
75 return -100;
76 }
77 int mcmcol = imcm % constants::NMCMROBINCOL + getROBSide(irob) * constants::NMCMROBINCOL; // MCM column number on ROC [0..7]
78 int padcol = mcmcol * constants::NCOLMCM + constants::NCOLMCM + 1 - iadc;
79 if (padcol < 0 || padcol >= constants::NCOLUMN) {
80 return -1; // this is commented because of reason above OK
81 }
82 return padcol;
83 }
84
85 static int getROBSide(int irob)
86 {
87 if (irob < 0 || irob >= constants::NROBC1) {
88 return -1;
89 }
90 return irob % 2;
91 }
92
93 static int getSector(int det)
94 {
95 return det / constants::NCHAMBERPERSEC;
96 }
97
98 static int getStack(int det)
99 {
101 }
102 static int getLayer(int det)
103 {
104 return det % constants::NLAYER;
105 }
106
107 static int getDetector(int sector, int stack, int layer)
108 {
110 }
111
112 static int getORIinSuperModule(int hcid)
113 {
114 // given a half chamber ID compute the link ID from [0..59]
115 // where link ID [0..29] is for A-side CRU and [30..59] for C-side CRU
116 int ori = -1;
117 int stack = getStack(hcid / 2);
118 int layer = getLayer(hcid / 2);
119 int side = (hcid % 2 == 0) ? 0 : 1;
120 bool isAside = false;
121 if (stack < 2 || (stack == 2 && side == 0)) {
122 isAside = true;
123 }
124 if (isAside) {
125 ori = stack * constants::NLAYER * 2 + side * constants::NLAYER + 5 - layer;
126 } else {
127 // C-side
128 ori = (4 - stack) * constants::NLAYER * 2 + side * constants::NLAYER + 5 - layer;
129 if (stack == 2) {
130 ori -= constants::NLAYER;
131 }
133 }
134 // TODO: put mapping into TDP and prepare for alternative mapping (CCDB?)
135 return ori;
136 }
137
138 static int getHCIDFromLinkID(int link)
139 {
140 // link = halfcrulink [0..14] + halfcru [0..71] * constants::NLINKSPERHALFCRU (15) -> [0..1079]
141
142 int sector = link / constants::NHCPERSEC;
143 int linkSector = link % constants::NHCPERSEC; // [0..59]
144 int linkCRU = linkSector % constants::NLINKSPERCRU; // [0..29]
145 int stack = linkCRU / (constants::NLAYER * 2);
146 int layer = 5 - (linkCRU % constants::NLAYER);
147 int side = (linkCRU / constants::NLAYER) % 2;
148 if (linkSector >= constants::NLINKSPERCRU) {
149 // C-side
150 stack = 4 - stack;
151 if (stack == 2) {
152 side = 1;
153 }
154 }
155 return sector * constants::NHCPERSEC + stack * constants::NLAYER * 2 + layer * 2 + side;
156 }
157
158 static int getLinkIDfromHCID(int hcid)
159 {
160 //return a number in range [0:29] for the link related to this hcid with in its respective CRU
161 //lower 15 is endpoint 0 and upper 15 is endpoint 1
162 //a side has 30, c side has 30 to give 60 links for a supermodule
163 int sector = hcid / constants::NHCPERSEC;
164 return getORIinSuperModule(hcid) + constants::NHCPERSEC * sector;
165 }
166
167 static int getChannelIndexInColumn(int rob, int mcm, int channel)
168 {
169 // the highest ADC channel number corresponds to the lowest pad column connected to given MCM
171 return mcmCol * constants::NADCMCM + constants::NADCMCM - 1 - channel;
172 }
173
174 static int getGlobalChannelIndex(int det, int rob, int mcm, int channel)
175 {
176 // return global readout channel index for given detector, ROB, MCM and channel index
177 // start with sector offset
179 // layer offset
181 // stack offset
183 // pad row offset
185 // position within pad column
186 idx += getChannelIndexInColumn(rob, mcm, channel);
187
188 return idx;
189 }
190
191 static void getPositionFromGlobalChannelIndex(int idx, int& det, int& rob, int& mcm, int& channel)
192 {
193 int sec = idx / constants::NCHANNELSPERSECTOR;
196 int stack, chamberIndex;
197 if (stackIndex >= 2 * constants::NCHANNELSC1 + constants::NCHANNELSC0) {
199 chamberIndex = (stackIndex - constants::NCHANNELSC0) % constants::NCHANNELSC1;
200 } else if (stackIndex > 2 * constants::NCHANNELSC1) {
201 stack = 2;
202 chamberIndex = stackIndex - 2 * constants::NCHANNELSC1;
203 } else {
204 stack = stackIndex / constants::NCHANNELSC1;
205 chamberIndex = stackIndex % constants::NCHANNELSC1;
206 }
207 int row = chamberIndex / constants::NCHANNELSPERROW;
208 int mcmCol = (chamberIndex % constants::NCHANNELSPERROW) / constants::NADCMCM;
209 det = getDetector(sec, stack, layer);
212 channel = constants::NADCMCM - 1 - ((chamberIndex % constants::NCHANNELSPERROW) % constants::NADCMCM);
213 }
214};
215
216} // namespace trd
217} // namespace o2
218
219#endif
uint16_t mcm
uint16_t rob
Global TRD definitions and constants.
uint32_t side
Definition RawData.h:0
uint32_t stack
Definition RawData.h:1
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
constexpr int NMCMROBINCOL
the number of MCMs per ROB in column direction
Definition Constants.h:49
constexpr int NROBC1
the number of ROBs per C1 chamber
Definition Constants.h:51
constexpr int NCHANNELSC1
the number of readout channels per C1 chamber
Definition Constants.h:56
constexpr int NLAYER
the number of layers
Definition Constants.h:27
constexpr int NCHANNELSC0
the number of readout channels per C0 chamber
Definition Constants.h:55
constexpr int NCOLUMN
the number of pad columns for each chamber
Definition Constants.h:41
constexpr int NCHANNELSPERSECTOR
then number of readout channels per sector
Definition Constants.h:58
constexpr int NLINKSPERCRU
the number of links per CRU (two CRUs serve one supermodule)
Definition Constants.h:35
constexpr int NSTACK
the number of stacks per sector
Definition Constants.h:26
constexpr int NMCMROBINROW
the number of MCMs per ROB in row direction
Definition Constants.h:48
constexpr int NADCMCM
the number of ADC channels per MCM
Definition Constants.h:52
constexpr int NHCPERSEC
the number of half-chambers per sector
Definition Constants.h:29
constexpr int NCOLMCM
the number of pads per MCM
Definition Constants.h:53
constexpr int NCHAMBERPERSEC
the number of chambers per sector
Definition Constants.h:28
constexpr int NROWC1
the number of pad rows for chambers of type C1 (installed in stacks 0, 1, 3 and 4)
Definition Constants.h:43
constexpr int NCHANNELSPERLAYER
then number of readout channels per layer
Definition Constants.h:59
constexpr int NCHANNELSPERROW
the number of readout channels per pad row
Definition Constants.h:54
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static int getGlobalChannelIndex(int det, int rob, int mcm, int channel)
static int getROBfromPad(int irow, int icol)
static void getPositionFromGlobalChannelIndex(int idx, int &det, int &rob, int &mcm, int &channel)
static void printSectorStackLayerSide(int hcid)
static std::string getSectorStackLayerSide(int hcid)
static int getColSide(int icol)
static int getDetector(int sector, int stack, int layer)
static int getPadRowFromMCM(int irob, int imcm)
static int getLinkIDfromHCID(int hcid)
static int getStack(int det)
static void printSectorStackLayer(int det)
static int getPadColFromADC(int irob, int imcm, int iadc)
static int getHCIDFromLinkID(int link)
static int getLayer(int det)
static int getSector(int det)
static int getMCMfromPad(int irow, int icol)
static int getROBSide(int irob)
static int getORIinSuperModule(int hcid)
static int getChannelIndexInColumn(int rob, int mcm, int channel)
std::vector< int > row