source: trunk/MagicSoft/Mars/readdaq.cc@ 6977

Last change on this file since 6977 was 6888, checked in by tbretz, 20 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 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, --help: 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.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
70 {
71 Usage();
72 return 2;
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 2;
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 2;
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 MRawEvtData evtdata2("MRawEvtData2");
146 plist.AddToList(&evtdata2);
147
148 MRawCrateArray cratearray;
149 plist.AddToList(&cratearray);
150
151 MTime evttime;
152 plist.AddToList(&evttime);
153
154 //
155 // create the tasks which should be executed and add them to the list
156 // in the case you don't need parameter containers, all of them can
157 // be created by MRawFileRead::PreProcess
158 //
159 MRawFileRead read(kNamein);
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.