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

Contents of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download)
Wed Oct 15 14:03:22 2008 UTC (16 years, 1 month ago) by pamelats
Branch: MAIN
CVS Tags: v3r03
Changes since 1.10: +28 -39 lines
Cambiamenti principali: TOF, AC; cambiamenti di struttura (tutti *h esterni si trovano in Digitizer.h)

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

  ViewVC Help
Powered by ViewVC 1.1.23