/[PAMELA software]/PamelaDigitizer/Pamelagp2Digits.cxx
ViewVC logotype

Contents of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download)
Tue Aug 11 14:56:31 2009 UTC (15 years, 6 months ago) by mocchiut
Branch: MAIN
Changes since 1.12: +5 -3 lines
Compilation warnings and errors with gcc >= 4.3 fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23