FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairVolumeList.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairVolumeList source file -----
10 // ----- Created 12/01/04 by M. Al-Turany -----
11 // -------------------------------------------------------------------------
12 
13 #include "FairVolumeList.h"
14 
15 #include "FairLogger.h" // for logging
16 #include "FairVolume.h" // for FairVolume
17 
19  : TObject()
20  , fData(new TObjArray())
21 {}
22 
24 {
25  if (fData) {
26  fData->Delete();
27  delete fData;
28  }
29 }
30 
32 {
33 
34  TObject* obj = findObject(*name);
35  if (obj) {
36  LOG(info) << "FairVolume getVolume " << name->Data() << "found";
37  }
38 
39  return static_cast<FairVolume*>(obj);
40 }
41 
42 Int_t FairVolumeList::getVolumeId(TString* name)
43 {
44  FairVolume* vol = getVolume(name);
45 
46  if (vol) {
47  return vol->getVolumeId();
48  } else {
49  return -111;
50  }
51 }
52 
54 {
55  FairVolume* obj = nullptr;
56 
57  for (int i = 0; i < fData->GetEntriesFast(); i++) {
58  obj = static_cast<FairVolume*>(fData->At(i));
59  if (obj) {
60  if (obj->GetName() == name) {
61  return static_cast<FairVolume*>(obj);
62  }
63  }
64  }
65 
66  return nullptr;
67 }
68 
70 {
71  FairVolume* v = static_cast<FairVolume*>(findObject(elem->GetName()));
72 
73  if (v) {
74  LOG(error) << "FairVolumeList element: " << elem->GetName() << " VolId : " << elem->getVolumeId()
75  << " already defined " << v->getVolumeId();
76  } else {
77  fData->Add(elem);
78  }
79 }
80 
Int_t getVolumeId()
Definition: FairVolume.h:38
ClassImp(FairEventBuilder)
Int_t getVolumeId(TString *name)
void addVolume(FairVolume *elem)
FairVolume * getVolume(TString *name)
virtual ~FairVolumeList()
FairVolume * findObject(TString name)