source: branches/removing_cpp11_features/readdaq.cc@ 18282

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