HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hdetparasciifileio.h
Go to the documentation of this file.
1 #ifndef HDETPARASCIIFILEIO_H
2 #define HDETPARASCIIFILEIO_H
3 using namespace std;
4 
5 #include <fstream>
6 #include "hdetpario.h"
7 #include "TArrayI.h"
8 #include "hgeomtransform.h"
9 
10 class HDetGeomPar;
11 class HGeomVolume;
12 class HGeomShapes;
13 class HDetector;
14 class HTrb3Calpar;
15 
16 class HDetParAsciiFileIo : public HDetParIo {
17 protected:
18  TString fHeader; //! header of container output in file
19  TString sepLine; //! comment line
20  fstream* pFile; //! pointer to ascii file
21  virtual Bool_t write(HDetector*) {
22  return kTRUE;
23  }
24  Bool_t findContainer(const Text_t* name);
25  Bool_t checkAllFound(Int_t*, Int_t);
26  void writeHeader(const Text_t*, const Text_t* context = "",
27  const Text_t* author = "", const Text_t* description = "");
28  void writeComment(HParSet*);
29  void readComment(const Char_t*, HParSet*);
30  Bool_t readLabPositions(const Text_t*, HDetGeomPar*, Int_t*, Int_t, Int_t);
31  Bool_t readVolumes(const Text_t*, HDetGeomPar*);
32  void readTransform(HGeomTransform&);
33  Bool_t readVolume(HGeomVolume*, HGeomShapes*, Text_t*);
34  void writeTransform(const HGeomTransform&);
35  void writeVolume(HGeomVolume*, HGeomShapes*);
36 public:
37  HDetParAsciiFileIo(fstream* f);
38  virtual ~HDetParAsciiFileIo() {}
39  Bool_t read(HDetGeomPar*, Int_t*);
40  Bool_t read(HTrb3Calpar*);
41  Int_t writeFile(HDetGeomPar*);
42 
43  template<class T> Bool_t readFile(T* pPar);
44  template<class T> Int_t writeFile(T* pPar);
45 
46  ClassDef(HDetParAsciiFileIo, 0) // Class for detector parameter I/O from ascii file
47 };
48 
49 template<class T> Bool_t
51 {
52  // template function for parameter containers
53  // searches the container in the file, reads the data line by line and
54  // called the member function readline(...) of the container class
55 
56  if (kFALSE == findContainer(pPar->GetName())) {
57  return kFALSE;
58  }
59 
60  pPar->clear();
61  const Int_t maxbuf = 155;
62  Text_t buf[maxbuf];
63  Bool_t rc = kTRUE;
64  while (!pFile->eof() && rc) {
65  pFile->getline(buf, maxbuf);
66  if (buf[0] == '#') {
67  break;
68  }
69  if (buf[0] != '/' && buf[0] != '\0') {
70  rc = pPar->readline(buf);
71  }
72  }
73  if (kTRUE == rc) {
74  pPar->setInputVersion(1, inputNumber);
75  pPar->setChanged();
76  Info("readFile", "%s initialized from Ascii file", pPar->GetName());
77  }
78  return rc;
79 }
80 
81 template<class T> Int_t
83 {
84  // template function for parameter containers
85  // calls the function putAsciiHeader(TString&) of the parameter container,
86  // writes the header and calls the function write(fstream&) of the class
87 
88  if (NULL != pFile) {
89  pPar->putAsciiHeader(fHeader);
90  writeHeader(pPar->GetName(), pPar->getParamContext());
91  pPar->write(*pFile);
92  pFile->write(sepLine, strlen(sepLine));
93  pPar->setChanged(kFALSE);
94  return 1;
95  }
96  Error("writeFile", "Output is not writable");
97  return -1;
98 }
99 
100 #endif /* !HDETPARASCIIFILEIO_H */
fstream * pFile
comment line
Bool_t readFile(T *pPar)
Definition: hparset.h:9
Bool_t rc
virtual Bool_t write(HDetector *)
pointer to ascii file
Int_t writeFile(HDetGeomPar *)
TString sepLine
header of container output in file