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

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

  ViewVC Help
Powered by ViewVC 1.1.23