1 |
///////////////////////////////////////////////////////////////////////// |
2 |
// Program to convert an gpamela ntuple to pamela raw data (.pam). |
3 |
// A root file containing the ntuple is also produced. |
4 |
// The conversion is done using a slightly patched version of |
5 |
// Rene Brun's h2root. |
6 |
// |
7 |
// Created : 2006 Jan Conrad (conrad@particle.kth.se) |
8 |
// Modified: 2007 Silvio Orsi (silvio.orsi@roma2.infn.it) |
9 |
// |
10 |
// |
11 |
// HOWTO (RECOMMENDED): |
12 |
// ./ Pamelagp2Digits -hbookfile filename.his |
13 |
// It generates filename.pam (PAMELA raw data) and filename.gp.root (sim info) |
14 |
// |
15 |
// NB: more details are present in the file HOW-TO-DIGIT.TXT |
16 |
// |
17 |
// HOWTO |
18 |
// see usage(). Example: |
19 |
// Pamelagp2Digits -hbookfile filename.his -rootfile filename.root -pamfile filename.pam -calocompress [VAL] -rootcompress [VAL] |
20 |
// The following flags are from h2root and default values are used: |
21 |
// if rootcompress is missing (or = 1) the ROOT file will be compressed |
22 |
// if rootcompress = 0 the ROOT file will not be compressed. |
23 |
// if tolower is missing (or = 1) ntuple column names are converted to lower case |
24 |
// but the first character is converted to upper case. |
25 |
// if tolower = 2 same as tolower=1 except that the first character is also |
26 |
// convertex to lower case |
27 |
// |
28 |
// |
29 |
// MODIFICATIONS: |
30 |
// (C.Pizzolotto. Trieste. october 2009) |
31 |
// - added DigitizeCALOCOMPRESS to write calorimeter data in compress mode |
32 |
// - changed way of reading input parameters. now the input order is not important. |
33 |
// |
34 |
// v. 1.5 (S.Orsi, Roma2, 11 October 2007) |
35 |
// - file HOW-TO-DIGIT.TXT written (mainly by S.Bottai): contains information on how to run the chain from the DB creation to DarthVader through Digitizer, yoda and YodaProfiler |
36 |
// |
37 |
// v. 1.4 (S.Orsi, Roma2, 11 October 2007) |
38 |
// - similar to v. 1.3 |
39 |
// |
40 |
// v. 1.3 (S.Orsi, Roma2, 11 October 2007) |
41 |
// - TOF: + changes and major corrections in ADC and TDC (W.Menn, D.Campana, S.Orsi) |
42 |
// + flag DEBUG added (default: DEBUG=false; if true, print on screem some messages to debug) |
43 |
// - AC: + shift register filled; |
44 |
// + minor bugs fixed |
45 |
// + counters increment by 1 at each event (they were constant before) |
46 |
// - S4: + minor bugs fixed (S.Borisov) |
47 |
// + the routine DigitizeS4() is now inserted in the code. For DV versions earlier than October 2007, the option "-S4" is still needed because S4 calibration is not present |
48 |
// - corrected severe bug that caused yoda to process only part of large data files (file.pam). S4 data were written to file even if the DigitizeS4() routine was not called. Previous versions of the digitizer should have crashed always, but unexpectedly worked on small files. |
49 |
// - file HOW-TO-DIGIT.TXT written (mainly by S.Bottai): contains information on how to run the chain from the DB creation to DarthVader through Digitizer, yoda and YodaProfiler. The file is included only from release 1.5 |
50 |
// - digitizer version numbers modified according to CVS repository (v1.00->v1.1, v1.01->v1.2) |
51 |
// - some flags (LDFLAGS) in the Makefile have been changed; they are needed on some machines (e.g. pamelatov.roma2.infn.it), but give errors on others (e.g. pamelaws02.na.infn.it). See Makefile for details if the compilation fails due to library errors) |
52 |
// |
53 |
// v. 1.2 (S.Orsi, Roma2, 28 September 2007) |
54 |
// - TOF TDC inserted (to be tuned) |
55 |
// - improved tracker dEdx, tracker saturation inserted (S.Bottai) |
56 |
// - S4 routine inserted in code (not in read-out) |
57 |
// - bugs with packet length corrected |
58 |
// - small bugs fixed |
59 |
// - NB: Run DarthVader with the options: "DarthVader -zerofill -idRun 1 -ALL +RUN +CAL [ --no-crosstalk ] +TRK +TOF +AC +TRG +ND" or "DarthVader -zerofill -idRun 1 +CAL [ --no-crosstalk ] -S4", i.e. without S4 |
60 |
// |
61 |
// v. 1.1 (S.Orsi, Roma2, 13 September 2007) |
62 |
// - trigger (dummy), tof (preliminary, adc only), ND (preliminary) inserted |
63 |
// - various changes and bug fixes |
64 |
// - padding increased (fPADbuffer=64, fPadding = padbytes+64) |
65 |
// |
66 |
// v. beta (J.Conrad, KTH, 2006) |
67 |
// - compiles; includes pscu, calo, trk, ac; not present on cvs |
68 |
// |
69 |
///////////////////////////////////////////////////////////////////////// |
70 |
|
71 |
#include "Digitizer.h" |
72 |
|
73 |
using namespace std; |
74 |
|
75 |
//int Error; //to be removed soon |
76 |
|
77 |
// Define the names of the Fortran common blocks for the different OSs |
78 |
|
79 |
#ifndef WIN32 |
80 |
#define PAWC_SIZE 5000000 |
81 |
# define pawc pawc_ |
82 |
# define quest quest_ |
83 |
# define hcbits hcbits_ |
84 |
# define hcbook hcbook_ |
85 |
# define rzcl rzcl_ |
86 |
int pawc[PAWC_SIZE]; |
87 |
int quest[100]; |
88 |
int hcbits[37]; |
89 |
int hcbook[51]; |
90 |
int rzcl[11]; |
91 |
#else |
92 |
// on windows /pawc/ must have the same length as in libPacklib.a !! |
93 |
#define PAWC_SIZE 2000000 |
94 |
# define pawc PAWC |
95 |
# define quest QUEST |
96 |
# define hcbits HCBITS |
97 |
# define hcbook HCBOOK |
98 |
# define rzcl RZCL |
99 |
extern "C" int pawc[PAWC_SIZE]; |
100 |
extern "C" int quest[100]; |
101 |
extern "C" int hcbits[37]; |
102 |
extern "C" int hcbook[51]; |
103 |
extern "C" int rzcl[11]; |
104 |
#endif |
105 |
|
106 |
int *iq, *lq; |
107 |
float *q; |
108 |
char idname[128]; |
109 |
int nentries; |
110 |
char chtitl[128]; |
111 |
int ncx,ncy,nwt,idb; |
112 |
int lcont, lcid, lcdir; |
113 |
float xmin,xmax,ymin,ymax; |
114 |
int comprcalomode; |
115 |
const Int_t kMIN1 = 7; |
116 |
const Int_t kMAX1 = 8; |
117 |
|
118 |
#if defined __linux |
119 |
//On linux Fortran wants this, so we give to it! |
120 |
int xargv=0; |
121 |
int xargc=0; |
122 |
void MAIN__() {} |
123 |
#endif |
124 |
|
125 |
// Define the names of the Fortran subroutine and functions for the different OSs |
126 |
|
127 |
#ifndef WIN32 |
128 |
# define hlimit hlimit_ |
129 |
# define hropen hropen_ |
130 |
# define hrin hrin_ |
131 |
# define hnoent hnoent_ |
132 |
# define hgive hgive_ |
133 |
# define hgiven hgiven_ |
134 |
# define hprntu hprntu_ |
135 |
# define hgnpar hgnpar_ |
136 |
# define hgnf hgnf_ |
137 |
# define hgnt hgnt_ |
138 |
# define rzink rzink_ |
139 |
# define hdcofl hdcofl_ |
140 |
# define hmaxim hmaxim_ |
141 |
# define hminim hminim_ |
142 |
# define hdelet hdelet_ |
143 |
# define hntvar2 hntvar2_ |
144 |
# define hbname hbname_ |
145 |
# define hbnamc hbnamc_ |
146 |
# define hbnam hbnam_ |
147 |
# define hi hi_ |
148 |
# define hie hie_ |
149 |
# define hif hif_ |
150 |
# define hij hij_ |
151 |
# define hix hix_ |
152 |
# define hijxy hijxy_ |
153 |
# define hije hije_ |
154 |
# define hcdir hcdir_ |
155 |
# define zitoh zitoh_ |
156 |
# define uhtoc uhtoc_ |
157 |
|
158 |
# define type_of_call |
159 |
# define DEFCHAR const char* |
160 |
# define PASSCHAR(string) string |
161 |
#else |
162 |
# define hlimit HLIMIT |
163 |
# define hropen HROPEN |
164 |
# define hrin HRIN |
165 |
# define hnoent HNOENT |
166 |
# define hgive HGIVE |
167 |
# define hgiven HGIVEN |
168 |
# define hprntu HPRNTU |
169 |
# define hgnpar HGNPAR |
170 |
# define hgnf HGNF |
171 |
# define hgnt HGNT |
172 |
# define rzink RZINK |
173 |
# define hdcofl HDCOFL |
174 |
# define hmaxim HMAXIM |
175 |
# define hminim HMINIM |
176 |
# define hdelet HDELET |
177 |
# define hntvar2 HNTVAR2 |
178 |
# define hbname HBNAME |
179 |
# define hbnamc HBNAMC |
180 |
# define hbnam HBNAM |
181 |
# define hi HI |
182 |
# define hie HIE |
183 |
# define hif HIF |
184 |
# define hij HIJ |
185 |
# define hix HIX |
186 |
# define hijxy HIJXY |
187 |
# define hije HIJE |
188 |
# define hcdir HCDIR |
189 |
# define zitoh ZITOH |
190 |
# define uhtoc UHTOC |
191 |
# define type_of_call _stdcall |
192 |
# define DEFCHAR const char*, const int |
193 |
# define PASSCHAR(string) string, strlen(string) |
194 |
#endif |
195 |
|
196 |
extern "C" void type_of_call hlimit(const int&); |
197 |
#ifndef WIN32 |
198 |
extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR, |
199 |
const int&,const int&,const int,const int,const int); |
200 |
#else |
201 |
extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR, |
202 |
const int&,const int&); |
203 |
#endif |
204 |
|
205 |
extern "C" void type_of_call hrin(const int&,const int&,const int&); |
206 |
extern "C" void type_of_call hnoent(const int&,const int&); |
207 |
#ifndef WIN32 |
208 |
extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&, |
209 |
const int&,const float&,const float&,const int&,const int&,const int); |
210 |
#else |
211 |
extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&, |
212 |
const int&,const float&,const float&,const int&,const int&); |
213 |
#endif |
214 |
|
215 |
#ifndef WIN32 |
216 |
extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR, |
217 |
const float&,const float&,const int,const int); |
218 |
#else |
219 |
extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR, |
220 |
const float&,const float&); |
221 |
#endif |
222 |
|
223 |
#ifndef WIN32 |
224 |
extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&,const int,const int, const int); |
225 |
#else |
226 |
extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&); |
227 |
#endif |
228 |
|
229 |
#ifndef WIN32 |
230 |
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,const int, const int); |
231 |
#else |
232 |
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&); |
233 |
#endif |
234 |
|
235 |
extern "C" void type_of_call hprntu(const int&); |
236 |
extern "C" void type_of_call hgnpar(const int&,const char *,const int); |
237 |
extern "C" void type_of_call hgnf(const int&,const int&,const float&,const int&); |
238 |
extern "C" void type_of_call hgnt(const int&,const int&,const int&); |
239 |
extern "C" void type_of_call rzink(const int&,const int&,const char *,const int); |
240 |
extern "C" void type_of_call hdcofl(); |
241 |
extern "C" void type_of_call hmaxim(const int&,const float&); |
242 |
extern "C" void type_of_call hminim(const int&,const float&); |
243 |
extern "C" void type_of_call hdelet(const int&); |
244 |
extern "C" float type_of_call hi(const int&,const int&); |
245 |
extern "C" float type_of_call hie(const int&,const int&); |
246 |
extern "C" float type_of_call hif(const int&,const int&); |
247 |
extern "C" float type_of_call hij(const int&,const int&,const int&); |
248 |
extern "C" void type_of_call hix(const int&,const int&,const float&); |
249 |
extern "C" void type_of_call hijxy(const int&,const int&,const int&,const float&,const float&); |
250 |
extern "C" float type_of_call hije(const int&,const int&,const int&); |
251 |
#ifndef WIN32 |
252 |
extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR ,const int,const int); |
253 |
#else |
254 |
extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR); |
255 |
#endif |
256 |
|
257 |
extern "C" void type_of_call zitoh(const int&,const int&,const int&); |
258 |
#ifndef WIN32 |
259 |
extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&,const int); |
260 |
#else |
261 |
extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&); |
262 |
#endif |
263 |
|
264 |
extern void convert_directory(const char*, char* file_raw); |
265 |
extern void convert_1d(Int_t id); |
266 |
extern void convert_cwn(Int_t id,char* file_raw); |
267 |
|
268 |
|
269 |
Int_t golower = 1; |
270 |
Int_t bufsize = 64000; |
271 |
Int_t optcwn = 1; |
272 |
|
273 |
char *DigitizerInfo(bool print); |
274 |
|
275 |
|
276 |
|
277 |
void usage(){ |
278 |
printf("\nUsage:\n"); |
279 |
printf("\n Pamelagp2Digits [options] -hbookfile file.hbook \n"); |
280 |
printf("\n -hbookfile path to the file that has to be converted \n"); |
281 |
printf("\n Options are:\n\n"); |
282 |
printf(" -h | --help print this help and exit \n"); |
283 |
printf(" -rootfile name of the root file in output finename.root,\n"); |
284 |
printf(" if parameter is missing the name is generated from the hbook file name\n"); |
285 |
printf(" -pamfile name of the pam file in output filename.pam \n"); |
286 |
printf(" if parameter is missing the name is generated from the hbook file name\n"); |
287 |
printf(" -calocompress compression of data in calorimeter- By default is 1.\n"); |
288 |
printf(" 0 is RAW, 1 is COMPRESS, 2 is FULL (2 not yet implemented)\n"); |
289 |
printf(" -rootcompress compression of root file = 1 by default (use 0 for no compression)\n"); |
290 |
printf(" -tolower = 1 by default : ntuple column names are converted to lower case \n"); |
291 |
printf(" but the first character is converted to upper case.\n"); |
292 |
printf(" if 2 same as tolower=1 but also the first character is converted to lower case.\n"); |
293 |
printf(" use 0 to keep case of column names\n"); |
294 |
printf(" -lrecl =0 by default (must be specified if >8092)\n"); |
295 |
printf(" -bufsize = 8000 by default (branch buffer size)\n"); |
296 |
printf(" -optcwn for cwn ntuple only: optcwn\n"); |
297 |
printf(" = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n"); |
298 |
printf("\n The order of input files and options does not matter. \n"); |
299 |
printf("\n Example: \n"); |
300 |
printf(" Pamelagp2Digits -hbookfile /path/to/files/protons_1_300-500.rz -caloCompress 1 \n\n"); |
301 |
} |
302 |
|
303 |
|
304 |
int main(int argc, char *argv[]) |
305 |
{ |
306 |
|
307 |
printf("init\n"); |
308 |
lq = &pawc[9]; |
309 |
iq = &pawc[17]; |
310 |
void *qq = iq; |
311 |
q = (float*)qq; |
312 |
|
313 |
char *file_out = new char[512]; |
314 |
strcpy(file_out," "); |
315 |
char *file_raw; |
316 |
Int_t rootcompress = 1; |
317 |
Int_t calocompress = 1; |
318 |
int ier=0, record_size=0; |
319 |
|
320 |
char *rootfile = new char[512]; |
321 |
strcpy(rootfile," "); |
322 |
char *pamfile = new char[512]; |
323 |
strcpy(pamfile," "); |
324 |
char *file_in; |
325 |
file_in = NULL ; |
326 |
|
327 |
Int_t i = 0; |
328 |
if ( argc > 1 ){ |
329 |
while ( i < argc ){ |
330 |
if ( !strcmp(argv[i],"-h") || !strcmp(argv[i],"--help") ){ |
331 |
usage(); |
332 |
return 0; |
333 |
}; |
334 |
if ( !strcmp(argv[i],"-hbookfile") ) { |
335 |
if ( argc-1 < i+1 ){ |
336 |
usage(); |
337 |
return 1; |
338 |
}; |
339 |
file_in = argv[i+1]; |
340 |
}; |
341 |
if ( !strcmp(argv[i],"-rootfile") ) { |
342 |
if ( argc-1 < i+1 ){ |
343 |
usage(); |
344 |
return 1; |
345 |
}; |
346 |
rootfile = argv[i+1]; |
347 |
}; |
348 |
if ( !strcmp(argv[i],"-pamfile") ) { |
349 |
if ( argc-1 < i+1 ){ |
350 |
usage(); |
351 |
return 1; |
352 |
}; |
353 |
pamfile = argv[i+1]; |
354 |
}; |
355 |
if ( !strcmp(argv[i],"-calocompress") ) { |
356 |
if ( argc-1 < i+1 ){ |
357 |
usage(); |
358 |
return 1; |
359 |
}; |
360 |
calocompress = atoi(argv[i+1]); |
361 |
}; |
362 |
if ( !strcmp(argv[i],"-rootcompress") ) { |
363 |
if ( argc-1 < i+1 ){ |
364 |
usage(); |
365 |
return 1; |
366 |
}; |
367 |
rootcompress = atoi(argv[i+1]); |
368 |
}; |
369 |
if ( !strcmp(argv[i],"-tolower") ) { |
370 |
if ( argc-1 < i+1 ){ |
371 |
usage(); |
372 |
return 1; |
373 |
}; |
374 |
golower = atoi(argv[i+1]); |
375 |
}; |
376 |
if ( !strcmp(argv[i],"-lrecl") ) { |
377 |
if ( argc-1 < i+1 ){ |
378 |
usage(); |
379 |
return 1; |
380 |
}; |
381 |
record_size = atoi(argv[i+1]); |
382 |
}; |
383 |
if ( !strcmp(argv[i],"-bufsize") ) { |
384 |
if ( argc-1 < i+1 ){ |
385 |
usage(); |
386 |
return 1; |
387 |
}; |
388 |
bufsize = atoi(argv[i+1]); |
389 |
}; |
390 |
if ( !strcmp(argv[i],"-optcwn") ) { |
391 |
if ( argc-1 < i+1 ){ |
392 |
usage(); |
393 |
return 1; |
394 |
}; |
395 |
optcwn = atoi(argv[i+1]); |
396 |
}; |
397 |
i++; |
398 |
}; |
399 |
} else { |
400 |
// |
401 |
// no input parameters exit with error, we need at least the input file |
402 |
// |
403 |
cout << "\n ERROR: NO INPUT PARAMETERS \n"; |
404 |
usage(); |
405 |
return 1; |
406 |
}; |
407 |
|
408 |
if ( file_in==NULL) { |
409 |
// |
410 |
// file is not defined. exit with error, we need at least the input file |
411 |
// |
412 |
cout << "\n ERROR: NO INPUT PARAMETERS \n"; |
413 |
usage(); |
414 |
return 1; |
415 |
} |
416 |
|
417 |
// define calo writing format (general variable) |
418 |
comprcalomode = calocompress ; |
419 |
// Define the root and pam file |
420 |
if ( !strcmp(pamfile," ")) { |
421 |
file_raw= new char[2000]; |
422 |
strcpy(file_raw,file_in); |
423 |
char *dot = strrchr(file_raw,'.'); |
424 |
if (dot) strcpy(dot+1,"pam"); |
425 |
else strcat(file_out,".pam"); |
426 |
} else { |
427 |
file_raw=pamfile; |
428 |
} |
429 |
if (!strcmp(rootfile," ")) { |
430 |
file_out= new char[2000]; |
431 |
strcpy(file_out,file_in); |
432 |
char *dot = strrchr(file_out,'.'); |
433 |
if (dot) strcpy(dot+1,"gp.root"); //modified S.Orsi 09/'07 |
434 |
else strcat(file_out,".gp.root"); |
435 |
} else { |
436 |
file_out=rootfile; |
437 |
} |
438 |
|
439 |
|
440 |
cout<<" Check input parameters inputfile="<<file_in<<" root="<<file_out<<" pam="<<file_raw<<endl; |
441 |
cout<<" calocompress="<<calocompress<<" rootcompress="<<rootcompress<<" golow="<<golower<<endl; |
442 |
cout<<" bufsize="<<bufsize<<" cwn="<<optcwn<<endl; |
443 |
|
444 |
|
445 |
#if defined(_HIUX_SOURCE) && !defined(__GNUC__) |
446 |
hf_fint((char *)NULL); |
447 |
#endif |
448 |
|
449 |
|
450 |
int pawc_size = PAWC_SIZE; |
451 |
hlimit(pawc_size); |
452 |
|
453 |
int lun = 10; |
454 |
#ifndef WIN32 |
455 |
hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("p"),record_size,ier,7,strlen(file_in),1); |
456 |
#else |
457 |
hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("p"),record_size,ier); |
458 |
#endif |
459 |
|
460 |
if (ier) printf (" Error on hropen was %d \n", ier); |
461 |
if (quest[0]) { |
462 |
printf("Error cannot open input file: %s\n",file_in); |
463 |
return 1; |
464 |
} |
465 |
|
466 |
char root_file_title[2000]; |
467 |
|
468 |
TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,rootcompress); |
469 |
|
470 |
if (!hfile) { |
471 |
printf("Error: can't open output file: %s \n",file_out); |
472 |
return 1; |
473 |
} |
474 |
|
475 |
convert_directory("//example",file_raw); |
476 |
|
477 |
//hfile->Write(); |
478 |
//hfile->ls(); |
479 |
|
480 |
hfile->Close(); |
481 |
delete hfile; |
482 |
return(0); |
483 |
} |
484 |
|
485 |
|
486 |
//____________________________________________________________________________ |
487 |
void convert_directory(const char *dir, char* file_raw) |
488 |
{ |
489 |
|
490 |
|
491 |
printf(" Converting directory %s\n",dir); |
492 |
Int_t id; |
493 |
// Int_t nastycase=0; |
494 |
// Int_t nastyprint=0; |
495 |
// Int_t idold = 0; |
496 |
for (Int_t key=1;key<1000000;key++) { |
497 |
int z0 = 0; |
498 |
rzink(key,z0,"S",1); |
499 |
if (quest[0]) break; |
500 |
if (quest[13] & 8) { |
501 |
continue; |
502 |
// if (!nastyprint) { |
503 |
// printf("Found nasty Hbook case!! You had an Hbook error message\n"); |
504 |
// printf(" when creating the file (too many records)\n"); |
505 |
// printf(" Hbook file should have been created with a bigger LRECL\n"); |
506 |
// printf(" ROOT will try to recover\n"); |
507 |
// nastyprint = 1; |
508 |
// } |
509 |
// nastycase = 1; |
510 |
} |
511 |
id = quest[20]; |
512 |
// if (id == idold && nastycase) continue; |
513 |
// nastycase = 0; |
514 |
// idold = id; |
515 |
int i999 = 999; |
516 |
hrin(id,i999,0); |
517 |
if (quest[0]) { |
518 |
printf("Error cannot read ID = %d\n",id); |
519 |
break; |
520 |
} |
521 |
hdcofl(); |
522 |
lcid = hcbook[10]; |
523 |
lcont = lq[lcid-1]; |
524 |
if (hcbits[3]) { |
525 |
convert_cwn(id,file_raw); |
526 |
hdelet(id); |
527 |
continue; |
528 |
} |
529 |
|
530 |
if (hcbits[0]) { |
531 |
convert_1d(id); |
532 |
hdelet(id); |
533 |
continue; |
534 |
} |
535 |
|
536 |
} |
537 |
|
538 |
// converting subdirectories of this directory |
539 |
const Int_t kKLS = 26; |
540 |
const Int_t kKNSD = 23; |
541 |
lcdir = rzcl[2]; |
542 |
Int_t ls = iq[lcdir+kKLS]; |
543 |
Int_t ndir = iq[lcdir+kKNSD]; |
544 |
Int_t nch=16; |
545 |
Int_t ihdir[4]; |
546 |
Int_t ncw = 4; |
547 |
TDirectory *cursav = gDirectory; |
548 |
Int_t i; |
549 |
char chdir[17]; |
550 |
char hbookdir[17]; |
551 |
for (Int_t k=0;k<ndir;k++) { |
552 |
lcdir = rzcl[2]; |
553 |
zitoh(iq[lcdir+ls+7*k],ihdir[0],ncw); |
554 |
for (i=0;i<17;i++) chdir[i] = 0; |
555 |
#ifndef WIN32 |
556 |
uhtoc(ihdir[0],ncw,chdir,nch ,16); |
557 |
#else |
558 |
uhtoc(ihdir[0],ncw,chdir,16,nch); |
559 |
#endif |
560 |
strcpy(hbookdir,chdir); |
561 |
for (i=16;i>0;i--) { |
562 |
if (chdir[i] == 0) continue; |
563 |
if (chdir[i] != ' ') break; |
564 |
chdir[i] = 0; |
565 |
} |
566 |
#ifndef WIN32 |
567 |
hcdir(PASSCHAR(hbookdir),PASSCHAR(" "),16,1); |
568 |
#else |
569 |
hcdir(PASSCHAR(hbookdir),PASSCHAR(" ")); |
570 |
#endif |
571 |
TDirectory *newdir = new TDirectory(chdir,chdir); |
572 |
newdir->cd(); |
573 |
convert_directory(chdir, file_raw); |
574 |
#ifndef WIN32 |
575 |
hcdir(PASSCHAR("\\"),PASSCHAR(" "),1,1); |
576 |
#else |
577 |
hcdir(PASSCHAR("\\"),PASSCHAR(" ")); |
578 |
#endif |
579 |
newdir->Write(); |
580 |
cursav->cd(); |
581 |
} |
582 |
} |
583 |
|
584 |
//____________________________________________________________________________ |
585 |
void convert_1d(Int_t id) |
586 |
{ |
587 |
if (id > 0) sprintf(idname,"h%d",id); |
588 |
else sprintf(idname,"h_%d",-id); |
589 |
hnoent(id,nentries); |
590 |
#ifndef WIN32 |
591 |
hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80); |
592 |
#else |
593 |
hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb); |
594 |
#endif |
595 |
chtitl[4*nwt] = 0; |
596 |
TH1F *h1; |
597 |
Int_t i; |
598 |
if (hcbits[5]) { |
599 |
Int_t lbins = lq[lcid-2]; |
600 |
Double_t *xbins = new Double_t[ncx+1]; |
601 |
for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1]; |
602 |
h1 = new TH1F(idname,chtitl,ncx,xbins); |
603 |
delete [] xbins; |
604 |
} else { |
605 |
h1 = new TH1F(idname,chtitl,ncx,xmin,xmax); |
606 |
} |
607 |
if (hcbits[8]) h1->Sumw2(); |
608 |
TGraph *gr = 0; |
609 |
if (hcbits[11]) { |
610 |
gr = new TGraph(ncx); |
611 |
h1->GetListOfFunctions()->Add(gr); |
612 |
} |
613 |
|
614 |
Float_t x; |
615 |
for (i=0;i<=ncx+1;i++) { |
616 |
x = h1->GetBinCenter(i); |
617 |
h1->Fill(x,hi(id,i)); |
618 |
if (hcbits[8]) h1->SetBinError(i,hie(id,i)); |
619 |
if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i)); |
620 |
} |
621 |
Float_t ymin, ymax; |
622 |
if (hcbits[19]) { |
623 |
ymax = q[lcid+kMAX1]; |
624 |
h1->SetMaximum(ymax); |
625 |
} |
626 |
if (hcbits[20]) { |
627 |
ymin = q[lcid+kMIN1]; |
628 |
h1->SetMinimum(ymin); |
629 |
} |
630 |
h1->SetEntries(nentries); |
631 |
h1->Write(); |
632 |
// delete h1; |
633 |
h1->Delete(); |
634 |
} |
635 |
//____________________________________________________________________________ |
636 |
void convert_cwn(Int_t id,char* file_raw) |
637 |
{ |
638 |
const int kNchar=9; |
639 |
int nvar; |
640 |
int ier=0; |
641 |
int i,j; |
642 |
int nsub,itype,isize,ielem; |
643 |
char *chtag_out; |
644 |
float *x; |
645 |
float rmin[1000], rmax[1000]; |
646 |
|
647 |
if (id > 0) sprintf(idname,"h%d",id); |
648 |
else sprintf(idname,"h_%d",-id); |
649 |
hnoent(id,nentries); |
650 |
printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries); |
651 |
nvar=0; |
652 |
#ifndef WIN32 |
653 |
hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0); |
654 |
#else |
655 |
hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]); |
656 |
#endif |
657 |
|
658 |
|
659 |
chtag_out = new char[nvar*kNchar+1]; |
660 |
Int_t *charflag = new Int_t[nvar]; |
661 |
Int_t *lenchar = new Int_t[nvar]; |
662 |
Int_t *boolflag = new Int_t[nvar]; |
663 |
Int_t *lenbool = new Int_t[nvar]; |
664 |
UChar_t *boolarr = new UChar_t[10000]; |
665 |
x = new float[nvar]; |
666 |
char *bigbuf = new char[2500000]; |
667 |
|
668 |
chtag_out[nvar*kNchar]=0; |
669 |
for (i=0;i<80;i++)chtitl[i]=0; |
670 |
#ifndef WIN32 |
671 |
hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar); |
672 |
#else |
673 |
hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]); |
674 |
#endif |
675 |
#ifndef WIN32 |
676 |
hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6); |
677 |
#else |
678 |
hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0); |
679 |
#endif |
680 |
|
681 |
Int_t bufpos = 0; |
682 |
Int_t isachar = 0; |
683 |
Int_t isabool = 0; |
684 |
char fullname[1024]; |
685 |
char name[512]; |
686 |
char block[512]; |
687 |
char oldblock[512]; |
688 |
Int_t nbits = 0; |
689 |
strcpy(oldblock,"OLDBLOCK"); |
690 |
Int_t oldischar = -1; |
691 |
for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; } |
692 |
TTree *tree = new TTree(idname,chtitl); |
693 |
for(i=0; i<nvar;i++) { |
694 |
memset(name,' ',sizeof(name)); |
695 |
name[sizeof(name)-1] = 0; |
696 |
memset(block,' ',sizeof(block)); |
697 |
block[sizeof(block)-1] = 0; |
698 |
memset(fullname,' ',sizeof(fullname)); |
699 |
fullname[sizeof(fullname)-1]=0; |
700 |
#ifndef WIN32 |
701 |
hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,512,1024,512); |
702 |
#else |
703 |
hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem); |
704 |
#endif |
705 |
|
706 |
for (j=510;j>0;j--) { |
707 |
if(golower) name[j] = tolower(name[j]); |
708 |
if (name[j] == ' ') name[j] = 0; |
709 |
} |
710 |
if (golower == 2) name[0] = tolower(name[0]); |
711 |
|
712 |
for (j=1022;j>0;j--) { |
713 |
if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]); |
714 |
// convert also character after [, if golower == 2 |
715 |
if (golower == 2) fullname[j] = tolower(fullname[j]); |
716 |
if (fullname[j] == ' ') fullname[j] = 0; |
717 |
} |
718 |
// convert also first character, if golower == 2 |
719 |
if (golower == 2) fullname[0] = tolower(fullname[0]); |
720 |
for (j=510;j>0;j--) { |
721 |
if (block[j] == ' ') block[j] = 0; |
722 |
else break; |
723 |
} |
724 |
if (itype == 1) { |
725 |
if( isize == 4 ) strcat(fullname,"/F"); |
726 |
else if( isize == 8) strcat(fullname,"/D"); |
727 |
} |
728 |
|
729 |
|
730 |
// add support for 1-byte (Char_t) and 2-byte (Short_t) integers |
731 |
Int_t nBytesUsed = 4; // default for integers |
732 |
|
733 |
if( itype == 2 ) |
734 |
{ |
735 |
if( optcwn == 1 ) |
736 |
{ |
737 |
if( nbits > 16 ) |
738 |
{ |
739 |
strcat(fullname,"/I"); |
740 |
} |
741 |
else |
742 |
{ |
743 |
if( nbits > 8 ) |
744 |
{ |
745 |
strcat(fullname,"/S"); |
746 |
nBytesUsed = 2; |
747 |
} |
748 |
else |
749 |
{ |
750 |
strcat(fullname,"/B"); |
751 |
nBytesUsed = 1; |
752 |
} |
753 |
} |
754 |
} |
755 |
else |
756 |
{ |
757 |
strcat(fullname,"/I"); |
758 |
} |
759 |
} |
760 |
|
761 |
// add support for 1-byte (UChar_t) and 2-byte (UShort_t) integers |
762 |
if ( itype == 3 ) |
763 |
{ |
764 |
if( optcwn == 1 ) |
765 |
{ |
766 |
if( nbits > 16) |
767 |
{ |
768 |
strcat(fullname,"/i"); |
769 |
} |
770 |
else |
771 |
{ |
772 |
if( nbits > 8 ) |
773 |
{ |
774 |
strcat(fullname,"/s"); |
775 |
nBytesUsed = 2; |
776 |
} |
777 |
else |
778 |
{ |
779 |
strcat(fullname,"/b"); |
780 |
nBytesUsed = 1; |
781 |
} |
782 |
} |
783 |
} |
784 |
else |
785 |
{ |
786 |
strcat(fullname,"/i"); |
787 |
} |
788 |
} |
789 |
|
790 |
|
791 |
|
792 |
|
793 |
// if (itype == 4) strcat(fullname,"/i"); |
794 |
if (itype == 4) strcat(fullname,"/b"); |
795 |
if (itype == 5) strcat(fullname,"/C"); |
796 |
//printf("Creating branch:%s, block:%s, fullname:%s, nsub=%d, itype=%d, isize=%d, ielem=%d\n",name,block,fullname,nsub,itype,isize,ielem); |
797 |
Int_t ischar; |
798 |
if (itype == 5) ischar = 1; |
799 |
else ischar = 0; |
800 |
if (ischar != oldischar || strcmp(oldblock,block) != 0) { |
801 |
strcpy(oldblock,block); |
802 |
oldischar = ischar; |
803 |
Int_t lblock = strlen(block); |
804 |
Long_t add= (Long_t)&bigbuf[bufpos]; |
805 |
#ifndef WIN32 |
806 |
hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4); |
807 |
#else |
808 |
hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar); |
809 |
#endif |
810 |
|
811 |
} |
812 |
TBranch *branch = tree->Branch(name,(void*)&bigbuf[bufpos],fullname,bufsize); |
813 |
boolflag[i] = -10; |
814 |
charflag[i] = 0; |
815 |
if (itype == 4) {isabool++; boolflag[i] = bufpos; lenbool[i] = ielem;} |
816 |
bufpos += isize*ielem; |
817 |
if (ischar) {isachar++; charflag[i] = bufpos-1; lenchar[i] = isize*ielem;} |
818 |
TObjArray *ll= branch->GetListOfLeaves(); |
819 |
TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0); |
820 |
if (!leaf) continue; |
821 |
TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount(); |
822 |
if (leafcount) { |
823 |
if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem); |
824 |
} |
825 |
} |
826 |
Int_t cf,l; |
827 |
for(i=1;i<=nentries;i++) { |
828 |
hgnt(id,i,ier); |
829 |
if (isabool) { // if column is boolean |
830 |
for (j=0;j<nvar;j++) { |
831 |
cf = boolflag[j]; |
832 |
if (cf >-1) { |
833 |
for (l=0;l<lenbool[j];l++) { |
834 |
#ifdef R__BYTESWAP |
835 |
boolarr[l] = (UChar_t)bigbuf[cf+4*l]; |
836 |
#else |
837 |
boolarr[l] = (UChar_t)bigbuf[cf+4*l+3]; |
838 |
#endif |
839 |
} |
840 |
memcpy(&bigbuf[cf],boolarr,lenbool[j]); |
841 |
} |
842 |
} |
843 |
} |
844 |
if (isachar) { // if column is character, set terminator |
845 |
for (j=0;j<nvar;j++) { |
846 |
cf = charflag[j]; |
847 |
if (cf) { |
848 |
bigbuf[cf] = '\0'; |
849 |
if (bigbuf[cf-1] != ' ') continue; |
850 |
bigbuf[cf-1] = '\0'; |
851 |
if (bigbuf[cf-2] != ' ') continue; |
852 |
bigbuf[cf-2] = '\0'; |
853 |
} |
854 |
} |
855 |
} |
856 |
|
857 |
// if optimizing cwn ntuple then look up bufpos and adjust integers to be shorts or chars |
858 |
if( optcwn == 1 ) |
859 |
{ |
860 |
bufpos = 0; |
861 |
for(int k=0; k<nvar;k++) |
862 |
{ |
863 |
#ifndef WIN32 |
864 |
hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32); |
865 |
#else |
866 |
hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem); |
867 |
#endif |
868 |
|
869 |
Int_t nBytesUsed = 4; // default for integers |
870 |
|
871 |
if ( itype == 2 || itype == 3) |
872 |
{ |
873 |
if( nbits > 16) |
874 |
{ |
875 |
// do nothing for integers of 4 byte |
876 |
} |
877 |
else |
878 |
{ |
879 |
if( nbits > 8 ) |
880 |
{ |
881 |
nBytesUsed = 2; |
882 |
} |
883 |
else |
884 |
{ |
885 |
nBytesUsed = 1; |
886 |
} |
887 |
} |
888 |
} |
889 |
|
890 |
if(nBytesUsed == 1) |
891 |
{ |
892 |
|
893 |
for(Int_t index = 0; index < ielem; index++) |
894 |
{ |
895 |
// shift all chars with data to be one after another |
896 |
bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize]; |
897 |
} |
898 |
} |
899 |
else |
900 |
{ |
901 |
if(nBytesUsed == 2) |
902 |
{ |
903 |
|
904 |
for(Int_t index = 0; index < ielem; index++) |
905 |
{ |
906 |
// shift all shorts ( 2 chars) with data to be one after another |
907 |
bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize]; |
908 |
bigbuf[bufpos + index*nBytesUsed+1 ] = bigbuf[bufpos + index * isize+1]; |
909 |
} |
910 |
} |
911 |
} |
912 |
bufpos += isize*ielem; |
913 |
} |
914 |
} |
915 |
|
916 |
tree->Fill(); |
917 |
} |
918 |
|
919 |
tree->Write(); |
920 |
|
921 |
cout << "Invoking Digitizer" << endl << flush; |
922 |
const char *ndl[9]; |
923 |
char *q,*q1; |
924 |
q=(char*)malloc(5 *sizeof(char)); |
925 |
q1=(char*)malloc(5 *sizeof(char)); |
926 |
ndl[0]="nspe"; |
927 |
ndl[1]="ntof"; |
928 |
ndl[2]="ncat"; |
929 |
ndl[3]="ncas"; |
930 |
ndl[4]="ncar"; |
931 |
ndl[5]="ncal"; |
932 |
ndl[6]="nndd"; |
933 |
ndl[7]="nstr"; |
934 |
ndl[8]="comprcalomod"; |
935 |
|
936 |
int nspe=200,ntof=200,ncat=50,ncas=50,ncar=100,ncal=1000,nnd=200,nstr=1000,par[9],tmp=0,t; |
937 |
par[0]=nspe; |
938 |
par[1]=ntof; |
939 |
par[2]=ncat; |
940 |
par[3]=ncas; |
941 |
par[4]=ncar; |
942 |
par[5]=ncal; |
943 |
par[6]=nnd; |
944 |
par[7]=nstr; |
945 |
par[8]=comprcalomode; |
946 |
|
947 |
ifstream np("vectpar.dat",ios::in); |
948 |
if(!np)printf("ATTENTION: Using default vector legths!\n"); |
949 |
else{ |
950 |
while(!np.eof()){ |
951 |
np>>q>>tmp; |
952 |
if(np.eof())break; |
953 |
if(tmp<=0){ |
954 |
cout<<"ATTENTION: Length of one vector is negative or equal 0!"<<endl<<q<<"="<<tmp<<endl; |
955 |
break; |
956 |
} |
957 |
t=0; |
958 |
while(tmp){ |
959 |
strcpy(q1,ndl[t]); |
960 |
if(q[0]==q1[0] && q[1]==q1[1] && q[2]==q1[2] && q[3]==q1[3]){ |
961 |
par[t]=tmp; |
962 |
tmp=0; |
963 |
cout<<q<<" "<<par[t]<<"["<<t<<"]"<<endl; |
964 |
} |
965 |
t++; |
966 |
} |
967 |
} |
968 |
nspe=par[0]; |
969 |
ntof=par[1]; |
970 |
ncat=par[2]; |
971 |
ncas=par[3]; |
972 |
ncar=par[4]; |
973 |
ncal=par[5]; |
974 |
nnd=par[6]; |
975 |
nstr=par[7]; |
976 |
comprcalomode=par[8]; |
977 |
} |
978 |
Digitizer* dig = new Digitizer(tree,file_raw,nspe,ntof,ncat,ncas,ncar,ncal,nnd,nstr,comprcalomode); |
979 |
dig->Loop(); |
980 |
dig->Close(); |
981 |
|
982 |
cout << "Finished" << endl; |
983 |
|
984 |
} |
985 |
|
986 |
|