source: trunk/MagicSoft/Mars/readcorsika.cc@ 9347

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