BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
CbmStsParAsciiFileIo.cxx
Go to the documentation of this file.
1
//*-- AUTHOR : Denis Bertini
2
//*-- Created : 21/06/2005
3
4
///////////////////////////////////////////////////////////////
5
// CbmStsParAsciiFileIo
6
//
7
// Class for Sts parameter input/output from/into Ascii file
8
//
9
///////////////////////////////////////////////////////////////
10
#include "
CbmStsParAsciiFileIo.h
"
11
12
#include "
CbmStsDigiPar.h
"
13
14
#include <iostream>
15
16
using
std::cerr;
17
using
std::cout;
18
using
std::endl;
19
20
CbmStsParAsciiFileIo::CbmStsParAsciiFileIo
(fstream* f)
21
:
FairDetParAsciiFileIo
(f)
22
{
23
// constructor calls the base class constructor
24
fName =
"CbmStsParIo"
;
25
}
26
27
Bool_t
CbmStsParAsciiFileIo::init
(
FairParSet
* pPar)
28
{
29
// calls the appropriate read function for the container
30
const
Text_t
* name = pPar->GetName();
31
cout <<
"-I- Ascii Io init() "
<< pPar->GetName() << endl;
32
33
if
(pFile) {
34
if
(!strcmp(name,
"CbmStsDigiPar"
))
35
return
read
((
CbmStsDigiPar
*)pPar, 0,
kTRUE
);
36
cerr <<
"initialization of "
<< name <<
" not possible from file!"
<< endl;
37
return
kFALSE
;
38
}
39
cerr <<
"no input file open"
<< endl;
40
return
kFALSE
;
41
}
42
43
Int_t
CbmStsParAsciiFileIo::write
(
FairParSet
* pPar)
44
{
45
// calls the appropriate write function for the container
46
if
(pFile) {
47
const
Text_t
* name = pPar->GetName();
48
if
(!strcmp(name,
"CbmStsDigiPar"
))
49
return
writeFile2
((
CbmStsDigiPar
*)pPar);
50
// problem with container name
51
cerr << name <<
" could not be written to Ascii file"
<< endl;
52
return
-1;
53
}
54
cerr <<
"no output file open"
<< endl;
55
return
-1;
56
}
57
58
template
<
class
T>
59
Bool_t
CbmStsParAsciiFileIo::read
(T* pPar,
Int_t
* set,
Bool_t
needsClear)
60
{
61
// template function for all parameter containers
62
// searches the container in the file, reads the data line by line and
63
// called the member function readline(...) of the container class
64
// cout << "-I- Read Ascii IO " << endl;
65
// return kTRUE;
66
67
const
Text_t
* name = pPar->GetName();
68
if
(!findContainer(name))
69
return
kFALSE
;
70
if
(needsClear)
71
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] ==
'#'
)
77
break
;
78
if
(buf[0] !=
'/'
&& buf[0] !=
'\0'
)
79
// printf("-I- CbmStsParAsciiFileIo container name: %s",
80
// pPar->GetName());
81
pPar->readline(buf, set, pFile);
82
}
83
pPar->setInputVersion(1, inputNumber);
84
pPar->setChanged();
85
Bool_t
allFound =
kTRUE
;
86
// if (allFound) printf("%s initialized from Ascii file\n",name);
87
printf(
"%s initialized from Ascii file\n"
, name);
88
89
return
allFound;
90
}
91
92
template
<
class
T>
93
Int_t
CbmStsParAsciiFileIo::writeFile2
(T* pPar)
94
{
95
// template function for all parameter containers with 2 levels
96
// writes the header, loops over the container and calls its member
97
// function writeline(...)
98
pPar->putAsciiHeader(fHeader);
99
writeHeader(pPar->GetName());
100
// Text_t buf[155];
101
/*
102
Int_t n0 = (*pPar).getSize();
103
for(Int_t i0=0; i0<n0; i0++) {
104
Int_t n1 = (*pPar)[i0].getSize();
105
for(Int_t i1=0; i1<n1; i1++) {
106
if (pPar->writeline(buf,i0,i1))
107
pFile->write(buf,strlen(buf));
108
}
109
}
110
pPar->setChanged(kFALSE);
111
pFile->write(sepLine,strlen(sepLine));
112
*/
113
return
1;
114
}
Bool_t
bool Bool_t
Int_t
int Int_t
Text_t
char Text_t
kFALSE
constexpr Bool_t kFALSE
kTRUE
constexpr Bool_t kTRUE
CbmStsDigiPar
Definition
CbmStsDigiPar.h:31
CbmStsParAsciiFileIo::init
Bool_t init(FairParSet *)
Definition
CbmStsParAsciiFileIo.cxx:27
CbmStsParAsciiFileIo::read
Bool_t read(T *, Int_t *, Bool_t needsClear=kFALSE)
Definition
CbmStsParAsciiFileIo.cxx:59
CbmStsParAsciiFileIo::CbmStsParAsciiFileIo
CbmStsParAsciiFileIo(fstream *)
Definition
CbmStsParAsciiFileIo.cxx:20
CbmStsParAsciiFileIo::writeFile2
Int_t writeFile2(T *)
Definition
CbmStsParAsciiFileIo.cxx:93
CbmStsParAsciiFileIo::write
Int_t write(FairParSet *)
Definition
CbmStsParAsciiFileIo.cxx:43
FairDetParAsciiFileIo
FairParSet
CbmStsDigiPar.h
CbmStsParAsciiFileIo.h
detectors
sts
CbmStsParAsciiFileIo.cxx
Generated on
for BmnRoot by
1.17.0