BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
add_Tof701_mapping.C
Go to the documentation of this file.
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7/*
8 * File: add_Tof2_mapping.C
9 * Author: mikhailr
10 *
11 * Created on Sep 11, 2024, 3:01 PM
12 */
13
14#include <cstdlib>
15#include <vector>
16
17using namespace std;
18
19/*
20 *
21 */
22void add_Tof701_mapping(TString placement_map_filename = "TOF701_PlaceMap_RUN9.txt",
23 TString main_map_filename = "TOF701_StripMap_RUN9.txt",
24 int sP = 9,
25 int sR = 8978,
26 int eP = 9,
27 int eR = 10775)
28{
29 fstream ff;
30
31 unsigned int fserial;
32 int fchan;
33 int fplane;
34 int fstrip;
35 char side_c;
36 unsigned int fcrate;
37 int fslot;
38 bool side;
39
40 // array for store in DB
41 vector<UniValue*> PlMap;
42
43 // Read Placement map
44 // Stored in 1D UInt_t array format
45 //(HEX: Create serial), (Slot), (HEX: TDC Serial), (HEX: Crate serial)...
46
47 TString dir = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", placement_map_filename.Data());
48 ff.open(dir.Data(), std::fstream::in);
49 if (ff.fail()) {
50 cout << "Failed to open " << placement_map_filename << endl;
51 return;
52 }
53 while (!ff.eof()) {
54 ff >> std::hex >> fcrate >> std::dec >> fslot >> std::hex >> fserial;
55 if (ff.eof() || fcrate == 0)
56 break;
57
58 cout << std::hex << fcrate << " : " << std::dec << fslot << std::hex << " -> " << fserial << std::dec << endl;
59 // Fill db value
60 MapIntValue* tempMap = new MapIntValue;
61 tempMap->serial = fcrate;
62 tempMap->channel = fslot;
63 tempMap->value = fserial;
64 PlMap.push_back(tempMap);
65 }
66 ff.close();
67
68 cout << PlMap.size() << " TDCs in the mapping " << endl;
69 // getchar();
70
71 bool return_error = false;
72 // create parameter in DB
73 // UniParameter* pParameter =
74 // UniParameter::CreateParameter("TOF2_TdcMap", MapIntType, 0); //(TString parameter_name, int parameter_type)
75 // delete pParameter;
76
77 // write detector parameters in DB
78 UniDetectorParameter* pDetectorParameter =
79 UniDetectorParameter::CreateDetectorParameter("TOF2", "TOF2_TdcMap", sP, sR, eP, eR, PlMap);
80 if (pDetectorParameter == nullptr)
81 return_error = true;
82
83 // clean memory after work
84 for (int i = 0; i < PlMap.size(); i++)
85 delete PlMap[i];
86 if (pDetectorParameter)
87 delete pDetectorParameter;
88
89 // read strip map
90 vector<UniValue*> StrMap;
91 dir = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", main_map_filename.Data());
92 ff.open(dir.Data(), std::fstream::in);
93 if (ff.fail()) {
94 cout << "Failed to open " << main_map_filename << endl;
95 return;
96 }
97
98 // for (Int_t i = 0; i < 48; i++)
99 while (!ff.eof()) {
100 MapDVectorValue* tempMap2 = new MapDVectorValue;
101 vector<Double_t> strmaptemp;
102 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
103 cout << std::hex << fserial << " : " << std::dec << fchan << " " << fplane << " " << fstrip << " " << side_c
104 << endl;
105
106 strmaptemp.clear();
107 // strmaptemp.resize(3);
108
109 if (ff.eof() || fserial == 0 || fstrip == -1)
110 continue;
111
112 if (side_c != 'L' && side_c != 'R') {
113 cout << "Wrong mapping file: Side is not L or R." << endl;
114 continue;
115 }
116 tempMap2->serial = fserial;
117 tempMap2->channel = fchan;
118 // tempMap2->value.push_back(fplane);
119 // tempMap2->value.push_back(fstrip);
120 strmaptemp.push_back(fplane);
121 strmaptemp.push_back(fstrip);
122 if (side_c == 'L') {
123 strmaptemp.push_back(0);
124 // tempMap2->value.push_back(0);
125 } else {
126 strmaptemp.push_back(1);
127 // tempMap2->value.push_back(1);
128 }
129 // cout << "Write to strmaptemp: " << strmaptemp.at(0) << " " << strmaptemp.at(1) << " " <<
130 // strmaptemp.at(2) << endl;
131 tempMap2->value = strmaptemp;
132 StrMap.push_back(tempMap2);
133
134 // cout << std::hex << tempMap2->serial << std::dec << " ch " << tempMap2->channel << " -> " <<
135 // tempMap2->value.at(0) << " " << tempMap2->value.at(1) << " " << tempMap2->value.at(2) << endl;
136 }
137 ff.close();
138
139 // MapDVectorValue* tempMap2 = new MapDVectorValue;
140 // for (int i = 0; i < StrMap.size(); i++) {
141 // tempMap2 = (MapDVectorValue*) StrMap.at(i);
142 // cout << i << " " << std::hex << tempMap2->serial << std::dec << " ch " << tempMap2->channel << " -> " <<
143 // tempMap2->value.at(0) << " " << tempMap2->value.at(1) << " " << tempMap2->value.at(2) << endl;
144 // }
145 // getchar();
146
147 // // create parameter in DB
148 // UniParameter* pParameter2 = UniParameter::CreateParameter("TOF2_StripMap", MapDVectorType,
149 // 0); //(TString parameter_name, int parameter_type)
150 // delete pParameter2;
151
152 // write detector parameters in DB
153 cout << "Write to DB " << endl;
154 UniDetectorParameter* pDetectorParameter2 =
155 UniDetectorParameter::CreateDetectorParameter("TOF2", "TOF2_StripMap", sP, sR, eP, eR, StrMap);
156 if (pDetectorParameter2 == nullptr)
157 return_error = true;
158
159 // clean memory after work
160 cout << "clear memory " << endl;
161 for (int i = 0; i < StrMap.size(); i++)
162 delete StrMap[i];
163 if (pDetectorParameter2)
164 delete pDetectorParameter2;
165
166 if (return_error)
167 cout << "\nMacro finished with errors" << endl;
168 else
169 cout << "\nMacro finished successfully" << endl;
170}
int i
Definition P4_F32vec4.h:22
char * Form(const char *fmt,...)
void add_Tof701_mapping(TString placement_map_filename="TOF701_PlaceMap_RUN9.txt", TString main_map_filename="TOF701_StripMap_RUN9.txt", int sP=9, int sR=8978, int eP=9, int eR=10775)
const char * Data() const
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
Definition json.hpp:4446
vector< double > value