Skip to content

Commit ea5fd7c

Browse files
real LUT in CCDB (#5089)
* real LUT * printout
1 parent 1be7b8c commit ea5fd7c

File tree

19 files changed

+513
-71
lines changed

19 files changed

+513
-71
lines changed

DataFormats/Detectors/FIT/FT0/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ o2_add_library(DataFormatsFT0
1818
PUBLIC_LINK_LIBRARIES O2::CommonDataFormat
1919
O2::Headers
2020
O2::SimulationDataFormat
21+
O2::CCDB
22+
O2::DetectorsCalibration
2123
O2::FT0Base)
2224

2325
o2_target_root_dictionary(DataFormatsFT0

DataFormats/Detectors/FIT/FT0/include/DataFormatsFT0/LookUpTable.h

Lines changed: 113 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,21 @@
1919
// Look Up Table FT0
2020
//////////////////////////////////////////////
2121

22+
#include "CCDB/BasicCCDBManager.h"
23+
2224
#include <Rtypes.h>
2325
#include <cassert>
26+
#include <exception>
2427
#include <iostream>
28+
#include <fstream>
29+
#include <stdexcept>
2530
#include <tuple>
31+
#include <TSystem.h>
32+
#include <cstdlib>
33+
#include <map>
34+
#include <string_view>
35+
#include <vector>
36+
2637
namespace o2
2738
{
2839
namespace ft0
@@ -33,15 +44,54 @@ struct Topo {
3344
ClassDefNV(Topo, 1);
3445
};
3546

47+
// enum class Side : char { A, C };
48+
// struct PM {
49+
// Side side;
50+
// uint8_t PM_num, PM_channel;
51+
// };
52+
53+
struct HVchannel {
54+
enum class HVBoard : uint8_t { NA,
55+
A_out,
56+
A_in,
57+
C_up,
58+
C_down,
59+
C_mid };
60+
uint8_t channel;
61+
Topo pm;
62+
HVBoard HV_board;
63+
uint8_t HV_channel;
64+
std::string MCP_SN;
65+
std::string HV_cabel;
66+
std::string signal_cable;
67+
68+
ClassDefNV(HVchannel, 1);
69+
};
70+
3671
inline bool operator<(Topo const& a, Topo const& b)
3772
{
3873
return (a.mPM < b.mPM || (a.mPM == b.mPM && a.mMCP < b.mMCP));
3974
}
4075

76+
inline o2::ft0::Topo read_Topo(std::string_view str)
77+
{
78+
assert(str.substr(0, 2) == "PM" && str[4] == '/' && str[5] == 'C' && str[6] == 'h');
79+
char side = str[2];
80+
uint8_t pm_num = str[3] - '0';
81+
uint8_t pm_ch = (str[7] - '0') * 10 + (str[8] - '0') - 1;
82+
assert(side == 'A' || side == 'C');
83+
if (str.substr(0, 4) == "PMA9") {
84+
pm_num = 18;
85+
}
86+
return Topo{(side == 'C' ? 8 : 0) + pm_num, pm_ch};
87+
}
88+
4189
class LookUpTable
4290
{
91+
using CcdbManager = o2::ccdb::BasicCCDBManager;
92+
using CcdbApi = o2::ccdb::CcdbApi;
4393
static constexpr int NUMBER_OF_MCPs = 12;
44-
static constexpr int NUMBER_OF_PMs = 18;
94+
static constexpr int NUMBER_OF_PMs = 19;
4595

4696
public:
4797
///
@@ -58,8 +108,11 @@ class LookUpTable
58108
channel;
59109
}
60110
}
61-
111+
LookUpTable() = default;
62112
~LookUpTable() = default;
113+
114+
HVchannel mHVchannel;
115+
63116
void printFullMap() const
64117
{
65118
for (size_t channel = 0; channel < mTopoVector.size(); ++channel) {
@@ -77,8 +130,14 @@ class LookUpTable
77130
return mInvTopo[getIdx(link, mcp)];
78131
}
79132

80-
int getLink(int channel) const { return mTopoVector[channel].mPM; }
81-
int getMCP(int channel) const { return mTopoVector[channel].mMCP; }
133+
int getLink(int channel) const
134+
{
135+
return mTopoVector[channel].mPM;
136+
}
137+
int getMCP(int channel) const
138+
{
139+
return mTopoVector[channel].mMCP;
140+
}
82141

83142
static o2::ft0::LookUpTable linear()
84143
{
@@ -91,23 +150,67 @@ class LookUpTable
91150
return o2::ft0::LookUpTable{lut_data};
92151
}
93152

153+
static o2::ft0::LookUpTable readTableFile()
154+
{
155+
std::string inputDir;
156+
const char* aliceO2env = std::getenv("O2_ROOT");
157+
if (aliceO2env) {
158+
inputDir = aliceO2env;
159+
}
160+
inputDir += "/share/Detectors/FT0/files/";
161+
162+
std::string lutPath = inputDir + "FT0ChannelsTable.txt";
163+
lutPath = gSystem->ExpandPathName(lutPath.data()); // Expand $(ALICE_ROOT) into real system path
164+
165+
std::ifstream infile;
166+
infile.open(lutPath.c_str());
167+
168+
std::vector<o2::ft0::Topo> lut_data(NUMBER_OF_MCPs * NUMBER_OF_PMs - 8);
169+
std::string comment; // dummy, used just to read 4 first lines and move the cursor to the 5th, otherwise unused
170+
if (!getline(infile, comment)) { // first comment line
171+
/* std::cout << "Error opening ascii file (it is probably a folder!): " << filename.c_str() << std::endl; */
172+
throw std::runtime_error("Error reading lookup table");
173+
}
174+
int channel;
175+
std::string pm, pm_channel, hv_board, hv_channel, mcp_sn, hv_cable, signal_cable;
176+
std::getline(infile, pm); // skip one line
177+
while (infile >> channel >> pm >> pm_channel >> hv_board >> hv_channel >> mcp_sn >> hv_cable >> signal_cable) {
178+
lut_data[channel] = read_Topo(pm_channel);
179+
}
180+
return o2::ft0::LookUpTable{lut_data};
181+
}
182+
static o2::ft0::LookUpTable readTable()
183+
{
184+
185+
std::vector<o2::ft0::Topo> lut_data;
186+
auto& mgr = o2::ccdb::BasicCCDBManager::instance();
187+
mgr.setURL("http://ccdb-test.cern.ch:8080");
188+
auto hvch = mgr.get<std::vector<o2::ft0::HVchannel>>("FT0/LookUpTable");
189+
size_t max = 0;
190+
for (auto const& chan : *hvch)
191+
if (max < chan.channel)
192+
max = chan.channel;
193+
lut_data.resize(max + 1);
194+
for (auto const& chan : *hvch) {
195+
o2::ft0::Topo topo = chan.pm;
196+
lut_data[chan.channel] = topo;
197+
}
198+
return o2::ft0::LookUpTable{lut_data};
199+
}
200+
94201
private:
95202
std::vector<Topo> mTopoVector;
96203
std::vector<int> mInvTopo;
97204

98205
static int getIdx(int link, int mcp)
99206
{
100-
if (mcp >= NUMBER_OF_MCPs) {
101-
std::cout << " !!! MCP number > max NUMBER_OF_MCPs " << mcp << " data will be skipped " << std::endl;
102-
return -1;
103-
}
104-
//assert(mcp < NUMBER_OF_MCPs);
207+
assert(mcp < NUMBER_OF_MCPs);
105208
return link * NUMBER_OF_MCPs + mcp;
106209
}
107210
static int getLinkFromIdx(int idx) { return idx / NUMBER_OF_MCPs; }
108211
static int getMCPFromIdx(int idx) { return idx % NUMBER_OF_MCPs; }
109212

110-
ClassDefNV(LookUpTable, 1);
213+
ClassDefNV(LookUpTable, 2);
111214
};
112215

113216
} // namespace ft0

DataFormats/Detectors/FIT/FT0/include/DataFormatsFT0/RawEventData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ft0
3232
{
3333
constexpr int Nchannels_FT0 = 208;
3434
constexpr int Nchannels_PM = 12;
35-
constexpr int NPMs = 19;
35+
constexpr int NPMs = 20;
3636
constexpr size_t sizeWord = 16;
3737

3838
struct EventHeader {

DataFormats/Detectors/FIT/FT0/src/DataFormatsFT0LinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#pragma link C++ class o2::ft0::EventHeader + ;
4444
#pragma link C++ class o2::ft0::EventData + ;
4545
#pragma link C++ class o2::ft0::Topo + ;
46+
#pragma link C++ class o2::ft0::HVchannel + ;
47+
#pragma link C++ class vector < o2::ft0::HVchannel> + ;
4648

4749
#pragma link C++ class o2::ft0::CTFHeader + ;
4850
#pragma link C++ class o2::ft0::CompressedDigits + ;

0 commit comments

Comments
 (0)