CFEL - ASG Software Suite  2.5.0
CASS
file_parser.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file file_parser.cpp contains the base class for all file parsers
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <sstream>
10 #include <stdexcept>
11 #include <iostream>
12 
13 #include "file_parser.h"
14 
15 #include "lma_parser.h"
16 #include "raw_sss_parser.h"
17 #include "frms6_parser.h"
18 #include "txt_parser.h"
19 #include "file_reader.h"
20 #include "log.h"
21 
22 #ifdef LCLSLIBRARY
23 #include "xtc_parser.h"
24 #endif
25 
26 using namespace cass;
27 using namespace std;
28 using namespace std::tr1;
29 
31  event2positionreaders_t &event2posreader,
32  QReadWriteLock &lock)
33  : lmf::PausableThread(),
34  _readerpointerpair(readerpointerpair),
35  _event2posreader(event2posreader),
36  _lock(lock)
37 {}
38 
40 {}
41 
43  const filereaderpointerpair_t readerpointerpair,
44  event2positionreaders_t &event2posreader,
45  QReadWriteLock &lock)
46 {
47  shared_pointer ptr;
48  if (type == "lma")
49  ptr = shared_pointer(new ACQIRIS::LMAParser(readerpointerpair,event2posreader, lock));
50  else if (type == "txt")
51  ptr = shared_pointer(new TxtParser(readerpointerpair,event2posreader, lock));
52 #ifdef LCLSLIBRARY
53  else if (type == "xtc")
54  ptr = shared_pointer(new XtcParser(readerpointerpair,event2posreader, lock));
55 #endif
56  else
57  throw invalid_argument("FileParser::instance: file extension '"+ type +
58  "' is unknown.");
59  return ptr;
60 }
61 
62 void FileParser::savePos(const std::streampos& eventStartPos, const uint64_t eventId)
63 {
64  _readerpointerpair.second._pos = eventStartPos;
65  if (!eventId)
66  {
67  Log::add(Log::WARNING,"FileParser::savePos: EventId '"+ toString(eventId) +
68  "' from parser type '"+type()+"' of seems to be wrong; skipping event.");
69  return;
70  }
71  QWriteLocker lock(&_lock);
72  _event2posreader[eventId].push_back(_readerpointerpair);
73 }
event2positionreaders_t & _event2posreader
reference to the map containing the beginnings of the event
Definition: file_parser.h:87
contains class to parse xtc files
static shared_pointer instance(const std::string type, const filereaderpointerpair_t readerpointerpair, event2positionreaders_t &event2posreader, QReadWriteLock &lock)
create an instance of the requested type
Definition: file_parser.cpp:42
contains base class for all file parsers
STL namespace.
class for parsing xtc files
Definition: xtc_parser.h:27
Will parse a txt files.
Definition: txt_parser.h:23
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
filereaderpointerpair_t _readerpointerpair
the file pointer
Definition: file_parser.h:84
std::tr1::shared_ptr< FileParser > shared_pointer
typedef the shared pointer of this
Definition: file_parser.h:45
contains class to parse a txt ascii file
contains base class for all file readers
QReadWriteLock & _lock
Lock that protects the map.
Definition: file_parser.h:90
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
void savePos(const std::streampos &eventStartPos, const uint64_t eventId)
put current file position in the eventmap
Definition: file_parser.cpp:62
std::pair< std::tr1::shared_ptr< FileReader >, FilePointer > filereaderpointerpair_t
pair of a file pointer with the associated file reader
Definition: cass.h:276
contains class to parse a frms6 file created by Xonline.
FileParser(const filereaderpointerpair_t readerpointerpair, event2positionreaders_t &event2posreader, QReadWriteLock &lock)
constructor
Definition: file_parser.cpp:30
virtual ~FileParser()
virtual destructor
Definition: file_parser.cpp:39
contains class to parse a lma file
contains class to parse a file containing the commercial ccd images created by Per Johnsonns program...
std::map< uint64_t, positionreaders_t > event2positionreaders_t
the list of events contained in a file with the associated position and reader
Definition: cass.h:282
virtual const std::string type()
Definition: file_parser.h:69
Will parse a lma file.
Definition: lma_parser.h:22
contains a logger for cass