source: trunk/Mars/mreport/MReportFileReadCC.cc@ 10314

Last change on this file since 10314 was 8955, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MReportFileReadCC
28//
29// This is a report file reader which implements the CC header checking.
30// Because diffrent subsystem are writing different headers it is not
31// easily possible to have one Reader for all files. Because of this
32// you must know to which subsystem the file belongs before you can
33// instantiate your reader if you need the header or want to check the
34// header.
35//
36// If you want to restrict reading to 'single run report files' you can
37// call SetRunNumber(12345). In this case Checking the Header will fail
38// if no run information is available or the runnumber in the header
39// doesn't match. To request a 'all run' file use SetRunNumber(0).
40// To allow both file types to be read use SetRunNumber(-1) <default>
41//
42//////////////////////////////////////////////////////////////////////////////
43#include "MReportFileReadCC.h"
44
45#include <fstream>
46#include <stdlib.h> // atoi on gcc 2.95.3
47
48#include <TRegexp.h>
49
50#include "MLog.h"
51#include "MLogManip.h"
52
53ClassImp(MReportFileReadCC);
54
55using namespace std;
56
57// --------------------------------------------------------------------------
58//
59// Default constructor. It tries to open the given file and creates a
60// THashTable which allows faster access to the MReport* objects.
61//
62MReportFileReadCC::MReportFileReadCC(const char *fname, const char *name, const char *title)
63 : MReportFileRead(fname, name, title), fTelescope(-1), fRunNumber(-1), fFileNumber(-1)
64{
65 fName = name ? name : "MReportFileReadCC";
66 fTitle = title ? title : "Read task to read Central Control report files";
67}
68
69Int_t MReportFileReadCC::GetRunNumber(const TString &str) const
70{
71 Int_t run = -1;
72
73 // whole night report file
74 if (str==TString("[CC Report File]"))
75 run = 0;
76
77 // report file matching a single run
78 if (!str(TRegexp("^[CC Run [0-9]+ Control File]$")).IsNull())
79 run = atoi(str(TRegexp(" [0-9]+")).Data());
80
81 if (run<0)
82 {
83 *fLog << err << "ERROR - First line doesn't match '[CC Report File]' ";
84 *fLog << "nor '^[CC Run [0-9]+ Control File]$'" << endl;
85 return -1;
86 }
87
88 if (fRunNumber!=-1 && fRunNumber!=run)
89 {
90 *fLog << err << "ERROR - Requested run #" << fRunNumber << " doesn't ";
91 *fLog << "match, found run #" << run << endl;
92 return -1;
93 }
94
95 return run;
96}
97
98Int_t MReportFileReadCC::GetVersion(const TString &str) const
99{
100 if (str(TRegexp("^Arehucas Version Number [0-9]+-[0-9]$")).IsNull())
101 {
102 *fLog << err << "ERROR - Version '^Arehucas Version Number [0-9]+-[0-9]$' ";
103 *fLog << "not found in second line." << endl;
104 return -1;
105 }
106
107 TString num = str(TRegexp("[0-9]+-[0-9]"));
108 num.Prepend("20");
109 num.ReplaceAll("-", "");
110
111 return atoi(num.Data());
112}
113
114Int_t MReportFileReadCC::GetTelescope(const TString &str) const
115{
116 if (str(TRegexp("^Telescope M[0-9]$")).IsNull())
117 {
118 *fLog << err << "ERROR - '^Telescope M[0-9]$' not found in third line." << endl;
119 return -1;
120 }
121
122 const Int_t num = atoi(str.Data()+11);
123
124 if (fTelescope != 1 && fTelescope !=2)
125 {
126 *fLog << err << "ERROR - Telsope number M" << num << " in third line unknown." << endl;
127 return -1;
128 }
129
130 if (fTelescope!=-1 && fTelescope!=num)
131 {
132 *fLog << err << "ERROR - Requested telescope M" << fTelescope << " doesn't ";
133 *fLog << "match, found M" << num << endl;
134 return -1;
135 }
136
137 return num;
138}
139
140Int_t MReportFileReadCC::GetFileNumber(const TString &str) const
141{
142 if (str(TRegexp("^Subrun [0-9]+$")).IsNull())
143 {
144 *fLog << err << "ERROR - '^Subrun [0-9]+$' not found in fourth line." << endl;
145 return -1;
146 }
147
148 const Int_t num = atoi(str.Data()+7);
149
150 if (fFileNumber!=-1 && fFileNumber!=num)
151 {
152 *fLog << err << "ERROR - Requested file number (subrun) " << fFileNumber << " doesn't ";
153 *fLog << "match, found " << num << endl;
154 return -1;
155 }
156
157 return num;
158}
159
160// --------------------------------------------------------------------------
161//
162// Check whether the file header corresponds to a central control file
163// header and check for the existance of a correct version number.
164// The version number may later be used to be able to read different
165// file versions
166//
167Int_t MReportFileReadCC::CheckFileHeader()
168{
169 TString str;
170 str.ReadLine(*fIn); // Read to EOF or newline
171 if (!*fIn)
172 {
173 *fLog << "ERROR - Unexpected end of file (file empty)" << endl;
174 return -1;
175 }
176
177 const Int_t run = GetRunNumber(str);
178 if (run<0)
179 return -1;
180
181 fRunNumber = run;
182
183 // -----------------------------------------------------------
184
185 str.ReadLine(*fIn); // Read to EOF or newline
186 if (!*fIn)
187 {
188 *fLog << "ERROR - Unexpected end of file after line 1." << endl;
189 return -1;
190 }
191
192 const Int_t ver = GetVersion(str);
193 if (ver<0)
194 return -1;
195
196 *fLog << all << "Report File version: <" << ver << ">" << endl;
197 SetVersion(ver);
198
199 // -----------------------------------------------------------
200
201 fTelescope = 1;
202
203 if (ver<200805190)
204 return 3;
205
206 str.ReadLine(*fIn); // Read to EOF or newline
207 if (!*fIn)
208 {
209 *fLog << "ERROR - Unexpected end of file after line 2." << endl;
210 return -1;
211 }
212
213 const Int_t tel = GetTelescope(str);
214 if (tel<0)
215 return -1;
216
217 fTelescope = tel;
218
219 // -----------------------------------------------------------
220
221 if (fRunNumber==0)
222 return kTRUE;
223
224 str.ReadLine(*fIn); // Read to EOF or newline
225 if (!*fIn)
226 {
227 *fLog << "ERROR - Unexpected end of file after line 3." << endl;
228 return -1;
229 }
230
231 const Int_t num = GetFileNumber(str);
232 if (num<0)
233 return -1;
234
235 fFileNumber = num;
236
237 // -----------------------------------------------------------
238
239 return 4;
240}
Note: See TracBrowser for help on using the repository browser.