source: trunk/Mars/readcorsika.cc@ 9969

Last change on this file since 9969 was 9949, checked in by tbretz, 14 years ago
Fixed a problem reading the RUNE section in the raw corsika files and accelerated plain readcorsika.
File size: 5.1 KB
Line 
1#include <TClass.h>
2#include <TSystem.h>
3#include <TVector2.h>
4
5#include "MParList.h"
6#include "MTaskList.h"
7#include "MEvtLoop.h"
8
9#include "MLog.h"
10#include "MLogManip.h"
11
12#include "MArgs.h"
13#include "MPrint.h"
14
15#include "MCorsikaRead.h"
16
17#include "MWriteRootFile.h"
18
19
20using namespace std;
21
22static void StartUpMessage()
23{
24 gLog << all << endl;
25
26 // 1 2 3 4 5
27 // 12345678901234567890123456789012345678901234567890
28 gLog << "==================================================" << endl;
29 gLog << " ReadCorsika - MARS V" << MARSVER << endl;
30 gLog << " MARS - Read and print corsika data files" << endl;
31 gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
32 gLog << "==================================================" << endl;
33 gLog << endl;
34}
35
36static void Usage()
37{
38 gLog << all << endl;
39 gLog << "Sorry the usage is:" << endl;
40 gLog << " readcorsika [-h] [-?] [-vn] [-dec] [-a0] inputfile[.raw] [outputfile[.root]]" << endl << endl;
41 gLog << " inputfile: corsika raw file" << endl;
42 gLog << " outputfile: root file" << endl;
43 gLog << " -ff Force reading of file even if problems occur" << endl;
44 gLog.Usage();
45// gLog << " -f: force reading of runheader" << endl;
46 gLog << " -?, -h, --help: This help" << endl << endl;
47}
48
49int main(int argc, char **argv)
50{
51 if (!MARS::CheckRootVer())
52 return 0xff;
53
54 MLog::RedirectErrorHandler(MLog::kColor);
55
56 //
57 // Evaluate arguments
58 //
59 MArgs arg(argc, argv);
60 gLog.Setup(arg);
61
62 StartUpMessage();
63
64 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
65 {
66 Usage();
67 return 2;
68 }
69
70 arg.RemoveRootArgs();
71
72 const Int_t kCompLvl = arg.GetIntAndRemove("--comp=", 1);
73 const Bool_t kForce = arg.HasOnlyAndRemove("-f");
74 const Bool_t kForceRd = arg.HasOnlyAndRemove("-ff");
75
76 //
77 // check for the right usage of the program
78 //
79 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
80 {
81 Usage();
82 return 2;
83 }
84
85 //
86 // This is to make argv[i] more readable insidethe code
87 //
88 TString kNamein = arg.GetArgumentStr(0);
89 TString kNameout = arg.GetArgumentStr(1);
90
91// if (!kNamein.EndsWith(".raw") && !kNamein.EndsWith(".raw.gz"))
92// kNamein += ".raw";
93
94 if (!kNameout.IsNull() && !kNameout.EndsWith(".root"))
95 kNameout += ".root";
96
97 //
98 // Initialize Non-GUI (batch) mode
99 //
100 TObject::Class()->IgnoreTObjectStreamer();
101 TVector2::Class()->IgnoreTObjectStreamer();
102 MParContainer::Class()->IgnoreTObjectStreamer();
103
104 gROOT->SetBatch();
105
106 //
107 // check whether the given files are OK.
108 //
109 if (gSystem->AccessPathName(kNamein, kFileExists))
110 {
111 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
112 return 2;
113 }
114
115 //
116 // open the file
117 //
118 gLog << " Open the file '" << kNamein << "'" << endl;
119
120
121 //
122 // create a (empty) list of parameters which can be used by the tasks
123 // and an (empty) list of tasks which should be executed
124 //
125 MParList plist;
126
127 MTaskList tasks;
128 tasks.SetOwner();
129 plist.AddToList(&tasks);
130
131 //
132 // ---- The following is only necessary to supress some output ----
133 //
134 /*
135 MCorsikaRunHeader runheader;
136 plist.AddToList(&runheader);
137
138 MCorsikaEvtHeader evtheader;
139 plist.AddToList(&evtheader);
140
141 MCorsikaData evtdata;
142 plist.AddToList(&evtdata);
143 */
144 //
145 // create the tasks which should be executed and add them to the list
146 // in the case you don't need parameter containers, all of them can
147 // be created by MCorsikaRead::PreProcess
148 //
149 MCorsikaRead read(kNamein);
150 read.SetForceMode(kForceRd);
151 tasks.AddToList(&read);
152
153 MPrint print0;
154 MPrint print1("MCorsikaEvtHeader", "", "PrintEvtHeader");
155 MPrint print4("MPhotonEvent", "", "PrintEvent");
156
157 MWriteRootFile write(kNameout, kForce?"RECREATE":"NEW", "Corsika File", kCompLvl);
158 write.AddContainer("MCorsikaRunHeader", "RunHeaders");
159 write.AddContainer("MCorsikaEvtHeader", "Events");
160 write.AddContainer("MPhotonEvent", "Events");
161
162 if (kNameout.IsNull())
163 {
164 tasks.AddToList(&print0);
165 tasks.AddToList(&print1);
166 if (gLog.GetDebugLevel()>2)
167 tasks.AddToList(&print4);
168 }
169 else
170 tasks.AddToList(&write);
171
172 //
173 // create the looping object and tell it about the parameters to use
174 // and the tasks to execute
175 //
176 MEvtLoop magic;
177 magic.SetParList(&plist);
178
179 //
180 // Start the eventloop which reads the raw file (MCorsikaRead) and
181 // write all the information into a root file (MCorsikaFileWrite)
182 //
183 // between reading and writing we can do, transformations, checks, etc.
184 // (I'm think of a task like MCorsikaDataCheck)
185 //
186 if (!magic.Eventloop())
187 {
188 gLog << err << "ERROR: Reading Corsika file failed!" << endl;
189 return 2;
190 }
191
192 gLog << all << "Reading Corsika file finished successfull!" << endl;
193
194 // end of small readin program
195
196 return 0;
197}
Note: See TracBrowser for help on using the repository browser.