Skip to content

Commit fd4900d

Browse files
committed
refactor(alpide):Update R3BAlpideMappingPar and use by R3BAlpideMapped2Cal
Change the use of parameters to std::vector Change mapping par to manage big arrays Minor change Minor change Change to decimal numbers Change to decimal numbers Final change Forgot 1-base in the array
1 parent 9c69af3 commit fd4900d

6 files changed

Lines changed: 148 additions & 170 deletions

File tree

alpide/calibration/R3BAlpideMapped2Cal.cxx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ void R3BAlpideMapped2Cal::SetParameter()
7070
//--- Parameter Container ---
7171
// R3BLOG(info, "Nb of sensors: " << fMap_Par->GetNbSensors());
7272
fMap_Par->printParams();
73+
74+
auto nSensors = fMap_Par->GetNbSensors();
75+
auto nNbMaskPixels = fMap_Par->GetNbMaskPixel();
76+
77+
inUseCache.resize(nSensors, std::vector<std::vector<int>>(DAlpideCols, std::vector<int>(DAlpideRows, 1)));
78+
79+
for (auto pixel = 0; pixel < nNbMaskPixels; ++pixel)
80+
{
81+
auto pixelid = fMap_Par->GetMaskPixel(pixel);
82+
auto sen = fMap_Par->GetSensorId(pixelid) - 1;
83+
auto col = fMap_Par->GetCol(pixelid) - 1;
84+
auto row = fMap_Par->GetRow(pixelid) - 1;
85+
inUseCache[sen][col][row] = 0;
86+
}
7387
}
7488

7589
// ----- Public method Init --------------------------------------------
@@ -115,23 +129,24 @@ void R3BAlpideMapped2Cal::Exec(Option_t*)
115129
Reset();
116130

117131
// Reading the Input -- Mapped Data --
118-
int nHits = fAlpideMappedData->GetEntriesFast();
119-
if (nHits == 0)
132+
if (fAlpideMappedData->GetEntriesFast() == 0)
120133
{
121134
return;
122135
}
123136

