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

Contents of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Wed May 21 09:50:46 2008 UTC (16 years, 6 months ago) by pamelats
Branch: MAIN
Changes since 1.8: +828 -895 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23