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

Last change on this file since 5773 was 4732, 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#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), fRunNumber(-1)
64{
65 fName = name ? name : "MReportFileReadCC";
66 fTitle = title ? title : "Read task to read Central Control report files";
67}
68
69// --------------------------------------------------------------------------
70//
71// Check whether the file header corresponds to a central control file
72// header and check for the existance of a correct version number.
73// The version number may later be used to be able to read different
74// file versions
75//
76Int_t MReportFileReadCC::CheckFileHeader()
77{
78 Int_t line = 0;
79
80 TString str;
81 str.ReadLine(*fIn); // Read to EOF or newline
82 if (!*fIn)
83 return line;
84
85 line++;
86
87 Int_t run = -1;
88
89 // whole night report file
90 if (str==TString("[CC Report File]"))
91 run = 0;
92
93 // report file matching a single run
94 if (!str(TRegexp("^[CC Run [0-9]+ Control File]$")).IsNull())
95 run = atoi(str(TRegexp(" [0-9]+")).Data());
96
97 if (run<0)
98 {
99 *fLog << err << "ERROR - First line doesn't match '[CC Report File]' ";
100 *fLog << "nor '^[CC Run [0-9]+ Control File]$'" << endl;
101 return line;
102 }
103
104 if (fRunNumber!=-1 && fRunNumber!=run)
105 {
106 *fLog << err << "ERROR - Requested run #" << fRunNumber << " doesn't ";
107 *fLog << "match found run #" << run << endl;
108 return line;
109 }
110
111 str.ReadLine(*fIn); // Read to EOF or newline
112 if (!*fIn)
113 return line;
114
115 if (str(TRegexp("^Arehucas Version Number [0-9]+-[0-9]$")).IsNull())
116 {
117 *fLog << err << "ERROR - Version '^Arehucas Version Number [0-9]+-[0-9]$' ";
118 *fLog << "not found in second line." << endl;
119 return line;
120 }
121 line++;
122
123 str = str(TRegexp("[0-9]+-[0-9]"));
124 str.Prepend("20");
125 str.ReplaceAll("-", "");
126
127 const Int_t ver = atoi(str.Data());
128
129 *fLog << dbg << "Report File version: <" << ver << ">" << endl;
130
131 SetVersion(ver);
132
133 return line;
134}
Note: See TracBrowser for help on using the repository browser.