EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairDetParAsciiFileIo.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairDetParAsciiFileIo.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Created : 21/10/2004
3 //*-- modified : 28/01/2009 by Ilse Koenig
5 // FairDetParAsciiFileIo
6 //
7 // Class for parameter input/output from/into Ascii file
8 // Base class for all detector Ascii I/Os
9 //
11 
12 
13 #include "FairDetParAsciiFileIo.h"
14 #include "FairParSet.h"
15 
16 using std::ios;
17 
18 
19 
20 
21 
23  :FairDetParIo(),
24  fHeader(""),
25  sepLine("##############################################################################\n"),
26  pFile(f)
27 {
28  // constructor
29  /* pFile=f;
30  sepLine=
31  "##############################################################################\n";
32  */
33 }
34 
35 
37 {
38  // searches the container in the file
39  const Int_t maxbuf=4000;
40  Text_t buf[maxbuf];
41  Text_t buf2[maxbuf];
42  sprintf(buf2,"%s%s%s","[",name,"]");
43  pFile->clear();
44  pFile->seekg(0,ios::beg);
45  while (!pFile->eof()) {
46  pFile->getline(buf,maxbuf);
47  if (buf[0]!='[') { continue; }
48  if (!strncmp(buf,buf2,strlen(buf2))) { break; }
49  }
50  if (pFile->eof()) { return kFALSE; }
51  return kTRUE;
52 }
53 
54 
55 Bool_t FairDetParAsciiFileIo::checkAllFound(Int_t* set, Int_t setSize)
56 {
57  // checks if all modules have been initialized
58  Bool_t allFound=kTRUE;
59  for(Int_t i=0; i<setSize; i++) {
60  if (set[i]==999) {
61  set[i]=0;
62  printf(" %i",i);
63  }
64  if (set[i]) { allFound=kFALSE; }
65  }
66  printf("\n");
67  return allFound;
68 }
69 
70 
71 void FairDetParAsciiFileIo::writeHeader(const Text_t* name, const Text_t* context,
72  const Text_t* author, const Text_t* description)
73 {
74  // calls the function putAsciiHeader(...) of the parameter container
75  // class and writes the header to the file
76  pFile->write(sepLine,strlen(sepLine));
77  pFile->write(fHeader.Data(),fHeader.Length());
78  pFile->write(sepLine,strlen(sepLine));
79  *pFile<<"["<<name<<"]\n";
80  if (strlen(context)>0) { *pFile<<"// Parameter Context: "<<context<<"\n"; }
81  if (strlen(author)>0) { *pFile<<"author: "<<author<<"\n"; }
82  TString t=description;
83  if (!t.IsNull()) {
84  t=t.ReplaceAll("\n"," \\\n");
85  *pFile<<"description: "<<t<<"\n";
86  }
87  *pFile<<"//-----------------------------------------------------------"
88  "-----------------\n";
89 }
90 
91 
92 void FairDetParAsciiFileIo::readComment(const Char_t* lastBuf, FairParSet* pPar)
93 {
94  // reads the author or the description
95  const Int_t maxbuf=4000;
96  Text_t buf[maxbuf];
97  TString s=lastBuf;
98  TString pName, pVal;
99  Ssiz_t n=s.First(':');
100  Ssiz_t m=s.Last('\\');
101  pName=s(0,n);
102  if (m>0) { pVal=s(n+1,m-n-1); }
103  else { pVal=s(n+1,s.Length()-n-1); }
104  pVal=pVal.Strip(pVal.kLeading);
105  while (m>0) {
106  pVal+="\n";
107  pFile->getline(buf,maxbuf);
108  if (buf[0]!='/') {
109  s=buf;
110  m=s.Last('\\');
111  if (m>0) { pVal+=s(0,m); }
112  else { pVal+=s; }
113  }
114  }
115  if (pName.CompareTo("author")==0) { pPar->setAuthor(pVal.Data()); }
116  else if ( pName.CompareTo("description")==0) { pPar->setDescription(pVal.Data()); }
117 }
118 
120 {
121  TString t=pPar->getAuthor();
122  if (!t.IsNull()) { *pFile<<"author: "<<t<<"\n"; }
123  t=pPar->getDescription();
124  if (!t.IsNull()) {
125  t=t.ReplaceAll("\n"," \\\n");
126  *pFile<<"description: "<<t<<"\n";
127  }
128 }
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
153 /*
154 FairDetParAsciiFileIo::FairDetParAsciiFileIo(fstream* f) {
155  // constructor
156  pFile=f;
157  sepLine=
158  "##############################################################################\n";
159 }
160 
161 Bool_t FairDetParAsciiFileIo::findContainer(const Text_t* name) {
162  // searches the container in the file
163  const Int_t maxbuf=4000;
164  Text_t buf[maxbuf];
165  Text_t buf2[maxbuf];
166  sprintf(buf2,"%s%s%s","[",name,"]");
167  pFile->clear();
168  pFile->seekg(0,ios::beg);
169  while (!pFile->eof()) {
170  pFile->getline(buf,maxbuf);
171  if (buf[0]!='[') continue;
172  if (!strncmp(buf,buf2,strlen(buf2))) break;
173  }
174  if (pFile->eof()) return kFALSE;
175  return kTRUE;
176 }
177 
178 void FairDetParAsciiFileIo::writeHeader(const Text_t* name, const Text_t* context,
179  const Text_t* author, const Text_t* description) {
180  // calls the function putAsciiHeader(...) of the parameter container
181  // class and writes the header to the file
182  pFile->write(sepLine,strlen(sepLine));
183  pFile->write(fHeader.Data(),fHeader.Length());
184  pFile->write(sepLine,strlen(sepLine));
185  *pFile<<"["<<name<<"]\n";
186  if (strlen(context)>0) *pFile<<"// Parameter Context: "<<context<<"\n";
187  if (strlen(author)>0) *pFile<<"author: "<<author<<"\n";
188  TString t=description;
189  if (!t.IsNull()) {
190  t=t.ReplaceAll("\n"," \\\n");
191  *pFile<<"description: "<<t<<"\n";
192  }
193  *pFile<<"//-----------------------------------------------------------"
194  "-----------------\n";
195 }
196 
197 void FairDetParAsciiFileIo::readComment(const char* lastBuf, FairParSet* pPar) {
198  // reads the author or the description
199  const Int_t maxbuf=4000;
200  Text_t buf[maxbuf];
201  TString s=lastBuf;
202  TString pName, pVal;
203  Ssiz_t n=s.First(':');
204  Ssiz_t m=s.Last('\\');
205  pName=s(0,n);
206  if (m>0) pVal=s(n+1,m-n-1);
207  else pVal=s(n+1,s.Length()-n-1);
208  pVal=pVal.Strip(pVal.kLeading);
209  while (m>0) {
210  pVal+="\n";
211  pFile->getline(buf,maxbuf);
212  if (buf[0]!='/') {
213  s=buf;
214  m=s.Last('\\');
215  if (m>0) pVal+=s(0,m);
216  else pVal+=s;
217  }
218  }
219  if (pName.CompareTo("author")==0) pPar->setAuthor(pVal.Data());
220  else if ( pName.CompareTo("description")==0) pPar->setDescription(pVal.Data());
221 }
222 
223 void FairDetParAsciiFileIo::writeComment(FairParSet* pPar) {
224  TString t=pPar->getAuthor();
225  if (!t.IsNull()) *pFile<<"author: "<<t<<"\n";
226  t=pPar->getDescription();
227  if (!t.IsNull()) {
228  t=t.ReplaceAll("\n"," \\\n");
229  *pFile<<"description: "<<t<<"\n";
230  }
231 }
232 */