CFEL - ASG Software Suite  2.5.0
CASS
frms6_reader.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file frms6_reader.cpp contains class to read frms6 files
5  * created by Xonline
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <iterator>
11 
12 #include "frms6_reader.h"
13 
14 #include "cass_event.h"
15 #include "cass.h"
16 #include "pixeldetector.hpp"
17 
18 using namespace cass;
19 using namespace pixeldetector;
20 using namespace std;
21 using Streaming::operator >>;
22 
24  : FileReader("frms6")
25 {}
26 
28 {
29 }
30 
31 void Frms6Reader::readHeaderInfo(std::ifstream &file)
32 {
33  file >> _fileHead;
34 }
35 
36 bool Frms6Reader::operator ()(ifstream &file, CASSEvent& evt)
37 {
38  /** read frame header and calculate the frame data size from the contained
39  * info. Set the eventid according to the id in the info Then read the frame
40  * from the stream into the frame buffer.
41  */
42  file >> _frameHead;
43  evt.id() = _frameHead.external_id;
44  const size_t framesize(_fileHead.the_width * _frameHead.the_height);
45  const size_t framesizeBytes(framesize * sizeof(hllDataTypes::pixel));
46  _hllFrameBuffer.resize(framesize);
47  file.read(reinterpret_cast<char*>(&_hllFrameBuffer.front()), framesizeBytes);
48 
49  /** get the detector associated with the frame info id from the event */
50  CASSEvent::devices_t &devices(evt.devices());
51  CASSEvent::devices_t::iterator devIt(devices.find(CASSEvent::PixelDetectors));
52  if(devIt == devices.end())
53  throw runtime_error("Frms6Reader: There is no pixeldetector device within the CASSEvent");
54  Device &dev(dynamic_cast<Device&>(*(devIt->second)));
55  Detector &det(dev.dets()[_frameHead.id]);
56  det.id() = evt.id();
57 
58  /** set the information of the frame to the detector */
59  det.columns() = _fileHead.the_width/2;
60  det.rows() = _frameHead.the_height*2;
61  det.frame().resize(_hllFrameBuffer.size());
62 
63  /** convert hll frame format to cass frame format */
64  size_t quadrantColumns = _frameHead.the_height;
65  size_t quadrantRows = quadrantColumns; /** @todo: read out somehow? */
66  size_t HLLColumns = _fileHead.the_width;
67  hllDataTypes::HLL2CASS(_hllFrameBuffer,det.frame(),quadrantColumns,quadrantRows,HLLColumns);
68 
69  return (evt.id());
70 }
Event to store all LCLS Data.
Definition: cass_event.h:32
file contains declaration of the CASSEvent
hllDataTypes::FrameHeader _frameHead
header that comes before every frame
Definition: frms6_reader.h:61
void HLL2CASS(const inputContainerType &HLLMatrix, outputContainerType &CASSMatrix, size_t quadrantColumns, size_t quadrantRows, size_t HLLColumns)
convert a linearised matrix in the hll format to the CASS format
Definition: hlltypes.hpp:322
detectors_t & dets()
instrument setter
STL namespace.
bool operator()(std::ifstream &file, CASSEvent &event)
read the frms6 file contents put them into cassevent
base class for all file readers
Definition: file_reader.h:24
devices_t & devices()
setters
Definition: cass_event.h:66
uint16_t the_width
the true number of channels
Definition: hlltypes.hpp:66
file contains global definitions for project cass
contains class to read frms6 files created by Xonline.
id_t & id()
setters
Definition: cass_event.h:64
void loadSettings()
load the settings of the reader
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
Definition: cass_event.h:46
void readHeaderInfo(std::ifstream &file)
read the file header
contains container for simple pixel detector data
the device containing pixel detector data
Detector containing a ccd camera image.
hllDataTypes::Frms6FileHeader _fileHead
the frms6 file header
Definition: frms6_reader.h:58
std::vector< hllDataTypes::pixel > _hllFrameBuffer
a buffer to not allocate the read buffer for each event
Definition: frms6_reader.h:64
int16_t pixel
define a pixel
Definition: hlltypes.hpp:27