HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hspecparrootfileio.cc
Go to the documentation of this file.
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Modified : 06/12/2009 by Ilse Koenig
3 
4 //_HADES_CLASS_DESCRIPTION
5 /////////////////////////////////////////////////////////////
6 //
7 // HSpecParRootFileIo
8 //
9 // Class for parameter input/output from/into ROOT file for
10 // the spectrometer (not related to a special detector)
11 //
12 /////////////////////////////////////////////////////////////
13 
14 #include "hspecparrootfileio.h"
15 #include "hgeomvolume.h"
16 #include "hgeomshapes.h"
17 #include "hspecgeompar.h"
18 
20 
22  // constructor calls the base class constructor
23  fName="HSpecParIo";
24 }
25 
26 
27 Bool_t HSpecParRootFileIo::init(HParSet* pPar,Int_t* set) {
28  // calls the appropriate read function of the container
29  const Text_t* name=pPar->GetName();
30  if (pFile) {
31  if (strcmp(name,"SpecGeomPar")==0) return read((HSpecGeomPar*)pPar,set);
32  if (strcmp(name,"TrbLookup")==0) return HDetParRootFileIo::read(pPar);
33  if (strcmp(name,"TrbnetAddressMapping")==0) return HDetParRootFileIo::read(pPar);
34  if (strcmp(name,"SlowPar")==0) return HDetParRootFileIo::read(pPar);
35  }
36  cerr<<"initialization of "<<name<<" not possible from ROOT file!"<<endl;
37  return kFALSE;
38 }
39 
40 
41 Bool_t HSpecParRootFileIo::read(HSpecGeomPar* pPar,Int_t* set) {
42  // reads and fills the container "SpecGeomPar" which holds the geometry
43  // parameters of the cave, the sectors and the target
44  Text_t* name=(Char_t*)pPar->GetName();
45  Int_t version=findInputVersion(name);
46  if (version<=0) {
47  pPar->setInputVersion(-1,inputNumber);
48  return kFALSE; // not in ROOT file
49  }
50  if (pPar->getInputVersion(inputNumber)==version
51  && pPar->getInputVersion(inputNumber)!=-1) return kTRUE;
52  // needs reinitialization
53  HSpecGeomPar* r=(HSpecGeomPar*)findContainer(name,version);
54  pPar->clear();
55  Bool_t allFound=kTRUE;
56  pPar->copyComment(*r);
57  if (pPar->isFirstInitialization()) {
58  if (set[0]) {
59  HGeomVolume* cave=r->getCave();
60  if (cave) {
61  pPar->addCave(cave);
62  set[0]=0;
63  }
64  else allFound=kFALSE;
65  }
66  if (set[1]) {
67  Int_t n=r->getNumSectors();
68  if (n>0) {
69  for(Int_t i=0;i<n;i++) pPar->addSector(r->getSector(i));
70  set[1]=0;
71  }
72  else allFound=kFALSE;
73  }
74  } else set[0]=set[1]=0;
75  if (set[2]) {
76  Int_t n=r->getNumTargets();
77  if (n>0) {
78  for(Int_t i=0;i<n;i++) pPar->addTarget(r->getTarget(i));
79  set[2]=0;
80  }
81  else allFound=kFALSE;
82  }
83  pPar->setInputVersion(version,inputNumber);
84  pPar->setChanged();
85  delete r;
86  if (allFound) pPar->setNotFirstInit();
87  return allFound;
88 }
89 
void clear(void)
Int_t getNumSectors(void)
Definition: hspecgeompar.cc:61
Int_t findInputVersion(const Text_t *contName)
void addTarget(HGeomVolume *)
Int_t getNumTargets(void)
Definition: hspecgeompar.cc:68
virtual Bool_t read(HParSet *)
void setNotFirstInit()
Definition: hspecgeompar.h:30
ClassImp(HSpecParRootFileIo) HSpecParRootFileIo
Int_t inputNumber
Definition: hdetpario.h:15
Int_t n
void setInputVersion(Int_t v=-1, Int_t i=0)
Definition: hparset.h:31
HGeomVolume * getCave(void)
Definition: hspecgeompar.h:26
Bool_t read(HSpecGeomPar *, Int_t *)
TObject * findContainer(const Text_t *contName, Int_t version)
Definition: hparset.h:9
HGeomVolume * getTarget(const Int_t n)
Definition: hspecgeompar.cc:82
void addCave(HGeomVolume *v)
HParRootFile * pFile
Bool_t init(HParSet *, Int_t *)
void copyComment(HParSet &r)
Definition: hparset.h:52
HGeomVolume * getSector(const Int_t n)
Definition: hspecgeompar.cc:75
void setChanged(Bool_t flag=kTRUE)
Definition: hparset.h:40
void addSector(HGeomVolume *)
Bool_t isFirstInitialization()
Definition: hspecgeompar.h:29
Int_t getInputVersion(Int_t i)
Definition: hparset.h:34