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