124-
for (int i = 0; i < nHits; i++)
137+
for (auto* obj : *fAlpideMappedData)
125138
{
126-
auto mappedData = dynamic_cast<R3BAlpideMappedData const*>(fAlpideMappedData->At(i));
127-
auto det = mappedData->GetSensorId();
128-
auto col = mappedData->GetCol();
129-
auto row = mappedData->GetRow();
130-
// std::cout << det <<" "<< col <<" "<< row <<std::endl;
131-
// if (fMap_Par->GetInUse(det, col, row) == 1)
132-
//{
133-
AddCalData(det, row, col);
134-
//}
139+
if (auto const* mappedData = dynamic_cast<R3BAlpideMappedData const*>(obj))
140+
{
141+
auto sen = mappedData->GetSensorId();
142+
auto col = mappedData->GetCol();
143+
auto row = mappedData->GetRow();
144+
// std::cout << det <<" "<< col <<" "<< row <<std::endl;
145+
if (inUseCache[sen - 1][col - 1][row - 1] == 1)
146+
{
147+
AddCalData(sen, row, col);
148+
}
149+
}
135150
}
136151
return;
137152
}
@@ -151,7 +166,7 @@ R3BAlpideCalData* R3BAlpideMapped2Cal::AddCalData(uint16_t senId, uint16_t row,
151166
{
152167
// It fills the R3BAlpideCalData
153168
TClonesArray& clref = *fAlpideCalData;
154-
Int_t size = clref.GetEntriesFast();
169+
auto size = clref.GetEntriesFast();
155170
return new (clref[size]) R3BAlpideCalData(senId, row, col);
156171
}
157172

alpide/calibration/R3BAlpideMapped2Cal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "R3BAlpideCalData.h"
2424

2525
#include <Rtypes.h>
26+
#include <vector>
2627

2728
class TClonesArray;
2829
class R3BAlpideMappingPar;
@@ -65,6 +66,8 @@ class R3BAlpideMapped2Cal : public FairTask
6566
TClonesArray* fAlpideMappedData = nullptr; // Array with Alpide Mapped input data
6667
TClonesArray* fAlpideCalData = nullptr; // Array with Alpide Cal output data
6768

69+
std::vector<std::vector<std::vector<int>>> inUseCache;
70+
6871
// Private method AddCalData
6972
R3BAlpideCalData* AddCalData(uint16_t senId, uint16_t row, uint16_t col);
7073

alpide/pars/R3BAlpideMappingPar.cxx

Lines changed: 45 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
* Copyright (C) 2022 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2022-2023 Members of R3B Collaboration *
3+
* Copyright (C) 2022-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *
@@ -16,47 +16,25 @@
1616
// ----- Created 11/02/22 by J.L. Rodriguez-Sanchez -----
1717
// --------------------------------------------------------------
1818

19-
#include "FairLogger.h"
20-
#include "FairParamList.h"
21-
2219
#include "R3BAlpideMappingPar.h"
2320
#include "R3BLogger.h"
2421

22+
#include <FairLogger.h>
23+
#include <FairParamList.h>
24+
25+
#include <TArrayD.h>
26+
#include <sstream>
27+
#include <string>
28+
2529
// ---- Standard Constructor ---------------------------------------------------
2630
R3BAlpideMappingPar::R3BAlpideMappingPar(const char* name, const char* title, const char* context)
2731
: FairParGenericSet(name, title, context)
28-
, fNbSensors(363)
29-
, fGeoVersion(2024)
30-
, fAlpideCols(DAlpideCols)
31-
, fAlpideRows(DAlpideRows)
3232
{
33-
for (Int_t c = 0; c < fAlpideCols; c++)
34-
for (Int_t r = 0; r < fAlpideRows; r++)
35-
{
36-
fIn_use[c][r].resize(fNbSensors);
37-
for (Int_t s = 0; s < fNbSensors; s++)
38-
{
39-
fIn_use[c][r][s] = 1;
40-
}
41-
}
4233
}
4334

4435
// ---- Destructor ------------------------------------------------------------
4536
R3BAlpideMappingPar::~R3BAlpideMappingPar() { clear(); }
4637

47-
// ---- Method SetNbSensors ---------------------------------------------------
48-
void R3BAlpideMappingPar::SetNbSensors(Int_t n)
49-
{
50-
fNbSensors = n;
51-
for (Int_t c = 0; c < fAlpideCols; c++)
52-
for (Int_t r = 0; r < fAlpideRows; r++)
53-
{
54-
fIn_use[c][r].resize(fNbSensors);
55-
for (Int_t s = 0; s < fNbSensors; s++)
56-
fIn_use[c][r][s] = 1;
57-
}
58-
}
59-
6038
// ---- Method clear ----------------------------------------------------------
6139
void R3BAlpideMappingPar::clear()
6240
{
@@ -80,16 +58,15 @@ void R3BAlpideMappingPar::putParams(FairParamList* list)
8058
list->add("NbSensorsPar", fNbSensors);
8159
R3BLOG(info, "Nb of ALPIDE sensors: " << fNbSensors);
8260

83-
Int_t defzero = 0;
84-
char name[300];
85-
for (int s = 1; s <= fNbSensors; s++)
86-
for (int c = 1; c <= fAlpideCols; c++)
87-
for (int r = 1; r <= fAlpideRows; r++)
88-
if (fIn_use[c - 1][r - 1][s - 1] == 0)
89-
{
90-
sprintf(name, "Sensor%dCol%dRow%dPar", s, c, r);
91-
list->add(name, defzero);
92-
}
61+
list->add("NbMaskPixelsPar", fNbMaskPixels);
62+
R3BLOG(info, "Nb of masking pixels: " << fNbMaskPixels);
63+
64+
TArrayD fMask_pixels(fNbMaskPixels);
65+
for (auto pixel = 0; pixel < fNbMaskPixels; pixel++)
66+
{
67+
fMask_pixels[pixel] = fMask_sensors[pixel];
68+
}
69+
list->add("MaskPixelPar", fMask_pixels);
9370
}
9471

9572
// ---- Method getParams ------------------------------------------------------
@@ -122,49 +99,36 @@ Bool_t R3BAlpideMappingPar::getParams(FairParamList* list)
12299
R3BLOG(info, "Nb of ALPIDE sensors: " << fNbSensors);
123100
}
124101

