source: trunk/MagicSoft/Simulation/Corsika/MaxiSingle/maxisingle.cxx@ 14809

Last change on this file since 14809 was 790, checked in by domingo, 24 years ago
Version 1 of the MaxiSingle sources
File size: 7.4 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2//
3// PROGRAM MaxiSingle
4//
5// MAXI files (multiple event) built form SINGLE event files
6// version 1.0
7//
8/////////////////////////////////////////////////////////////////////////////
9//
10//
11// AUTHOR Carles Domingo
12// May 15, 2001
13//
14/////////////////////////////////////////////////////////////////////////////
15//
16// PROCEDURE
17//
18// This program reads a set of files in the old MMCS output format (one
19// file per event) and writes the information from those files in the
20// new MMCS output format (one file per run).
21//
22// To perform this task, the information to fill in the Run headers, the
23// run end records and the event end record (which were missing in the
24// old format files) has to be rebuilt from the information read for
25// the events.
26//
27// Some new CORtype classes had to be defined to cope with this
28// information in an adequate way. The classes COREventEnd, CORRunHeader
29// and CORRunEnd are now defined and operational.
30//
31// In order to run the program you must supply as an argument the full
32// path of a directory containing the output files (cer and dat), starting
33// from 000001 of a given (old) MMCS run. The program will automatically
34// create inside this directory two files (named cer_allfiles and
35// dat_allfiles) containing the information of the complete run in the
36// new single file per run output format. Afterwards you can use this files
37// for the new reflector, camera, and guisimone programs.
38//
39/////////////////////////////////////////////////////////////////////////////
40//
41// REMARKS
42//
43// Tricky stuff for locating the event ends in the dat FILES!! See comments
44// on the program
45//
46//
47// ATTENTION: The estructure of the input CER files and that of
48// the DAT files is different in the "one file per event" version
49// of the MMCS program.
50//
51// CER files have:
52// Event header EVTH
53// A bunch of cerenkov photons (in blocks of 7*39=273 bytes)
54//
55// while DAT files have:
56// Event header EVTH
57// A bunch of particles (in blocks of 7*39=273 bytes)
58// Event end EVTE
59//
60/////////////////////////////////////////////////////////////////////////////
61/////////////////////////////////////////////////////////////////////////////
62//
63// NOTE
64//
65// If anybody modifies this program, make sure it is well documented !!!!
66//
67/////////////////////////////////////////////////////////////////////////////
68
69
70#include <stdlib.h>
71#include <stdio.h>
72
73#include "COREventHeader.hxx"
74#include "COREventEnd.hxx"
75#include "CORParticle.hxx"
76#include "CORRunHeader.hxx"
77#include "CORRunEnd.hxx"
78
79int main(int argc, char **argv)
80{
81 char incername[120] ;
82 char indatname[120] ;
83 char outcername[120] ;
84 char outdatname[120] ;
85
86 Float_t NumberRun ;
87 Float_t EvtsProc ;
88 Float_t TestVal ;
89
90 ifstream incerfile ;
91 ifstream indatfile ;
92 ofstream outcerfile ;
93 ofstream outdatfile ;
94
95 COREventHeader Event ;
96 COREventHeader EventDat ;
97 COREventEnd EventE ;
98 CORParticle Photon ;
99 CORParticle Particle ;
100 CORRunHeader Run ;
101 CORRunEnd RunE ;
102
103 cout << " ============================================================" << endl ;
104 cout << " MaxiSingle" << endl ;
105 cout << " " << endl ;
106 cout << " MAXI (multiple events) file from SINGLE event multiple files" << endl ;
107 cout << " " << endl ;
108 cout << " ============================================================" << endl ;
109
110 if ( argc <= 1 ) {
111 cout << endl ;
112 cout << " INFO: You have to start the program with "<< endl << endl ;
113 cout << " -> maxisingle DIRECTORY_WITH_CER_FILES" << endl << endl ;
114 cout << " no SLASH at the end of the directory name"<< endl ;
115 cout << " (example: -> maxisingle /hd123/Protons "<< endl ;
116 cout << " " << endl ;
117 exit (-1) ;
118 }
119
120 // create and open the OUTput filenames
121
122 sprintf ( outcername, "%s/cer_allfiles", argv[1] ) ;
123 sprintf ( outdatname, "%s/dat_allfiles", argv[1] ) ;
124 outcerfile.open (outcername) ;
125 if ( outcerfile.bad() ) {
126 cout << "Cannot open CER output file: " << outcername << endl ;
127 exit (1) ;
128 }
129 outdatfile.open (outdatname) ;
130 if ( outdatfile.bad() ) {
131 cout << "Cannot open DAT output file: " << outdatname << endl ;
132 exit (1) ;
133 }
134
135 EvtsProc = 0 ;
136 for (int i_cer = 1; i_cer <= 100000; i_cer++ ) {
137
138 // inform about progress
139
140 if (!( i_cer %100) ) cout << " Processing event number: " << i_cer << endl ;
141
142 // create the file names
143
144 sprintf ( incername, "%s/cer%06d", argv[1], i_cer ) ;
145 sprintf ( indatname, "%s/dat%06d", argv[1], i_cer ) ;
146
147 // try to open the files
148
149 incerfile.open( incername );
150 if ( incerfile.bad() ) break ;
151 indatfile.open( indatname );
152 if ( indatfile.bad() ) break ;
153
154 // read and write the event header
155
156 Event.read( incerfile ) ;
157 EventDat.read( indatfile ) ;
158
159 // if first event, create and write a RUN header in
160 // both outcerfile and outdatfile
161
162 if (i_cer == 1 ) {
163 // Event.print() ;
164 Run.transport (&Event) ;
165 NumberRun = Run.get_number () ;
166 Run.write (outcerfile) ;
167 Run.write (outdatfile) ;
168 // Run.print () ;
169 }
170
171 Event.write( outcerfile ) ;
172 EventDat.write( outdatfile ) ;
173 EvtsProc++ ;
174
175 // loop over the photons in incerfile, read and write them
176
177 while( ! (incerfile.eof() || incerfile.bad() )) {
178 Photon.read ( incerfile ) ;
179 Photon.write ( outcerfile ) ;
180 }
181
182 // loop over the particles in indatfile, read and write them
183 // This procedure is somewhat tricky, in order to find the event end record
184
185 while( ! (indatfile.eof() || indatfile.bad() )) {
186
187 Particle.read ( indatfile ) ;
188 // Particle.print () ;
189
190 // TRICKY STUFF
191 //
192 // here we get the value which is in the first position of the particle
193 // record. Whenever there is a particle, this Float_t variable has an
194 // integer value. If there is no particle (but we still have a particle
195 // type record that MMCS has filled with zeroes), the value is 0. But if
196 // the EVENT END record is found, we find the Char_t identifier 'EVTE'
197 // in that first position. If 'EVTE' is read as Float_t it returns a value
198 // of 3397.39 both in OSF1 and Linux, so we can easyly check for that value,
199 // also making sure that it is not integer (any number between 3397.38 and
200 // 3397.40 CANNOT be integer)... so it is sure it is NOT a real particle.
201
202 TestVal = Particle.get_id () ;
203 if (TestVal > 3397.38 && TestVal < 3397.40) {
204
205 // Go back in the file to read again the record not as a particle record
206 // but as EVENT END
207
208 indatfile.seekg( -28, ios::cur ) ;
209 EventE.read( indatfile );
210 break ;
211 }
212 Particle.write ( outdatfile ) ;
213 // Particle.print () ;
214 }
215
216 // close input files and write the EVENT end record in outputs
217
218 incerfile.close () ;
219 indatfile.close () ;
220 // EventE.print () ;
221 EventE.write( outcerfile );
222 EventE.write( outdatfile );
223
224 }
225
226 // write the RUN end record and close output files
227
228 cout << " ---> Processed a total of " << EvtsProc << " events" << endl ;
229 RunE.fill ( NumberRun , EvtsProc ) ;
230 RunE.write( outcerfile );
231 RunE.write( outdatfile );
232 outcerfile.close ();
233 outdatfile.close ();
234
235}
236
237
238
239
240
241
242
243
Note: See TracBrowser for help on using the repository browser.