source: trunk/MagicSoft/Mars/mreport/MReportFileReadCC.cc@ 4651

Last change on this file since 4651 was 4587, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.2 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-2004
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
47#include <TRegexp.h>
48
49#include "MLog.h"
50#include "MLogManip.h"
51
52ClassImp(MReportFileReadCC);
53
54using namespace std;
55
56// --------------------------------------------------------------------------
57//
58// Default constructor. It tries to open the given file and creates a
59// THashTable which allows faster access to the MReport* objects.
60//
61MReportFileReadCC::MReportFileReadCC(const char *fname, const char *name, const char *title)
62 : MReportFileRead(fname, name, title), fRunNumber(-1)
63{
64 fName = name ? name : "MReportFileReadCC";
65 fTitle = title ? title : "Read task to read Central Control report files";
66}
67
68// --------------------------------------------------------------------------
69//
70// Check whether the file header corresponds to a central control file
71// header and check for the existance of a correct version number.
72// The version number may later be used to be able to read different
73// file versions
74//
75Int_t MReportFileReadCC::CheckFileHeader()
76{
77 Int_t line = 0;
78
79 TString str;
80 str.ReadLine(*fIn); // Read to EOF or newline
81 if (!*fIn)
82 return line;
83
84 line++;
85
86 Int_t run = -1;
87
88 // whole night report file
89 if (str==TString("[CC Report File]"))
90 run = 0;
91
92 // report file matching a single run
93 if (!str(TRegexp("^[CC Run [0-9]+ Control File]$")).IsNull())
94 run = atoi(str(TRegexp(" [0-9]+")).Data());
95
96 if (run<0)
97 {
98 *fLog << err << "ERROR - First line doesn't match '[CC Report File]' ";
99 *fLog << "nor '^[CC Run [0-9]+ Control File]$'" << endl;
100 return line;
101 }
102
103 if (fRunNumber!=-1 && fRunNumber!=run)
104 {
105 *fLog << err << "ERROR - Requested run #" << fRunNumber << " doesn't ";
106 *fLog << "match found run #" << run << endl;
107 return line;
108 }
109
110 str.ReadLine(*fIn); // Read to EOF or newline
111 if (!*fIn)
112 return line;
113
114 if (str(TRegexp("^Arehucas Version Number [0-9]+-[0-9]$")).IsNull())
115 {
116 *fLog << err << "ERROR - Version '^Arehucas Version Number [0-9]+-[0-9]$' ";
117 *fLog << "not found in second line." << endl;
118 return line;
119 }
120 line++;
121
122 str = str(TRegexp("[0-9]+-[0-9]"));
123 str.Prepend("20");
124 str.ReplaceAll("-", "");
125
126 const Int_t ver = atoi(str.Data());
127
128 *fLog << dbg << "Report File version: <" << ver << ">" << endl;
129
130 SetVersion(ver);
131
132 return line;
133}
Note: See TracBrowser for help on using the repository browser.