source: tags/Mars-V0.8.3/readdaq.cc@ 10107

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