source: trunk/Mars/readcorsika.cc@ 9855

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