BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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///////////////////////////////////////////////////////////////
11
12#include "CbmStsDigiPar.h"
13
14#include <iostream>
15
16using std::cerr;
17using std::cout;
18using std::endl;
19
22{
23 // constructor calls the base class constructor
24 fName = "CbmStsParIo";
25}
26
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
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
58template<class T>
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
92template<class T>
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 Bool_t
int Int_t
char Text_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
Bool_t init(FairParSet *)
Bool_t read(T *, Int_t *, Bool_t needsClear=kFALSE)
Int_t write(FairParSet *)