1 | /* |
---|
2 | * John Idarraga <idarraga@cern.ch> |
---|
3 | * |
---|
4 | */ |
---|
5 | |
---|
6 | #include <iostream> |
---|
7 | #include <string> |
---|
8 | #include <vector> |
---|
9 | |
---|
10 | #include "TH2.h" |
---|
11 | #include "TCanvas.h" |
---|
12 | #include "TApplication.h" |
---|
13 | #include "TColor.h" |
---|
14 | #include "TPaletteAxis.h" |
---|
15 | #include "TStyle.h" |
---|
16 | #include "TROOT.h" |
---|
17 | #include "TPaveLabel.h" |
---|
18 | #include "TControlBar.h" |
---|
19 | #include "TObject.h" |
---|
20 | #include "TString.h" |
---|
21 | |
---|
22 | #include "MediPixViewer.h" |
---|
23 | #include "listHandler.h" |
---|
24 | #include "control.h" |
---|
25 | #include "MediPixWriteToEntuple.h" |
---|
26 | #include "allpix_dm.h" |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | void checkParameters(int, char**, TString *); |
---|
31 | void histoProperties(TH2I *, TCanvas *); |
---|
32 | TApplication * g_theApp = new TApplication("Output", 0, NULL); |
---|
33 | Int_t g_direction = 0; |
---|
34 | |
---|
35 | int main(int argc, char ** argv){ |
---|
36 | |
---|
37 | ///////////////////////////////////// |
---|
38 | // check flags |
---|
39 | TString tempScratchDir = ""; |
---|
40 | checkParameters(argc, argv, &tempScratchDir); |
---|
41 | |
---|
42 | // create ntuple and FramesHandler |
---|
43 | TString dataset = argv[2]; |
---|
44 | WriteToNtuple MPXnTuple(dataset, tempScratchDir); |
---|
45 | FramesHandler frames(dataset); |
---|
46 | |
---|
47 | long int skipFrames = 0; |
---|
48 | if(argc == 5) |
---|
49 | skipFrames = atoi(argv[4]); |
---|
50 | |
---|
51 | ///////////////////////////////////// |
---|
52 | // Handle the list of files |
---|
53 | ListHandler handlerL(argv[1]); |
---|
54 | std::vector<std::string> listOfFiles = handlerL.getListToLoop(tempScratchDir, FRAME_FILES); |
---|
55 | std::cout << "[INFO] there are " << listOfFiles.size() << " frame files in directory" << std::endl; |
---|
56 | |
---|
57 | std::vector<std::string> listOfDSCFiles = handlerL.getListToLoop(tempScratchDir, DSC_FILES); |
---|
58 | std::cout << "[INFO] there are " << listOfDSCFiles.size() << " DSC files in directory" << std::endl; |
---|
59 | |
---|
60 | |
---|
61 | if(listOfFiles.empty()){ |
---|
62 | std::cout << "[ERROR] I could not find any frame files in the specified directory," << std::endl; |
---|
63 | std::cout << " or the dir does not exist at all ... leaving" << std::endl; |
---|
64 | exit(1); |
---|
65 | } |
---|
66 | |
---|
67 | /* make sure frames list and DSC list match alright */ |
---|
68 | if(listOfDSCFiles.size() != 0) |
---|
69 | listOfDSCFiles = handlerL.OrderFilesPairMatch(listOfFiles, listOfDSCFiles); |
---|
70 | |
---|
71 | /* |
---|
72 | vector<std::string>::iterator itrr = listOfDSCFiles.begin(); |
---|
73 | for( ; itrr != listOfDSCFiles.end() ; itrr++){ |
---|
74 | cout << *itrr << endl; |
---|
75 | } |
---|
76 | exit(1); |
---|
77 | */ |
---|
78 | |
---|
79 | if( listOfFiles.size() != listOfDSCFiles.size() ) { |
---|
80 | std::cout << "[ERROR] you have a different amount of dsc and frame files." << std::endl; |
---|
81 | std::cout << " You probably have an extra file that doesn't correspond" << std::endl; |
---|
82 | std::cout << " to the data taking ... check it out. Giving up." << std::endl; |
---|
83 | exit(1); |
---|
84 | } |
---|
85 | |
---|
86 | Long_t filesItr; |
---|
87 | std::string oneFileName = ""; |
---|
88 | std::string oneDSCFileName = ""; |
---|
89 | |
---|
90 | for(filesItr = 0 ; filesItr < (Int_t)listOfFiles.size() ; filesItr++) |
---|
91 | { |
---|
92 | |
---|
93 | if(filesItr < skipFrames) continue; // skip if needed |
---|
94 | |
---|
95 | oneFileName = listOfFiles[filesItr]; |
---|
96 | oneDSCFileName = listOfDSCFiles[filesItr]; |
---|
97 | //frames.getAFrameMatrix((TString) oneFileName, (TString) oneDSCFileName); |
---|
98 | bool frameread = frames.readOneFrame((TString) oneFileName, (TString) oneDSCFileName); |
---|
99 | |
---|
100 | if(frameread) { |
---|
101 | MPXnTuple.fillVars(&frames); |
---|
102 | } |
---|
103 | |
---|
104 | } |
---|
105 | |
---|
106 | MPXnTuple.closeNtuple(); |
---|
107 | |
---|
108 | std::cout << "[ OK ] done with the conversion. Check your output file --> " |
---|
109 | << MPXnTuple.GetNtupleFileName() << std::endl; |
---|
110 | |
---|
111 | |
---|
112 | // erasing possible remaining working files |
---|
113 | |
---|
114 | std::string command0 = "/bin/bash -c 'if [ -e "; |
---|
115 | if(tempScratchDir.Length() > 0) { command0 += tempScratchDir.Data(); command0 += "/"; } |
---|
116 | command0 += "listOfFiles.txt ] ; then rm -f "; |
---|
117 | if(tempScratchDir.Length() > 0) { command0 += tempScratchDir.Data(); command0 += "/"; } |
---|
118 | command0 += "listOfFiles.txt ; fi'"; |
---|
119 | |
---|
120 | std::string command02 = "/bin/bash -c 'if [ -e "; |
---|
121 | if(tempScratchDir.Length() > 0) { command02 += tempScratchDir.Data(); command02 += "/"; } |
---|
122 | command02 += "listOfFiles.dsc.txt ] ; then rm -f "; |
---|
123 | if(tempScratchDir.Length() > 0) { command02 += tempScratchDir.Data(); command02 += "/"; } |
---|
124 | command02 += "listOfFiles.dsc.txt ; fi'"; |
---|
125 | |
---|
126 | system(command0.c_str()); |
---|
127 | system(command02.c_str()); |
---|
128 | |
---|
129 | return 0; |
---|
130 | } |
---|
131 | |
---|
132 | void checkParameters(int argc, char ** argv, TString * tempScratchDir){ |
---|
133 | |
---|
134 | if(argc < 3) |
---|
135 | { |
---|
136 | std::cout << " use:" << std::endl; |
---|
137 | std::cout << " " << argv[0] << " pathToData outputFileName tempScratchDir(optional. ./ default) skip(optional)" << std::endl; |
---|
138 | std::cout << " pathToData : Directory where your have stored your data in ascii" << std::endl; |
---|
139 | std::cout << " format (uncompressed). Can be an absolute or " << std::endl; |
---|
140 | std::cout << " relative path." << std::endl; |
---|
141 | std::cout << " dataSetNumber: A short string to easily identify your data later on." << std::endl; |
---|
142 | std::cout << " Example --> MediPix_SPS_TOTmode_25-06-2007" << std::endl; |
---|
143 | std::cout << " please do not use special character or spaces." << std::endl; |
---|
144 | std::cout << " tempFilesDir : In case you can only read from the directory" << std::endl; |
---|
145 | std::cout << " containing the data but can't write, you can" << std::endl; |
---|
146 | std::cout << " tell " << argv[0] << "to use a different temp dir."<< std::endl; |
---|
147 | std::cout << " skip : Number of events to skip optional (int)" << std::endl; |
---|
148 | |
---|
149 | exit(1); |
---|
150 | } |
---|
151 | |
---|
152 | TString dataSet = argv[2]; |
---|
153 | |
---|
154 | if (dataSet == "" || dataSet.Contains(' ')) |
---|
155 | { |
---|
156 | std::cout << "[ERROR] badformat in dataSet !" << std::endl; |
---|
157 | std::cout << " dataSetNumber: example --> MediPix_SPS_TOTmode_25-06-2007" << std::endl; |
---|
158 | std::cout << " please do not use special character or spaces." << std::endl; |
---|
159 | exit(1); |
---|
160 | } |
---|
161 | |
---|
162 | // user decided to use a different scratch dir |
---|
163 | // optional |
---|
164 | if(argc > 2){ |
---|
165 | *tempScratchDir += argv[3]; |
---|
166 | if(tempScratchDir->Length() == 0) *tempScratchDir = "./"; |
---|
167 | std::cout << "[INFO] working directory is " << *tempScratchDir << std::endl; |
---|
168 | } |
---|
169 | |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | void histoProperties(TH2I * h1, TCanvas * c){ |
---|
174 | |
---|
175 | h1->SetStats(false); |
---|
176 | gStyle->SetPalette(1,0); |
---|
177 | |
---|
178 | c->SetBorderMode(0); |
---|
179 | c->SetFillColor(kWhite); |
---|
180 | |
---|
181 | c->Update(); |
---|
182 | |
---|
183 | } |
---|