FairRoot/PandaRoot
PndSttParAsciiFileIo.cxx
Go to the documentation of this file.
1 //*-- AUTHOR : Denis Bertini
2 //*-- Created : 21/06/2005
3 
4 
6 // CbmStsParAsciiFileIo
7 //
8 // Class for Stt parameter input/output from/into Ascii file
9 //
11 
12 #include "PndSttParAsciiFileIo.h"
13 #include "PndSttDigiPar.h"
14 
15 #include <iostream>
16 
17 using std::cout;
18 using std::cerr;
19 using std::endl;
20 
22 
23 PndSttParAsciiFileIo::PndSttParAsciiFileIo(std::fstream* f) : FairDetParAsciiFileIo(f)
24 {
25  // constructor calls the base class constructor
26  fName="PndSttParIo";
27 }
28 
29 Bool_t PndSttParAsciiFileIo::init(FairParSet* pPar)
30 {
31  // calls the appropriate read function for the container
32  const Text_t* name=pPar->GetName();
33  cout << "-I- Ascii Io init() " << pPar->GetName() << endl;
34 
35  if (pFile)
36  {
37  if (!strcmp(name,"PndSttDigiPar")) return read((PndSttDigiPar*)pPar,0,kTRUE);
38  cerr<<"initialization of "<<name<<" not possible from file!"<<endl;
39  return kFALSE;
40  }
41  cerr<<"no input file open"<<endl;
42  return kFALSE;
43 }
44 
45 Int_t PndSttParAsciiFileIo::write(FairParSet* pPar)
46 {
47  // calls the appropriate write function for the container
48  if (pFile)
49  {
50  const Text_t* name=pPar->GetName();
51  if (!strcmp(name,"PndSttDigiPar")) return writeFile2((PndSttDigiPar*)pPar);
52  //problem with container name
53  cerr<<name<<" could not be written to Ascii file"<<endl;
54  return -1;
55  }
56  cerr<<"no output file open"<<endl;
57  return -1;
58 }
59 
60 template<class T> Bool_t PndSttParAsciiFileIo::read(T* pPar, Int_t* set,
61  Bool_t needsClear)
62 {
63  // template function for all parameter containers
64  // searches the container in the file, reads the data line by line and
65  // called the member function readline(...) of the container class
66  // cout << "-I- Read Ascii IO " << endl;
67  // return kTRUE;
68 
69  const Text_t* name=pPar->GetName();
70  if (!findContainer(name)) return kFALSE;
71  if (needsClear) pPar->clear();
72  const Int_t maxbuf=155;
73  Text_t buf[maxbuf];
74  while (!pFile->eof()) {
75  pFile->getline(buf, maxbuf);
76  if (buf[0]=='#') break;
77  if (buf[0]!='/' && buf[0]!='\0')
78  // printf("-I- CbmStsParAsciiFileIo container name: %s",
79  // pPar->GetName());
80  pPar->readline(buf,set,pFile);
81  }
82  pPar->setInputVersion(1,inputNumber);
83  pPar->setChanged();
84  Bool_t allFound=kTRUE;
85  // if (allFound) printf("%s initialized from Ascii file\n",name);
86  printf("%s initialized from Ascii file\n",name);
87 
88  return allFound;
89 }
90 
91 
92 template<class T> Int_t PndSttParAsciiFileIo::writeFile2(T* pPar) {
93  // template function for all parameter containers with 2 levels
94  // writes the header, loops over the container and calls its member
95  // function writeline(...)
96  pPar->putAsciiHeader(fHeader);
97  writeHeader(pPar->GetName());
98  //Text_t buf[155]; //[R.K. 01/2017] unused variable
99  return 1;
100 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Bool_t init(FairParSet *)
TTree * T
Definition: anaLmdReco.C:32
TFile * f
Definition: bump_analys.C:12
TString name
return buf
ClassImp(PndSttParAsciiFileIo) PndSttParAsciiFileIo
Int_t write(FairParSet *)
Bool_t read(T *, Int_t *, Bool_t needsClear=kFALSE)