125-
char name[300];
126-
for (int s = 1; s <= fNbSensors; s++)
127-
for (Int_t c = 1; c <= fAlpideCols; c++)
128-
for (Int_t r = 1; r <= fAlpideRows; r++)
129-
{
130-
sprintf(name, "Sensor%dCol%dRow%dPar", s, c, r);
131-
Int_t value = 1;
132-
auto check = fillParams(name, &value, list);
133-
if (check)
134-
{
135-
fIn_use[c - 1][r - 1][s - 1] = 0;
136-
}
137-
}
138-
return kTRUE;
139-
}
140-
141-
Bool_t R3BAlpideMappingPar::fillParams(const Text_t* name, Int_t* values, FairParamList* paramList, const Int_t nValues)
142-
{
143-
// Copies the data from the list object into the parameter array of type Int_t.
144-
// The function returns an error, if the array size of the list object is not equal
145-
// to nValues.
146-
if (values == 0)
102+
if (!list->fill("NbMaskPixelsPar", &fNbMaskPixels))
147103
{
104+
R3BLOG(error, "Could not initialize NbMaskPixelsPar");
148105
return kFALSE;
149106
}
150-
auto o = paramList->find(name);
151-
if (o && strcmp(o->getParamType(), "Int_t") == 0)
107+
else
152108
{
153-
Int_t l = o->getLength();
154-
Int_t n = o->getNumParams();
109+
R3BLOG(info, "Nb of masking pixels: " << fNbMaskPixels);
110+
}
155111

156-
if (n == nValues)
112+
if (fNbMaskPixels > 0)
113+
{
114+
TArrayD fMask_pixels(fNbMaskPixels);
115+
if (!(list->fill("MaskPixelPar", &fMask_pixels)))
157116
{
158-
memcpy(values, o->getParamValue(), l);
159-
return kTRUE;
117+
R3BLOG(error, "Could not initialize MaskPixelPar");
118+
return kFALSE;
160119
}
161-
else
120+
121+
for (auto pixel = 0; pixel < fNbMaskPixels; pixel++)
162122
{
163-
R3BLOG(error, "Different array sizes for parameter " << name);
164-
return kFALSE;
123+
fMask_sensors.push_back(fMask_pixels[pixel]);
124+
125+
auto sen = this->GetSensorId(fMask_sensors[pixel]);
126+
auto col = this->GetCol(fMask_sensors[pixel]);
127+
auto row = this->GetRow(fMask_sensors[pixel]);
128+
LOG(info) << "Skipping Sensor: " << sen << " Col: " << col << " Row: " << row;
165129
}
166130
}
167-
return kFALSE;
131+
return kTRUE;
168132
}
169133

170134
// ---- Method print ----------------------------------------------------------
@@ -174,15 +138,15 @@ void R3BAlpideMappingPar::print() { printParams(); }
174138
void R3BAlpideMappingPar::printParams()
175139
{
176140
R3BLOG(info, "Nb Sensors: " << fNbSensors);
177-
for (Int_t s = 0; s < fNbSensors; s++)
141+
R3BLOG(info, "Geo Version: " << fGeoVersion);
142+
R3BLOG(info, "Nb masked pixels: " << fNbMaskPixels);
143+
144+
for (auto pixel = 0; pixel < fNbMaskPixels; pixel++)
178145
{
179-
R3BLOG(info, "ALPIDE sensor: " << s + 1);
180-
for (Int_t c = 0; c < fAlpideCols; c++)
181-
for (Int_t r = 0; r < fAlpideRows; r++)
182-
{
183-
if (fIn_use[c][r][s] == 0)
184-
LOG(info) << "Pixel column: " << c + 1 << ", row: " << r + 1 << " is skipped";
185-
}
146+
auto sen = this->GetSensorId(fMask_sensors[pixel]);
147+
auto col = this->GetCol(fMask_sensors[pixel]);
148+
auto row = this->GetRow(fMask_sensors[pixel]);
149+
LOG(info) << "Skipping Sensor: " << sen << " Col: " << col << " Row: " << row;
186150
}
187151
}
188152

