source: tags/Mars-V0.8.1/merpp.cc@ 17873

Last change on this file since 17873 was 2299, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.7 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
38void Usage()
39{
40 gLog << "Sorry the usage is:" << endl;
41 gLog << " merpp [-a0] [-vn] [-cn] inputfile[.raw] [outputfile[.root]]" << endl << endl;
42 gLog << " input file: Magic DAQ binary file." << endl;
43 gLog << " ouput file: Merpped root file." << endl;
44 gLog << " -a0: Do not use Ansii codes." << endl;
45 gLog << " -cn: Compression level n=1..9 [default=1]" << endl;
46 gLog << " -vn: Verbosity level n [default=2]" << endl << endl;
47}
48
49int main(const int argc, const char **argv)
50{
51 MArgs arg(argc, argv);
52
53 gLog << "==================================================" << endl ;
54 gLog << " MERPP v0.1" << endl;
55 gLog << " MARS Merging and Preprocessing Program" << endl ;
56 gLog << " Compiled on <" << __DATE__ << ">" << endl ;
57 gLog << " Using ROOT v" << ROOTVER << endl ;
58 gLog << "==================================================" << endl ;
59 gLog << endl;
60
61 //
62 // Set verbosity to highest level.
63 //
64 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
65
66 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
67 gLog.SetNoColors();
68
69 const int kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
70
71 //
72 // check for the right usage of the program
73 //
74 if (arg.GetNumArguments()<1 || arg.GetNumArguments()>2)
75 {
76 Usage();
77 return -1;
78 }
79
80 //
81 // This is to make argv[i] more readable insidethe code
82 //
83 TString kNamein = arg.GetArgumentStr(0);
84 TString kNameout = arg.GetArgumentStr(1);
85
86 //
87 // initialize ROOT (this is obligatory here)
88 //
89 TROOT merpp("merpp", "Mars - Merging and Preprocessing Program");
90 merpp.SetBatch();
91
92 if (!kNamein.EndsWith(".raw"))
93 kNamein += ".raw";
94
95 if (kNameout.IsNull())
96 kNameout = kNamein(0, kNamein.Last('.'));
97
98 if (!kNameout.EndsWith(".root"))
99 kNameout += ".root";
100
101 //
102 // check whether the given files are OK.
103 //
104 if (gSystem->AccessPathName(kNamein, kFileExists))
105 {
106 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
107 return -1;
108 }
109
110 if (!gSystem->AccessPathName(kNameout, kFileExists))
111 gLog << warn << "Warning: A file '" << kNameout << "' exists." << endl;
112 else
113 if (!gSystem->AccessPathName(kNameout, kWritePermission))
114 {
115 gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
116 return -1;
117 }
118
119 MArray::Class()->IgnoreTObjectStreamer();
120 MParContainer::Class()->IgnoreTObjectStreamer();
121
122 //
123 // create a (empty) list of parameters which can be used by the tasks
124 // and an (empty) list of tasks which should be executed
125 //
126 MParList plist;
127
128 MTaskList tasks;
129 plist.AddToList(&tasks);
130
131 //
132 // ---- The following is only necessary to supress some output ----
133 //
134 MRawRunHeader runheader;
135 plist.AddToList(&runheader);
136
137 MRawEvtHeader evtheader;
138 plist.AddToList(&evtheader);
139
140 MRawEvtData evtdata;
141 plist.AddToList(&evtdata);
142
143 MRawCrateArray cratearray;
144 plist.AddToList(&cratearray);
145
146 MTime evttime("MRawEvtTime");
147 plist.AddToList(&evttime);
148
149 //
150 // create the tasks which should be executed and add them to the list
151 // in the case you don't need parameter containers, all of them can
152 // be created by MRawFileRead::PreProcess
153 //
154 MRawFileRead reader(kNamein);
155 MRawFileWrite writer(kNameout, "RECREATE", "Magic root-file", kComprlvl);
156 tasks.AddToList(&reader);
157 tasks.AddToList(&writer);
158
159 //
160 // create the looping object and tell it about the parameters to use
161 // and the tasks to execute
162 //
163 MEvtLoop magic;
164 magic.SetParList(&plist);
165
166 //
167 // Start the eventloop which reads the raw file (MRawFileRead) and
168 // write all the information into a root file (MRawFileWrite)
169 //
170 // between reading and writing we can do, transformations, checks, etc.
171 // (I'm think of a task like MRawDataCheck)
172 //
173 if (!magic.Eventloop())
174 {
175 gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
176 return -1;
177 }
178
179 gLog << all << "Merpp finished successfull!" << endl;
180 return 0;
181}
182
183
Note: See TracBrowser for help on using the repository browser.