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