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

Annotation of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Fri Sep 28 10:46:27 2007 UTC (17 years, 2 months ago) by orsi
Branch: MAIN
Changes since 1.1: +11 -2 lines
TOF TDC added; TRK improved; bug fixes

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

  ViewVC Help
Powered by ViewVC 1.1.23