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 | // Input Containers: //
|
---|
43 | // MParContainer //
|
---|
44 | // //
|
---|
45 | // Output Containers: //
|
---|
46 | // -/- //
|
---|
47 | // //
|
---|
48 | //////////////////////////////////////////////////////////////////////////////
|
---|
49 | #include "MClone.h"
|
---|
50 |
|
---|
51 | #include "MLog.h"
|
---|
52 | #include "MLogManip.h"
|
---|
53 |
|
---|
54 | #include "MParList.h"
|
---|
55 |
|
---|
56 | ClassImp(MClone);
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // Initializes name and title of the object. It is called by all
|
---|
61 | // constructors.
|
---|
62 | //
|
---|
63 | void MClone::Init(const char *name, const char *title)
|
---|
64 | {
|
---|
65 | *fName = name ? name : "MClone";
|
---|
66 | *fTitle = title ? title : "Task to clone a parameter container for later usage";
|
---|
67 |
|
---|
68 | fClone = NULL;
|
---|
69 | fParContainer = NULL;
|
---|
70 | }
|
---|
71 |
|
---|
72 | // --------------------------------------------------------------------------
|
---|
73 | //
|
---|
74 | // Constructor. Remembers the name to search for in the parameter list.
|
---|
75 | //
|
---|
76 | MClone::MClone(const char *par, const char *name, const char *title)
|
---|
77 | {
|
---|
78 | Init(name, title);
|
---|
79 |
|
---|
80 | fParContainerName = par;
|
---|
81 | }
|
---|
82 |
|
---|
83 | // --------------------------------------------------------------------------
|
---|
84 | //
|
---|
85 | // Constructor. Remember the pointer of the object which has to be cloned.
|
---|
86 | //
|
---|
87 | MClone::MClone(const MParContainer *par, const char *name, const char *title)
|
---|
88 | {
|
---|
89 | Init(name, title);
|
---|
90 |
|
---|
91 | fParContainer = par;
|
---|
92 | }
|
---|
93 |
|
---|
94 | // --------------------------------------------------------------------------
|
---|
95 | //
|
---|
96 | // Destructor. Deletes the cloned object.
|
---|
97 | //
|
---|
98 | MClone::~MClone()
|
---|
99 | {
|
---|
100 | Clear();
|
---|
101 | }
|
---|
102 |
|
---|
103 | // --------------------------------------------------------------------------
|
---|
104 | //
|
---|
105 | // Checks the parameter list for the existance of the parameter container. If
|
---|
106 | // the name of it was given in the constructor.
|
---|
107 | //
|
---|
108 | Bool_t MClone::PreProcess(MParList *pList)
|
---|
109 | {
|
---|
110 | //
|
---|
111 | // The pointer is already given by the user.
|
---|
112 | //
|
---|
113 | if (fParContainer)
|
---|
114 | return kTRUE;
|
---|
115 |
|
---|
116 | //
|
---|
117 | // Try to find the parameter container with the given name in the list
|
---|
118 | //
|
---|
119 | fParContainer = (MParContainer*)pList->FindObject(fParContainerName);
|
---|
120 | if (fParContainer)
|
---|
121 | return kTRUE;
|
---|
122 |
|
---|
123 | //
|
---|
124 | // If it couldn't get found stop Eventloop
|
---|
125 | //
|
---|
126 | *fLog << dbginf << fParContainerName << " not found... aborting." << endl;
|
---|
127 | return kFALSE;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // --------------------------------------------------------------------------
|
---|
131 | //
|
---|
132 | // Delete the cloned object if one is existing
|
---|
133 | //
|
---|
134 | void MClone::Clear(Option_t *)
|
---|
135 | {
|
---|
136 | //
|
---|
137 | // Check if an object has been initialized
|
---|
138 | //
|
---|
139 | if (!fClone)
|
---|
140 | return;
|
---|
141 |
|
---|
142 | //
|
---|
143 | // Delete it and set the pointer to NULL for the sanity check (above)
|
---|
144 | //
|
---|
145 | delete fClone;
|
---|
146 | fClone = NULL;
|
---|
147 | }
|
---|
148 |
|
---|
149 | // --------------------------------------------------------------------------
|
---|
150 | //
|
---|
151 | // Deletes an existing clone and clones the object (parameter container)
|
---|
152 | // again.
|
---|
153 | //
|
---|
154 | Bool_t MClone::Process()
|
---|
155 | {
|
---|
156 | //
|
---|
157 | // Delete an existing clone
|
---|
158 | //
|
---|
159 | Clear();
|
---|
160 |
|
---|
161 | //
|
---|
162 | // Clone the given parameter container
|
---|
163 | //
|
---|
164 | fClone = fParContainer->Clone();
|
---|
165 |
|
---|
166 | return kTRUE;
|
---|
167 | }
|
---|
168 |
|
---|