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

Contents of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Thu Oct 11 11:29:25 2007 UTC (17 years, 1 month ago) by orsi
Branch: MAIN
Changes since 1.2: +20 -5 lines
TOF/AC/S4 changes;packet length bug 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 : Jan Conrad (conrad@particle.kth.se)
8 // Modified: 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.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 // v. 1.3 (S.Orsi, Roma2, 11 October 2007)
31 // - TOF: + changes and major corrections in ADC and TDC (W.Menn, D.Campana, S.Orsi)
32 // + flag DEBUG added (default: DEBUG=false; if true, print on screem some messages to debug)
33 // - AC: + shift register filled;
34 // + minor bugs fixed
35 // + counters increment by 1 at each event (they were constant before)
36 // - S4: + minor bugs fixed (S.Borisov)
37 // + 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
38 // - 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.
39 // - 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
40 // - digitizer version numbers modified according to CVS repository (v1.00->v1.1, v1.01->v1.2)
41 // - 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)
42 //
43 // v. 1.2 (S.Orsi, Roma2, 28 September 2007)
44 // - TOF TDC inserted (to be tuned)
45 // - improved tracker dEdx, tracker saturation inserted (S.Bottai)
46 // - S4 routine inserted in code (not in read-out)
47 // - bugs with packet length corrected
48 // - small bugs fixed
49 // - 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
50 //
51 // v. 1.1 (S.Orsi, Roma2, 13 September 2007)
52 // - trigger (dummy), tof (preliminary, adc only), ND (preliminary) inserted
53 // - various changes and bug fixes
54 // - padding increased (fPADbuffer=64, fPadding = padbytes+64)
55 //
56 // v. beta (J.Conrad, KTH, 2006)
57 // - compiles; includes pscu, calo, trk, ac; not present on cvs
58 //
59 /////////////////////////////////////////////////////////////////////////
60
61 #include <stdlib.h>
62 #include <string.h>
63 #include <ctype.h>
64 #include "Riostream.h"
65 #include "TFile.h"
66 #include "TDirectory.h"
67 #include "TTree.h"
68 #include "TLeafI.h"
69 #include "TH1.h"
70 #include "TH2.h"
71 #include "TProfile.h"
72 #include "TGraph.h"
73 #include "TMath.h"
74 #include "Digitizer.h"
75
76 int Error; //to be removed soon
77
78 // Define the names of the Fortran common blocks for the different OSs
79
80 #ifndef WIN32
81 #define PAWC_SIZE 5000000
82 # define pawc pawc_
83 # define quest quest_
84 # define hcbits hcbits_
85 # define hcbook hcbook_
86 # define rzcl rzcl_
87 int pawc[PAWC_SIZE];
88 int quest[100];
89 int hcbits[37];
90 int hcbook[51];
91 int rzcl[11];
92 #else
93 // on windows /pawc/ must have the same length as in libPacklib.a !!
94 #define PAWC_SIZE 2000000
95 # define pawc PAWC
96 # define quest QUEST
97 # define hcbits HCBITS
98 # define hcbook HCBOOK
99 # define rzcl RZCL
100 extern "C" int pawc[PAWC_SIZE];
101 extern "C" int quest[100];
102 extern "C" int hcbits[37];
103 extern "C" int hcbook[51];
104 extern "C" int rzcl[11];
105 #endif
106
107 int *iq, *lq;
108 float *q;
109 char idname[128];
110 int nentries;
111 char chtitl[128];
112 int ncx,ncy,nwt,idb;
113 int lcont, lcid, lcdir;
114 float xmin,xmax,ymin,ymax;
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
274 int main(int argc, char **argv)
275
276 {
277 if (argc < 2) {
278 printf("Error: Pamelagp2Digits \n");
279 printf("Pamelagp2Digits file.hbook file.root file.pam [compress] [tolower] [lrecl] [bufsize] [optcwn] \n");
280 printf(" if file.root is not given it will be = file.root\n");
281 printf(" compress = 1 by default (use 0 for no compression)\n");
282 printf(" tolower = 1 by default (use 0 to keep case of column names)\n");
283 printf(" lrecl =0 by default (must be specified if >8092)\n");
284 printf(" bufsize = 8000 by default (branch buffer size)\n");
285 printf(" for cwn ntuple only: optcwn = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n");
286 return 1;
287 }
288
289 lq = &pawc[9];
290 iq = &pawc[17];
291 void *qq = iq;
292 q = (float*)qq;
293 char *file_in=argv[1];
294 char *file_out = " ";
295 char *file_raw;
296
297 Int_t compress = 1;
298 int ier=0, record_size=0;
299
300 if (argc > 8) {
301 optcwn = atoi(argv[8]);
302 }
303 if (argc > 7) {
304 bufsize = atoi(argv[7]);
305 }
306 if (argc > 6) {
307 record_size = atoi(argv[6]);
308 }
309 if (argc > 5) {
310 golower = atoi(argv[5]);
311 }
312 if (argc > 4) {
313 compress = atoi(argv[4]);
314 }
315
316 if (argc > 3) {
317 file_raw=argv[3];
318 } else {
319 file_raw= new char[2000];
320 strcpy(file_raw,file_in);
321 char *dot = strrchr(file_raw,'.');
322 if (dot) strcpy(dot+1,"pam");
323 else strcat(file_out,".pam");
324 }
325
326 if (argc > 2) {
327 file_out=argv[2];
328 } else {
329 file_out= new char[2000];
330 strcpy(file_out,file_in);
331 char *dot = strrchr(file_out,'.');
332 if (dot) strcpy(dot+1,"gp.root"); //modified S.Orsi 09/'07
333 else strcat(file_out,".gp.root");
334 }
335
336
337
338 #if defined(_HIUX_SOURCE) && !defined(__GNUC__)
339 hf_fint((char *)NULL);
340 #endif
341
342
343 int pawc_size = PAWC_SIZE;
344 hlimit(pawc_size);
345
346 int lun = 10;
347 #ifndef WIN32
348 hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("p"),record_size,ier,7,strlen(file_in),1);
349 #else
350 hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("p"),record_size,ier);
351 #endif
352
353 if (ier) printf (" Error on hropen was %d \n", ier);
354 if (quest[0]) {
355 printf("Error cannot open input file: %s\n",file_in);
356 return 1;
357 }
358
359 char root_file_title[2000];
360
361 TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,compress);
362
363 if (!hfile) {
364 printf("Error: can't open output file: %s \n",file_out);
365 return 1;
366 }
367
368 convert_directory("//example",file_raw);
369
370 //hfile->Write();
371 //hfile->ls();
372
373 hfile->Close();
374 delete hfile;
375 return(0);
376 }
377
378
379 //____________________________________________________________________________
380 void convert_directory(const char *dir, char* file_raw)
381 {
382
383
384 printf(" Converting directory %s\n",dir);
385 Int_t id;
386 // Int_t nastycase=0;
387 // Int_t nastyprint=0;
388 // Int_t idold = 0;
389 for (Int_t key=1;key<1000000;key++) {
390 int z0 = 0;
391 rzink(key,z0,"S",1);
392 if (quest[0]) break;
393 if (quest[13] & 8) {
394 continue;
395 // if (!nastyprint) {
396 // printf("Found nasty Hbook case!! You had an Hbook error message\n");
397 // printf(" when creating the file (too many records)\n");
398 // printf(" Hbook file should have been created with a bigger LRECL\n");
399 // printf(" ROOT will try to recover\n");
400 // nastyprint = 1;
401 // }
402 // nastycase = 1;
403 }
404 id = quest[20];
405 // if (id == idold && nastycase) continue;
406 // nastycase = 0;
407 // idold = id;
408 int i999 = 999;
409 hrin(id,i999,0);
410 if (quest[0]) {
411 printf("Error cannot read ID = %d\n",id);
412 break;
413 }
414 hdcofl();
415 lcid = hcbook[10];
416 lcont = lq[lcid-1];
417 if (hcbits[3]) {
418 convert_cwn(id,file_raw);
419 hdelet(id);
420 continue;
421 }
422
423 if (hcbits[0]) {
424 convert_1d(id);
425 hdelet(id);
426 continue;
427 }
428
429 }
430
431 // converting subdirectories of this directory
432 const Int_t kKLS = 26;
433 const Int_t kKNSD = 23;
434 lcdir = rzcl[2];
435 Int_t ls = iq[lcdir+kKLS];
436 Int_t ndir = iq[lcdir+kKNSD];
437 Int_t nch=16;
438 Int_t ihdir[4];
439 Int_t ncw = 4;
440 TDirectory *cursav = gDirectory;
441 Int_t i;
442 char chdir[17];
443 char hbookdir[17];
444 for (Int_t k=0;k<ndir;k++) {
445 lcdir = rzcl[2];
446 zitoh(iq[lcdir+ls+7*k],ihdir[0],ncw);
447 for (i=0;i<17;i++) chdir[i] = 0;
448 #ifndef WIN32
449 uhtoc(ihdir[0],ncw,chdir,nch ,16);
450 #else
451 uhtoc(ihdir[0],ncw,chdir,16,nch);
452 #endif
453 strcpy(hbookdir,chdir);
454 for (i=16;i>0;i--) {
455 if (chdir[i] == 0) continue;
456 if (chdir[i] != ' ') break;
457 chdir[i] = 0;
458 }
459 #ifndef WIN32
460 hcdir(PASSCHAR(hbookdir),PASSCHAR(" "),16,1);
461 #else
462 hcdir(PASSCHAR(hbookdir),PASSCHAR(" "));
463 #endif
464 TDirectory *newdir = new TDirectory(chdir,chdir);
465 newdir->cd();
466 convert_directory(chdir, file_raw);
467 #ifndef WIN32
468 hcdir(PASSCHAR("\\"),PASSCHAR(" "),1,1);
469 #else
470 hcdir(PASSCHAR("\\"),PASSCHAR(" "));
471 #endif
472 newdir->Write();
473 cursav->cd();
474 }
475 }
476
477 //____________________________________________________________________________
478 void convert_1d(Int_t id)
479 {
480 if (id > 0) sprintf(idname,"h%d",id);
481 else sprintf(idname,"h_%d",-id);
482 hnoent(id,nentries);
483 #ifndef WIN32
484 hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80);
485 #else
486 hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb);
487 #endif
488 chtitl[4*nwt] = 0;
489 TH1F *h1;
490 Int_t i;
491 if (hcbits[5]) {
492 Int_t lbins = lq[lcid-2];
493 Double_t *xbins = new Double_t[ncx+1];
494 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
495 h1 = new TH1F(idname,chtitl,ncx,xbins);
496 delete [] xbins;
497 } else {
498 h1 = new TH1F(idname,chtitl,ncx,xmin,xmax);
499 }
500 if (hcbits[8]) h1->Sumw2();
501 TGraph *gr = 0;
502 if (hcbits[11]) {
503 gr = new TGraph(ncx);
504 h1->GetListOfFunctions()->Add(gr);
505 }
506
507 Float_t x;
508 for (i=0;i<=ncx+1;i++) {
509 x = h1->GetBinCenter(i);
510 h1->Fill(x,hi(id,i));
511 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
512 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
513 }
514 Float_t ymin, ymax;
515 if (hcbits[19]) {
516 ymax = q[lcid+kMAX1];
517 h1->SetMaximum(ymax);
518 }
519 if (hcbits[20]) {
520 ymin = q[lcid+kMIN1];
521 h1->SetMinimum(ymin);
522 }
523 h1->SetEntries(nentries);
524 h1->Write();
525 delete h1;
526 }
527 //____________________________________________________________________________
528 void convert_cwn(Int_t id,char* file_raw)
529 {
530 const int kNchar=9;
531 int nvar;
532 int ier=0;
533 int i,j;
534 int nsub,itype,isize,ielem;
535 char *chtag_out;
536 float *x;
537 float rmin[1000], rmax[1000];
538
539 if (id > 0) sprintf(idname,"h%d",id);
540 else sprintf(idname,"h_%d",-id);
541 hnoent(id,nentries);
542 printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries);
543 nvar=0;
544 #ifndef WIN32
545 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
546 #else
547 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
548 #endif
549
550
551 chtag_out = new char[nvar*kNchar+1];
552 Int_t *charflag = new Int_t[nvar];
553 Int_t *lenchar = new Int_t[nvar];
554 Int_t *boolflag = new Int_t[nvar];
555 Int_t *lenbool = new Int_t[nvar];
556 UChar_t *boolarr = new UChar_t[10000];
557 x = new float[nvar];
558 char *bigbuf = new char[2500000];
559
560 chtag_out[nvar*kNchar]=0;
561 for (i=0;i<80;i++)chtitl[i]=0;
562 #ifndef WIN32
563 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar);
564 #else
565 hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]);
566 #endif
567 #ifndef WIN32
568 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6);
569 #else
570 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0);
571 #endif
572
573 Int_t bufpos = 0;
574 Int_t isachar = 0;
575 Int_t isabool = 0;
576 char fullname[1024];
577 char name[512];
578 char block[512];
579 char oldblock[512];
580 Int_t nbits = 0;
581 strcpy(oldblock,"OLDBLOCK");
582 Int_t oldischar = -1;
583 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
584 TTree *tree = new TTree(idname,chtitl);
585 for(i=0; i<nvar;i++) {
586 memset(name,' ',sizeof(name));
587 name[sizeof(name)-1] = 0;
588 memset(block,' ',sizeof(block));
589 block[sizeof(block)-1] = 0;
590 memset(fullname,' ',sizeof(fullname));
591 fullname[sizeof(fullname)-1]=0;
592 #ifndef WIN32
593 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,512,1024,512);
594 #else
595 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
596 #endif
597
598 for (j=510;j>0;j--) {
599 if(golower) name[j] = tolower(name[j]);
600 if (name[j] == ' ') name[j] = 0;
601 }
602 if (golower == 2) name[0] = tolower(name[0]);
603
604 for (j=1022;j>0;j--) {
605 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
606 // convert also character after [, if golower == 2
607 if (golower == 2) fullname[j] = tolower(fullname[j]);
608 if (fullname[j] == ' ') fullname[j] = 0;
609 }
610 // convert also first character, if golower == 2
611 if (golower == 2) fullname[0] = tolower(fullname[0]);
612 for (j=510;j>0;j--) {
613 if (block[j] == ' ') block[j] = 0;
614 else break;
615 }
616 if (itype == 1) {
617 if( isize == 4 ) strcat(fullname,"/F");
618 else if( isize == 8) strcat(fullname,"/D");
619 }
620
621
622 // add support for 1-byte (Char_t) and 2-byte (Short_t) integers
623 Int_t nBytesUsed = 4; // default for integers
624
625 if( itype == 2 )
626 {
627 if( optcwn == 1 )
628 {
629 if( nbits > 16 )
630 {
631 strcat(fullname,"/I");
632 }
633 else
634 {
635 if( nbits > 8 )
636 {
637 strcat(fullname,"/S");
638 nBytesUsed = 2;
639 }
640 else
641 {
642 strcat(fullname,"/B");
643 nBytesUsed = 1;
644 }
645 }
646 }
647 else
648 {
649 strcat(fullname,"/I");
650 }
651 }
652
653 // add support for 1-byte (UChar_t) and 2-byte (UShort_t) integers
654 if ( itype == 3 )
655 {
656 if( optcwn == 1 )
657 {
658 if( nbits > 16)
659 {
660 strcat(fullname,"/i");
661 }
662 else
663 {
664 if( nbits > 8 )
665 {
666 strcat(fullname,"/s");
667 nBytesUsed = 2;
668 }
669 else
670 {
671 strcat(fullname,"/b");
672 nBytesUsed = 1;
673 }
674 }
675 }
676 else
677 {
678 strcat(fullname,"/i");
679 }
680 }
681
682
683
684
685 // if (itype == 4) strcat(fullname,"/i");
686 if (itype == 4) strcat(fullname,"/b");
687 if (itype == 5) strcat(fullname,"/C");
688 //printf("Creating branch:%s, block:%s, fullname:%s, nsub=%d, itype=%d, isize=%d, ielem=%d\n",name,block,fullname,nsub,itype,isize,ielem);
689 Int_t ischar;
690 if (itype == 5) ischar = 1;
691 else ischar = 0;
692 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
693 strcpy(oldblock,block);
694 oldischar = ischar;
695 Int_t lblock = strlen(block);
696 Long_t add= (Long_t)&bigbuf[bufpos];
697 #ifndef WIN32
698 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
699 #else
700 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
701 #endif
702
703 }
704 TBranch *branch = tree->Branch(name,(void*)&bigbuf[bufpos],fullname,bufsize);
705 boolflag[i] = -10;
706 charflag[i] = 0;
707 if (itype == 4) {isabool++; boolflag[i] = bufpos; lenbool[i] = ielem;}
708 bufpos += isize*ielem;
709 if (ischar) {isachar++; charflag[i] = bufpos-1; lenchar[i] = isize*ielem;}
710 TObjArray *ll= branch->GetListOfLeaves();
711 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
712 if (!leaf) continue;
713 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
714 if (leafcount) {
715 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
716 }
717 }
718 Int_t cf,l;
719 for(i=1;i<=nentries;i++) {
720 hgnt(id,i,ier);
721 if (isabool) { // if column is boolean
722 for (j=0;j<nvar;j++) {
723 cf = boolflag[j];
724 if (cf >-1) {
725 for (l=0;l<lenbool[j];l++) {
726 #ifdef R__BYTESWAP
727 boolarr[l] = (UChar_t)bigbuf[cf+4*l];
728 #else
729 boolarr[l] = (UChar_t)bigbuf[cf+4*l+3];
730 #endif
731 }
732 memcpy(&bigbuf[cf],boolarr,lenbool[j]);
733 }
734 }
735 }
736 if (isachar) { // if column is character, set terminator
737 for (j=0;j<nvar;j++) {
738 cf = charflag[j];
739 if (cf) {
740 bigbuf[cf] = '\0';
741 if (bigbuf[cf-1] != ' ') continue;
742 bigbuf[cf-1] = '\0';
743 if (bigbuf[cf-2] != ' ') continue;
744 bigbuf[cf-2] = '\0';
745 }
746 }
747 }
748
749 // if optimizing cwn ntuple then look up bufpos and adjust integers to be shorts or chars
750 if( optcwn == 1 )
751 {
752 bufpos = 0;
753 for(int k=0; k<nvar;k++)
754 {
755 #ifndef WIN32
756 hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
757 #else
758 hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
759 #endif
760
761 Int_t nBytesUsed = 4; // default for integers
762
763 if ( itype == 2 || itype == 3)
764 {
765 if( nbits > 16)
766 {
767 // do nothing for integers of 4 byte
768 }
769 else
770 {
771 if( nbits > 8 )
772 {
773 nBytesUsed = 2;
774 }
775 else
776 {
777 nBytesUsed = 1;
778 }
779 }
780 }
781
782 if(nBytesUsed == 1)
783 {
784
785 for(Int_t index = 0; index < ielem; index++)
786 {
787 // shift all chars with data to be one after another
788 bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize];
789 }
790 }
791 else
792 {
793 if(nBytesUsed == 2)
794 {
795
796 for(Int_t index = 0; index < ielem; index++)
797 {
798 // shift all shorts ( 2 chars) with data to be one after another
799 bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize];
800 bigbuf[bufpos + index*nBytesUsed+1 ] = bigbuf[bufpos + index * isize+1];
801 }
802 }
803 }
804 bufpos += isize*ielem;
805 }
806 }
807
808 tree->Fill();
809 }
810
811 tree->Write();
812
813 std::cout << "Invoking Digitizer" << endl << flush;
814
815 Digitizer* dig = new Digitizer(tree,file_raw);
816 dig->Loop();
817 dig->Close();
818
819 std::cout << "Finished" << endl << flush;
820
821 }
822
823

  ViewVC Help
Powered by ViewVC 1.1.23