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

Last change on this file since 2626 was 2604, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.5 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//
55Bool_t MReport::InterpreteHeader(TString &str)
56{
57 int len, state;
58 int yea, mon, day, hor, min, sec, ms;
59
60 int n = sscanf(str.Data(),
61 fHasReportTime ?
62 " %d %d %d %d %d %d %d %d "
63 "%*d %*d %*d %*d %*d %*d %*d %*d %n" :
64 " %d %*d %*d %*d %d %d %d %d ",
65 &state, &yea, &mon, &day, &hor, &min, &sec, &ms, &len);
66 if (n!=8)
67 {
68 *fLog << err << "ERROR - Cannot interprete Body of " << fIdentifier << endl;
69 return kFALSE;
70 }
71
72 fState=state;
73 if (fTime)
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 return kTRUE;
84}
85
86// --------------------------------------------------------------------------
87//
88// Report Body must be overwritten. It will get the line idetified to belong
89// to fIdentifier without the leading status and time infomration as an
90// argument.
91//
92Bool_t MReport::InterpreteBody(TString &str)
93{
94 *fLog << warn << "No interpreter existing for: " << fIdentifier << endl;
95 return kTRUE;
96}
97
98// --------------------------------------------------------------------------
99//
100// Interprets Header and Body of a report file line. Calls SetReadyToSave()
101// in case the interpretation was successfull. And fTime->SetReadyToSave()
102// when a corresponding time container exists.
103//
104Bool_t MReport::Interprete(TString &str)
105{
106 if (!InterpreteHeader(str))
107 return kFALSE;
108
109 if (!InterpreteBody(str))
110 return kFALSE;
111
112 SetReadyToSave();
113 if (fTime)
114 fTime->SetReadyToSave();
115
116 return kTRUE;
117}
118
119// --------------------------------------------------------------------------
120//
121// Check for the existance of a corresponding MTime in the given parameter
122// list. If it is not found a new one will be created. The name of the
123// MTime object is created by taking the ClassName() of the derived MReport
124// class and stripping the leading MReport
125//
126Bool_t MReport::SetupReading(MParList &plist)
127{
128 fTime = NULL;
129
130 TString id(ClassName());
131 if (!id.BeginsWith("MReport"))
132 {
133 *fLog << warn << " WARNING - Class name '" << id << "' ";
134 *fLog << " doesn't begin with 'MReport'... no MTime assigned." << endl;
135 return kFALSE;
136 }
137
138 id.Remove(0, 7);
139 if (id.IsNull())
140 {
141 *fLog << warn << " WARNING - No postfix existing... no MTime assigned." << endl;
142 return kFALSE;
143 }
144
145 id.Prepend("MTime");
146
147 fTime = (MTime*)plist.FindCreateObj("MTime", id);
148 if (!fTime)
149 return kFALSE;
150
151 return kTRUE;
152}
Note: See TracBrowser for help on using the repository browser.