GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
ConvertDriftFiles.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <fstream>
4#include <sstream>
5#include <vector>
6#include <string>
7
8#include "TChannel.h"
9
10int main(int argc, char** argv)
11{
12 if(argc < 3) {
13 std::cerr<<"Usage: "<<argv[0]<<" <cal-file> <drift-files>"<<std::endl;
14 return 1;
15 }
16
17 for(int i = 2; i < argc; ++i) {
18 // re-open the TChannel for each file to reset all parameters
20 TChannel::ReadCalFile(argv[1]);
21
22 // open the input file
23 std::ifstream driftFile(argv[i]);
24 // get the run number from the file name
25 std::string name(argv[i]);
26 std::stringstream str(name.substr(name.size()-10,6));
27 int runNumber;
28 str>>runNumber;
29
30 // create name for the output cal-file from the run number
31 str.str("");
32 str.clear();
33 str<<"run"<<runNumber<<".cal";
34 name = str.str();
35
36 std::string line;
37 while(std::getline(driftFile, line)) {
38 // skip empty lines and comments
39 if(line.empty() || std::all_of(line.begin(), line.end(), [](char c){ return std::isspace(c); }) || line[0] == '#') continue;
40
41 int globId;
42 double coefficent;
43
44 str.str(line);
45 str.clear();
46 str>>globId;
47 //std::cout<<"from line \""<<line<<"\" got globId "<<globId<<std::endl;
48
49 TChannel* channel = TChannel::GetChannelByNumber(globId+1);
50
51 if(channel == nullptr) {
52 std::cerr<<"Failed to find a channel for ID "<<globId<<std::endl;
53 continue;
54 }
55 //std::cout<<"Found channel "<<channel->GetName()<<" for ID "<<globId<<std::endl;
56
57 while(!(str>>coefficent).fail()) {
58 channel->AddENGDriftCoefficent(coefficent);
59 }
60 }
61
62 // write the cal-file
64 }
65
66 return 0;
67}
68
int main(int argc, char **argv)
static void WriteCalFile(const std::string &outfilename="")
Definition TChannel.cxx:992
static void DeleteAllChannels()
Definition TChannel.cxx:273
static Int_t ReadCalFile(std::ifstream &infile)
void AddENGDriftCoefficent(Float_t temp)
Definition TChannel.h:209
static TChannel * GetChannelByNumber(int temp_num)
Definition TChannel.cxx:482