source: trunk/Mars/mbase/MParameters.cc@ 20106

Last change on this file since 20106 was 18568, checked in by tbretz, 8 years ago
Implemented function SetupFits to be able to read from a fits file.
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 03/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MParameterD, MParameterDerr, MParameterI
28//
29// Storage Container for doubles and ints
30//
31// This classes can be used for intermidiate variables which we don't want
32// to have in a special container.
33//
34//
35// MParameterDerr - Version 2:
36// - inherits from MParemeterD now, where fVal comes from
37//
38/////////////////////////////////////////////////////////////////////////////
39#include "MParameters.h"
40
41#include <fstream>
42
43#include "fits.h"
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48ClassImp(MParameterD);
49ClassImp(MParameterI);
50ClassImp(MParameterDerr);
51//ClassImp(MParameter);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Default constructor.
58//
59MParameterD::MParameterD(const char *name, const char *title)
60{
61 fName = name ? name : "MParameterD";
62 fTitle = title ? title : "Storgare container for general parameters (double)";
63}
64
65// --------------------------------------------------------------------------
66//
67// Default constructor.
68//
69MParameterDerr::MParameterDerr(const char *name, const char *title)
70{
71 fName = name ? name : "MParameterDerr";
72 fTitle = title ? title : "Storgare container for general parameters (double) and its error";
73}
74
75// --------------------------------------------------------------------------
76//
77// Default constructor.
78//
79MParameterI::MParameterI(const char *name, const char *title)
80{
81 fName = name ? name : "MParameterI";
82 fTitle = title ? title : "Storgare container for general parameters (integer)";
83}
84
85// --------------------------------------------------------------------------
86//
87// Print value of container.
88//
89void MParameterD::Print(Option_t *) const
90{
91 *fLog << all << GetDescriptor() << ": Val=" << fVal << endl;
92}
93
94// --------------------------------------------------------------------------
95//
96// Print value and error of container.
97//
98void MParameterDerr::Print(Option_t *) const
99{
100 *fLog << all << GetDescriptor() << ": Val=" << GetVal() << " Err=" << fErr << endl;
101}
102
103// --------------------------------------------------------------------------
104//
105// Print value of container.
106//
107void MParameterI::Print(Option_t *) const
108{
109 *fLog << all << GetDescriptor() << ": Val=" << fVal << endl;
110}
111
112// --------------------------------------------------------------------------
113//
114// MParameterD.Val: 55.7
115//
116Int_t MParameterD::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
117{
118 Bool_t rc = kFALSE;
119 if (IsEnvDefined(env, prefix, "Val", print))
120 {
121 rc = kTRUE;
122 fVal = GetEnvValue(env, prefix, "Val", fVal);
123 }
124 return rc;
125}
126
127// --------------------------------------------------------------------------
128//
129// MParameterD.Val: 55.7
130// MParameterD.Err: 12.3
131//
132Int_t MParameterDerr::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
133{
134 Int_t rc = MParameterD::ReadEnv(env, prefix, print);
135 if (rc==kERROR)
136 return kERROR;
137
138 if (IsEnvDefined(env, prefix, "Err", print))
139 {
140 rc = kTRUE;
141 fErr = GetEnvValue(env, prefix, "Err", fErr);
142 }
143 return rc;
144}
145
146// --------------------------------------------------------------------------
147//
148// MParameterD.Val: 42
149//
150Int_t MParameterI::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
151{
152 Bool_t rc = kFALSE;
153 if (IsEnvDefined(env, prefix, "Val", print))
154 {
155 rc = kTRUE;
156 fVal = GetEnvValue(env, prefix, "Val", fVal);
157 }
158 return rc;
159}
160
161Bool_t MParameterD::SetupFits(fits &fin)
162{
163 return fin.SetRefAddress(Form("%s.fVal", fName.Data()), fVal);
164}
165
166Bool_t MParameterDerr::SetupFits(fits &fin)
167{
168 if (!fin.SetRefAddress(Form("%s.fErr", fName.Data()), fErr))
169 return kFALSE;
170 return MParameterD::SetupFits(fin);
171}
172
173Bool_t MParameterI::SetupFits(fits &fin)
174{
175 return fin.SetRefAddress(Form("%s.fVal", fName.Data()), fVal);
176}
Note: See TracBrowser for help on using the repository browser.