source: tags/Mars-V0.9.6/readdaq.cc@ 10113

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