source: trunk/MagicSoft/Mars/merpp.cc@ 2522

Last change on this file since 2522 was 2521, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.1 KB
Line 
1#include <TSystem.h>
2
3#include "MParList.h"
4#include "MTaskList.h"
5#include "MEvtLoop.h"
6
7#include "MRawFileRead.h"
8#include "MRawFileWrite.h"
9
10#include "MLog.h"
11#include "MLogManip.h"
12
13#include "MArgs.h"
14#include "MTime.h"
15#include "MArray.h"
16#include "MRawEvtData.h"
17#include "MRawRunHeader.h"
18#include "MRawEvtHeader.h"
19#include "MRawCrateArray.h"
20
21using namespace std;
22
23//////////////////////////////////////////////////////////////////////////////
24// //
25// This is an easy implementation of the Merging process //
26// (as compilable prog) //
27// //
28// at the moment it reads a binary file ("rawtest.bin") which was written //
29// in the DAQ raw format. //
30// //
31// The data are stored in root container objects (classes derived from //
32// TObject like MRawRunHeader) //
33// //
34// This containers are written to a root file ("rawtest.root") //
35// //
36//////////////////////////////////////////////////////////////////////////////
37
38static void StartUpMessage()
39{
40 gLog << all << endl;
41
42 // 1 2 3 4 5
43 // 12345678901234567890123456789012345678901234567890
44 gLog << "==================================================" << endl;
45 gLog << " MERPP - MARS V" << MARSVER << endl;
46 gLog << " MARS - Merging and Preprocessing Program" << endl;
47 gLog << " Compiled on <" << __DATE__ << ">" << endl;
48 gLog << " Using ROOT v" << ROOTVER << endl;
49 gLog << "==================================================" << endl;
50 gLog << endl;
51}
52
53static void Usage()
54{
55 gLog << all << endl;
56 gLog << "Sorry the usage is:" << endl;
57 gLog << " merpp [-h] [-?] [-a0] [-vn] [-cn] inputfile[.raw] [outputfile[.root]]" << endl << endl;
58 gLog << " input file: Magic DAQ binary file." << endl;
59 gLog << " ouput file: Merpped root file." << endl;
60 gLog << " -a0: Do not use Ansii codes." << endl;
61 gLog << " -cn: Compression level n=1..9 [default=2]" << endl;
62 gLog << " -vn: Verbosity level n [default=2]" << endl;
63 gLog << " -?/-h: This help" << endl << endl;
64}
65
66int main(const int argc, const char **argv)
67{
68 StartUpMessage();
69
70 //
71 // Evaluate arguments
72 //
73 MArgs arg(argc, argv);
74
75 if (arg.HasOption("-?") || arg.HasOption("-h"))
76 {
77 Usage();
78 return -1;
79 }
80
81 //
82 // Set verbosity to highest level.
83 //
84 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
85
86 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
87 gLog.SetNoColors();
88
89 const int kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
90
91 //
92 // check for the right usage of the program
93 //
94 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
95 {
96 Usage();
97 return -1;
98 }
99
100 //
101 // This is to make argv[i] more readable insidethe code
102 //
103 TString kNamein = arg.GetArgumentStr(0);
104 TString kNameout = arg.GetArgumentStr(1);
105
106 if (!kNamein.EndsWith(".raw"))
107 kNamein += ".raw";
108
109 if (kNameout.IsNull())
110 kNameout = kNamein(0, kNamein.Last('.'));
111
112 if (!kNameout.EndsWith(".root"))
113 kNameout += ".root";
114
115 //
116 // Initialize Non-GUI (batch) mode
117 //
118 gROOT->SetBatch();
119
120 //
121 // check whether the given files are OK.
122 //
123 if (gSystem->AccessPathName(kNamein, kFileExists))
124 {
125 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
126 return -1;
127 }
128
129 if (!gSystem->AccessPathName(kNameout, kFileExists))
130 gLog << warn << "Warning: A file '" << kNameout << "' exists." << endl;
131 else
132 if (!gSystem->AccessPathName(kNameout, kWritePermission))
133 {
134 gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
135 return -1;
136 }
137
138 MArray::Class()->IgnoreTObjectStreamer();
139 MParContainer::Class()->IgnoreTObjectStreamer();
140
141 //
142 // create a (empty) list of parameters which can be used by the tasks
143 // and an (empty) list of tasks which should be executed
144 //
145 MParList plist;
146
147 MTaskList tasks;
148 plist.AddToList(&tasks);
149
150 //
151 // ---- The following is only necessary to supress some output ----
152 //
153 MRawRunHeader runheader;
154 plist.AddToList(&runheader);
155
156 MRawEvtHeader evtheader;
157 plist.AddToList(&evtheader);
158
159 MRawEvtData evtdata;
160 plist.AddToList(&evtdata);
161
162 MRawCrateArray cratearray;
163 plist.AddToList(&cratearray);
164
165 MTime evttime("MRawEvtTime");
166 plist.AddToList(&evttime);
167
168 //
169 // create the tasks which should be executed and add them to the list
170 // in the case you don't need parameter containers, all of them can
171 // be created by MRawFileRead::PreProcess
172 //
173 MRawFileRead reader(kNamein);
174 MRawFileWrite writer(kNameout, "RECREATE", "Magic root-file", kComprlvl);
175 tasks.AddToList(&reader);
176 tasks.AddToList(&writer);
177
178 //
179 // create the looping object and tell it about the parameters to use
180 // and the tasks to execute
181 //
182 MEvtLoop magic;
183 magic.SetParList(&plist);
184
185 //
186 // Start the eventloop which reads the raw file (MRawFileRead) and
187 // write all the information into a root file (MRawFileWrite)
188 //
189 // between reading and writing we can do, transformations, checks, etc.
190 // (I'm think of a task like MRawDataCheck)
191 //
192 if (!magic.Eventloop())
193 {
194 gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
195 return -1;
196 }
197
198 gLog << all << "Merpp finished successfull!" << endl;
199 return 0;
200}
201
202
Note: See TracBrowser for help on using the repository browser.