HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hstartparrootfileio.cc
Go to the documentation of this file.
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Modified : 03/12/2009 by I.Koenig
3 
4 //_HADES_CLASS_DESCRIPTION
5 /////////////////////////////////////////////////////////////
6 // HStartParRootFileIo
7 //
8 // Class for Start parameter input/output from/into ROOT file
9 //
10 // It is derived from the base class HDetParRootFileIo and
11 // inherits from it basic functions e.g. write(...)
12 //
13 /////////////////////////////////////////////////////////////
14 
15 #include "hades.h"
16 #include "hparrootfileio.h"
17 #include "hruntimedb.h"
18 #include "hspectrometer.h"
19 #include "hstart2calpar.h"
20 #include "hstart2detector.h"
21 #include "hstart2trb2lookup.h"
22 #include "hstart2geompar.h"
23 #include "hstart2trb3lookup.h"
24 #include "hstart2trb3calpar.h"
25 #include "hstartparrootfileio.h"
26 
27 #include <iostream>
28 
29 using namespace std;
30 
32 
34 {
35  // constructor sets the name of the detector I/O "HStartParIo"
36  fName = "HStartParIo";
37  Int_t n = gHades->getSetup()->getDetector("Start")->getMaxModules();
38  initModules = new TArrayI(n);
39 }
40 
41 
43 {
44  // destructor
45  if (modulesFound) {
46  delete modulesFound;
47  modulesFound = 0;
48  }
49  if (initModules) {
50  delete initModules;
51  initModules = 0;
52  }
53 }
54 
55 Bool_t HStartParRootFileIo::init(HParSet* pPar, Int_t* set)
56 {
57  // Initializes a container called by name, but only the modules defined
58  // in the array 'set.
59  // Calls the special read function for this container.
60  // If it is called the first time, it reads the setup found in the file.
61  if (!isActiv) readModules("Start");
62  const Text_t* name = pPar->GetName();
63  if (pFile) {
64  if (strcmp(name, "Start2Trb2Lookup") == 0) return HDetParRootFileIo::read(pPar);
65  if (strcmp(name, "Start2Calpar") == 0) return read((HStart2Calpar*)pPar, set);
66  if (strcmp(name, "Start2GeomPar")==0)
67  return HDetParRootFileIo::read((HStart2GeomPar*)pPar,set);
68  if (strcmp(name, "Start2Trb3Lookup") == 0) return HDetParRootFileIo::read(pPar);
69  if (strcmp(name, "Start2Trb3Calpar") == 0) return HDetParRootFileIo::read(pPar);
70  }
71  cerr << "initialization of " << name << " not possible from ROOT file!" << endl;
72  return kFALSE;
73 }
74 
75 Bool_t HStartParRootFileIo::read(HStart2Calpar* pPar, Int_t* set)
76 {
77  // Reads and fills the container "Start2CalPar"
78  Text_t* name = (Char_t*)pPar->GetName();
79  Int_t version = findInputVersion(name);
80  if (version <= 0) {
81  pPar->setInputVersion(-1, inputNumber);
82  return kFALSE; // not in ROOT file
83  }
84  if (pPar->getInputVersion(inputNumber) == version
85  && pPar->getInputVersion(inputNumber) != -1) return kTRUE;
86  // needs reinitialization
87  pPar->clear();
88  HStart2Calpar* rStart = (HStart2Calpar*)findContainer(name, version);
89  Bool_t allFound = kTRUE;
90  initModules->Reset();
91  for (Int_t m = 0; m < pPar->getSize(); m++) {
92  if (set[m]) {
93  HStart2CalparMod& r = (*rStart)[m];
94  HStart2CalparMod& p = (*pPar)[m];
95  Int_t pModSize = p.getSize();
96  if (pModSize && r.getSize() == pModSize) {
97  for (Int_t c = 0; c < pModSize; c++) p[c].fill(r[c]);
98  initModules->AddAt(m + 1, m);
99  } else allFound = kFALSE;
100  }
101  }
102  if (allFound) {
103  pPar->setInputVersion(version, inputNumber);
104  pPar->setChanged();
105  cout << name << " initialized from ROOT file" << endl;
106  }
107  delete rStart;
108  return allFound;
109 }
110 
Int_t getMaxModules(void)
Definition: hdetector.h:24
virtual Bool_t read(HParSet *)
Int_t n
void setInputVersion(Int_t v=-1, Int_t i=0)
Definition: hparset.h:31
HSpectrometer * getSetup(void)
Definition: hades.h:112
HDetector * getDetector(const Char_t *name)
Definition: hparset.h:9
Hades * gHades
Definition: hades.cc:1213
ClassImp(HStartParRootFileIo) HStartParRootFileIo
Bool_t init(HParSet *, Int_t *)
void setChanged(Bool_t flag=kTRUE)
Definition: hparset.h:40
Bool_t read(HStart2Calpar *, Int_t *)
Int_t getInputVersion(Int_t i)
Definition: hparset.h:34