//*-- AUTHOR : Ilse Koenig //*-- Created : 21/10/2004 //*-- modified : 28/01/2009 by Ilse Koenig ///////////////////////////////////////////////////////////// // FairDetParAsciiFileIo // // Class for parameter input/output from/into Ascii file // Base class for all detector Ascii I/Os // ///////////////////////////////////////////////////////////// #include "FairDetParAsciiFileIo.h" #include "FairParSet.h" using std::ios; FairDetParAsciiFileIo::FairDetParAsciiFileIo(fstream* f) :FairDetParIo(), fHeader(""), sepLine("##############################################################################\n"), pFile(f) { // constructor /* pFile=f; sepLine= "##############################################################################\n"; */ } Bool_t FairDetParAsciiFileIo::findContainer(const Text_t* name) { // searches the container in the file const Int_t maxbuf=4000; Text_t buf[maxbuf]; Text_t buf2[maxbuf]; sprintf(buf2,"%s%s%s","[",name,"]"); pFile->clear(); pFile->seekg(0,ios::beg); while (!pFile->eof()) { pFile->getline(buf,maxbuf); if (buf[0]!='[') { continue; } if (!strncmp(buf,buf2,strlen(buf2))) { break; } } if (pFile->eof()) { return kFALSE; } return kTRUE; } Bool_t FairDetParAsciiFileIo::checkAllFound(Int_t* set, Int_t setSize) { // checks if all modules have been initialized Bool_t allFound=kTRUE; for(Int_t i=0; iwrite(sepLine,strlen(sepLine)); pFile->write(fHeader.Data(),fHeader.Length()); pFile->write(sepLine,strlen(sepLine)); *pFile<<"["<0) { *pFile<<"// Parameter Context: "<0) { *pFile<<"author: "<0) { pVal=s(n+1,m-n-1); } else { pVal=s(n+1,s.Length()-n-1); } pVal=pVal.Strip(pVal.kLeading); while (m>0) { pVal+="\n"; pFile->getline(buf,maxbuf); if (buf[0]!='/') { s=buf; m=s.Last('\\'); if (m>0) { pVal+=s(0,m); } else { pVal+=s; } } } if (pName.CompareTo("author")==0) { pPar->setAuthor(pVal.Data()); } else if ( pName.CompareTo("description")==0) { pPar->setDescription(pVal.Data()); } } void FairDetParAsciiFileIo::writeComment(FairParSet* pPar) { TString t=pPar->getAuthor(); if (!t.IsNull()) { *pFile<<"author: "<getDescription(); if (!t.IsNull()) { t=t.ReplaceAll("\n"," \\\n"); *pFile<<"description: "<clear(); pFile->seekg(0,ios::beg); while (!pFile->eof()) { pFile->getline(buf,maxbuf); if (buf[0]!='[') continue; if (!strncmp(buf,buf2,strlen(buf2))) break; } if (pFile->eof()) return kFALSE; return kTRUE; } void FairDetParAsciiFileIo::writeHeader(const Text_t* name, const Text_t* context, const Text_t* author, const Text_t* description) { // calls the function putAsciiHeader(...) of the parameter container // class and writes the header to the file pFile->write(sepLine,strlen(sepLine)); pFile->write(fHeader.Data(),fHeader.Length()); pFile->write(sepLine,strlen(sepLine)); *pFile<<"["<0) *pFile<<"// Parameter Context: "<0) *pFile<<"author: "<0) pVal=s(n+1,m-n-1); else pVal=s(n+1,s.Length()-n-1); pVal=pVal.Strip(pVal.kLeading); while (m>0) { pVal+="\n"; pFile->getline(buf,maxbuf); if (buf[0]!='/') { s=buf; m=s.Last('\\'); if (m>0) pVal+=s(0,m); else pVal+=s; } } if (pName.CompareTo("author")==0) pPar->setAuthor(pVal.Data()); else if ( pName.CompareTo("description")==0) pPar->setDescription(pVal.Data()); } void FairDetParAsciiFileIo::writeComment(FairParSet* pPar) { TString t=pPar->getAuthor(); if (!t.IsNull()) *pFile<<"author: "<getDescription(); if (!t.IsNull()) { t=t.ReplaceAll("\n"," \\\n"); *pFile<<"description: "<