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

Contents of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Wed Nov 28 18:54:31 2007 UTC (17 years ago) by silvio
Branch: MAIN
Changes since 1.6: +10 -2 lines
Various ToF improvements

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

  ViewVC Help
Powered by ViewVC 1.1.23