CFEL - ASG Software Suite  2.5.0
CASS
shm_deserializer.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file shm_deserializer.cpp contains functors to
5  * deserialize the data stream sent by shm2tcp.
6  *
7  * @author Lutz Foucar
8  */
9 
10 #include <QtCore/QDataStream>
11 
12 #include "shm_deserializer.h"
13 
14 #include "cass_event.h"
15 #include "pixeldetector.hpp"
16 #include "hlltypes.hpp"
17 
18 using namespace cass;
19 using namespace pixeldetector;
20 using namespace std;
21 using Streaming::operator >>;
22 
24 {
26  stream >> fileHead;
27  _width = fileHead.the_width;
28  return sizeof(hllDataTypes::Frms6FileHeader);
29 }
30 
32 {
33  size_t nBytesRead(0);
34  /** read frame header and calculate the frame data size from the contained
35  * info. Set the eventid according to the id in the info Then read the frame
36  * from the stream into the frame buffer.
37  */
38  hllDataTypes::FrameHeader frameHead;
39  stream >> frameHead;
40  nBytesRead += sizeof(hllDataTypes::FrameHeader);
41  evt.id() = frameHead.external_id;
42  const size_t framesize(_width * frameHead.the_height);
43  const size_t framesizeBytes(framesize * sizeof(hllDataTypes::pixel));
44  _hllFrameBuffer.resize(framesize);
45  stream.readRawData(reinterpret_cast<char*>(&_hllFrameBuffer.front()), framesizeBytes);
46  nBytesRead += framesizeBytes;
47 
48  /** get the detector associated with the frame info id from the event */
49  CASSEvent::devices_t &devices(evt.devices());
50  CASSEvent::devices_t::iterator devIt(devices.find(CASSEvent::PixelDetectors));
51  if(devIt == devices.end())
52  throw runtime_error("SHMStreamer: There is no pixeldetector device within the CASSEvent");
53  Device &dev(dynamic_cast<Device&>(*(devIt->second)));
54  Detector &det(dev.dets()[frameHead.id]);
55  det.id() = evt.id();
56 
57  /** set the information of the frame to the detector */
58  det.columns() = _width/2;
59  det.rows() = frameHead.the_height*2;
60  det.frame().resize(_hllFrameBuffer.size());
61 
62  /** convert the hll type frame to the cass type frame */
63  const size_t quadrantColumns = frameHead.the_height;
64  const size_t quadrantRows = quadrantColumns; /** @todo: read out somehow? */
65  const size_t HLLColumns = _width;
66  hllDataTypes::HLL2CASS(_hllFrameBuffer,det.frame(),quadrantColumns,quadrantRows,HLLColumns);
67 
68  return nBytesRead;
69 }
Event to store all LCLS Data.
Definition: cass_event.h:32
file contains declaration of the CASSEvent
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.
contains the layout of the hll data types and conversion to cass data types
the header that describe the frames
Definition: hlltypes.hpp:82
contains functors to deserialize the data stream sent by shm2tcp.
readRawData(char *s, int len)
size_t operator()(QDataStream &stream, CASSEvent &evt)
deserialize stream
devices_t & devices()
setters
Definition: cass_event.h:66
uint16_t the_width
the true number of channels
Definition: hlltypes.hpp:66
id_t & id()
setters
Definition: cass_event.h:64
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
Definition: cass_event.h:46
contains container for simple pixel detector data
the device containing pixel detector data
Detector containing a ccd camera image.
int16_t pixel
define a pixel
Definition: hlltypes.hpp:27