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+
2637namespace o2
2738{
2839namespace 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+
3671inline 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+
4189class 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
0 commit comments