source: tags/Mars-V0.5/mbase/MParContainer.cc

Last change on this file was 1030, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.3 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 (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
45ClassImp(MParContainer);
46
47// --------------------------------------------------------------------------
48//
49// MParContainer copy ctor
50//
51MParContainer::MParContainer(const MParContainer &named)
52{
53 fName = named.fName;
54 fTitle = named.fTitle;
55
56 fLog = named.fLog;
57
58 fReadyToSave = named.fReadyToSave;
59}
60
61// --------------------------------------------------------------------------
62//
63// MParContainer assignment operator.
64//
65MParContainer& MParContainer::operator=(const MParContainer& rhs)
66{
67 if (this == &rhs)
68 return *this;
69
70 TObject::operator=(rhs);
71
72 fName = rhs.fName;
73 fTitle = rhs.fTitle;
74
75 fLog = rhs.fLog;
76 fReadyToSave = rhs.fReadyToSave;
77
78 return *this;
79}
80
81// --------------------------------------------------------------------------
82//
83// Make a clone of an object using the Streamer facility.
84// If newname is specified, this will be the name of the new object
85//
86TObject *MParContainer::Clone(const char *newname) const
87{
88
89 MParContainer *named = (MParContainer*)TObject::Clone();
90 if (newname && strlen(newname)) named->SetName(newname);
91 return named;
92}
93
94// --------------------------------------------------------------------------
95//
96// Compare two MParContainer objects. Returns 0 when equal, -1 when this is
97// smaller and +1 when bigger (like strcmp).
98//
99Int_t MParContainer::Compare(const TObject *obj) const
100{
101 if (this == obj) return 0;
102 return fName.CompareTo(obj->GetName());
103}
104
105// --------------------------------------------------------------------------
106//
107// Copy this to obj.
108//
109void MParContainer::Copy(TObject &obj)
110{
111 MParContainer &cont = (MParContainer&)obj;
112
113 TObject::Copy(obj);
114
115 cont.fName = fName;
116 cont.fTitle = fTitle;
117
118 cont.fLog = fLog;
119 cont.fReadyToSave = fReadyToSave;
120}
121
122// --------------------------------------------------------------------------
123//
124// Encode MParContainer into output buffer.
125//
126void MParContainer::FillBuffer(char *&buffer)
127{
128 fName.FillBuffer(buffer);
129 fTitle.FillBuffer(buffer);
130}
131
132// --------------------------------------------------------------------------
133//
134// List MParContainer name and title.
135//
136void MParContainer::ls(Option_t *) const
137{
138 TROOT::IndentLevel();
139 *fLog <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : "
140 << Int_t(TestBit(kCanDelete)) << endl;
141}
142
143// --------------------------------------------------------------------------
144//
145// Print MParContainer name and title.
146//
147void MParContainer::Print(Option_t *) const
148{
149 *fLog <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << endl;
150}
151
152// --------------------------------------------------------------------------
153//
154// Change (i.e. set) the name of the MParContainer.
155// WARNING !!
156// If the object is a member of a THashTable, THashList container
157// The HashTable must be Rehashed after SetName
158// For example the list of objects in the current directory is a THashList
159//
160void MParContainer::SetName(const char *name)
161{
162 fName = name;
163 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
164}
165
166// --------------------------------------------------------------------------
167//
168// Change (i.e. set) all the MParContainer parameters (name and title).
169// See also WARNING in SetName
170//
171void MParContainer::SetObject(const char *name, const char *title)
172{
173 fName = name;
174 fTitle = title;
175 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
176}
177
178// --------------------------------------------------------------------------
179//
180// Change (i.e. set) the title of the MParContainer.
181//
182void MParContainer::SetTitle(const char *title)
183{
184 fTitle = title;
185 if (gPad && TestBit(kMustCleanup)) gPad->Modified();
186}
187
188// --------------------------------------------------------------------------
189//
190// Return size of the MParContainer part of the TObject.
191//
192Int_t MParContainer::Sizeof() const
193{
194 Int_t nbytes = fName.Sizeof() + fTitle.Sizeof();
195 return nbytes;
196}
197
198void MParContainer::AsciiRead(ifstream &fin)
199{
200 *fLog << "To use the the ascii input of " << GetName();
201 *fLog << " you have to overload " << GetName() << "::AsciiRead." << endl;
202}
203
204void MParContainer::AsciiWrite(ofstream &fout) const
205{
206 *fLog << "To use the the ascii output of " << GetName();
207 *fLog << " you have to overload " << GetName() << "::AsciiWrite." << endl;
208}
Note: See TracBrowser for help on using the repository browser.