CFEL - ASG Software Suite  2.5.0
CASS
xtc_reader.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file xtc_reader.cpp contains the class to read xtc files
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include "pdsdata/xtc/Dgram.hh"
10 
11 #include <tr1/memory>
12 
13 #include "xtc_reader.h"
14 
15 #include "cass_event.h"
16 #include "format_converter.h"
17 #include "cass_settings.h"
18 #include "log.h"
19 
20 using namespace cass;
21 using namespace std;
22 using std::tr1::shared_ptr;
23 
24 void readDgramHeaderToBuf(ifstream &file, CASSEvent::buffer_t &buf)
25 {
26  buf.resize(sizeof(Pds::Dgram));
27  file.read(&buf.front(),sizeof(Pds::Dgram));
28 }
29 
30 void readDgramPayloadToBuf(ifstream &file, CASSEvent::buffer_t &buf)
31 {
32  Pds::Dgram& dg(reinterpret_cast<Pds::Dgram&>(buf.front()));
33  const int payloadSize(dg.xtc.sizeofPayload());
34  buf.resize(sizeof(Pds::Dgram) + payloadSize);
35  file.read(&buf[sizeof(Pds::Dgram)], payloadSize);
36 }
37 
39  : FileReader("xtc"),
40  _convert(*FormatConverter::instance())
41 {}
42 
44 {
46 }
47 
48 void XtcReader::readHeaderInfo(std::ifstream &file)
49 {
50  std::tr1::shared_ptr<CASSEvent> event(new CASSEvent);
51  CASSEvent::buffer_t& buf(event->datagrambuffer());
52  while(1)
53  {
54  const streampos eventstartpos(file.tellg());
55  readDgramHeaderToBuf(file,buf);
56  Pds::Dgram& dg(reinterpret_cast<Pds::Dgram&>(buf.front()));
57  if (dg.seq.service() != Pds::TransitionId::L1Accept)
58  {
59  readDgramPayloadToBuf(file,buf);
60  _convert(event.get());
61  }
62  else
63  {
64  file.seekg(eventstartpos);
65  break;
66  }
67  }
68 }
69 
70 bool XtcReader::operator ()(ifstream &file, CASSEvent& event)
71 {
72  CASSEvent::buffer_t& buf(event.datagrambuffer());
73  readDgramHeaderToBuf(file,buf);
74  readDgramPayloadToBuf(file,buf);
75  return (_convert(&event));
76 }
Event to store all LCLS Data.
Definition: cass_event.h:32
file contains declaration of the CASSEvent
file contains declaration of the container for all format converters
void readHeaderInfo(std::ifstream &file)
read the file header
Definition: xtc_reader.cpp:48
STL namespace.
contains class to read xtc files
Format converter container.
bool operator()(std::ifstream &file, CASSEvent &event)
read the xtc file contents put them into cassevent
Definition: xtc_reader.cpp:70
std::vector< char > buffer_t
a buffer type
Definition: cass_event.h:49
base class for all file readers
Definition: file_reader.h:24
XtcReader()
constructor
Definition: xtc_reader.cpp:38
void readDgramHeaderToBuf(ifstream &file, CASSEvent::buffer_t &buf)
Definition: xtc_reader.cpp:24
FormatConverter & _convert
a reference to the format converter functor
Definition: xtc_reader.h:60
buffer_t & datagrambuffer()
setters
Definition: cass_event.h:65
file contains specialized class that do the settings for cass
void loadSettings()
load the settings of the reader
Definition: xtc_reader.cpp:43
contains a logger for cass
void loadSettings(size_t what)
function to load the settings for the format converter
void readDgramPayloadToBuf(ifstream &file, CASSEvent::buffer_t &buf)
Definition: xtc_reader.cpp:30