KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVGeoStrucElement.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Tue May 7 09:22:02 2013
2 //Author: John Frankland,,,
3 
4 #include "KVGeoStrucElement.h"
5 #include "KVDetector.h"
6 #include "Riostream.h"
7 #include <TROOT.h>
8 using namespace std;
9 
11 
12 
13 
16 void KVGeoStrucElement::init()
17 {
18  // Default initialisations
19  fStructures.SetOwner();
20  fStructures.SetCleanup();
21  fDetectors.SetCleanup();
22  fParentStrucList.SetCleanup();
23 }
24 
25 
26 
28 
30 {
31  fParentStrucList.Add(e);
32 }
33 
34 
35 
37 
39 {
40  fParentStrucList.Remove(e);
41 }
42 
43 
44 
47 
49 {
50  // Default constructor
51  init();
52 }
53 
54 
55 
56 
59 
60 KVGeoStrucElement::KVGeoStrucElement(const Char_t* name, const Char_t* type) : KVBase(name, type)
61 {
62  // Create a geometry structure element with given name and type
63  init();
64 }
65 
66 
67 
70 
72 {
73  // Destructor
74  Clear();
75 }
76 
77 
78 
82 
84 {
85  // Remove detectors of given type from this structure (default: all detectors)
86  // If they belong to the structure, they will be deleted.
87 
88  TList dummy;
89  dummy.AddAll(&fDetectors);
90  TIter next(&dummy);
91  KVDetector* d;
92  while ((d = (KVDetector*)next())) {
93  if (!strcmp(type, d->GetType()) || !strcmp(type, "")) {
94  Remove(d);
95  if (fDetectors.IsOwner()) delete d;
96  }
97  }
98  // avoid spurious warnings from TList::Clear with ROOT6
99  dummy.Clear("nodelete");
100 }
101 
102 
103 
107 
109 {
110  // Remove daughter structures of given type from this structure (default: all detectors)
111  // If they belong to the structure, they will be deleted.
112 
113  TList dummy;
114  dummy.AddAll(&fStructures);
115  TIter next(&dummy);
117  while ((e = (KVGeoStrucElement*)next())) {
118  if (!strcmp(type, e->GetType()) || !strcmp(type, "")) {
119  Remove(e);
120  if (fStructures.IsOwner()) delete e;
121  }
122  }
123  // avoid spurious warnings from TList::Clear with ROOT6
124  dummy.Clear("nodelete");
125 }
126 
127 
128 
134 
136 {
137  // Add a detector or a daughter structure to this structure.
138  // Note that daughter structures are by defeault owned by their mother and will be
139  // deleted by her destructor. Call SetOwnsDaughters(kFALSE) to change.
140  // Detectors are not owned by default - call SetOwnsDetectors(kTRUE) to change.
141 
142  if (element->InheritsFrom(KVDetector::Class())) {
143  fDetectors.Add(element);
144  dynamic_cast<KVDetector*>(element)->AddParentStructure(this);
145  }
146  else if (element->InheritsFrom(KVGeoStrucElement::Class())) {
147  fStructures.Add(element);
148  dynamic_cast<KVGeoStrucElement*>(element)->AddParentStructure(this);
149  }
150  else {
151  Error("Add", "Cannot add elements of class %s", element->ClassName());
152  }
153 }
154 
155 
156 
160 
162 {
163  // Remove a detector or structure element from this structure
164  // User's responsibility to delete the detector or structure element.
165 
166  if (element->InheritsFrom(KVDetector::Class())) {
167  fDetectors.Remove(element);
168  dynamic_cast<KVDetector*>(element)->RemoveParentStructure(this);
169  }
170  else if (element->InheritsFrom(KVGeoStrucElement::Class())) {
171  fStructures.Remove(element);
172  dynamic_cast<KVGeoStrucElement*>(element)->RemoveParentStructure(this);
173  }
174  else {
175  Error("Add", "Cannot add elements of class %s", element->ClassName());
176  }
177 }
178 
179 
180 
183 
185 {
186  // Empty lists of detectors, daughter structures, and parent structures
187 
188  fStructures.Clear();
189  fDetectors.Clear();
191 }
192 
193 
194 
197 
199 {
200  // Get structure with type and number
201 
202  unique_ptr<KVSeqCollection> typelist(GetStructureTypeList(type));
203  KVGeoStrucElement* elem = (KVGeoStrucElement*)typelist->FindObjectByNumber(num);
204  return elem;
205 }
206 
207 
208 
211 
213 {
214  // Get structure with type and name
216 }
217 
218 
219 
224 
226 {
227  // Create and fill a list with all structures of given type which are daughters
228  // of this structure.
229  // DELETE LIST AFTER USE - or, better: unique_ptr<KVSeqCollection> list(toto->GetStructureTypeList(...))
230 
232 }
233 
234 
235 
238 
240 {
241  // Return detector in this structure with given name
242  return (KVDetector*)fDetectors.FindObject(name);
243 }
244 
245 
246 
249 
251 {
252  // Return detector in this structure with given type
254 }
255 
256 
257 
261 
263 {
264  // Create and fill a list with all detectors of given type in this structure.
265  // DELETE LIST AFTER USE - or, better: unique_ptr<KVSeqCollection> list(toto->GetDetectorTypeList(...))
266 
268 }
269 
270 
271 
276 
278 {
279  // Return detector in structure with given name.
280  // If not found in this structure, we look in all daughter structures
281  // for a detector with the name.
282 
283  KVDetector* det = (KVDetector*)GetDetectors()->FindObject(name);
284  if (!det) {
285  TIter next(GetStructures());
286  KVGeoStrucElement* elem;
287  while ((elem = (KVGeoStrucElement*)next())) {
288  det = elem->GetDetectorAny(name);
289  if (det) return det;
290  }
291  }
292  return (KVDetector*)nullptr;
293 
294 }
295 
296 
297 
301 
303 {
304  // Returns kTRUE if any detector or structure element in this structure
305  // has 'Fired' with the given option
306 
307  TIter nextd(GetDetectors());
308  KVDetector* det;
309  while ((det = (KVDetector*)nextd())) if (det->Fired(opt)) return kTRUE;
310  TIter nexts(GetStructures());
311  KVGeoStrucElement* elem;
312  while ((elem = (KVGeoStrucElement*)nexts())) if (elem->Fired(opt)) return kTRUE;
313  return kFALSE;
314 }
315 
316 
317 
321 
323 {
324  // Get parent geometry structure element of given type.
325  // Give unique name of structure if more than one element of same type is possible.
326  KVGeoStrucElement* el = 0;
327  if (strcmp(name, "")) {
329  el = (KVGeoStrucElement*)strucs->FindObject(name);
330  delete strucs;
331  }
332  else
334  return el;
335 }
336 
337 
338 
340 
342 {
344  cout << ClassName() << "::" << GetName() << " [TYPE=" << GetType() << "]" << endl << endl;
346  if (GetDetectors()->GetEntries()) {
348  cout << "DETECTORS : " << endl << endl;
349  TIter next(GetDetectors());
350  TObject* d;
352  while ((d = next())) {
354  cout << " " << d->GetName() << endl;
355  }
356  cout << endl;
358  }
359  TIter next(GetStructures());
360  KVGeoStrucElement* el;
361  //TROOT::IncreaseDirLevel();
362  while ((el = (KVGeoStrucElement*)next())) {
363  el->Print(option);
364  }
366  cout << endl;
367 }
368 
369 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define d(i)
#define e(i)
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
const char Option_t
int type
Base class for KaliVeda framework.
Definition: KVBase.h:141
virtual const Char_t * GetType() const
Definition: KVBase.h:176
Base class for detector geometry description.
Definition: KVDetector.h:159
virtual Bool_t Fired(Option_t *opt="any") const
Definition: KVDetector.h:450
Base class describing elements of array geometry.
virtual Bool_t Fired(Option_t *opt="any") const
void RemoveParentStructure(KVGeoStrucElement *)
KVUniqueNameList fDetectors
detectors in this structure element
void Print(Option_t *option="") const
void AddParentStructure(KVGeoStrucElement *)
KVDetector * GetDetector(const Char_t *name) const
Return detector in this structure with given name.
KVUniqueNameList fStructures
daughter structures
const KVSeqCollection * GetDetectors() const
virtual void Remove(KVBase *)
KVSeqCollection * GetDetectorTypeList(const Char_t *type) const
KVUniqueNameList fParentStrucList
parent structures
const KVSeqCollection * GetStructures() const
KVDetector * GetDetectorAny(const Char_t *name)
KVGeoStrucElement()
Default constructor.
virtual void Add(KVBase *)
virtual ~KVGeoStrucElement()
Destructor.
KVSeqCollection * GetStructureTypeList(const Char_t *type) const
KVGeoStrucElement * GetStructure(const Char_t *name) const
void Clear(Option_t *opt="")
Empty lists of detectors, daughter structures, and parent structures.
void ClearStructures(const Char_t *type="")
void init()
Default initialisations.
KVGeoStrucElement * GetParentStructure(const Char_t *type, const Char_t *name="") const
void ClearDetectors(const Char_t *type="")
KVDetector * GetDetectorByType(const Char_t *type) const
Return detector in this structure with given type.
KaliVeda extensions to ROOT collection classes.
virtual void Clear(Option_t *option="")
KVSeqCollection * GetSubListWithType(const Char_t *retvalue) const
virtual TObject * FindObjectByType(const Char_t *) const
virtual TObject * FindObjectWithNameAndType(const Char_t *name, const Char_t *type) const
virtual TObject * Remove(TObject *obj)
Remove object from list.
virtual TObject * FindObject(const char *name) const
virtual void Add(TObject *obj)
virtual void AddAll(const TCollection *col)
Bool_t IsOwner() const
virtual void Clear(Option_t *option="")
virtual const char * GetName() const
virtual const char * ClassName() const
virtual Bool_t InheritsFrom(const char *classname) const
virtual void Error(const char *method, const char *msgfmt,...) const
static Int_t IncreaseDirLevel()
static void IndentLevel()
static Int_t DecreaseDirLevel()