//*-- AUTHOR : Ilse Koenig //*-- Created : 16/11/2015 //_HADES_CLASS_DESCRIPTION //_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////////////////////////// // HStsParAsciiFileIo // // Class for parameter input/output from/into Ascii file for the Forward detector // ///////////////////////////////////////////////////////////////////////////////// #include "hstsparasciifileio.h" #include "hades.h" #include "hdetector.h" #include "hparset.h" #include "hspectrometer.h" #include "hstscalpar.h" #include "hstsgeompar.h" #include "hstsstatuspar.h" #include "hststrb3calpar.h" #include "hststrb3lookup.h" ClassImp(HStsParAsciiFileIo); HStsParAsciiFileIo::HStsParAsciiFileIo(fstream *f) : HDetParAsciiFileIo(f) { // constructor calls the base class constructor fName = "HStsParIo"; } Bool_t HStsParAsciiFileIo::init(HParSet *pPar, Int_t *set) { // calls the appropriate read function for the container const Text_t *name = pPar->GetName(); if (pFile) { if (0 == strncmp(name, "StsGeomPar", strlen("StsGeomPar"))) return HDetParAsciiFileIo::read((HDetGeomPar *)pPar, set); if (0 == strncmp(name, "StsTrb3Lookup", strlen("StsTrb3Lookup"))) return HDetParAsciiFileIo::readFile((HStsTrb3Lookup *)pPar); if (0 == strncmp(name, "StsTrb3Calpar", strlen("StsTrb3Calpar"))) return HDetParAsciiFileIo::read((HStsTrb3Calpar *)pPar); if (0 == strncmp(name, "StsCalPar", strlen("StsCalPar"))) return read((HStsCalPar *)pPar, set); Error("init(HParSet*,Int_t*)", "Initialization of %s not possible from ASCII file", name); return kFALSE; } Error("init(HParSet*,Int_t*)", "No input file open"); return kFALSE; } Int_t HStsParAsciiFileIo::write(HParSet *pPar) { // calls the appropriate write function for the container if (pFile) { const Text_t *name = pPar->GetName(); if (0 == strncmp(name, "StsGeomPar", strlen("StsGeomPar"))) return HDetParAsciiFileIo::writeFile((HDetGeomPar *)pPar); if (0 == strncmp(name, "StsTrb3Lookup", strlen("StsTrb3Lookup"))) return writeFile((HStsTrb3Lookup *)pPar); if (0 == strncmp(name, "StsTrb3Calpar", strlen("StsTrb3Calpar"))) return HDetParAsciiFileIo::writeFile((HTrb3Calpar *)pPar); if (0 == strncmp(name, "StsCalPar", strlen("StsCalPar"))) return HDetParAsciiFileIo::writeFile((HStsCalPar *)pPar); Error("write(HParSet*)", "%s could not be written to ASCII file", name); return -1; } Error("write(HParSet*)", "No output file open"); return -1; } template Bool_t HStsParAsciiFileIo::read(T *pPar, Int_t *set) { // template function for all parameter containers // searches the container in the file, reads the data line by line and // calles the member function readline(...) of the container class const Text_t *name = pPar->GetName(); HDetector *det = gHades->getSetup()->getDetector("Sts"); Int_t nSize = det->getMaxModules(); if (!findContainer(name)) return kFALSE; pPar->clear(); const Int_t maxbuf = 155; Text_t buf[maxbuf]; while (!pFile->eof()) { pFile->getline(buf, maxbuf); if (buf[0] == '#') break; if (buf[0] != '/' && buf[0] != '\0') pPar->readline(buf, set); } Bool_t allFound = kTRUE; for (Int_t i = 0; i < nSize; i++) { if (set[i]) { if (set[i] == 999) set[i] = 1; else allFound = kFALSE; } } if (allFound) { pPar->setInputVersion(1, inputNumber); pPar->setChanged(); Info("readFile", "%s initialized from Ascii file", pPar->GetName()); } return allFound; } template Int_t HStsParAsciiFileIo::write(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 pPar->putAsciiHeader(fHeader); writeHeader(pPar->GetName(), pPar->getParamContext()); pPar->write(*pFile); pFile->write(sepLine, strlen(sepLine)); pPar->setChanged(kFALSE); return 1; }