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