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

Last change on this file since 2555 was 2531, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.0 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, 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 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
82 gLog.SetNoColors();
83
84 const int kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
85
86 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
87
88 //
89 // check for the right usage of the program
90 //
91 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
92 {
93 Usage();
94 return -1;
95 }
96
97 //
98 // This is to make argv[i] more readable insidethe code
99 //
100 TString kNamein = arg.GetArgumentStr(0);
101 TString kNameout = arg.GetArgumentStr(1);
102
103 if (!kNamein.EndsWith(".raw"))
104 kNamein += ".raw";
105
106 if (kNameout.IsNull())
107 kNameout = kNamein(0, kNamein.Last('.'));
108
109 if (!kNameout.EndsWith(".root"))
110 kNameout += ".root";
111
112 //
113 // Initialize Non-GUI (batch) mode
114 //
115 gROOT->SetBatch();
116
117 //
118 // check whether the given files are OK.
119 //
120 if (gSystem->AccessPathName(kNamein, kFileExists))
121 {
122 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
123 return -1;
124 }
125
126 if (!gSystem->AccessPathName(kNameout, kFileExists))
127 gLog << warn << "Warning: A file '" << kNameout << "' exists." << endl;
128 else
129 if (!gSystem->AccessPathName(kNameout, kWritePermission))
130 {
131 gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
132 return -1;
133 }
134
135 MArray::Class()->IgnoreTObjectStreamer();
136 MParContainer::Class()->IgnoreTObjectStreamer();
137
138 //
139 // create a (empty) list of parameters which can be used by the tasks
140 // and an (empty) list of tasks which should be executed
141 //
142 MParList plist;
143
144 MTaskList tasks;
145 plist.AddToList(&tasks);
146
147 //
148 // ---- The following is only necessary to supress some output ----
149 //
150 MRawRunHeader runheader;
151 plist.AddToList(&runheader);
152
153 MRawEvtHeader evtheader;
154 plist.AddToList(&evtheader);
155
156 MRawEvtData evtdata;
157 plist.AddToList(&evtdata);
158
159 MRawCrateArray cratearray;
160 plist.AddToList(&cratearray);
161
162 MTime evttime("MRawEvtTime");
163 plist.AddToList(&evttime);
164
165 //
166 // create the tasks which should be executed and add them to the list
167 // in the case you don't need parameter containers, all of them can
168 // be created by MRawFileRead::PreProcess
169 //
170 MRawFileRead reader(kNamein);
171 MRawFileWrite writer(kNameout, "RECREATE", "Magic root-file", kComprlvl);
172 tasks.AddToList(&reader);
173 tasks.AddToList(&writer);
174
175 //
176 // create the looping object and tell it about the parameters to use
177 // and the tasks to execute
178 //
179 MEvtLoop magic;
180 magic.SetParList(&plist);
181
182 //
183 // Start the eventloop which reads the raw file (MRawFileRead) and
184 // write all the information into a root file (MRawFileWrite)
185 //
186 // between reading and writing we can do, transformations, checks, etc.
187 // (I'm think of a task like MRawDataCheck)
188 //
189 if (!magic.Eventloop())
190 {
191 gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
192 return -1;
193 }
194
195 gLog << all << "Merpp finished successfull!" << endl;
196 return 0;
197}
198
199
Note: See TracBrowser for help on using the repository browser.