CFEL - ASG Software Suite  2.5.0
CASS
txt_parser.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file txt_parser.cpp contains class to parse txt ascii files
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <fstream>
10 #include <iostream>
11 #include <tr1/memory>
12 
13 #include "txt_parser.h"
14 
15 #include "cass_settings.h"
16 #include "file_reader.h"
17 #include "cass_event.h"
18 #include "input_base.h"
19 
20 using namespace cass;
21 using namespace std;
22 using namespace std::tr1;
23 
25 {
26  ifstream &file(*(_readerpointerpair.second._filestream));
27  file.seekg (0, ios::end);
28  const streampos filesize(file.tellg());
29  file.seekg (0, ios::beg);
30 
31  FileReader& read(*_readerpointerpair.first);
32  read.readHeaderInfo(file);
33 
34  std::tr1::shared_ptr<CASSEvent> event(new CASSEvent);
35  streampos eventstartpos;
36  while((!InputBase::reference().shouldQuit()) && (file.tellg()<filesize))
37  {
38  eventstartpos = file.tellg();
39  read(file,*event);
40  savePos(eventstartpos,event->id());
41  }
42 
43 // Splitter split;
44 // string headerline;
45 // vector<string> headers;
46 // while (true)
47 // {
48 // getline(file, headerline);
49 // headers.clear();
50 // split(headerline,headers,delim);
51 // if (!headers.empty() &&
52 // !QString::fromStdString(headerline).contains("GMD (GMD_DATA) - GMD main vlaues"))
53 // break;
54 // }
55 // cout <<"TxtParser: the txt file contains the following variables:";
56 // vector<string>::const_iterator h(headers.begin());
57 // for (; h != headers.end();++h)
58 // cout <<"'"<<*h<<"',";
59 // cout <<endl;
60 
61 // string line;
62 // vector<double> values;
63 // map<string,double> head2value;
64 // streampos eventstartpos;
65 // while(file.tellg()<filesize)
66 // {
67 // while(true)
68 // {
69 // eventstartpos = file.tellg();
70 // getline(file, line);
71 // values.clear();
72 // split(line,values,delim);
73 // if (!values.empty())
74 // break;
75 // }
76 // if(headers.size() != values.size())
77 // throw runtime_error("TxtParser():There are not enough values for the amount of values suggested by the header");
78 
79 // vector<double>::const_iterator value(values.begin());
80 // vector<string>::const_iterator head(headers.begin());
81 // for (;value != values.end(); ++value, ++head)
82 // {
83 // head2value[*head] = *value;
84 //// cout << "'"<<*head<<"'="<<*value<<", ";
85 // }
86 //// cout <<endl;
87 // const uint64_t eventId(head2value[eventIdhead]);
88 // savePos(eventstartpos,eventId);
89 // }
90 }
Event to store all LCLS Data.
Definition: cass_event.h:32
file contains declaration of the CASSEvent
STL namespace.
virtual void readHeaderInfo(std::ifstream &)
read the file header
Definition: file_reader.h:61
base class for all file readers
Definition: file_reader.h:24
void read(const std::string &filename, std::string &headerstring, std::vector< float > &matrix, std::pair< int, int > &shape)
read the cbf data into a linearized 2d array
Definition: cbf_handle.hpp:191
contains class to parse a txt ascii file
contains base class for all file readers
contains the base class for all input modules
file contains specialized class that do the settings for cass
void runthis()
parse the frms6 file
Definition: txt_parser.cpp:24
static shared_pointer::element_type & reference()
get reference to the singelton instance
Definition: input_base.cpp:28