1 |
kusanagi |
1.1 |
#include <yodaUtility.h> |
2 |
|
|
#include <TObject.h> |
3 |
|
|
#include <TKey.h> |
4 |
|
|
|
5 |
|
|
using namespace std; |
6 |
|
|
/** |
7 |
|
|
* digForFile(TTree& out, TSystemDirectory* tsd, string defin) |
8 |
|
|
* author Nagni |
9 |
|
|
* version 1.0 - 1 September 2004 |
10 |
|
|
* |
11 |
|
|
* version 1.1 - 27 December 2004 |
12 |
|
|
* Checks on TFiles/TList existance |
13 |
|
|
* |
14 |
|
|
* Retrieves and store into a TList according to the root directory and |
15 |
|
|
* a string contained into the filename. |
16 |
|
|
* |
17 |
|
|
* Parameters: |
18 |
|
|
* out - the output Tlist of files |
19 |
|
|
* tsd - the root directory |
20 |
|
|
* defin - the filename substring |
21 |
|
|
* |
22 |
|
|
*/ |
23 |
|
|
void Utility::digForFiles(TList& out, TSystemDirectory *tsd, string defin){ |
24 |
|
|
//char *initialDir = gSystem->pwd(); |
25 |
|
|
TList *lnk = tsd->GetListOfFiles(); |
26 |
|
|
if (lnk==0) return; |
27 |
|
|
|
28 |
|
|
TSystemFile *file = (TSystemFile*)lnk->First(); |
29 |
|
|
|
30 |
|
|
if (file->IsZombie()) { |
31 |
|
|
//gSystem->cd(initialDir); |
32 |
|
|
return; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
string *fileDes = new string(file->GetName()); |
36 |
|
|
unsigned int loc = 0; |
37 |
|
|
|
38 |
|
|
while(file){ |
39 |
|
|
fileDes = new string(file->GetName()); |
40 |
|
|
if(!((fileDes->compare(".") == 0) || (fileDes->compare("..") == 0))){ |
41 |
|
|
if (file->IsDirectory()){ |
42 |
|
|
Utility::digForFiles(out, (TSystemDirectory*)file, defin); |
43 |
|
|
} else { |
44 |
|
|
loc = fileDes->find(defin.c_str(), 0); |
45 |
|
|
if (loc != string::npos){ |
46 |
|
|
out.AddLast((TObject*)file); |
47 |
|
|
// printf("%s file name \n", file->GetName()); |
48 |
|
|
} else { |
49 |
|
|
|
50 |
|
|
} |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
} |
54 |
|
|
file = (TSystemFile*)lnk->After(file); |
55 |
|
|
} |
56 |
|
|
//gSystem->cd(initialDir); |
57 |
|
|
//printf("%d this is the actual size \n", out.GetSize()); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/** |
62 |
|
|
* makeAllFriend(TTree& out, TList* input) |
63 |
|
|
* author Nagni |
64 |
|
|
* version 1.0 - 1 September 2004 |
65 |
|
|
* |
66 |
|
|
* version 1.1 - 27 December 2004 |
67 |
|
|
* Checks on TFiles/TList existance |
68 |
|
|
* |
69 |
|
|
* Create a TTree promoting to friend all the files into the "input" parameter |
70 |
|
|
* returning a TTree |
71 |
|
|
* |
72 |
|
|
* Parameters: |
73 |
|
|
* input - the input Tlist of files |
74 |
|
|
* out - the returned TTree |
75 |
|
|
* |
76 |
|
|
*/ |
77 |
|
|
void Utility::makeAllFriend(TTree& out, TList* input){ |
78 |
|
|
TList *keys; |
79 |
|
|
TKey *key; |
80 |
|
|
TList *resList; |
81 |
|
|
TTree *tr; |
82 |
|
|
TFriendElement *tfe; |
83 |
|
|
string *base; |
84 |
|
|
string *target; |
85 |
|
|
string *className; |
86 |
|
|
unsigned int loc; |
87 |
|
|
bool cont = false; |
88 |
|
|
|
89 |
|
|
TSystemFile *tsf = (TSystemFile*)input->First(); |
90 |
|
|
if (tsf->IsZombie()) return; |
91 |
|
|
|
92 |
|
|
while(tsf){ |
93 |
|
|
base = new string(tsf->GetTitle()); |
94 |
|
|
base->append("/"); |
95 |
|
|
base->append(tsf->GetName()); |
96 |
|
|
//printf("baseAppend %s \n", base->c_str()); |
97 |
|
|
|
98 |
|
|
TFile *tf = new TFile(base->c_str()); |
99 |
|
|
if (tf->IsZombie()) { |
100 |
|
|
tsf = (TSystemFile*)input->After(tsf); |
101 |
|
|
continue; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
keys = tf->GetListOfKeys(); |
105 |
|
|
key = (TKey*)keys->First(); |
106 |
|
|
while(key){ |
107 |
|
|
className = new string(key->GetClassName()); |
108 |
|
|
loc = className->find("Tree", 0); |
109 |
|
|
// printf("%s className \n", className->c_str()); |
110 |
|
|
if(loc != string::npos){ |
111 |
|
|
tr = (TTree*)key->ReadObj(); |
112 |
|
|
if (tr->GetEntries() > 0){ |
113 |
|
|
if(cont){ |
114 |
|
|
tr = (TTree*)key->ReadObj(); |
115 |
|
|
// printf("%s TreeName \n", tr->GetName()); |
116 |
|
|
out.AddFriend(tr->GetName(), tf); |
117 |
|
|
} else { |
118 |
|
|
//out = (TTree*)key->ReadObj(); |
119 |
|
|
out.CopyAddresses((TTree*)key->ReadObj()); |
120 |
|
|
cont = true; |
121 |
|
|
} |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
key = (TKey*)keys->After(key); |
125 |
|
|
} |
126 |
|
|
tsf = (TSystemFile*)input->After(tsf); |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
/** |
131 |
|
|
* makeAllChained(TChain& out, TList* input) |
132 |
|
|
* author Nagni |
133 |
|
|
* version 1.0 - 1 September 2004 |
134 |
|
|
* |
135 |
|
|
* version 1.1 - 27 December 2004 |
136 |
|
|
* Checks on TFiles/TList existance |
137 |
|
|
* |
138 |
|
|
* Create a chain with all the files into the "input" parameter |
139 |
|
|
* returning a TChain |
140 |
|
|
* |
141 |
|
|
* Parameters: |
142 |
|
|
* input - the input Tlist of files |
143 |
|
|
* out - the returned TChain |
144 |
|
|
* |
145 |
|
|
*/ |
146 |
|
|
void Utility::makeAllChained(TChain& out, TList* input){ |
147 |
|
|
TList *keys; |
148 |
|
|
TKey *key; |
149 |
|
|
TList *resList; |
150 |
|
|
TTree *tr; |
151 |
|
|
TFriendElement *tfe; |
152 |
|
|
string *base; |
153 |
|
|
string *target; |
154 |
|
|
string *className; |
155 |
|
|
unsigned int loc; |
156 |
|
|
|
157 |
|
|
TSystemFile *tsf = (TSystemFile*)input->First(); |
158 |
|
|
if (tsf->IsZombie()) return; |
159 |
|
|
|
160 |
|
|
while(tsf){ |
161 |
|
|
base = new string(tsf->GetTitle()); |
162 |
|
|
base->append("/"); |
163 |
|
|
base->append(tsf->GetName()); |
164 |
|
|
//printf("baseAppend %s \n", base->c_str()); |
165 |
|
|
|
166 |
|
|
TFile *tf = new TFile(base->c_str()); |
167 |
|
|
if (tf->IsZombie()) { |
168 |
|
|
tsf = (TSystemFile*)input->After(tsf); |
169 |
|
|
continue; |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
keys = tf->GetListOfKeys(); |
173 |
|
|
key = (TKey*)keys->First(); |
174 |
|
|
while(key){ |
175 |
|
|
className = new string(key->GetClassName()); |
176 |
|
|
loc = className->find("Tree", 0); |
177 |
|
|
//printf("%s className \n", className->c_str()); |
178 |
|
|
if(loc != string::npos){ |
179 |
|
|
tr = (TTree*)key->ReadObj(); |
180 |
|
|
if (tr->GetEntries() > 0){ |
181 |
|
|
out.Add(base->c_str()); |
182 |
|
|
} |
183 |
|
|
} |
184 |
|
|
key = (TKey*)keys->After(key); |
185 |
|
|
} |
186 |
|
|
tsf = (TSystemFile*)input->After(tsf); |
187 |
|
|
} |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
// check to see if the Event class is in the dictionary |
191 |
|
|
// if it is not load the definition in the libXXX.so |
192 |
|
|
/*void Configurator::checkLib(){ |
193 |
|
|
if (!TClassTable::GetDict("pamela::TmtcEvent")){ |
194 |
|
|
// Load YODA/PAMELA class Library |
195 |
|
|
gSystem->Load(Configurator::libYoda); |
196 |
|
|
} |
197 |
|
|
}*/ |
198 |
|
|
|
199 |
|
|
/** |
200 |
|
|
* getFile (TString base, TString packetType, TString subType = "Event") |
201 |
|
|
* author Nagni |
202 |
|
|
* version 1.0 - 1 September 2004 |
203 |
|
|
* |
204 |
|
|
* version 1.1 - 27 December 2004 |
205 |
|
|
* Checks on TFiles/TList existance |
206 |
|
|
* |
207 |
|
|
* Taking advantage of the define structure of YODA created directory |
208 |
|
|
* this function retrieve a specific file from the specified directory. |
209 |
|
|
* Parameters: |
210 |
|
|
* base - the path to the root directory for the specific |
211 |
|
|
* Pamela unpack session |
212 |
|
|
* packetType - one of the Pamela PacketTypes (see in the end) |
213 |
|
|
* subType - can have value: "Event" (default) or "Header" |
214 |
|
|
* |
215 |
|
|
*/ |
216 |
|
|
TFile* Utility::getFile(TString base, TString packetType, TString subType = "Event"){ |
217 |
|
|
|
218 |
|
|
TSystemDirectory *targetDir = new TSystemDirectory("", base); |
219 |
|
|
|
220 |
|
|
TList *filesList = new TList; |
221 |
|
|
TFile *reportFile; |
222 |
|
|
TSystemFile *tsf; |
223 |
|
|
string *tmpString; |
224 |
|
|
|
225 |
|
|
/* |
226 |
|
|
It's an oversized use to find files but in future could be a usefulle generalization; |
227 |
|
|
up to now it's usefull just to make friends a Physics device.ROOT with it's direct Header.ROOT file |
228 |
|
|
because (for now) there is no sense to make friends such couples because of no guarantee |
229 |
|
|
on OBT and packetCounter beetween different downlinks. |
230 |
|
|
*/ |
231 |
|
|
tmpString = new string("."); |
232 |
|
|
tmpString->append(packetType); |
233 |
|
|
tmpString->append("."); |
234 |
|
|
tmpString->append(subType); |
235 |
|
|
tmpString->append("."); |
236 |
|
|
|
237 |
|
|
digForFiles(*filesList, targetDir, tmpString->c_str()); |
238 |
|
|
if (filesList->IsEmpty()) return 0; |
239 |
|
|
|
240 |
|
|
targetDir = new TSystemDirectory("", base); |
241 |
|
|
|
242 |
|
|
//Takes the physic header file |
243 |
|
|
tsf = (TSystemFile*)filesList->First(); |
244 |
|
|
// printf("Title: %s ----------------- Name: %s \n", tsf->GetTitle(), tsf->GetName()); |
245 |
|
|
tmpString = new string(tsf->GetTitle()); |
246 |
|
|
tmpString->append("/"); |
247 |
|
|
tmpString->append(tsf->GetName()); |
248 |
|
|
return new TFile(tmpString->c_str()); |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
/** |
252 |
|
|
* int getLastNotZeroBin (TH1 *histo) |
253 |
|
|
* author Nagni |
254 |
|
|
* version 1.0 - 22 February 2005 |
255 |
|
|
* |
256 |
|
|
* Returns the histogram smaller bin not equal to zero. |
257 |
|
|
* Parameters: |
258 |
|
|
* histo - the histogram object |
259 |
|
|
* |
260 |
|
|
* Return: |
261 |
|
|
* int - the value of the bin |
262 |
|
|
* |
263 |
|
|
*/ |
264 |
|
|
Int_t Utility::getLastNotZeroBin(TH1 *histo){ |
265 |
|
|
Int_t lastBin = 0; |
266 |
|
|
Int_t tempBin = 0; |
267 |
|
|
Stat_t minVal = 0; |
268 |
|
|
Stat_t tempVal = 0; |
269 |
|
|
Int_t range = histo->GetNbinsX(); |
270 |
|
|
|
271 |
|
|
tempBin = histo->GetMaximumBin(); |
272 |
|
|
tempVal = histo->GetBinContent(tempBin); |
273 |
|
|
minVal = tempVal; |
274 |
|
|
lastBin = tempBin; |
275 |
|
|
|
276 |
|
|
for (Int_t i = histo->GetMaximumBin() + 1; i < range; i++){ |
277 |
|
|
tempVal = histo->GetBinContent(i); |
278 |
|
|
if ((tempVal != 0) && (tempVal < minVal)) { |
279 |
|
|
minVal = tempVal; |
280 |
|
|
lastBin = i; |
281 |
|
|
} |
282 |
|
|
} |
283 |
|
|
//In the end I add 10% to the retrieved value |
284 |
|
|
return (Int_t)(lastBin*1.10); |
285 |
|
|
} |
286 |
|
|
|
287 |
|
|
/** |
288 |
|
|
* int getFirstNotZeroBin (TH1 *histo) |
289 |
|
|
* author Nagni |
290 |
|
|
* version 1.0 - 22 February 2005 |
291 |
|
|
* |
292 |
|
|
* Returns the histogram greater bin not equal to zero. |
293 |
|
|
* Parameters: |
294 |
|
|
* histo - the histogram object |
295 |
|
|
* |
296 |
|
|
* Return: |
297 |
|
|
* int - the value of the bin |
298 |
|
|
* |
299 |
|
|
*/ |
300 |
|
|
Int_t Utility::getFirstNotZeroBin(TH1 *histo){ |
301 |
|
|
Int_t lastBin = 0; |
302 |
|
|
Int_t tempBin = 0; |
303 |
|
|
Stat_t minVal = 0; |
304 |
|
|
Stat_t tempVal = 0; |
305 |
|
|
|
306 |
|
|
tempBin = histo->GetMaximumBin(); |
307 |
|
|
tempVal = histo->GetBinContent(tempBin); |
308 |
|
|
minVal = tempVal; |
309 |
|
|
lastBin = tempBin; |
310 |
|
|
|
311 |
|
|
for (Int_t i = histo->GetMaximumBin() - 1; i > 0; i--){ |
312 |
|
|
tempVal = histo->GetBinContent(i); |
313 |
|
|
if ((tempVal != 0) && (tempVal < minVal)) { |
314 |
|
|
minVal = tempVal; |
315 |
|
|
lastBin = i; |
316 |
|
|
} |
317 |
|
|
} |
318 |
|
|
//In the end I subtract 10% to the retrieved value |
319 |
|
|
return (Int_t)(lastBin*0.90); |
320 |
|
|
} |