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