source: tags/Mars-V0.9.2/readdaq.cc@ 18018

Last change on this file since 18018 was 7001, checked in by tbretz, 20 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.Usage();
54 gLog << " -d1: print data in decimal values" << endl;
55 gLog << " -c1: print MRawCrateArray data" << endl;
56 gLog << " -?, -h, --help: This help" << endl << endl;
57}
58
59int main(int argc, char **argv)
60{
61 //
62 // Evaluate arguments
63 //
64 MArgs arg(argc, argv);
65 gLog.Setup(arg);
66
67 StartUpMessage();
68
69 if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
70 {
71 Usage();
72 return 2;
73 }
74
75 //
76 // Set verbosity to highest level.
77 //
78 const bool kDecimal = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
79 const bool kPrintArray = arg.HasOption("-c") && arg.GetIntAndRemove("-c")==1;
80
81 //
82 // check for the right usage of the program
83 //
84 if (arg.GetNumArguments()!=1)
85 {
86 Usage();
87 return 2;
88 }
89
90 //
91 // This is to make argv[i] more readable insidethe code
92 //
93 TString kNamein = arg.GetArgumentStr(0);
94
95 if (!kNamein.EndsWith(".raw"))
96 kNamein += ".raw";
97
98 //
99 // Initialize Non-GUI (batch) mode
100 //
101 gROOT->SetBatch();
102
103 //
104 // check whether the given files are OK.
105 //
106 if (gSystem->AccessPathName(kNamein, kFileExists))
107 {
108 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
109 return 2;
110 }
111
112 //
113 // open the file
114 //
115 gLog << " Open the file '" << kNamein << "'" << endl;
116
117
118 //
119 // create a (empty) list of parameters which can be used by the tasks
120 // and an (empty) list of tasks which should be executed
121 //
122 MParList plist;
123
124 MTaskList tasks;
125 tasks.SetOwner();
126 plist.AddToList(&tasks);
127
128 //
129 // ---- The following is only necessary to supress some output ----
130 //
131 MRawRunHeader runheader;
132 plist.AddToList(&runheader);
133
134 MRawEvtHeader evtheader;
135 plist.AddToList(&evtheader);
136
137 MRawEvtData evtdata;
138 plist.AddToList(&evtdata);
139
140 MRawEvtData evtdata2("MRawEvtData2");
141 plist.AddToList(&evtdata2);
142
143 MRawCrateArray cratearray;
144 plist.AddToList(&cratearray);
145
146 MTime evttime;
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 read(kNamein);
155 tasks.AddToList(&read);
156
157 MPrint print0;
158 MPrint print1("MRawEvtHeader", "nogains", "PrintEvtHeader");
159 MPrint print2("MTime", "", "PrintTime");
160 MPrint print3("MRawCrateArray", "", "PrintCrateArray");
161 MPrint print4("MRawEvtData", kDecimal?"dec":"hex", "PrintEvtData");
162 MPrint print5("MRawEvtData2", kDecimal?"dec":"hex", "PrintEvtData2");
163
164 tasks.AddToList(&print0);
165 tasks.AddToList(&print1);
166 tasks.AddToList(&print2);
167 if (kPrintArray)
168 tasks.AddToList(&print3);
169 tasks.AddToList(&print4);
170 tasks.AddToList(&print5);
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 2;
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.