source: trunk/Mars/readcorsika.cc@ 9938

Last change on this file since 9938 was 9933, checked in by tbretz, 14 years ago
Added RunHeaders-tree and fixed usage-info in 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 tasks.AddToList(&print4);
167 }
168 else
169 tasks.AddToList(&write);
170
171 //
172 // create the looping object and tell it about the parameters to use
173 // and the tasks to execute
174 //
175 MEvtLoop magic;
176 magic.SetParList(&plist);
177
178 //
179 // Start the eventloop which reads the raw file (MCorsikaRead) and
180 // write all the information into a root file (MCorsikaFileWrite)
181 //
182 // between reading and writing we can do, transformations, checks, etc.
183 // (I'm think of a task like MCorsikaDataCheck)
184 //
185 if (!magic.Eventloop())
186 {
187 gLog << err << "ERROR: Reading Corsika file failed!" << endl;
188 return 2;
189 }
190
191 gLog << all << "Reading Corsika file finished successfull!" << endl;
192
193 // end of small readin program
194
195 return 0;
196}
Note: See TracBrowser for help on using the repository browser.