BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
add_Tof1_mapping_New.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_Tof1_mapping_New.C
9 * Author: mikhailr
10 *
11 * Created on August 24, 2021, 3:25 PM
12 */
13
14#include <cstdlib>
15#include <vector>
16
17using namespace std;
18
19/*
20 *
21 */
22void add_Tof1_mapping_New(TString placement_map_filename = "TOF400_PlaceMap_RUN9.txt",
23 TString main_map_filename = "TOF400_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
70 bool return_error = false;
71 // create parameter in DB
72 // UniParameter* pParameter = UniParameter::CreateParameter("TOF1_TdcMap", MapIntType, 0); //(TString
73 // parameter_name, int parameter_type) delete pParameter;
74 // write detector parameters in DB
75 UniDetectorParameter* pDetectorParameter =
76 UniDetectorParameter::CreateDetectorParameter("TOF1", "TOF1_TdcMap", sP, sR, eP, eR, PlMap);
77 if (pDetectorParameter == nullptr)
78 return_error = true;
79 //
80 // // clean memory after work
81 for (int i = 0; i < PlMap.size(); i++)
82 delete PlMap[i];
83 if (pDetectorParameter)
84 delete pDetectorParameter;
85
86 // read strip map
87 vector<UniValue*> StrMap;
88 dir = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", main_map_filename.Data());
89 ff.open(dir.Data(), std::fstream::in);
90 if (ff.fail()) {
91 cout << "Failed to open " << main_map_filename << endl;
92 return;
93 }
94
95 // for (Int_t i = 0; i < 48; i++)
96 while (!ff.eof()) {
97 MapDVectorValue* tempMap2 = new MapDVectorValue;
98 vector<Double_t> strmaptemp;
99 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
100 cout << std::hex << fserial << " : " << std::dec << fchan << " " << fplane << " " << fstrip << " " << side_c
101 << endl;
102
103 strmaptemp.clear();
104 // strmaptemp.resize(3);
105
106 if (ff.eof() || fserial == 0 || fstrip == -1)
107 continue;
108
109 if (side_c != 'L' && side_c != 'R') {
110 cout << "Wrong mapping file: Side is not L or R." << endl;
111 continue;
112 }
113 tempMap2->serial = fserial;
114 tempMap2->channel = fchan;
115 // tempMap2->value.push_back(fplane);
116 // tempMap2->value.push_back(fstrip);
117 strmaptemp.push_back(fplane);
118 strmaptemp.push_back(fstrip);
119 if (side_c == 'L') {
120 strmaptemp.push_back(0);
121 // tempMap2->value.push_back(0);
122 } else {
123 strmaptemp.push_back(1);
124 // tempMap2->value.push_back(1);
125 }
126 // cout << "Write to strmaptemp: " << strmaptemp.at(0) << " " << strmaptemp.at(1) << " " <<
127 // strmaptemp.at(2) << endl;
128 tempMap2->value = strmaptemp;
129 StrMap.push_back(tempMap2);
130
131 // cout << std::hex << tempMap2->serial << std::dec << " ch " << tempMap2->channel << " -> " <<
132 // tempMap2->value.at(0) << " " << tempMap2->value.at(1) << " " << tempMap2->value.at(2) << endl;
133 }
134 ff.close();
135 //
136 // MapDVectorValue* tempMap2 = new MapDVectorValue;
137 // for (int i = 0; i < StrMap.size(); i++) {
138 // tempMap2 = (MapDVectorValue*) StrMap.at(i);
139 // cout << std::hex << tempMap2->serial << std::dec << " ch " << tempMap2->channel << " -> " <<
140 // tempMap2->value.at(0) << " " << tempMap2->value.at(1) << " " << tempMap2->value.at(2) << endl;
141 // }
142
143 // create parameter in DB
144 // UniParameter* pParameter2 = UniParameter::CreateParameter("TOF1_StripMap", MapDVectorType, 0); //(TString
145 // parameter_name, int parameter_type) delete pParameter2;
146 // write detector parameters in DB
147 cout << "Write to DB " << endl;
148 UniDetectorParameter* pDetectorParameter2 =
149 UniDetectorParameter::CreateDetectorParameter("TOF1", "TOF1_StripMap", sP, sR, eP, eR, StrMap);
150 if (pDetectorParameter2 == nullptr)
151 return_error = true;
152
153 // clean memory after work
154 cout << "clear memory " << endl;
155 // for (int i = 0; i < StrMap.size(); i++) delete StrMap[i];
156 // if (pDetectorParameter2)
157 // delete pDetectorParameter2;
158
159 if (return_error)
160 cout << "\nMacro finished with errors" << endl;
161 else
162 cout << "\nMacro finished successfully" << endl;
163}
int i
Definition P4_F32vec4.h:22
char * Form(const char *fmt,...)
void add_Tof1_mapping_New(TString placement_map_filename="TOF400_PlaceMap_RUN9.txt", TString main_map_filename="TOF400_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