CFEL - ASG Software Suite  2.5.0
CASS
raw_sss_reader.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 Lutz Foucar
2 
3 /**
4  * @file raw_sss_reader.cpp contains the class to read
5  * commercial ccd files created with Per Johnsonn's program
6  *
7  * @author Lutz Foucar
8  */
9 #include <sstream>
10 #include <stdexcept>
11 
12 #include "raw_sss_reader.h"
13 
14 #include "cass_event.h"
15 #include "pixeldetector.hpp"
16 #include "log.h"
17 
18 using namespace cass;
19 using namespace pixeldetector;
20 using namespace std;
21 using Streaming::operator >>;
22 
24  : FileReader("sss"),
25  _imagecounter(0)
26 {}
27 
29 {
30 }
31 
32 void RAWSSSReader::readHeaderInfo(std::ifstream &file)
33 {
34  _imagecounter = 0;
35  file >> _header;
36  _imageBuffer.resize(_header.width*_header.height,0);
37  _imageSize = _imageBuffer.size() * sizeof(sssFile::image_t::value_type);
38  Log::add(Log::VERBOSEINFO,"RAWSSSReader(): '" + _filename +"' contains '" +
39  toString(_header.nFrames) +"' images");
40 }
41 
42 bool RAWSSSReader::operator ()(ifstream &file, CASSEvent& event)
43 {
44  ++_imagecounter;
46  throw runtime_error("RAWSSSReader(): We are trying to read more '" +
47  toString(_imagecounter) + "' images in '" + _filename +
48  "' than there reported to be in the file header '" +
49  toString(_header.nFrames) + "'");
50  event.id() = Streaming::retrieve<uint32_t>(file);
51 
52  file.read(reinterpret_cast<char*>(&_imageBuffer.front()),_imageSize);
53 
54  CASSEvent::devices_t &devices(event.devices());
55  CASSEvent::devices_t::iterator devIt(devices.find(CASSEvent::PixelDetectors));
56  if(devIt == devices.end())
57  throw runtime_error("RAWSSSReader: There is no pixeldetector device within the CASSEvent");
58  Device &dev(dynamic_cast<Device&>(*(devIt->second)));
59  Detector &det(dev.dets()[100]);
60  det.id() = event.id();
61  det.columns() = _header.width;
62  det.rows() = _header.height;
63  det.frame().resize(_imageBuffer.size());
64 
65  copy(_imageBuffer.begin(),_imageBuffer.end(),det.frame().begin());
66 
67  return event.id();
68 }
Event to store all LCLS Data.
Definition: cass_event.h:32
void loadSettings()
load the settings of the reader
void readHeaderInfo(std::ifstream &file)
read the file header
file contains declaration of the CASSEvent
detectors_t & dets()
instrument setter
STL namespace.
contains class to read commercial ccd files created with Per Johnsonn's program
bool operator()(std::ifstream &file, CASSEvent &event)
read the raw.sss file contents put them into cassevent
base class for all file readers
Definition: file_reader.h:24
static void add(Level level, const std::string &line)
add a string to the log
Definition: log.cpp:31
uint32_t width
width of the frame
devices_t & devices()
setters
Definition: cass_event.h:66
uint32_t nFrames
number of frames contained in file
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
std::map< Device, DeviceBackend::shared_pointer > devices_t
mapping from device type to handler instance
Definition: cass_event.h:46
std::string _filename
the name of the file that we read the values from
Definition: file_reader.h:92
contains container for simple pixel detector data
the device containing pixel detector data
sssFile::Header _header
the file header information
uint32_t _imagecounter
counter to see how many images have been read from file
Detector containing a ccd camera image.
size_t _imageSize
the length of the image in bytes
contains a logger for cass
sssFile::image_t _imageBuffer
buffer for images
uint32_t height
the height of the frame