source: tags/Mars-V2.2/readdaq.cc@ 18018

Last change on this file since 18018 was 9141, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.5 KB
Line 
1#include <TSystem.h>
2
3#include "MParList.h"
4#include "MTaskList.h"
5#include "MEvtLoop.h"
6
7#include "MLog.h"
8#include "MLogManip.h"
9
10#include "MArgs.h"
11#include "MTime.h"
12#include "MPrint.h"
13#include "MRawRunHeader.h"
14#include "MRawEvtHeader.h"
15#include "MRawEvtData.h"
16#include "MRawCrateArray.h"
17#include "MRawFileRead.h"
18
19
20//#include "MInputStreamID.h"
21//#include "MMcEvt.hxx"
22//#include "MMcTrig.hxx"
23
24using namespace std;
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// This is an demonstration how to read in a unmerpped daq file
29//
30/////////////////////////////////////////////////////////////////////////////
31
32static void StartUpMessage()
33{
34 gLog << all << endl;
35
36 // 1 2 3 4 5
37 // 12345678901234567890123456789012345678901234567890
38 gLog << "==================================================" << endl;
39 gLog << " ReadDaq - MARS V" << MARSVER << endl;
40 gLog << " MARS - Read and print daq data files" << endl;
41 gLog << " Compiled with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
42 gLog << "==================================================" << endl;
43 gLog << endl;
44}
45
46static void Usage()
47{
48 gLog << all << endl;
49 gLog << "Sorry the usage is:" << endl;
50 gLog << " readdaq [-h] [-?] [-vn] [-dec] [-a0] inputfile[.raw]" << endl << endl;
51 gLog << " input file: Magic DAQ binary file." << endl;
52 gLog.Usage();
53 gLog << " -d1: print data in decimal values" << endl;
54 gLog << " -c1: print MRawCrateArray data" << endl;
55 gLog << " -ff: force reading of broken runheader" << endl;
56 gLog << " -f: force reading of files with problems" << endl;
57 gLog << " -?, -h, --help: This help" << endl << endl;
58}
59
60int main(int argc, char **argv)
61{
62 if (!MARS::CheckRootVer())
63 return 0xff;
64
65 MLog::RedirectErrorHandler(MLog::kColor);
66
67 //
68 // Evaluate arguments
69 //
70 MArgs arg(argc, argv);
71 gLog.Setup(arg);
72
73 StartUpMessage();
74
75 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
76 {
77 Usage();
78 return 2;
79 }
80
81 arg.RemoveRootArgs();
82
83 //
84 // Set verbosity to highest level.
85 //
86 const Bool_t kDecimal = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
87 const Bool_t kPrintArray = arg.HasOption("-c") && arg.GetIntAndRemove("-c")==1;
88 const Bool_t kForce = arg.HasOnlyAndRemove("-ff");
89 const Bool_t kForceMode = arg.HasOnlyAndRemove("-f");
90
91 //
92 // check for the right usage of the program
93 //
94 if (arg.GetNumArguments()!=1)
95 {
96 Usage();
97 return 2;
98 }
99
100 //
101 // This is to make argv[i] more readable insidethe code
102 //
103 TString kNamein = arg.GetArgumentStr(0);
104
105 if (!kNamein.EndsWith(".raw") && !kNamein.EndsWith(".raw.gz"))
106 kNamein += ".raw";
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 2;
120 }
121
122 //
123 // open the file
124 //
125 gLog << " Open the file '" << kNamein << "'" << endl;
126
127
128 //
129 // create a (empty) list of parameters which can be used by the tasks
130 // and an (empty) list of tasks which should be executed
131 //
132 MParList plist;
133
134 MTaskList tasks;
135 tasks.SetOwner();
136 plist.AddToList(&tasks);
137
138 //
139 // ---- The following is only necessary to supress some output ----
140 //
141 MRawRunHeader runheader;
142 plist.AddToList(&runheader);
143
144 MRawEvtHeader evtheader;
145 plist.AddToList(&evtheader);
146
147 MRawEvtData evtdata;
148 plist.AddToList(&evtdata);
149
150 MRawEvtData evtdata2("MRawEvtData2");
151 plist.AddToList(&evtdata2);
152
153 MRawCrateArray cratearray;
154 plist.AddToList(&cratearray);
155
156 MTime evttime;
157 plist.AddToList(&evttime);
158
159 //
160 // create the tasks which should be executed and add them to the list
161 // in the case you don't need parameter containers, all of them can
162 // be created by MRawFileRead::PreProcess
163 //
164 MRawFileRead read(kNamein);
165 read.SetForce(kForce);
166 read.SetForceMode(kForceMode);
167 tasks.AddToList(&read);
168
169 MPrint print0;
170 MPrint print1("MRawEvtHeader", "nogains", "PrintEvtHeader");
171 MPrint print2("MTime", "", "PrintTime");
172 MPrint print3("MRawCrateArray", "", "PrintCrateArray");
173 MPrint print4("MRawEvtData", kDecimal?"dec":"hex", "PrintEvtData");
174 MPrint print5("MRawEvtData2", kDecimal?"dec":"hex", "PrintEvtData2");
175
176 tasks.AddToList(&print0);
177 tasks.AddToList(&print1);
178 tasks.AddToList(&print2);
179 if (kPrintArray)
180 tasks.AddToList(&print3);
181 tasks.AddToList(&print4);
182 tasks.AddToList(&print5);
183
184 //
185 // create the looping object and tell it about the parameters to use
186 // and the tasks to execute
187 //
188 MEvtLoop magic;
189 magic.SetParList(&plist);
190
191 //
192 // Start the eventloop which reads the raw file (MRawFileRead) and
193 // write all the information into a root file (MRawFileWrite)
194 //
195 // between reading and writing we can do, transformations, checks, etc.
196 // (I'm think of a task like MRawDataCheck)
197 //
198 if (!magic.Eventloop())
199 {
200 gLog << err << "ERROR: Reading DAQ file failed!" << endl;
201 return 2;
202 }
203
204 gLog << all << "Reading DAQ file finished successfull!" << endl;
205
206 // end of small readin program
207
208 return 0;
209}
Note: See TracBrowser for help on using the repository browser.