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

Annotation of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Wed Oct 31 18:17:59 2007 UTC (17 years, 1 month ago) by orsi
Branch: MAIN
Changes since 1.5: +11 -0 lines
ToF improved; HOW-TO-DIGIT.TXT extended

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

  ViewVC Help
Powered by ViewVC 1.1.23