BmnRoot 26.10.0-19-g6979a6c6
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
add_Tof1_INL_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_INL_new.C
9 * Author: mikhailr
10 *
11 * Created on August 31, 2021, 1:46 PM
12 */
13
14#include <fstream>
15#include <iostream>
16#include <sstream>
17#include <string>
18#include <vector>
19
20#define CHANNEL_NUMBER 72
21#define BIN_NUMBER 1024
22
23using namespace std;
24// add_Tof1_INL(the .ini filename, start period, start run, end period, end run)
25
26void add_Tof1_INL_new(TString ListOfINLFiles = "ListINLFiles_Run9.txt",
27 int sP = 9,
28 int sR = 8978,
29 int eP = 9,
30 int eR = 10775)
31{
32 cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
33 fstream fList(ListOfINLFiles, std::fstream::in);
34 if (fList.fail()) {
35 cout << "Failed to open " << ListOfINLFiles << endl;
36 return;
37 }
38
39 TString FileINL[100];
40 UInt_t TDCSerial;
41 Int_t counter = 0;
42 Double_t Inltemp, InlSum;
43 TString dir = Form("%s%s", getenv("VMCWORKDIR"), "/input/");
44 cout << "Location for INL file is " << dir.Data() << endl << endl;
45
46 vector<UniValue*> InlData;
47
48 while (!fList.eof()) {
49
50 TdcInlValue* tempInl = new TdcInlValue;
51
52 fList >> FileINL[counter];
53 if (FileINL[counter] == "")
54 break;
55
56 cout << "INL file " << FileINL[counter].Data() << endl;
57 fstream fINL(dir + FileINL[counter], std::fstream::in);
58 if (fINL.fail()) {
59 cout << "Failed to open " << FileINL[counter].Data() << endl;
60 return;
61 } else
62 cout << "Open File " << FileINL[counter].Data() << endl;
63 // The format of the header seems to be [TDC-THESERIAL-inl_corr]
64 fINL.ignore(10, '-');
65 fINL >> std::hex >> TDCSerial >> std::dec;
66 tempInl->serial = TDCSerial;
67 cout << std::hex << TDCSerial << std::dec << endl;
68 fINL.ignore(100, '\n');
69
70 // Fill the INL with 0s
71 for (int i = 0; i < CHANNEL_NUMBER; i++)
72 for (int j = 0; j < BIN_NUMBER; j++) {
73 tempInl->inl[i][j] = 0;
74 }
75 int lines_num = 0;
76 while (!fINL.eof()) {
77 int channel_id;
78 string line, number;
79
80 // Read the line
81 std::getline(fINL, line, '\n');
82 if (fINL.eof()) {
83 break;
84 }
85 istringstream ss(line);
86 istringstream ns;
87
88 // Read the channel id
89 char dummy;
90 ss >> channel_id >> dummy; //"dummy" is needed to read the "=" character
91 // cout << "Loading channel " << channel_id << "..." << std::flush;
92
93 // Read until the end of sstream (line)
94 int i_bin = 0;
95 InlSum = 0;
96 while (ss.tellg() != -1) {
97 if (i_bin >= BIN_NUMBER) {
98 cerr << "Too many bins in the INL file for channel " << channel_id << endl;
99 break;
100 }
101
102 // Read until the ',' character or the end of line
103 std::getline(ss, number, ',');
104 ns.str(number);
105 ns.clear();
106 Inltemp = 0;
107 ns >> Inltemp;
108 tempInl->inl[channel_id][i_bin] = Inltemp;
109 InlSum += Inltemp;
110 i_bin++;
111 }
112 // cout << " loaded " << i_bin << " bins" << ". InlSum = " << InlSum << endl;
113 lines_num++;
114 }
115 fINL.close();
116 InlData.push_back(tempInl);
117 if (lines_num != CHANNEL_NUMBER)
118 cerr << "Wrong number of lines in the file (" << lines_num << ")" << endl;
119 cout << endl;
120 counter++;
121 }
122 fList.close();
123
124 // read INL data from vector
125 //
126 // for (Int_t i = 0; i < InlData.size(); i++) {
127 //
128 // TdcInlValue* tempInlread = (TdcInlValue*) InlData.at(i);
129 // cout << "Inl for TDC " << std::hex << tempInlread->serial << std::dec << endl;
130 // for (Int_t ch = 0; ch < 72; ch++) {
131 // InlSum = 0;
132 // for (Int_t j = 0; j < 1024; j++) {
133 // InlSum+= tempInlread->inl[ch][j];
134 // }
135 // cout << " read " << ch << " channel" << ". InlSum = " << InlSum << endl;
136 // }
137 // cout << endl;
138 //
139 // }
140
141 // create parameter in DB
142 // UniParameter* pParameter2 = UniParameter::CreateParameter("TOF1_inl", TdcInlType, 0); //(TString
143 // parameter_name, int parameter_type) delete pParameter2;
144
145 char anwser;
146 cout << "Will be uploaded " << counter << " INL's file" << endl;
147 printf("\tStart: period%d - run%d\n\tStop: period%d - run%d\n", sP, sR, eP, eR);
148 cout << "Okay to upload it? (y/N) ";
149 cin >> anwser;
150 if (anwser == 'Y' || anwser == 'y') {
151 // Upload it
153 UniDetectorParameter::CreateDetectorParameter("TOF1", "TOF1_inl", sP, sR, eP, eR, InlData);
154 if (t == nullptr) {
155 cerr << "Failed to upload the INL" << endl;
156 } else {
157 delete t;
158 cout << "Uupload finished successfully " << endl;
159 }
160 cout << endl;
161 }
162}
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
double Double_t
char * Form(const char *fmt,...)
#define CHANNEL_NUMBER
#define BIN_NUMBER
void add_Tof1_INL_new(TString ListOfINLFiles="ListINLFiles_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
double inl[72][1024]