source: tags/Mars-V2.1.1/readdaq.cc@ 19203

Last change on this file since 19203 was 8946, 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 //
82 // Set verbosity to highest level.
83 //
84 const Bool_t kDecimal = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
85 const Bool_t kPrintArray = arg.HasOption("-c") && arg.GetIntAndRemove("-c")==1;
86 const Bool_t kForce = arg.HasOnlyAndRemove("-ff");
87 const Bool_t kForceMode = arg.HasOnlyAndRemove("-f");
88
89 //
90 // check for the right usage of the program
91 //
92 if (arg.GetNumArguments()!=1)
93 {
94 Usage();
95 return 2;
96 }
97
98 //
99 // This is to make argv[i] more readable insidethe code
100 //
101 TString kNamein = arg.GetArgumentStr(0);
102
103 if (!kNamein.EndsWith(".raw") && !kNamein.EndsWith(".raw.gz"))
104 kNamein += ".raw";
105
106 //
107 // Initialize Non-GUI (batch) mode
108 //
109 gROOT->SetBatch();
110
111 //
112 // check whether the given files are OK.
113 //
114 if (gSystem->AccessPathName(kNamein, kFileExists))
115 {
116 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
117 return 2;
118 }
119
120 //
121 // open the file
122 //
123 gLog << " Open the file '" << kNamein << "'" << endl;
124
125
126 //
127 // create a (empty) list of parameters which can be used by the tasks
128 // and an (empty) list of tasks which should be executed
129 //
130 MParList plist;
131
132 MTaskList tasks;
133 tasks.SetOwner();
134 plist.AddToList(&tasks);
135
136 //
137 // ---- The following is only necessary to supress some output ----
138 //
139 MRawRunHeader runheader;
140 plist.AddToList(&runheader);
141
142 MRawEvtHeader evtheader;
143 plist.AddToList(&evtheader);
144
145 MRawEvtData evtdata;
146 plist.AddToList(&evtdata);
147
148 MRawEvtData evtdata2("MRawEvtData2");
149 plist.AddToList(&evtdata2);
150
151 MRawCrateArray cratearray;
152 plist.AddToList(&cratearray);
153
154 MTime evttime;
155 plist.AddToList(&evttime);
156
157 //
158 // create the tasks which should be executed and add them to the list
159 // in the case you don't need parameter containers, all of them can
160 // be created by MRawFileRead::PreProcess
161 //
162 MRawFileRead read(kNamein);
163 read.SetForce(kForce);
164 read.SetForceMode(kForceMode);
165 tasks.AddToList(&read);
166
167 MPrint print0;
168 MPrint print1("MRawEvtHeader", "nogains", "PrintEvtHeader");
169 MPrint print2("MTime", "", "PrintTime");
170 MPrint print3("MRawCrateArray", "", "PrintCrateArray");
171 MPrint print4("MRawEvtData", kDecimal?"dec":"hex", "PrintEvtData");
172 MPrint print5("MRawEvtData2", kDecimal?"dec":"hex", "PrintEvtData2");
173
174 tasks.AddToList(&print0);
175 tasks.AddToList(&print1);
176 tasks.AddToList(&print2);
177 if (kPrintArray)
178 tasks.AddToList(&print3);
179 tasks.AddToList(&print4);
180 tasks.AddToList(&print5);
181
182 //
183 // create the looping object and tell it about the parameters to use
184 // and the tasks to execute
185 //
186 MEvtLoop magic;
187 magic.SetParList(&plist);
188
189 //
190 // Start the eventloop which reads the raw file (MRawFileRead) and
191 // write all the information into a root file (MRawFileWrite)
192 //
193 // between reading and writing we can do, transformations, checks, etc.
194 // (I'm think of a task like MRawDataCheck)
195 //
196 if (!magic.Eventloop())
197 {
198 gLog << err << "ERROR: Reading DAQ file failed!" << endl;
199 return 2;
200 }
201
202 gLog << all << "Reading DAQ file finished successfull!" << endl;
203
204 // end of small readin program
205
206 return 0;
207}
Note: See TracBrowser for help on using the repository browser.