BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
add_Tof1_mapping.C
Go to the documentation of this file.
1// Uploads Tof1 mapping from two text files
2#include <fstream>
3#include <iostream>
4#include <string>
5
6using namespace std;
7// sP is start period
8// sR is start run
9// eP is end period
10// eR is end run
11
12// FILES FORMAT:
13
14// Placement map:
15// Each line:
16//[HEX: Crate serial] [Slot id] [HEX: TDC Serial]
17
18// Main map:
19// Each line:
20//[HEX: TDC Serial] [Channel] [Plane id] [Strip id] [Side: L or R]
21
22void add_Tof1_mapping(string placement_map_filename = "/home/mikhailr/bmnroot/input/TOF400_PlaceMap_Period5_v3.txt",
23 string main_map_filename = "/home/mikhailr/bmnroot/input/TOF400_StripMap_Period5_v3.txt",
24 int sP = 5,
25 int sR = 419,
26 int eP = 5,
27 int eR = 10000)
28{
29 gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
30 basiclibs();
31 gSystem->Load("libUniDb");
32
33 char anwser;
34 int nLines;
35 fstream ff;
36
37 unsigned int fserial;
38 int fchan;
39 int fplane;
40 int fstrip;
41 char side_c;
42 unsigned int fcrate;
43 int fslot;
44 bool side;
45
46 // Placement map
47 // Stored in 1D UInt_t array format
48 //(HEX: Create serial), (Slot), (HEX: TDC Serial), (HEX: Crate serial)...
49
50 unsigned int map1[100];
51 int map1Size = 0;
52
53 nLines = 0;
54 ff.open(placement_map_filename.c_str(), std::fstream::in);
55 if (ff.fail()) {
56 cout << "Failed to open " << placement_map_filename << endl;
57 return;
58 }
59 while (!ff.eof()) {
60 ff >> std::hex >> fcrate >> std::dec >> fslot >> std::hex >> fserial;
61 if (ff.eof() || fcrate == 0)
62 break;
63
64 cout << std::hex << fcrate << " : " << std::dec << fslot << std::hex << " -> " << fserial << std::dec << endl;
65 map1[nLines * 3 + 0] = fcrate;
66 map1[nLines * 3 + 1] = fslot;
67 map1[nLines * 3 + 2] = fserial;
68 nLines++;
69 }
70 ff.close();
71
72 int nTDC = nLines;
73 map1Size = nTDC * 3;
74 cout << nTDC << " TDCs in the mapping " << endl;
75
76 // Load the main map
77
78 nLines = 0;
79 ff.open(main_map_filename.c_str(), std::fstream::in);
80 if (ff.fail()) {
81 cout << "Failed to open " << main_map_filename << endl;
82 return;
83 }
84 while (!ff.eof()) {
85 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
86 if (ff.eof() || fserial == 0)
87 break;
88
89 if (side_c != 'L' && side_c != 'R')
90 cout << "Wrong mapping file: Side is not L or R." << endl;
91
92 // cout << nLines << std::hex << fserial << std::dec << " " << fchan << " " << fplane << " " << fstrip << " " <<
93 // side_c << endl;
94 nLines++;
95 }
96
97 ff.close();
98
99 // Check if number of lines is correct (should be 72 * nTDC)
100 cout << nLines << " lines in the main mapping file" << endl;
101 cout << (double(nLines) / 72.0) << " TDCs in the main mapping file" << endl;
102 /*if (double(nLines) / 72.0 != nTDC)
103 {
104 cout << "Error!" << endl;
105 return;
106 }*/
107
108 cout << "Resulting array of unsigned int: " << endl;
109 for (int i = 0; i < map1Size; i++) {
110 cout << map1[i] << " (" << std::hex << map1[i] << std::dec << endl;
111 }
112
113 // Upload the placement map
114 cout << "\nOkay to upload it? (y/N)" << endl;
115 cin >> anwser;
116 if (anwser == 'y' || anwser == 'Y') {
117 unsigned char* pt = reinterpret_cast<unsigned char*>(map1);
119 "TOF1", "placementmap", sP, sR, eP, eR, pt, map1Size * sizeof(unsigned int), UIntArrayType);
120 if (t == NULL) {
121 cout << "Cannot upload the placement map" << endl;
122 return;
123 }
124 delete t;
125 }
126
127 // Upload the main mapping
128 int nLines = 0;
129 cout << "Okay to upload the main map? (y/N)" << endl;
130 cin >> anwser;
131 if (anwser == 'y' || anwser == 'Y') {
132 ff.open(main_map_filename.c_str(), std::fstream::in);
133 while (!ff.eof()) {
134 cout << "Uploading line " << nLines << endl;
135 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
136 if (side_c == 'L') {
137 side = true;
138 } else if (side_c == 'R') {
139 side = false;
140 } else {
141 cout << "Error: side is not L or R" << endl;
142 return;
143 }
144 cout << std::hex << fserial << " " << std::dec << fchan << " " << fplane << " " << fstrip << " " << side_c;
145
146 if (ff.eof() || fserial == 0) {
147 break;
148 }
149
151 t = UniDetectorParameter::CreateDetectorParameter("TOF1", "plane", sP, sR, eP, eR, fserial, fchan, fplane);
152 if (t == 0x00) {
153 cout << "Cannot upload the placement map" << endl;
154 break;
155 } else {
156 delete t;
157 }
158 t = UniDetectorParameter::CreateDetectorParameter("TOF1", "strip", sP, sR, eP, eR, fserial, fchan, fstrip);
159 if (t == 0x00) {
160 cout << "Cannot upload the placement map" << endl;
161 break;
162 } else {
163 delete t;
164 }
165 t = UniDetectorParameter::CreateDetectorParameter("TOF1", "side", sP, sR, eP, eR, fserial, fchan, side);
166 if (t == 0x00) {
167 cout << "Cannot upload the placement map" << endl;
168 break;
169 } else {
170 delete t;
171 }
172
173 nLines++;
174 }
175 ff.close();
176 }
177}
int i
Definition P4_F32vec4.h:22
#define gROOT
R__EXTERN TSystem * gSystem
static UniDetectorParameter * CreateDetectorParameter(TString detector_name, int parameter_id, int start_period, int start_run, int end_period, int end_run, int value_key, unsigned char *parameter_value, Long_t size_parameter_value, TDatime *expiry_date)
add new detector parameter to the database
void add_Tof1_mapping(string placement_map_filename="/home/mikhailr/bmnroot/input/TOF400_PlaceMap_Period5_v3.txt", string main_map_filename="/home/mikhailr/bmnroot/input/TOF400_StripMap_Period5_v3.txt", int sP=5, int sR=419, int eP=5, int eR=10000)
Definition json.hpp:4446