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

Last change on this file since 1003 was 1003, 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 (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}
96
97// --------------------------------------------------------------------------
98//
99// Destructor. Deletes the cloned object.
100//
101MClone::~MClone()
102{
103 Clear();
104}
105
106// --------------------------------------------------------------------------
107//
108// Checks the parameter list for the existance of the parameter container. If
109// the name of it was given in the constructor.
110//
111Bool_t MClone::PreProcess(MParList *pList)
112{
113 //
114 // The pointer is already given by the user.
115 //
116 if (fObject)
117 return kTRUE;
118
119 //
120 // Try to find the parameter container with the given name in the list
121 //
122 fObject = pList->FindObject(fObjName);
123 if (fObject)
124 return kTRUE;
125
126 //
127 // If it couldn't get found stop Eventloop
128 //
129 *fLog << dbginf << fObjName << " not found... aborting." << endl;
130 return kFALSE;
131}
132
133// --------------------------------------------------------------------------
134//
135// Delete the cloned object if one is existing
136//
137void MClone::Clear(Option_t *)
138{
139 //
140 // Check if an object has been initialized
141 //
142 if (!fClone)
143 return;
144
145 //
146 // Delete it and set the pointer to NULL for the sanity check (above)
147 //
148 delete fClone;
149 fClone = NULL;
150}
151
152// --------------------------------------------------------------------------
153//
154// Deletes an existing clone and clones the object (parameter container)
155// again.
156//
157Bool_t MClone::Process()
158{
159 //
160 // Delete an existing clone
161 //
162 Clear();
163
164 //
165 // Clone the given parameter container
166 //
167 fClone = fObject->Clone();
168
169 return kTRUE;
170}
171
Note: See TracBrowser for help on using the repository browser.