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

Annotation of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Thu Sep 13 11:00:53 2007 UTC (17 years, 2 months ago) by silvio
Branch: MAIN
Branch point for: PamelaDigitizer/
Initial revision

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

  ViewVC Help
Powered by ViewVC 1.1.23