Project
Loading...
Searching...
No Matches
EMCALPedestalHelper.cxx
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
13using namespace o2::emcal;
14
15std::vector<char> EMCALPedestalHelper::createPedestalInstruction(const Pedestal& obj, const int runNum)
16{
17
18 setZero();
19
22
23 for (int itower = 0; itower < 17664; itower++) {
24 auto [ddl, row, col] = geo->getOnlineID(itower);
25 auto [sm, mod, iphi, ieta] = geo->GetCellIndex(itower);
26 const auto& mapping = mapper.getMappingForDDL(ddl);
27 int ircu = ddl % 2;
29 addressHG = mapping.getHardwareAddress(row, col, o2::emcal::ChannelType_t::HIGH_GAIN);
38 fMeanPed[sm][ircu][branchHG][fecHG][chipHG][channelHG] = obj.getPedestalValue(itower, false, false);
39 fMeanPed[sm][ircu][branchLG][fecLG][chipLG][channelLG] = obj.getPedestalValue(itower, true, false);
40 }
41
42 for (int iledmon = 0; iledmon < 480; iledmon++) {
43 int sm = iledmon / 24,
44 col = iledmon % 24,
45 ircu = 0, // LEDMONS always on RCU 0
46 iddl = 2 * sm + ircu;
47 const auto& mapping = mapper.getMappingForDDL(iddl);
48 auto addressLG = mapping.getHardwareAddress(0, col, o2::emcal::ChannelType_t::LEDMON),
49 addressHG = mapping.getHardwareAddress(1, col, o2::emcal::ChannelType_t::LEDMON);
58 fMeanPed[sm][ircu][branchHG][fecHG][chipHG][channelHG] = obj.getPedestalValue(iledmon, false, true);
59 fMeanPed[sm][ircu][branchLG][fecLG][chipLG][channelLG] = obj.getPedestalValue(iledmon, true, true);
60 }
61
62 return createInstructionString(runNum);
63}
64
65void EMCALPedestalHelper::setZero()
66{
67 for (int ism = 0; ism < kNSM; ism++) {
68 for (int ircu = 0; ircu < kNRCU; ircu++) {
69 for (int ibranch = 0; ibranch < kNBranch; ibranch++) {
70 for (int ifec = 0; ifec < kNFEC; ifec++) {
71 for (int ichip = 0; ichip < kNChip; ichip++) {
72 for (int ichan = 0; ichan < kNChan; ichan++) {
73 fMeanPed[ism][ircu][ibranch][ifec][ichip][ichan] = 0;
74 }
75 }
76 }
77 }
78 }
79 }
80}
81
82std::vector<char> EMCALPedestalHelper::createInstructionString(const int runNum)
83{
84 std::stringstream fout;
85
86 if (runNum > 0) {
87 fout << runNum << std::endl;
88 }
89
90 unsigned int lineValue = 0;
91
92 const unsigned int FECheaderCode = 0xC0000000;
93 // const unsigned int FECwordCode = 0x80000000;
94 const unsigned int FEClineCode = 0x40000000;
95
96 const unsigned int TrailerLineCode = 0xFFFFFFFF;
97
98 short iSM = 0;
99 short iRCU = 0;
100 short ibranch = 0;
101 short iFEC = 0;
102 short ichip = 0;
103 short ichan = 0;
104 short Ped = 0;
105 short iDTC = 0;
106
107 for (iSM = 0; iSM < kNSM; iSM++) {
108 int iside = iSM % 2;
109 int isect = iSM / 2;
110 if (iSM > 11) {
111 isect += 3; // skip non-installed sectors
112 }
113
114 std::bitset<kNDTC> activeDTC;
115 for (iDTC = 0; iDTC < kNDTC; iDTC++) {
116 if (iDTC == 10 || iDTC == 20 || iDTC == 30) { // skip TRU
117 activeDTC[iDTC] = 0;
118 } else {
119 if (iSM < 10) { // not special third SMs or DCal SMs
120 activeDTC[iDTC] = 1;
121 } else {
122 if (iSM == 10 || iSM == 19) { // SMA5 or SMC12
123 if (iDTC < 14) {
124 activeDTC[iDTC] = 1;
125 } else {
126 activeDTC[iDTC] = 0;
127 }
128 } else if (iSM == 11 || iSM == 18) { // SMC5 or SMA12
129 if (iDTC == 0 || iDTC >= 27) {
130 activeDTC[iDTC] = 1;
131 } else {
132 activeDTC[iDTC] = 0;
133 }
134 } else {
135 // DCal... no FECs in 9,11-13, 23-26, 36-39
136 if ((iDTC >= 9 && iDTC <= 13) || (iDTC >= 23 && iDTC <= 26) ||
137 (iDTC >= 36 && iDTC <= 39)) {
138 activeDTC[iDTC] = 0;
139 } else {
140 activeDTC[iDTC] = 1;
141 }
142 } // DCal
143 } // non-EMCal
144 } // non-TRU
145 }
146
147 // OK, let's generate the files for all active FECs/DTCs
148 for (iDTC = 0; iDTC < kNDTC; iDTC++) {
149 if (activeDTC[iDTC] == 0) {
150 continue;
151 }
152
153 lineValue = FECheaderCode | isect << 9 | iside << 8 | iDTC;
154 fout << lineValue << std::endl;
155
156 iRCU = iDTC / 20;
157 ibranch = (iDTC % 20) / 10;
158 iFEC = iDTC % 10;
159 int ipos = iFEC + 10 * ibranch;
160
161 int dtcselUpper = 0;
162 int dtcselLower = 0;
163 if (iRCU == 0) {
164 dtcselLower = (1 << ipos);
165 } else { // crate == 1
166 dtcselUpper = (1 << ipos);
167 }
168
169 for (ichip = 0; ichip < kNChip; ichip++) { // ALTRO 0,2,3,4
170 if (ichip != 1) {
171 for (ichan = 0; ichan < kNChan; ichan++) {
172 if (iFEC != 0 || (ichan < 8 || ichan > 11)) {
173 Ped = fMeanPed[iSM][iRCU][ibranch][iFEC][ichip][ichan];
174 int writeAddr = (ichip << 4) | ichan;
175 lineValue = FEClineCode | (writeAddr << 12) | Ped;
176 fout << lineValue << std::endl;
177 }
178 }
179 }
180 } // chip
181
182 } // iDTC
183 } // iSM
184
185 if (runNum > 0) {
186 fout << TrailerLineCode << std::endl;
187 }
188
189 const std::string instructionString(fout.str());
190 std::vector<char> output(instructionString.begin(), instructionString.end());
191 return output;
192}
193
194void EMCALPedestalHelper::dumpInstructions(const std::string_view filename, const gsl::span<char>& data)
195{
196 std::ofstream fout(filename.data());
197 fout << data.data();
198 fout.close();
199}
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
uint32_t col
Definition RawData.h:4
static int getAltroIndexFromHwAddress(int hwaddress)
Extracting ALTRO index from the hardware address.
Definition Channel.h:167
static int getChannelIndexFromHwAddress(int hwaddress)
Extracting Channel index in FEC from the hardware address.
Definition Channel.h:171
static int getFecIndexFromHwAddress(int hwaddress)
Extracting FEC index in branch from the hardware address.
Definition Channel.h:163
static int getBranchIndexFromHwAddress(int hwaddress)
Extracting branch index from the hardware address.
Definition Channel.h:159
void dumpInstructions(const std::string_view filename, const gsl::span< char > &data)
print the vector produced by createInstructionString in a textfile
std::vector< char > createPedestalInstruction(const Pedestal &obj, const int runNum=-1)
Encodes the pedestal object into a string. This function fills fMeanPed which is then converted to a ...
EMCAL geometry definition.
Definition Geometry.h:40
static Geometry * GetInstanceFromRunNumber(Int_t runNumber, const std::string_view="", const std::string_view mcname="TGeant3", const std::string_view mctitle="")
Instanciate geometry depending on the run number. Mostly used in analysis and MC anchors.
Definition Geometry.cxx:219
std::tuple< int, int, int, int > GetCellIndex(Int_t absId) const
Get cell SM, module numbers from absolute ID number.
std::tuple< int, int, int > getOnlineID(int towerID)
Get link ID, row and column from cell ID, have a look here: https://alice.its.cern....
unsigned int getHardwareAddress(uint8_t row, uint8_t col, ChannelType_t channeltype) const
Get the hardware address for a channel.
Definition Mapper.cxx:88
Handler providing the correct mapping for the given DDL.
Definition Mapper.h:313
Mapper & getMappingForDDL(unsigned int ddl)
Get Mapping for given DDL.
Definition Mapper.cxx:112
CCDB container for pedestal values.
Definition Pedestal.h:48
short getPedestalValue(unsigned short cellID, bool isLowGain, bool isLEDMON) const
Get the time calibration coefficient for a certain cell.
Definition Pedestal.cxx:47
GLboolean * data
Definition glcorearb.h:298
@ HIGH_GAIN
High gain channel.
Definition Constants.h:35
@ LOW_GAIN
Low gain channel.
Definition Constants.h:34
@ LEDMON
LED monitor channel.
Definition Constants.h:37
std::string filename()
std::vector< int > row