source: tags/Mars-V1.2/readdaq.cc@ 14158

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