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

Last change on this file since 2602 was 2580, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.0 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 << " -?/-h: This help" << endl << endl;
57}
58
59int main(int argc, char **argv)
60{
61 StartUpMessage();
62
63 //
64 // Evaluate arguments
65 //
66 MArgs arg(argc, argv);
67
68 if (arg.HasOption("-?") || arg.HasOption("-h"))
69 {
70 Usage();
71 return -1;
72 }
73
74 //
75 // Set verbosity to highest level.
76 //
77 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
78
79 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
80 gLog.SetNoColors();
81
82 const bool kDecimal = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
83
84 //
85 // check for the right usage of the program
86 //
87 if (arg.GetNumArguments()!=1)
88 {
89 Usage();
90 return -1;
91 }
92
93 //
94 // This is to make argv[i] more readable insidethe code
95 //
96 TString kNamein = arg.GetArgumentStr(0);
97
98 if (!kNamein.EndsWith(".raw"))
99 kNamein += ".raw";
100
101 //
102 // Initialize Non-GUI (batch) mode
103 //
104 gROOT->SetBatch();
105
106 //
107 // check whether the given files are OK.
108 //
109 if (gSystem->AccessPathName(kNamein, kFileExists))
110 {
111 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
112 return -1;
113 }
114
115 //
116 // open the file
117 //
118 gLog << " Open the file '" << kNamein << "'" << endl;
119
120
121 //
122 // create a (empty) list of parameters which can be used by the tasks
123 // and an (empty) list of tasks which should be executed
124 //
125 MParList plist;
126
127 MTaskList tasks;
128 tasks.SetOwner();
129 plist.AddToList(&tasks);
130
131 //
132 // ---- The following is only necessary to supress some output ----
133 //
134 MRawRunHeader runheader;
135 plist.AddToList(&runheader);
136
137 MRawEvtHeader evtheader;
138 plist.AddToList(&evtheader);
139
140 MRawEvtData evtdata;
141 plist.AddToList(&evtdata);
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
163 tasks.AddToList(&print0);
164 tasks.AddToList(&print1);
165 tasks.AddToList(&print2);
166 tasks.AddToList(&print3);
167 tasks.AddToList(&print4);
168
169 //
170 // create the looping object and tell it about the parameters to use
171 // and the tasks to execute
172 //
173 MEvtLoop magic;
174 magic.SetParList(&plist);
175
176 //
177 // Start the eventloop which reads the raw file (MRawFileRead) and
178 // write all the information into a root file (MRawFileWrite)
179 //
180 // between reading and writing we can do, transformations, checks, etc.
181 // (I'm think of a task like MRawDataCheck)
182 //
183 if (!magic.Eventloop())
184 {
185 gLog << err << "ERROR: Reading DAQ file failed!" << endl;
186 return -1;
187 }
188
189 gLog << all << "Reading DAQ file finished successfull!" << endl;
190
191 // end of small readin program
192
193 return 0;
194}
Note: See TracBrowser for help on using the repository browser.