CFEL - ASG Software Suite  2.5.0
CASS
pixeldetector.hpp
Go to the documentation of this file.
1 //Copyright (C) 2011, 2015 Lutz Foucar
2 
3 /**
4  * @file pixeldetector.hpp contains container for simple pixel detector data
5  *
6  * @author Lutz Foucar
7  */
8 
9 
10 #ifndef _PIXEL_DETECTOR_HPP_
11 #define _PIXEL_DETECTOR_HPP_
12 
13 #include <iostream>
14 #include <vector>
15 #include <map>
16 #include <string>
17 #include <stdint.h>
18 
19 #include "serializable.hpp"
20 #include "device_backend.hpp"
21 
22 namespace cass
23 {
24 namespace pixeldetector
25 {
26 
27 /** Detector containing a ccd camera image.
28  *
29  * This class represents a ccd camera image with all its properties.
30  *
31  * @author Lutz Foucar
32  * @author Nicola Coppola
33  */
34 class Detector : public Serializable
35 {
36 public:
37  /** constructor */
39  : Serializable(1),
40  _columns(0),
41  _rows(0)
42  {}
43 
44  /** constructor
45  *
46  * constructs the Detector from data contained in the serialzer
47  *
48  * @param in the serializer object to read the data from
49  */
51  : Serializable(1)
52  {
53  deserialize(in);
54  }
55 
56 public:
57 /** define a pixel of the pixel detector */
58 typedef float pixel_t;
59 
60 /** a frame is a vector of pixels */
61 typedef std::vector<pixel_t> frame_t;
62 
63 /** define a shape of an image columnsxrows */
64 typedef std::pair<size_t,size_t> shape_t;
65 
66 public:
67  /** serialize the data to the Serializer
68  *
69  * serializes the frame, the info about colums and rows to the serializer.
70  *
71  * @param out the serializer object that the data will be serialzed to
72  */
73  void serialize(SerializerBackend &out)const
74  {
75  writeVersion(out);
76  /** write the columns rows and then the frame */
77  out.add(_columns);
78  out.add(_rows);
79  for (frame_t::const_iterator it=_frame.begin();it!=_frame.end();++it)
80  out.add(*it);
81  }
82 
83  /** deserialize the data from the Serializer
84  *
85  * reads the frame the info about columns and rows from the serialzer
86  *
87  * @return true when de serialization was successfull
88  * @param in the serializer object to read the data from
89  */
91  {
92  checkVersion(in);
93  /** get the number of columns and rows */
94  _columns = in.retrieve<uint16_t>();
95  _rows = in.retrieve<uint16_t>();
96  /** clear the frame and read it from the stream */
97  _frame.clear();
98  const int nPixels(_columns*_rows);
99  for (int i(0); i < nPixels;++i)
100  _frame.push_back(in.retrieve<frame_t::value_type>());
101  return true;
102  }
103 
104 public:
105  //@{
106  /** setter */
107  uint16_t &columns() {return _columns;}
108  uint16_t &rows() {return _rows;}
109  frame_t &frame() {return _frame;}
110  uint32_t &camaxMagic() {return _camaxMagic;}
111  std::string &info() {return _info;}
112  std::string &timingFilename() {return _timingFilename;}
113  uint64_t &id() {return _eventID;}
114  //@}
115  //@{
116  /** getter */
117  uint16_t columns()const {return _columns;}
118  uint16_t rows()const {return _rows;}
119  shape_t shape()const {return std::make_pair(_columns,_rows);}
120  const frame_t &frame()const {return _frame;}
121  uint32_t camaxMagic()const {return _camaxMagic;}
122  const std::string &info()const {return _info;}
123  const std::string &timingFilename()const {return _timingFilename;}
124  uint64_t id()const {return _eventID;}
125  //@}
126 
127 private:
128  /** Linear array of CCD data.
129  *
130  * see cass::pixeldetector::Converter for layout
131  */
132  frame_t _frame;
133 
134  /** number of columns of the frame */
135  uint16_t _columns;
136 
137  /** number of rows of the frame */
138  uint16_t _rows;
139 
140  /** magic camax info, encodes ie. the gain of the ccd (pnCCD specific)*/
141  uint32_t _camaxMagic;
142 
143  /** infostring of the detector, telling the name of the detector (pnCCD specific) */
144  std::string _info;
145 
146  /** filename of the file containing the timing info of the sequenzer (pnCCD specific)*/
147  std::string _timingFilename;
148 
149  /** the eventid that this detector belongs to (can be used for crosschecks */
150  uint64_t _eventID;
151 };
152 
153 /** the device containing pixel detector data
154  *
155  * @author Lutz Foucar
156  */
157 class Device : public DeviceBackend
158 {
159 public:
160  /** define the detector container */
161  typedef std::map<int32_t,Detector> detectors_t;
162 
163  /** constructor.*/
165  : DeviceBackend(1)
166  {}
167 
168 public:
169  /** instrument setter*/
170  detectors_t &dets() {return _detectors;}
171 
172  /** instrument getter*/
173  const detectors_t &dets()const {return _detectors;}
174 
175  /** serialize the data to the Serializer
176  *
177  * serializes the key within the map and then the detector to the serializer.
178  *
179  * @param out the serializer object that the data will be serialzed to
180  */
181  void serialize(SerializerBackend &out)const
182  {
183  writeVersion(out);
184  /** write how many items in the container there are */
185  out.add(static_cast<size_t>(_detectors.size()));
186  /** write the keys of the detector and the detector itself */
187  detectors_t::const_iterator it(_detectors.begin());
188  for(; it != _detectors.end(); ++it)
189  {
190  out.add(it->first);
191  it->second.serialize(out);
192  }
193  }
194 
195  /** deserialize the data from the Serializer
196  *
197  * reads the frame the the key and then the detctor from the serializer
198  *
199  * @return true when de serialization was successfull
200  * @param in the serializer object to read the data from
201  */
203  {
204  checkVersion(in);
205  /** read the number of detectors */
206  size_t nbrDetectors(in.retrieve<size_t>());
207  /** read the key of the detector and then deserialze the detector */
208  for(uint32_t i(0); i < nbrDetectors; ++nbrDetectors)
209  {
210  detectors_t::key_type key(in.retrieve<detectors_t::key_type>());
211  _detectors[key] = Detector(in);
212  }
213  return true;
214  }
215 
216 private:
217  /** Container for all pixel detectors */
218  detectors_t _detectors;
219 };
220 
221 }//end namespace pixeldetectors
222 }//end namespace cass
223 #endif
definition of front detector[PixelDetectors] FrontPnCCD Detector
uint32_t camaxMagic() const
getter
void serialize(SerializerBackend &out) const
serialize the data to the Serializer
Detector(SerializerBackend &in)
constructor
frame_t _frame
Linear array of CCD data.
std::string _info
infostring of the detector, telling the name of the detector (pnCCD specific)
std::string & info()
setter
uint32_t _camaxMagic
magic camax info, encodes ie.
uint16_t columns() const
getter
void serialize(SerializerBackend &out) const
serialize the data to the Serializer
detectors_t & dets()
instrument setter
virtual void writeVersion(SerializerBackend &out) const
write the version to the stream
uint64_t _eventID
the eventid that this detector belongs to (can be used for crosschecks
const detectors_t & dets() const
instrument getter
std::pair< size_t, size_t > shape_t
define a shape of an image columnsxrows
uint16_t _columns
number of columns of the frame
float pixel_t
define a pixel of the pixel detector
contains base class for all devices that are part of the cassevent.
const frame_t & frame() const
getter
file contains base class all serializable classes
shape_t shape() const
getter
bool deserialize(SerializerBackend &in)
deserialize the data from the Serializer
const std::string & timingFilename() const
getter
std::vector< pixel_t > frame_t
a frame is a vector of pixels
std::string & timingFilename()
setter
detectors_t _detectors
Container for all pixel detectors.
const std::string & info() const
getter
uint16_t _rows
number of rows of the frame
virtual void checkVersion(SerializerBackend &in) const
check the version
uint32_t & camaxMagic()
setter
uint16_t rows() const
getter
the device containing pixel detector data
uint64_t id() const
getter
Type retrieve()
read arbitrary value from stream
Definition: serializer.hpp:169
Detector containing a ccd camera image.
A Baseclass for all Devices in the CASSEvent.
std::map< int32_t, Detector > detectors_t
define the detector container
Serializable.
void add(const Type &value)
add arbitrary value to the stream
Definition: serializer.hpp:158
std::string _timingFilename
filename of the file containing the timing info of the sequenzer (pnCCD specific) ...
bool deserialize(SerializerBackend &in)
deserialize the data from the Serializer