source: tags/Mars-V0.7/mbase/MClone.cc

Last change on this file was 1080, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.6 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
61// --------------------------------------------------------------------------
62//
63// Initializes name and title of the object. It is called by all
64// constructors.
65//
66void MClone::Init(const char *name, const char *title)
67{
68 fName = name ? name : "MClone";
69 fTitle = title ? title : "Task to clone a parameter container for later usage";
70
71 fClone = NULL;
72 fObject = NULL;
73}
74
75// --------------------------------------------------------------------------
76//
77// Constructor. Remembers the name to search for in the parameter list.
78//
79MClone::MClone(const char *obj, const char *name, const char *title)
80{
81 Init(name, title);
82
83 fObjName = obj;
84}
85
86// --------------------------------------------------------------------------
87//
88// Constructor. Remember the pointer of the object which has to be cloned.
89//
90MClone::MClone(const TObject *obj, const char *name, const char *title)
91{
92 Init(name, title);
93
94 fObject = obj;
95 fObjName = obj->GetName();
96}
97
98// --------------------------------------------------------------------------
99//
100// Destructor. Deletes the cloned object.
101//
102MClone::~MClone()
103{
104 Clear();
105}
106
107// --------------------------------------------------------------------------
108//
109// Checks the parameter list for the existance of the parameter container. If
110// the name of it was given in the constructor.
111//
112Bool_t MClone::PreProcess(MParList *pList)
113{
114 //
115 // The pointer is already given by the user.
116 //
117 if (fObject)
118 return kTRUE;
119
120 //
121 // Try to find the parameter container with the given name in the list
122 //
123 fObject = pList->FindObject(fObjName);
124 if (fObject)
125 return kTRUE;
126
127 //
128 // If it couldn't get found stop Eventloop
129 //
130 *fLog << err << dbginf << fObjName << " not found... aborting." << endl;
131 return kFALSE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Delete the cloned object if one is existing
137//
138void MClone::Clear(Option_t *)
139{
140 //
141 // Check if an object has been initialized
142 //
143 if (!fClone)
144 return;
145
146 //
147 // Delete it and set the pointer to NULL for the sanity check (above)
148 //
149 delete fClone;
150 fClone = NULL;
151}
152
153// --------------------------------------------------------------------------
154//
155// Deletes an existing clone and clones the object (parameter container)
156// again.
157//
158Bool_t MClone::Process()
159{
160 //
161 // Delete an existing clone
162 //
163 Clear();
164
165 //
166 // Clone the given parameter container
167 //
168 fClone = fObject->Clone();
169
170 return kTRUE;
171}
172
Note: See TracBrowser for help on using the repository browser.