25 #include <TCollection.h>
26 #include <THashTable.h>
42 fName =
"FairGenericParIo";
52 if (pPar->InheritsFrom(
"FairParGenericSet")) {
53 return readGenericSet(static_cast<FairParGenericSet *>(pPar));
56 Error(
"init(FairParSet*)",
"%s does not inherit from FairParGenericSet", pPar->
GetName());
66 if (pPar->InheritsFrom(
"FairParGenericSet")) {
67 return writeGenericSet(static_cast<FairParGenericSet *>(pPar));
69 Error(
"write(FairParSet*)",
"%s does not inherit from FairParGenericSet", pPar->
GetName());
74 const UChar_t *FairGenericParAsciiFileIo::readData(type t,
const Char_t *format, TString &line, Int_t &length)
77 const Int_t st =
sizeof(t);
78 const Int_t maxbuf = 8000;
79 const Int_t bufSizeExt = 10000 * st;
80 const Char_t d[] =
" \t";
83 Int_t l = 0, bufSize = bufSizeExt;
84 UChar_t *val =
new UChar_t[bufSize];
85 Ssiz_t m = line.Last(
'\\');
87 sscanf(line.Data(), format, &t);
88 memcpy(&val[l], &t, st);
92 pFile->getline(buf, maxbuf);
93 if (buf[0] !=
'/' && buf[0] !=
'#') {
96 if (m > 0 && m < s.Length()) {
99 if ((bufSize - 1000) < l) {
100 bufSize += bufSizeExt;
101 UChar_t *va =
new UChar_t[bufSize];
106 Char_t *ss = strtok(const_cast<Char_t *>(s.Data()), d);
108 sscanf(ss, format, &t);
109 memcpy(&val[l], &t, st);
111 ss = strtok(NULL, d);
114 }
while (buf[0] !=
'#' && !
pFile->eof() && m > 0);
121 void FairGenericParAsciiFileIo::writeData(type *val, Int_t nParams)
125 while (k < nParams) {
130 *
pFile << val[k] <<
" ";
144 pFile->seekg(0, ios::beg);
145 const Text_t *name = (pPar->
GetName());
151 const Char_t d[] =
" \t";
153 const Int_t maxbuf = 8000;
156 TString s, pName, pVal, pType;
158 while (buf[0] !=
'#' && !
pFile->eof()) {
159 pFile->getline(buf, maxbuf);
160 if (buf[0] !=
'/' && buf[0] !=
'#') {
167 Error(
"readCond(FairParGenericSet*)",
"%s:\n Missing backslash for parameter %s", name, pName.Data());
172 s = s(n + 1, s.Length() - n - 1);
173 s = s.Strip(s.kLeading);
174 if (pName.CompareTo(
"author") == 0 || pName.CompareTo(
"description") == 0) {
182 pFile->getline(buf, maxbuf);
195 if (pName.CompareTo(
"author") == 0) {
197 }
else if (pName.CompareTo(
"description") == 0) {
201 Char_t *ss = strtok(const_cast<Char_t *>(s.Data()), d);
203 Int_t mt = s.Index(pType);
204 s = s(mt + pType.Length() + 1, s.Length() - mt - pType.Length() - 1);
205 if (pType.CompareTo(
"Text_t") == 0) {
212 pFile->getline(buf, maxbuf);
225 pVal = pVal.Strip(pVal.kLeading);
226 if (pVal.Length() > 0) {
227 paramList->
add(pName.Data(), pVal.Data());
230 const UChar_t *val = 0;
232 if (pType.CompareTo(
"Int_t") == 0) {
234 val = readData(v,
"%i", s, length);
235 }
else if (pType.CompareTo(
"Float_t") == 0) {
237 val = readData(v,
"%f", s, length);
238 }
else if (pType.CompareTo(
"Double_t") == 0) {
240 val = readData(v,
"%lf", s, length);
241 }
else if (pType.CompareTo(
"Char_t") == 0) {
243 val = readData(v,
"%c", s, length);
245 Error(
"readCond(FairParGenericSet*)",
246 "%s:\n Parameter %s with unsupported type %s",
255 UChar_t *pValue = obj->
setLength(length);
256 memcpy(pValue, val, length);
257 paramList->
getList()->Add(obj);
263 Bool_t allFound = pPar->
getParams(paramList);
267 printf(
"%s initialized from Ascii file\n", name);
280 const Text_t *name = pPar->
GetName();
283 *
pFile <<
"# Class: " << name <<
"\n# Context: " << context <<
"\n";
285 *
pFile <<
"[" << name <<
"]\n";
287 *
pFile <<
"//-----------------------------------------------------------"
288 "-----------------\n";
291 THashTable *pList = paramList->
getList();
294 while ((po = static_cast<FairParamObj *>(next()))) {
297 if (po->
isBasicType() && strcmp(pType,
"UChar_t") != 0) {
298 if (strcmp(pType,
"Text_t") == 0) {
299 TString val(reinterpret_cast<Char_t *>(pValue), po->
getLength());
300 val.ReplaceAll(
"\n",
" \\\n");
301 *
pFile << po->GetName() <<
": " << pType <<
" \\\n " << val.Data() << std::endl;
305 *
pFile << po->GetName() <<
": " << pType <<
" ";
307 *
pFile << po->GetName() <<
": " << pType <<
" \\\n ";
309 if (strcmp(pType,
"Char_t") == 0) {
310 writeData(reinterpret_cast<Char_t *>(pValue), nParams);
311 }
else if (strcmp(pType,
"Int_t") == 0) {
312 writeData(reinterpret_cast<Int_t *>(pValue), nParams);
313 }
else if (strcmp(pType,
"Float_t") == 0) {
314 writeData(reinterpret_cast<Float_t *>(pValue), nParams);
315 }
else if (strcmp(pType,
"Double_t") == 0) {
316 writeData(reinterpret_cast<Double_t *>(pValue), nParams);
320 Error(
"writeCond(FairParGenericSet*)",
321 "Type %s of parameter %s not supported by ASCII I/O",
332 Error(
"writeCond(FairParGenericSet*)",
"Output is not writable");
const char * getParamContext() const
virtual const char * GetName() const
const char * getParamType()
Bool_t findContainer(const Text_t *name)
pointer to ascii file
void setChanged(Bool_t flag=kTRUE)
Int_t write(FairParSet *)
ClassImp(FairEventBuilder)
virtual Bool_t getParams(FairParamList *)=0
Bool_t init(FairParSet *)
TString sepLine
header of container output in file
UChar_t * setLength(Int_t l)
UChar_t * getParamValue()
FairGenericParAsciiFileIo(std::fstream *f=0)
std::fstream * pFile
comment line
void setInputVersion(Int_t v=-1, Int_t i=0)
virtual void putParams(FairParamList *)=0
void writeComment(FairParSet *)
void setParamType(const Text_t *t)
void setAuthor(const char *s)
void setDescription(const char *s)