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

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

  ViewVC Help
Powered by ViewVC 1.1.23