source: trunk/Mars/readcorsika.cc@ 18679

Last change on this file since 18679 was 10060, checked in by rohlfs, 14 years ago
two new command line arguments of readcorsika: -A=arrayNo and -T=telescopeNo. New design of program flow in MCorsikaRead: It is now determined by the order of the data blocks in the input file.
File size: 5.6 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] [-A=arrayNo] [-T=telescopeNo] inputfile[.raw] [outputfile[.root]]" << endl << endl;
41 gLog << " inputfile: corsika raw file or eventio file" << endl;
42 gLog << " outputfile: root file" << endl;
43 gLog << " -A=arrayNo: use data only of array number arrayNo" << endl;
44 gLog << " -T=telescopeNo: use data only of telescope number telescopeNo (used only for eventio input file)" << endl;
45 gLog << " -ff Force reading of file even if problems occur" << endl;
46 gLog.Usage();
47// gLog << " -f: force reading of runheader" << endl;
48 gLog << " -?, -h, --help: This help" << endl << endl;
49}
50
51int main(int argc, char **argv)
52{
53 if (!MARS::CheckRootVer())
54 return 0xff;
55
56 MLog::RedirectErrorHandler(MLog::kColor);
57
58 //
59 // Evaluate arguments
60 //
61 MArgs arg(argc, argv);
62 gLog.Setup(arg);
63
64 StartUpMessage();
65
66 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
67 {
68 Usage();
69 return 2;
70 }
71
72 arg.RemoveRootArgs();
73
74 const Int_t kCompLvl = arg.GetIntAndRemove("--comp=", 1);
75 const Int_t kArrayNo = arg.GetIntAndRemove("-A=", -1);
76 const Int_t kTelNo = arg.GetIntAndRemove("-T=", -1);
77 const Bool_t kForce = arg.HasOnlyAndRemove("-f");
78 const Bool_t kForceRd = arg.HasOnlyAndRemove("-ff");
79
80
81 //
82 // check for the right usage of the program
83 //
84 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
85 {
86 Usage();
87 return 2;
88 }
89
90 //
91 // This is to make argv[i] more readable insidethe code
92 //
93 TString kNamein = arg.GetArgumentStr(0);
94 TString kNameout = arg.GetArgumentStr(1);
95
96// if (!kNamein.EndsWith(".raw") && !kNamein.EndsWith(".raw.gz"))
97// kNamein += ".raw";
98
99 if (!kNameout.IsNull() && !kNameout.EndsWith(".root"))
100 kNameout += ".root";
101
102 //
103 // Initialize Non-GUI (batch) mode
104 //
105 TObject::Class()->IgnoreTObjectStreamer();
106 TVector2::Class()->IgnoreTObjectStreamer();
107 MParContainer::Class()->IgnoreTObjectStreamer();
108
109 gROOT->SetBatch();
110
111 //
112 // check whether the given files are OK.
113 //
114 if (gSystem->AccessPathName(kNamein, kFileExists))
115 {
116 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
117 return 2;
118 }
119
120 //
121 // open the file
122 //
123 gLog << " Open the file '" << kNamein << "'" << endl;
124
125
126 //
127 // create a (empty) list of parameters which can be used by the tasks
128 // and an (empty) list of tasks which should be executed
129 //
130 MParList plist;
131
132 MTaskList tasks;
133 tasks.SetOwner();
134 plist.AddToList(&tasks);
135
136 //
137 // ---- The following is only necessary to supress some output ----
138 //
139 /*
140 MCorsikaRunHeader runheader;
141 plist.AddToList(&runheader);
142
143 MCorsikaEvtHeader evtheader;
144 plist.AddToList(&evtheader);
145
146 MCorsikaData evtdata;
147 plist.AddToList(&evtdata);
148 */
149 //
150 // create the tasks which should be executed and add them to the list
151 // in the case you don't need parameter containers, all of them can
152 // be created by MCorsikaRead::PreProcess
153 //
154 MCorsikaRead read(kNamein);
155 read.SetForceMode(kForceRd);
156 read.SetArrayIdx(kArrayNo);
157 read.SetTelescopeIdx(kTelNo);
158 tasks.AddToList(&read);
159
160 MPrint print0;
161 MPrint print1("MCorsikaEvtHeader", "", "PrintEvtHeader");
162 MPrint print4("MPhotonEvent", "", "PrintEvent");
163
164 MWriteRootFile write(kNameout, kForce?"RECREATE":"NEW", "Corsika File", kCompLvl);
165 write.AddContainer("MCorsikaRunHeader", "RunHeaders");
166 write.AddContainer("MCorsikaEvtHeader", "Events");
167 write.AddContainer("MPhotonEvent", "Events");
168
169 if (kNameout.IsNull())
170 {
171 tasks.AddToList(&print0);
172 tasks.AddToList(&print1);
173 if (gLog.GetDebugLevel()>2)
174 tasks.AddToList(&print4);
175 }
176 else
177 tasks.AddToList(&write);
178
179 //
180 // create the looping object and tell it about the parameters to use
181 // and the tasks to execute
182 //
183 MEvtLoop magic;
184 magic.SetParList(&plist);
185
186 //
187 // Start the eventloop which reads the raw file (MCorsikaRead) and
188 // write all the information into a root file (MCorsikaFileWrite)
189 //
190 // between reading and writing we can do, transformations, checks, etc.
191 // (I'm think of a task like MCorsikaDataCheck)
192 //
193 if (!magic.Eventloop())
194 {
195 gLog << err << "ERROR: Reading Corsika file failed!" << endl;
196 return 2;
197 }
198
199 gLog << all << "Reading Corsika file finished successfull!" << endl;
200
201 // end of small readin program
202
203 return 0;
204}
Note: See TracBrowser for help on using the repository browser.