BmnRoot
Loading...
Searching...
No Matches
BmnFieldParser.cxx
Go to the documentation of this file.
1
2// -------------------------------------------------------------------------
3// ----- BmnFieldParser source file -----
4// ----- Created 28/06/22 by M.Mamaev, S.Merts -----
5// -------------------------------------------------------------------------
6
7
8#include "BmnFieldParser.h"
9
10vector<BmnFieldPoint> BmnFieldParser::ParseData(TString file_name, Bool_t doShift) {
11 cout << "Reading file: " << file_name << endl;
12 Int_t idxStart = file_name.Index("file_") + 5;
13 Int_t idxEnd = file_name.Index("_CW.");
14 TString shift = file_name(idxStart, idxEnd - idxStart);
15 TString fileIdx = shift(0, shift.Index("_"));
16 Int_t yShift = (doShift) ? TString(shift(shift.Index("_") + 1, shift.Length() - shift.Index("_") - 1)).Atoi() : 0;
17 cout << "File index: " << fileIdx << " Y shift = " << yShift << endl;
18 ifstream in_file(file_name);
19 if (!in_file.is_open())
20 throw runtime_error("Unable to read file " + file_name);
21 string line;
22 size_t line_number = 0;
23 vector<BmnFieldPoint> field_points;
24 while (getline(in_file, line)) {
25 istringstream stream(line);
26 // Skipping the title of the table
27 if (line_number == 0) {
28 line_number++;
29 continue;
30 }
31 Double_t enc_pos = 0;
32 Double_t x = 0, y = 0, z = 0;
33 Double_t mon = 0;
34 Double_t bx = 0, by = 0, bz = 0;
35 stream >> enc_pos >> x >> y >> z >> mon >> bx >> by >> bz;
36 field_points.push_back(BmnFieldPoint(x, y + yShift, z, bx, by, bz));
37 line_number++;
38 }
39 cout << field_points.size() << " points are read" << endl;
40 return field_points;
41}
42
43map<pair<Int_t, Int_t>, BmnFieldPoint> BmnFieldParser::ParseDataMap(TString file_name, Bool_t doShift) {
44 cout << "Reading file: " << file_name << endl;
45 Int_t idxStart = file_name.Index("file_") + 5;
46 Int_t idxEnd = file_name.Index("_CW.");
47 TString shift = file_name(idxStart, idxEnd - idxStart);
48 TString fileIdx = shift(0, shift.Index("_"));
49 Int_t yShift = (doShift) ? TString(shift(shift.Index("_") + 1, shift.Length() - shift.Index("_") - 1)).Atoi() : 0;
50 cout << "File index: " << fileIdx << " Y shift = " << yShift << endl;
51 ifstream in_file(file_name);
52 if (!in_file.is_open())
53 throw runtime_error("Unable to read file " + file_name);
54 string line;
55 size_t line_number = 0;
56 map<pair<Int_t, Int_t>, BmnFieldPoint> field_points;
57 while (getline(in_file, line)) {
58 istringstream stream(line);
59 // Skipping the title of the table
60 if (line_number == 0) {
61 line_number++;
62 continue;
63 }
64 Double_t enc_pos = 0;
65 Double_t x = 0, y = 0, z = 0;
66 Double_t mon = 0;
67 Double_t bx = 0, by = 0, bz = 0;
68 stream >> enc_pos >> x >> y >> z >> mon >> bx >> by >> bz;
69 if (Int_t(y + yShift) == 3075) cout << Int_t(x) << " " << Int_t(y + yShift) << endl;
70 field_points.insert(pair<pair<Int_t, Int_t>, BmnFieldPoint>(pair<Int_t, Int_t>(Int_t(x), Int_t(y + yShift)), BmnFieldPoint(x, y + yShift, z, bx, by, bz)));
71 line_number++;
72 }
73 cout << field_points.size() << endl;
74 cout << field_points.size() << " points are read" << endl;
75 return field_points;
76}
77
vector< BmnFieldPoint > ParseData(TString file_name, Bool_t shift=kTRUE)
map< pair< Int_t, Int_t >, BmnFieldPoint > ParseDataMap(TString file_name, Bool_t shift=kTRUE)