12 using namespace
Diana;
13 using
std::istringstream;
15 using
std::stringstream;
19 fQObjectCache =
new std::map<std::string, QObject*>;
35 err.SetDescription(
GetName(),__LINE__,std::string(
"Cannot open file: ") + filename);
53 if(className ==
"Diana::QBaseType<int>") {
55 }
else if(className ==
"Diana::QBaseType<float>") {
57 }
else if(className ==
"Diana::QBaseType<double>") {
59 }
else if(className ==
"Diana::QBool") {
61 }
else if(className ==
"Diana::QString") {
73 std::map<std::string, QObject*>::const_iterator
object =
fQObjectCache->find(name);
78 int startline, endline;
79 string startstring, endstring;
87 err.SetDescription(
GetName(),__LINE__,
"no file is open");
91 startstring =
"# begin " + name;
96 err.SetDescription(
GetName(),__LINE__,std::string(
"Failed to find line: \"") + startstring +
"\"");
100 endstring =
"# end " + name;
105 if(readstring ==
"# QVector")
109 else if(readstring ==
"# QVectorC")
114 obj =
new QVectorC(*real, *imag);
116 else if(readstring ==
"# QTime")
120 else if(readstring ==
"# QMatrix")
123 istringstream iss(readstring);
126 if(!(iss >> c >> nrow >> ncol)) {
128 err.SetDescription(
GetName(),__LINE__,std::string(
"Cannot read row and column numbers of object ") + name);
134 for(
int i=0; i<ncol; i++)
144 istringstream iss(readstring);
145 char c;
string objtype;
146 if(!(iss>>c>>objtype)) {
148 err.SetDescription(
GetName(),__LINE__,std::string(
"Cannot read type of object ") + name);
154 msg<<
"Object \""<<name<<
"\" has invalid type \""<<objtype<<
"\"";
156 err.SetDescription(
GetName(),__LINE__,msg.str());
159 int line = startline+1;
160 while(line <= endline) {
162 if(!readstring.empty() && readstring.at(0) !=
'#') data<<readstring<<std::endl;;
165 err = obj->ReadFromStream(data);
171 msg<<
"Error while reading object \""<< name <<
"\": "<<
err.GetDescription();
172 err.SetDescription(
GetName(),__LINE__,msg.str());
181 (*fQObjectCache)[name] = obj;
191 int startline, endline;
192 string startstring, endstring;
197 err.SetDescription(
GetName(),__LINE__,
"no file is open");
202 startstring =
"# begin " + name;
207 err.SetDescription(
GetName(),__LINE__,std::string(
"Failed to find line: \"") + startstring +
"\"");
211 endstring =
"# end " + name;
232 err.SetDescription(
GetName(),__LINE__,
"no file is open");
236 startstring =
"# begin " + name;
241 err.SetDescription(
GetName(),__LINE__,std::string(
"Failed to find line: \"") + startstring +
"\"");
246 obj = atoi(readstring.c_str());
263 err.SetDescription(
GetName(),__LINE__,
"no file is open");
267 startstring =
"# begin " + name;
272 err.SetDescription(
GetName(),__LINE__,std::string(
"Failed to find line: \"") + startstring +
"\"");
277 obj = atof(readstring.c_str());
295 err.SetDescription(
GetName(),__LINE__,
"no file is open");
299 startstring =
"# begin " + name;
304 err.SetDescription(
GetName(),__LINE__,std::string(
"Failed to find line: \"") + startstring +
"\"");
309 istringstream ss(readstring);
328 err.SetDescription(
GetName(),__LINE__,
"no file is open");
331 startstring =
"# begin " + name;
337 err.SetDescription(
GetName(),__LINE__,std::string(
"Failed to find line: \"") + startstring +
"\"");
342 istringstream ss(readstring);
QBaseType< double > QDouble
double wrapped in a QObject
QBaseType< int > QInt
int wrapped in a QObject
QBaseType< float > QFloat
float wrapped in a QObject
#define REGISTER_GLOBAL_READER(clazz, ext)
global reader for txt files
bool GetBool(const std::string &name, QError &err) const
float GetFloat(const std::string &name, QError &err) const
QError Open(const std::string &filename, const std::string &opt="")
Open file, called by QGlobalReaderDispatcher.
QError Close()
Close file, called by QGlobalReaderDispatcher.
const Diana::QObject * GetQObject(const std::string &name, const std::string &className, QError &err) const
int GetInt(const std::string &name, QError &err) const
std::string GetString(const std::string &name, QError &err) const
std::map< std::string, Diana::QObject * > * fQObjectCache
double GetDouble(const std::string &name, QError &err) const
Class for reading and writing ascii text files.
bool Exists()
Returns true if the file exists and can be opened.
std::string ReadString(int startline=0, int endline=-1)
Reads entire file or subset of file into a string.
int FindLine(std::string pattern, int startline=0)
Finds a line matching the string pattern.
Diana::QVector * ReadQVector()
Reads a text file into a QVector. Text file should contain a list of numbers.
Diana::QTime * ReadQTime(int startline=0)
Reads an object of type QTime.
bool wrapped into a QObject
error class with error type and description
Abstract class for global readers.
Interface for matrices in Diana analysis.
void SetCol(UInt_t ncol, const QVector &vec)
set column to specific vector
const std::string & GetName() const
static QObject * New(const char *object)
string wrapped into a QObject
the Diana namespace is needed because sometimes we use Qt libraries, that use same class names of our...