source: branches/MarsFixTimeOffsetBranch/mbase/MClone.cc@ 18001

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