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

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