//*-- AUTHOR : Ilse Koenig //*-- Created : 16/11/2015 //_HADES_CLASS_DESCRIPTION //_HADES_CLASS_DESCRIPTION ///////////////////////////////////////////////////////////////////////////////// // HFRpcParAsciiFileIo // // Class for parameter input/output from/into Ascii file for the Forward detector // ///////////////////////////////////////////////////////////////////////////////// #include "hfrpcparasciifileio.h" #include "hades.h" #include "hdetector.h" #include "hfrpccalpar.h" #include "hfrpcgeompar.h" #include "hfrpcstrippar.h" #include "hfrpctrb3calpar.h" #include "hfrpctrb3lookup.h" #include "hparset.h" #include "hspectrometer.h" ClassImp(HFRpcParAsciiFileIo); HFRpcParAsciiFileIo::HFRpcParAsciiFileIo(fstream *f) : HDetParAsciiFileIo(f) { // constructor calls the base class constructor fName = "HFRpcParIo"; } Bool_t HFRpcParAsciiFileIo::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, "FRpcGeomPar", strlen("FRpcGeomPar"))) return HDetParAsciiFileIo::read((HDetGeomPar *)pPar, set); if (0 == strncmp(name, "FRpcTrb3Lookup", strlen("FRpcTrb3Lookup"))) return HDetParAsciiFileIo::readFile((HFRpcTrb3Lookup *)pPar); if (0 == strncmp(name, "FRpcTrb3Calpar", strlen("FRpcTrb3Calpar"))) return HDetParAsciiFileIo::read((HFRpcTrb3Calpar *)pPar); if (0 == strncmp(name, "FRpcCalPar", strlen("FRpcCalPar"))) return read((HFRpcCalPar *)pPar, set); if (0 == strncmp(name, "FRpcStripPar", strlen("FRpcStripPar"))) return read((HFRpcStripPar *)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 HFRpcParAsciiFileIo::write(HParSet *pPar) { // calls the appropriate write function for the container if (pFile) { const Text_t *name = pPar->GetName(); if (0 == strncmp(name, "FRpcGeomPar", strlen("FRpcGeomPar"))) return HDetParAsciiFileIo::writeFile((HDetGeomPar *)pPar); if (0 == strncmp(name, "FRpcTrb3Lookup", strlen("FRpcTrb3Lookup"))) return writeFile((HFRpcTrb3Lookup *)pPar); if (0 == strncmp(name, "FRpcTrb3Calpar", strlen("FRpcTrb3Calpar"))) return HDetParAsciiFileIo::writeFile((HTrb3Calpar *)pPar); if (0 == strncmp(name, "FRpcCalPar", strlen("FRpcCalPar"))) return HDetParAsciiFileIo::writeFile((HFRpcCalPar *)pPar); if (0 == strncmp(name, "FRpcStripPar", strlen("FRpcStripPar"))) return HDetParAsciiFileIo::writeFile((HFRpcStripPar *)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 HFRpcParAsciiFileIo::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("FRpc"); 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; }