source: trunk/MagicSoft/Mars/mbase/MClone.cc@ 3105

Last change on this file since 3105 was 2206, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.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 07/2001 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26// //
27// MClone //
28// //
29// This task clones a given paramter container. You can either specify //
30// the name of the container which should be cloned or a pointer to the //
31// container. If you specify a name the preprocessing tries to find the //
32// corresponding container in the parameter list. //
33// Cloning in this context means duplicating the object in memory. This //
34// may be used if you change an object in the eventloop (eg. the image //
35// cleaning is changing the image) and you want to compare both 'version' //
36// of this object afterwards. //
37// The cloned object can be accessed by using MClone::GetClone. //
38// To clone the container more than once use several instances of MClone. //
39// The object does only exist until a new object is cloned. It is deleted //
40// in the destructor. //
41// //
42// To use MClone you must make sure, that TObject::Clone is correctly //
43// working for this class (maybe you have to overload it) //
44// //
45// Input Containers: //
46// MParContainer //
47// //
48// Output Containers: //
49// -/- //
50// //
51//////////////////////////////////////////////////////////////////////////////
52#include "MClone.h"
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57#include "MParList.h"
58
59ClassImp(MClone);
60
61using namespace std;
62
63// --------------------------------------------------------------------------
64//
65// Initializes name and title of the object. It is called by all
66// constructors.
67//
68void MClone::Init(const char *name, const char *title)
69{
70 fName = name ? name : "MClone";
71 fTitle = title ? title : "Task to clone a parameter container for later usage";
72
73 fClone = NULL;
74 fObject = NULL;
75}
76
77// --------------------------------------------------------------------------
78//
79// Constructor. Remembers the name to search for in the parameter list.
80//
81MClone::MClone(const char *obj, const char *name, const char *title)
82{
83 Init(name, title);
84
85 fObjName = obj;
86}
87
88// --------------------------------------------------------------------------
89//
90// Constructor. Remember the pointer of the object which has to be cloned.
91//
92MClone::MClone(const TObject *obj, const char *name, const char *title)
93{
94 Init(name, title);
95
96 fObject = obj;
97 fObjName = obj->GetName();
98}
99
100// --------------------------------------------------------------------------
101//
102// Destructor. Deletes the cloned object.
103//
104MClone::~MClone()
105{
106 Clear();
107}
108
109// --------------------------------------------------------------------------
110//
111// Checks the parameter list for the existance of the parameter container. If
112// the name of it was given in the constructor.
113//
114Int_t MClone::PreProcess(MParList *pList)
115{
116 //
117 // The pointer is already given by the user.
118 //
119 if (fObject)
120 return kTRUE;
121
122 //
123 // Try to find the parameter container with the given name in the list
124 //
125 fObject = pList->FindObject(fObjName);
126 if (fObject)
127 return kTRUE;
128
129 //
130 // If it couldn't get found stop Eventloop
131 //
132 *fLog << err << dbginf << fObjName << " not found... aborting." << endl;
133 return kFALSE;
134}
135
136// --------------------------------------------------------------------------
137//
138// Delete the cloned object if one is existing
139//
140void MClone::Clear(Option_t *)
141{
142 //
143 // Check if an object has been initialized
144 //
145 if (!fClone)
146 return;
147
148 //
149 // Delete it and set the pointer to NULL for the sanity check (above)
150 //
151 delete fClone;
152 fClone = NULL;
153}
154
155// --------------------------------------------------------------------------
156//
157// Deletes an existing clone and clones the object (parameter container)
158// again.
159//
160Int_t MClone::Process()
161{
162 //
163 // Delete an existing clone
164 //
165 Clear();
166
167 //
168 // Clone the given parameter container
169 //
170 fClone = fObject->Clone();
171
172 return kTRUE;
173}
174
Note: See TracBrowser for help on using the repository browser.