alpide/pars/R3BAlpideMappingPar.h

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
* Copyright (C) 2022 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3-
* Copyright (C) 2022-2024 Members of R3B Collaboration *
3+
* Copyright (C) 2022-2026 Members of R3B Collaboration *
44
* *
55
* This software is distributed under the terms of the *
66
* GNU General Public Licence (GPL) version 3, *
@@ -21,6 +21,7 @@
2121
#include <FairParGenericSet.h>
2222

2323
#include <Rtypes.h>
24+
#include <cstdint>
2425
#include <stdint.h>
2526
#include <vector>
2627

@@ -41,40 +42,49 @@ class R3BAlpideMappingPar : public FairParGenericSet
4142
virtual ~R3BAlpideMappingPar();
4243

4344
/** Method to reset all parameters **/
44-
virtual void clear();
45+
void clear() override;
4546

4647
/** Method to store all parameters using FairRuntimeDB **/
47-
virtual void putParams(FairParamList* list);
48+
void putParams(FairParamList* list) override;
4849

4950
/** Method to retrieve all parameters using FairRuntimeDB**/
50-
Bool_t getParams(FairParamList* list);
51+
Bool_t getParams(FairParamList* list) override;
5152

5253
/** Method to print values of parameters to the standard output **/
53-
virtual void print();
54-
void printParams();
54+
void print() override;
55+
void printParams() override;
5556

5657
/** Accessor functions **/
57-
Int_t GetNbSensors() const { return fNbSensors; }
58-
Int_t GetGeoVersion() const { return fGeoVersion; }
59-
Int_t GetInUse(UInt_t sensor, UInt_t col, UInt_t row) const { return fIn_use[col - 1][row - 1][sensor - 1]; }
60-
61-
void SetNbSensors(Int_t n);
62-
void SetGeoVersion(Int_t v) { fGeoVersion = v; }
63-
void SetInUse(UInt_t sensor, UInt_t col, UInt_t row, Int_t val) { fIn_use[col - 1][row - 1][sensor - 1] = val; }
58+
[[nodiscard]] int GetNbSensors() const { return fNbSensors; }
59+
[[nodiscard]] int GetGeoVersion() const { return fGeoVersion; }
60+
[[nodiscard]] int GetNbMaskPixel() const { return fNbMaskPixels; }
61+
62+
// [SENSOR][ROW][COL]
63+
// 4 3 4 dígits
64+
[[nodiscard]] uint32_t GetRow(uint64_t id) { return (id / 10'000) % 1'000; }
65+
[[nodiscard]] uint32_t GetCol(uint64_t id) { return id % 10'000; }
66+
[[nodiscard]] uint32_t GetSensorId(uint64_t id) { return id / 10'000'000; }
67+
[[nodiscard]] uint64_t GetMaskPixel(int nbpixel) const { return fMask_sensors[nbpixel]; }
68+
69+
void SetNbSensors(int n) { fNbSensors = n; }
70+
void SetGeoVersion(int v) { fGeoVersion = v; }
71+
void SetMaskPixel(uint64_t maskid)
72+
{
73+
fMask_sensors.push_back(maskid);
74+
fNbMaskPixels = fMask_sensors.size();
75+
}
6476

6577
private:
66-
Int_t fNbSensors;
67-
Int_t fGeoVersion;
68-
Int_t fAlpideCols;
69-
Int_t fAlpideRows;
70-
std::vector<Int_t> fIn_use[DAlpideCols][DAlpideRows];
71-
72-
/** Method to fill all parameters using FairRuntimeDB **/
73-
Bool_t fillParams(const Text_t* name, Int_t* values, FairParamList* list, const Int_t nValues = 1);
78+
int fNbSensors = 363;
79+
int fNbMaskPixels = 0;
80+
int fGeoVersion = 2024;
81+
int fAlpideCols = DAlpideCols;
82+
int fAlpideRows = DAlpideRows;
83+
std::vector<uint64_t> fMask_sensors;
7484

7585
const R3BAlpideMappingPar& operator=(const R3BAlpideMappingPar&); /*< an assignment operator>*/
7686
R3BAlpideMappingPar(const R3BAlpideMappingPar&); /*< a copy constructor >*/
7787

7888
public:
79-
ClassDef(R3BAlpideMappingPar, 1);
89+
ClassDefOverride(R3BAlpideMappingPar, 2); // NOLINT
8090
};

0 commit comments

Comments
 (0)