ROOT logo
#ifndef HDETPARASCIIFILEIO_H
#define HDETPARASCIIFILEIO_H
using namespace std;

#include <fstream>
#include "hdetpario.h"
#include "TArrayI.h"
#include "hgeomtransform.h"

class HDetGeomPar;
class HGeomVolume;
class HGeomShapes;
class HDetector;
class HTrb3Calpar;

class HDetParAsciiFileIo : public HDetParIo {
protected:
   TString fHeader;  //! header of container output in file
   TString sepLine;  //! comment line
   fstream* pFile;   //! pointer to ascii file
   virtual Bool_t write(HDetector*) {
      return kTRUE;
   }
   Bool_t findContainer(const Text_t* name);
   Bool_t checkAllFound(Int_t*, Int_t);
   void writeHeader(const Text_t*, const Text_t* context = "",
                    const Text_t* author = "", const Text_t* description = "");
   void writeComment(HParSet*);
   void readComment(const Char_t*, HParSet*);
   Bool_t readLabPositions(const Text_t*, HDetGeomPar*, Int_t*, Int_t, Int_t);
   Bool_t readVolumes(const Text_t*, HDetGeomPar*);
   void readTransform(HGeomTransform&);
   Bool_t readVolume(HGeomVolume*, HGeomShapes*, Text_t*);
   void writeTransform(const HGeomTransform&);
   void writeVolume(HGeomVolume*, HGeomShapes*);
public:
   HDetParAsciiFileIo(fstream* f);
   virtual ~HDetParAsciiFileIo() {}
   Bool_t read(HDetGeomPar*, Int_t*);
   Bool_t read(HTrb3Calpar*);
   Int_t writeFile(HDetGeomPar*);

   template<class T> Bool_t readFile(T* pPar);
   template<class T> Int_t writeFile(T* pPar);

   ClassDef(HDetParAsciiFileIo, 0) // Class for detector parameter I/O from ascii file
};

template<class T> Bool_t
HDetParAsciiFileIo::readFile(T* pPar)
{
   // template function for parameter containers
   // searches the container in the file, reads the data line by line and
   // called the member function readline(...) of the container class

   if (kFALSE == findContainer(pPar->GetName())) {
      return kFALSE;
   }

   pPar->clear();
   const Int_t maxbuf = 155;
   Text_t buf[maxbuf];
   Bool_t rc = kTRUE;
   while (!pFile->eof() && rc) {
      pFile->getline(buf, maxbuf);
      if (buf[0] == '#') {
         break;
      }
      if (buf[0] != '/' && buf[0] != '\0') {
         rc = pPar->readline(buf);
      }
   }
   if (kTRUE == rc) {
      pPar->setInputVersion(1, inputNumber);
      pPar->setChanged();
      Info("readFile", "%s initialized from Ascii file", pPar->GetName());
   }
   return rc;
}

template<class T> Int_t
HDetParAsciiFileIo::writeFile(T* pPar)
{
   // template function for parameter containers
   // calls the function putAsciiHeader(TString&) of the parameter container,
   // writes the header and calls the function write(fstream&) of the class

   if (NULL != pFile) {
      pPar->putAsciiHeader(fHeader);
      writeHeader(pPar->GetName(), pPar->getParamContext());
      pPar->write(*pFile);
      pFile->write(sepLine, strlen(sepLine));
      pPar->setChanged(kFALSE);
      return 1;
   }
   Error("writeFile", "Output is not writable");
   return -1;
}

#endif  /* !HDETPARASCIIFILEIO_H */
 hdetparasciifileio.h:1
 hdetparasciifileio.h:2
 hdetparasciifileio.h:3
 hdetparasciifileio.h:4
 hdetparasciifileio.h:5
 hdetparasciifileio.h:6
 hdetparasciifileio.h:7
 hdetparasciifileio.h:8
 hdetparasciifileio.h:9
 hdetparasciifileio.h:10
 hdetparasciifileio.h:11
 hdetparasciifileio.h:12
 hdetparasciifileio.h:13
 hdetparasciifileio.h:14
 hdetparasciifileio.h:15
 hdetparasciifileio.h:16
 hdetparasciifileio.h:17
 hdetparasciifileio.h:18
 hdetparasciifileio.h:19
 hdetparasciifileio.h:20
 hdetparasciifileio.h:21
 hdetparasciifileio.h:22
 hdetparasciifileio.h:23
 hdetparasciifileio.h:24
 hdetparasciifileio.h:25
 hdetparasciifileio.h:26
 hdetparasciifileio.h:27
 hdetparasciifileio.h:28
 hdetparasciifileio.h:29
 hdetparasciifileio.h:30
 hdetparasciifileio.h:31
 hdetparasciifileio.h:32
 hdetparasciifileio.h:33
 hdetparasciifileio.h:34
 hdetparasciifileio.h:35
 hdetparasciifileio.h:36
 hdetparasciifileio.h:37
 hdetparasciifileio.h:38
 hdetparasciifileio.h:39
 hdetparasciifileio.h:40
 hdetparasciifileio.h:41
 hdetparasciifileio.h:42
 hdetparasciifileio.h:43
 hdetparasciifileio.h:44
 hdetparasciifileio.h:45
 hdetparasciifileio.h:46
 hdetparasciifileio.h:47
 hdetparasciifileio.h:48
 hdetparasciifileio.h:49
 hdetparasciifileio.h:50
 hdetparasciifileio.h:51
 hdetparasciifileio.h:52
 hdetparasciifileio.h:53
 hdetparasciifileio.h:54
 hdetparasciifileio.h:55
 hdetparasciifileio.h:56
 hdetparasciifileio.h:57
 hdetparasciifileio.h:58
 hdetparasciifileio.h:59
 hdetparasciifileio.h:60
 hdetparasciifileio.h:61
 hdetparasciifileio.h:62
 hdetparasciifileio.h:63
 hdetparasciifileio.h:64
 hdetparasciifileio.h:65
 hdetparasciifileio.h:66
 hdetparasciifileio.h:67
 hdetparasciifileio.h:68
 hdetparasciifileio.h:69
 hdetparasciifileio.h:70
 hdetparasciifileio.h:71
 hdetparasciifileio.h:72
 hdetparasciifileio.h:73
 hdetparasciifileio.h:74
 hdetparasciifileio.h:75
 hdetparasciifileio.h:76
 hdetparasciifileio.h:77
 hdetparasciifileio.h:78
 hdetparasciifileio.h:79
 hdetparasciifileio.h:80
 hdetparasciifileio.h:81
 hdetparasciifileio.h:82
 hdetparasciifileio.h:83
 hdetparasciifileio.h:84
 hdetparasciifileio.h:85
 hdetparasciifileio.h:86
 hdetparasciifileio.h:87
 hdetparasciifileio.h:88
 hdetparasciifileio.h:89
 hdetparasciifileio.h:90
 hdetparasciifileio.h:91
 hdetparasciifileio.h:92
 hdetparasciifileio.h:93
 hdetparasciifileio.h:94
 hdetparasciifileio.h:95
 hdetparasciifileio.h:96
 hdetparasciifileio.h:97
 hdetparasciifileio.h:98
 hdetparasciifileio.h:99
 hdetparasciifileio.h:100