source: tags/Mars-V0.10/readdaq.cc@ 18088

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