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

Diff of /PamelaDigitizer/Pamelagp2Digits.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.23