BmnRoot
Loading...
Searching...
No Matches
CbmStsParAsciiFileIo.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 Sts parameter input/output from/into Ascii file
9//
12
13#include "CbmStsDigiPar.h"
14
15#include <iostream>
16
17using std::cout;
18using std::cerr;
19using std::endl;
20
21CbmStsParAsciiFileIo::CbmStsParAsciiFileIo(fstream* f) : FairDetParAsciiFileIo(f) {
22 // constructor calls the base class constructor
23 fName="CbmStsParIo";
24}
25
26Bool_t CbmStsParAsciiFileIo::init(FairParSet* pPar) {
27 // calls the appropriate read function for the container
28 const Text_t* name=pPar->GetName();
29 cout << "-I- Ascii Io init() " << pPar->GetName() << endl;
30
31 if (pFile) {
32 if (!strcmp(name,"CbmStsDigiPar")) return read((CbmStsDigiPar*)pPar,0,kTRUE);
33 cerr<<"initialization of "<<name<<" not possible from file!"<<endl;
34 return kFALSE;
35 }
36 cerr<<"no input file open"<<endl;
37 return kFALSE;
38}
39
40Int_t CbmStsParAsciiFileIo::write(FairParSet* pPar) {
41 // calls the appropriate write function for the container
42 if (pFile) {
43 const Text_t* name=pPar->GetName();
44 if (!strcmp(name,"CbmStsDigiPar")) return writeFile2((CbmStsDigiPar*)pPar);
45 //problem with container name
46 cerr<<name<<" could not be written to Ascii file"<<endl;
47 return -1;
48 }
49 cerr<<"no output file open"<<endl;
50 return -1;
51}
52
53template<class T> Bool_t CbmStsParAsciiFileIo::read(T* pPar, Int_t* set,
54 Bool_t needsClear) {
55 // template function for all parameter containers
56 // searches the container in the file, reads the data line by line and
57 // called the member function readline(...) of the container class
58 // cout << "-I- Read Ascii IO " << endl;
59 // return kTRUE;
60
61 const Text_t* name=pPar->GetName();
62 if (!findContainer(name)) return kFALSE;
63 if (needsClear) pPar->clear();
64 const Int_t maxbuf=155;
65 Text_t buf[maxbuf];
66 while (!pFile->eof()) {
67 pFile->getline(buf, maxbuf);
68 if (buf[0]=='#') break;
69 if (buf[0]!='/' && buf[0]!='\0')
70 // printf("-I- CbmStsParAsciiFileIo container name: %s",
71 // pPar->GetName());
72 pPar->readline(buf,set,pFile);
73 }
74 pPar->setInputVersion(1,inputNumber);
75 pPar->setChanged();
76 Bool_t allFound=kTRUE;
77 // if (allFound) printf("%s initialized from Ascii file\n",name);
78 printf("%s initialized from Ascii file\n",name);
79
80 return allFound;
81}
82
83
84template<class T> Int_t CbmStsParAsciiFileIo::writeFile2(T* pPar) {
85 // template function for all parameter containers with 2 levels
86 // writes the header, loops over the container and calls its member
87 // function writeline(...)
88 pPar->putAsciiHeader(fHeader);
89 writeHeader(pPar->GetName());
90 // Text_t buf[155];
91/*
92 Int_t n0 = (*pPar).getSize();
93 for(Int_t i0=0; i0<n0; i0++) {
94 Int_t n1 = (*pPar)[i0].getSize();
95 for(Int_t i1=0; i1<n1; i1++) {
96 if (pPar->writeline(buf,i0,i1))
97 pFile->write(buf,strlen(buf));
98 }
99 }
100 pPar->setChanged(kFALSE);
101 pFile->write(sepLine,strlen(sepLine));
102 */
103 return 1;
104}
float f
Definition P4_F32vec4.h:21
Bool_t init(FairParSet *)
Bool_t read(T *, Int_t *, Bool_t needsClear=kFALSE)
Int_t write(FairParSet *)