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

Last change on this file since 6724 was 4575, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.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-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 %02d:%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//
93Int_t MReport::InterpreteBody(TString &str, Int_t ver)
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, Int_t ver)
108{
109 if (!InterpreteHeader(str))
110 return kFALSE;
111
112 // return -1: This is the special case: out of time limit
113 if (start && *fTime<start)
114 return -1;
115 if (stop && *fTime>stop)
116 return -1;
117
118 const Int_t rc = InterpreteBody(str, ver);
119 if (rc != kTRUE)
120 return rc;
121
122 SetReadyToSave();
123 fTime->SetReadyToSave();
124
125 return kTRUE;
126}
127
128// --------------------------------------------------------------------------
129//
130// Check for the existance of a corresponding MTime in the given parameter
131// list. If it is not found a new one will be created. The name of the
132// MTime object is created by taking the ClassName() of the derived MReport
133// class and stripping the leading MReport
134//
135Bool_t MReport::SetupReading(MParList &plist)
136{
137 fTime = NULL;
138
139 TString id(ClassName());
140 if (!id.BeginsWith("MReport"))
141 {
142 *fLog << warn << " WARNING - Class name '" << id << "' ";
143 *fLog << " doesn't begin with 'MReport'... no MTime assigned." << endl;
144 return kFALSE;
145 }
146
147 id.Remove(0, 7);
148 if (id.IsNull())
149 {
150 *fLog << warn << " WARNING - No postfix existing... no MTime assigned." << endl;
151 return kFALSE;
152 }
153
154 id.Prepend("MTime");
155
156 fTime = (MTime*)plist.FindCreateObj("MTime", id);
157 if (!fTime)
158 return kFALSE;
159
160 return kTRUE;
161}
Note: See TracBrowser for help on using the repository browser.