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

Contents of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations) (download)
Fri Jun 6 15:16:08 2008 UTC (16 years, 5 months ago) by pamelats
Branch: MAIN
CVS Tags: v3r00, v3r01, v3r02
Changes since 1.9: +58 -3 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23