source: trunk/MagicSoft/Mars/mbase/MParContainer.cc@ 1149

Last change on this file since 1149 was 1080, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MParContainer //
28// //
29// The MParContainer class is the base class for all MARS parameter //
30// containers. At the moment it is almost the same than ROOT's TNamed. //
31// A TNamed contains the essential elements (name, title) //
32// to identify a derived object in lists like our MParList or MTaskList. //
33// The main difference is that the name and title isn't stored and read //
34// to and from root files ("//!") //
35// //
36//////////////////////////////////////////////////////////////////////////////
37#include "MParContainer.h"
38
39#include <TClass.h> // IsA
40#include <TROOT.h> // TROOT::Identlevel
41#include <TVirtualPad.h> // gPad
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46ClassImp(MParContainer);
47
48// --------------------------------------------------------------------------
49//
50// MParContainer copy ctor
51//
52MParContainer::MParContainer(const MParContainer &named)
53{
54 fName = named.fName;
55 fTitle = named.fTitle;
56
57 fLog = named.fLog;
58
59 fReadyToSave = named.fReadyToSave;
60}
61
62// --------------------------------------------------------------------------
63//
64// MParContainer assignment operator.
65//
66MParContainer& MParContainer::operator=(const MParContainer& rhs)
67{
68 if (this == &rhs)
69 return *this;
70
71 TObject::operator=(rhs);
72
73 fName = rhs.fName;
74 fTitle = rhs.fTitle;
75
76 fLog = rhs.fLog;
77 fReadyToSave = rhs.fReadyToSave;
78
79 return *this;
80}
81
82// --------------------------------------------------------------------------
83//
84// Make a clone of an object using the Streamer facility.
85// If newname is specified, this will be the name of the new object
86//
87TObject *MParContainer::Clone(const char *newname) const
88{
89
90 MParContainer *named = (MParContainer*)TObject::Clone();
91 if (newname && strlen(newname)) named->SetName(newname);
92 return named;
93}
94
95// --------------------------------------------------------------------------
96//
97// Compare two MParContainer objects. Returns 0 when equal, -1 when this is
98// smaller and +1 when bigger (like strcmp).
99//
100Int_t MParContainer::Compare(const TObject *obj) const
101{
102 if (this == obj) return 0;
103 return fName.CompareTo(obj->GetName());
104}
105
106// --------------------------------------------------------------------------
107//
108// Copy this to obj.
109//
110void MParContainer::Copy(TObject &obj)
111{
112 MParContainer &cont = (MParContainer&)obj;
113
114 TObject::Copy(obj);
115
116 cont.fName = fName;
117 cont.fTitle = fTitle;
118
119 cont.fLog = fLog;
120 cont.fReadyToSave = fReadyToSave;
121}
122
123// --------------------------------------------------------------------------
124//
125// Encode MParContainer into output buffer.
126//
127void MParContainer::FillBuffer(char *&buffer)
128{
129 fName.FillBuffer(buffer);
130 fTitle.FillBuffer(buffer);
131}
132
133// --------------------------------------------------------------------------
134//
135// List MParContainer name and title.
136//
137void MParContainer::ls(Option_t *) const
138{
139 TROOT::IndentLevel();
140 *fLog << all << GetDescriptor() << " " << GetTitle() << ": kCanDelete=";
141 *fLog << Int_t(TestBit(kCanDelete)) << endl;
142}
143
144// --------------------------------------------------------------------------
145//
146// Print MParContainer name and title.
147//
148void MParContainer::Print(Option_t *) const
149{
150 *fLog << all << GetDescriptor() << " " << GetTitle() << endl;
151}
152
153// --------------------------------------------------------------------------
154//
155// Change (i.e. set) the name of the MParContainer.
156// WARNING !!
157// If the object is a member of a THashTable, THashList container
158// The HashTable must be Rehashed after SetName
159// For example the list of objects in the current directory is a THashList
160//
161void MParContainer::SetName(const char *name)
162{
163 fName = name;
164 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
165}
166
167// --------------------------------------------------------------------------
168//
169// Change (i.e. set) all the MParContainer parameters (name and title).
170// See also WARNING in SetName
171//
172void MParContainer::SetObject(const char *name, const char *title)
173{
174 fName = name;
175 fTitle = title;
176 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
177}
178
179// --------------------------------------------------------------------------
180//
181// Change (i.e. set) the title of the MParContainer.
182//
183void MParContainer::SetTitle(const char *title)
184{
185 fTitle = title;
186 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
187}
188
189// --------------------------------------------------------------------------
190//
191// Return size of the MParContainer part of the TObject.
192//
193Int_t MParContainer::Sizeof() const
194{
195 Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
196 return nbytes;
197}
198
199// --------------------------------------------------------------------------
200//
201// If you want to use Ascii-Input/-Output (eg. MWriteAsciiFile) of a
202// container, overload this function.
203//
204void MParContainer::AsciiRead(ifstream &fin)
205{
206 *fLog << warn << "To use the the ascii input of " << GetName();
207 *fLog << " you have to overload " << ClassName() << "::AsciiRead." << endl;
208}
209
210// --------------------------------------------------------------------------
211//
212// If you want to use Ascii-Input/-Output (eg. MWriteAsciiFile) of a
213// container, overload this function.
214//
215void MParContainer::AsciiWrite(ofstream &fout) const
216{
217 *fLog << warn << "To use the the ascii output of " << GetName();
218 *fLog << " you have to overload " << ClassName() << "::AsciiWrite." << endl;
219}
Note: See TracBrowser for help on using the repository browser.