source: trunk/MagicSoft/Mars/mreport/MReport.cc@ 2781

Last change on this file since 2781 was 2678, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.7 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-2003
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MReport
28//
29// This is a base class for all reports comming from subsystems stored in
30// a report file.
31//
32// Be carefull: The class name of all classes derived from this class
33// should start with 'MReport', see SetupReading
34//
35//////////////////////////////////////////////////////////////////////////////
36#include "MReport.h"
37
38#include "MLogManip.h"
39
40#include "MTime.h"
41#include "MParList.h"
42
43ClassImp(MReport);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Interpretes the beginning of a line which starts like:
50// status hour minute second millisec skip skip skip skip skip
51// The identifier is assumed to be removed.
52//
53// While skip are numbers which won't enter the analysis
54//
55// SetupReading must be called successfully before.
56//
57Bool_t MReport::InterpreteHeader(TString &str)
58{
59 int len, state;
60 int yea, mon, day, hor, min, sec, ms;
61
62 int n = sscanf(str.Data(),
63 fHasReportTime ?
64 " %d %d %d %d %d %d %d %d %*d %*d %*d %*d %*d %*d %*d %*d %n" :
65 " %d %d %d %d %d %d %d %d %n",
66 &state, &yea, &mon, &day, &hor, &min, &sec, &ms, &len);
67 if (n!=8)
68 {
69 *fLog << err << "ERROR - Cannot interprete Body of " << fIdentifier << " (n=" << n << ")" << endl;
70 return kFALSE;
71 }
72
73 fState=state;
74 if (!fTime->Set(yea, mon, day, hor, min, sec, ms))
75 {
76 *fLog << err << "ERROR - Event has invalid time: ";
77 *fLog << Form("%d.%d.%d %02s:%02d:%02d.%03d", day, mon, yea, hor, min, sec, ms);
78 *fLog << "... abort." << endl;
79 return kFALSE;
80 }
81
82 str.Remove(0, len);
83
84 return kTRUE;
85}
86
87// --------------------------------------------------------------------------
88//
89// Report Body must be overwritten. It will get the line idetified to belong
90// to fIdentifier without the leading status and time infomration as an
91// argument.
92//
93Bool_t MReport::InterpreteBody(TString &str)
94{
95 *fLog << warn << "No interpreter existing for: " << fIdentifier << endl;
96 return kTRUE;
97}
98
99// --------------------------------------------------------------------------
100//
101// Interprets Header and Body of a report file line. Calls SetReadyToSave()
102// in case the interpretation was successfull. And fTime->SetReadyToSave()
103// when a corresponding time container exists.
104//
105// SetupReading must be called successfully before.
106//
107Int_t MReport::Interprete(TString &str, const MTime &start, const MTime &stop)
108{
109 if (!InterpreteHeader(str))
110 return kFALSE;
111
112 if (start && *fTime<start)
113 return kCONTINUE;
114 if (stop && *fTime>stop)
115 return kCONTINUE;
116
117 if (!InterpreteBody(str))
118 return kFALSE;
119
120 SetReadyToSave();
121 fTime->SetReadyToSave();
122
123 return kTRUE;
124}
125
126// --------------------------------------------------------------------------
127//
128// Check for the existance of a corresponding MTime in the given parameter
129// list. If it is not found a new one will be created. The name of the
130// MTime object is created by taking the ClassName() of the derived MReport
131// class and stripping the leading MReport
132//
133Bool_t MReport::SetupReading(MParList &plist)
134{
135 fTime = NULL;
136
137 TString id(ClassName());
138 if (!id.BeginsWith("MReport"))
139 {
140 *fLog << warn << " WARNING - Class name '" << id << "' ";
141 *fLog << " doesn't begin with 'MReport'... no MTime assigned." << endl;
142 return kFALSE;
143 }
144
145 id.Remove(0, 7);
146 if (id.IsNull())
147 {
148 *fLog << warn << " WARNING - No postfix existing... no MTime assigned." << endl;
149 return kFALSE;
150 }
151
152 id.Prepend("MTime");
153
154 fTime = (MTime*)plist.FindCreateObj("MTime", id);
155 if (!fTime)
156 return kFALSE;
157
158 return kTRUE;
159}
Note: See TracBrowser for help on using the repository browser.