HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hemcparasciifileio.cc
Go to the documentation of this file.
1 //_HADES_CLASS_DESCRIPTION
2 //_HADES_CLASS_DESCRIPTION
3 /////////////////////////////////////////////////////////////
4 // HEmcParAsciiFileIo
5 //
6 // Class for EMC parameter input/output from/into Ascii file
7 //
8 /////////////////////////////////////////////////////////////
9 
10 #include "hemcparasciifileio.h"
11 #include "hades.h"
12 #include "hspectrometer.h"
13 #include "hdetector.h"
14 #include "hparset.h"
15 #include "hemcdetector.h"
16 #include "hemctrb3lookup.h"
17 #include "hemccalpar.h"
18 #include "hemcgeompar.h"
19 
21 
23  // constructor calls the base class constructor
24  fName="HEmcParIo";
25 }
26 
27 Bool_t HEmcParAsciiFileIo::init(HParSet* pPar,Int_t* set) {
28  // calls the appropriate read function for the container
29  const Text_t* name=pPar->GetName();
30  if (pFile) {
31  if (0 == strncmp(name, "EmcTrb3Lookup", strlen("EmcTrb3Lookup"))) {
32  return HDetParAsciiFileIo::readFile<HEmcTrb3Lookup>((HEmcTrb3Lookup*)pPar);
33  }
34  if (0 == strncmp(name, "EmcCalPar", strlen("EmcCalPar"))) {
35  return read((HEmcCalPar*)pPar,set);
36  }
37  if (0 == strncmp(name,"EmcGeomPar", strlen("EmcGeomPar"))) {
38  return HDetParAsciiFileIo::read((HDetGeomPar*)pPar,set);
39  }
40  Error("init(HParSet*,Int_t*)","Initialization of %s not possible from ASCII file",name);
41  return kFALSE;
42  }
43  Error("init(HParSet*,Int_t*)","No input file open");
44  return kFALSE;
45 }
46 
48  // calls the appropriate write function for the container
49  if (pFile) {
50  const Text_t* name=pPar->GetName();
51  if (0 == strncmp(name, "EmcTrb3Lookup", strlen("EmcTrb3Lookup"))) {
52  return HDetParAsciiFileIo::writeFile<HEmcTrb3Lookup>((HEmcTrb3Lookup*)pPar);
53  }
54  if (0 == strncmp(name, "EmcCalPar", strlen("EmcCalPar"))) {
55  return HDetParAsciiFileIo::writeFile<HEmcCalPar>((HEmcCalPar*)pPar);
56  }
57  if (0 == strncmp(name,"EmcGeomPar", strlen("EmcGeomPar"))) {
59  }
60  Error("write(HParSet*)","%s could not be written to ASCII file",name);
61  return -1;
62  }
63  Error("write(HParSet*)","No output file open");
64  return -1;
65 }
66 
67 template<class T> Bool_t HEmcParAsciiFileIo::read(T* pPar, Int_t* set) {
68  // template function for all parameter containers
69  // searches the container in the file, reads the data line by line and
70  // calles the member function readline(...) of the container class
71  const Text_t* name = pPar->GetName();
72  HDetector* det = gHades->getSetup()->getDetector("Emc");
73  Int_t nSize = det->getMaxModules();
74  if (!findContainer(name)) return kFALSE;
75  pPar->clear();
76  const Int_t maxbuf = 155;
77  Text_t buf[maxbuf];
78  while (!pFile->eof()) {
79  pFile->getline(buf, maxbuf);
80  if (buf[0] == '#') break;
81  if (buf[0] != '/' && buf[0] != '\0') pPar->readline(buf, set);
82  }
83  Bool_t allFound = kTRUE;
84  for (Int_t i = 0; i < nSize; i++) {
85  if (set[i]) {
86  if (set[i] == 999) set[i] = 1;
87  else allFound = kFALSE;
88  }
89  }
90  if (allFound) {
91  pPar->setInputVersion(1, inputNumber);
92  pPar->setChanged();
93  Info("readFile", "%s initialized from Ascii file", pPar->GetName());
94  }
95  return allFound;
96 }
97 
98 
Int_t getMaxModules(void)
Definition: hdetector.h:24
Bool_t read(HDetGeomPar *, Int_t *)
Int_t write(HParSet *)
Int_t inputNumber
Definition: hdetpario.h:15
ClassImp(HEmcParAsciiFileIo) HEmcParAsciiFileIo
fstream * pFile
comment line
Bool_t init(HParSet *, Int_t *)
HSpectrometer * getSetup(void)
Definition: hades.h:112
HDetector * getDetector(const Char_t *name)
Bool_t read(T *, Int_t *)
Definition: hparset.h:9
Hades * gHades
Definition: hades.cc:1213
Bool_t findContainer(const Text_t *name)
Int_t writeFile(HDetGeomPar *)