CFEL - ASG Software Suite  2.5.0
CASS
sacla_converter.h
Go to the documentation of this file.
1 // Copyright (C) 2014, 2015 Lutz Foucar
2 
3 /**
4  * @file sacla_converter.h contains class to convert sacla data to cassevent
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _SACLACONVERTER_
10 #define _SACLACONVERTER_
11 
12 #include <DataAccessUserAPI.h>
13 
14 #include "cass.h"
15 #include "pixeldetector.hpp"
16 
17 namespace cass
18 {
19 class CASSEvent;
20 
21 /** Class for reading SACLA data.
22  *
23  * This class will interface the API provided by SACLA to retrieve the available
24  * data. One can use it to retrieve data from the Database, Octal Detector and
25  * other detectors.
26  *
27  * The additional data of the MPCCD, such as the position, angle, gain,
28  * width and height will be written in to the BeamlineData and can be
29  * retrieved for each tile using the tilename:
30  * - "%tilename%_Width": The number of pixels in X
31  * - "%tilename%_Height": The number of pixels in Y
32  * - "%tilename%_PosX_um": The x position of the tile in um
33  * - "%tilename%_PosY_um": The y position of the tile in um
34  * - "%tilename%_PosZ_um": The z position of the tile in um
35  * - "%tilename%_Angle_deg": The angle of the tile in deg
36  * - "%tilename%_PixSize_um": The pixel size in um
37  * - "%tilename%_AbsGain": The absolute gain of the tile
38  *
39  * @cassttng SACLAConverter/{RetrieveAcceleratorData}\n
40  * Flag that tells whether the accelerator data should be retrieved.
41  * Default is true. When set to true the following data is available
42  * in the Machine Data:
43  * - "Acc_electronEnergy_eV"
44  * - "Acc_KParams"
45  * - "Acc_PhotonEnergy"
46  * @cassttng SACLAConverter/OctalPixelDetectors/{size}\n
47  * The number of octal MPCCD detectors one wants to retrieve. Be sure
48  * that for each detector there is a unique id in the list below.
49  * @cassttng SACLAConverter/OctalPixelDetectors/\%index\%/{DetectorName}\n
50  * The base name of the octal MPCCD. Unlike the API this name will be
51  * used to determine the names of the individual tiles of the MPCCD.
52  * Default is "Invalid" which will caus to skip this index.
53  * @cassttng SACLAConverter/OctalPixelDetectors/\%index\%/{CASSID}\n
54  * The id of the detector that CASS will use internally. Default is "0".
55  * @cassttng SACLAConverter/OctalPixelDetectors/\%index\%/{NormalizeToAbsGain}\n
56  * Using this option one can control whether the pixel values of the
57  * individual tiles will be normalized to the gain value of the first
58  * tile. When true, the pixel values of tiles 2 to 8 will modified
59  * using:
60  * \f$ pixval_{tile} = \frac{gain_{tile}}{gain_{tile1}}*pixval_{tile}\f$
61  * Default is true.
62  * @cassttng SACLAConverter/DatabaseValues/{size}\n
63  * The number of values one wants to retrieve from the database. Be sure
64  * that for each detector there is a unique id in the list below.
65  * @cassttng SACLAConverter/DatabaseValues/\%index\%/{ValueName}\n
66  * The name of the database value to retrieve. Default is "Invalid"
67  * which will cause to skip that index.
68  * @cassttng SACLAConverter/DatabaseValues/\%index\%/{CASSName}\n
69  * The name of the value that the database value should have within
70  * the cassevent. Default is the same name as ValueName
71  *
72  * @author Lutz Foucar
73  */
75 {
76 public:
77  /** constructor */
79 
80  /** read data from SaclaDataAccessUserAPI
81  *
82  * @return size of the filled data in bytes
83  * @param highTagNbr first part of the tag
84  * @param tagNbr the acutal Tag
85  * @param event the CASSEvent where the data will be put into
86  */
87  uint64_t operator()(const int highTagNbr,
88  const int tagNbr,
89  CASSEvent& event);
90 
91  /** load the settings of the reader */
92  void loadSettings();
93 
94  /** retrieve requested beamline parameters in one go
95  *
96  * this is a hack to improve speed, as requesting parameters for each tag
97  * individually seems to be a bottleneck
98  *
99  * @param first iterator to the first tag in the list
100  * @param last iterator to one beyond the last tag in the list
101  * @param blNbr the beamline number for the experiment
102  * @param runNbr the run number for the experiment
103  * @param highTagNbr the high tagnumber for the tag list
104  */
105  void cacheParameters(std::vector<int>::const_iterator first,
106  std::vector<int>::const_iterator last,
107  int blNbr, int runNbr, int highTagNbr);
108 
109 private:
110  /** container for the cached machine value */
112  {
113  /** the name of the machine value within the database */
114  std::string databaseName;
115 
116  /** the name of the machine value within the cassevent */
117  std::string cassName;
118 
119  /** define map with tags as key and value and mapped type */
120  typedef std::map<int, double> values_t;
121 
122  /** map that contains the tag as key and value for the value
123  * associated with the tag
124  */
125  values_t values;
126  };
127 
128  /** define the machine values */
129  typedef std::vector<MachineValue> machineVals_t;
130 
131  /** the list of requested machine values */
132  machineVals_t _machineVals;
133 
134 public:
135  /** non changeing parameters of a pixel detector tile */
137  {
138  /** constructor
139  *
140  * set the default parameters of the members
141  */
143  : name(""),
144  xsize(0),
145  ysize(0),
146  nPixels(0),
147  datasize_bytes(0),
148  pixsizex_um(0),
149  pixsizey_um(0),
150  posx_um(0),
151  posy_um(0),
152  posz_um(0),
153  angle_deg(0),
154  gain(0),
155  bytes_retrieved(0),
156  normalize(false),
157  relativeGain(1),
158  sreader(NULL),
159  readBuf(NULL)
160  {}
161 
162  /** destruct the tile parameter */
163  ~detTileParams();
164 
165  /** init the tile reader
166  *
167  * @throws SaclaPixDetError when SACLA USER API function returned an error
168  *
169  * @return status of the initialization
170  * @param runNbr the runnumber to intialize the stream reader with
171  * @param blNbr the beamline number to initialize the stream reader with
172  */
173  void init(int runNbr, int blNbr);
174 
175  /** retrieve data from streamer into buffer
176  *
177  * @NOTE one has to intialize the streamer using @see init
178  * prior to calling this function
179  *
180  * @throws SaclaPixDetError when SACLA USER API function returned an error
181  *
182  * @param tag the tag for which the data should be read
183  */
184  void readFromStreamer(unsigned int tag);
185 
186  /** cache the non-changing data
187  *
188  * @NOTE one has to intialize the streamer using @see init and then
189  * retrieve data into the readbuffer using @see readFromStreamer
190  * prior to calling this function
191  *
192  * @throws SaclaPixDetError when SACLA USER API function returned an error
193  *
194  * @return true when caching worked, false when error occured
195  */
196  void cache();
197 
198  /** copy data to frame
199  *
200  * retrieve the data from the buffer and normalize it directly
201  * to the right position within the frame
202  *
203  * @NOTE one has to intialize the streamer using @see init and then
204  * retrieve data into the readbuffer using @see readFromStreamer
205  * prior to calling this function
206  *
207  * @throws SaclaPixDetError when SACLA USER API function returned an error
208  *
209  * @param pos iterator to the frame in the cassevent
210  */
211  void copyTo(pixeldetector::Detector::frame_t::iterator pos);
212 
213  /** the name of the tile */
214  std::string name;
215 
216  /** the number of columns of the tile */
217  uint32_t xsize;
218 
219  /** the number of rows of the tile */
220  uint32_t ysize;
221 
222  /** the number of pixles of this tile */
223  uint32_t nPixels;
224 
225  /** the size of the frame in bytes */
227 
228  /** the x size of a pixel in um */
229  float pixsizex_um;
230 
231  /** the y size of a pixel in um */
232  float pixsizey_um;
233 
234  /** the position in x in lab space of the tile in um */
235  float posx_um;
236 
237  /** the position in y in lab space of the tile in um */
238  float posy_um;
239 
240  /** the position in z in lab space of the tile in um */
241  float posz_um;
242 
243  /** the angle in degree in lab space of the tile */
244  float angle_deg;
245 
246  /** the absolute gain of the tile */
247  float gain;
248 
249  /** the number of bytes retrieved for this tile */
251 
252  /** flag to tell whether the data of this tile should be normalized to
253  * another tile
254  */
255  bool normalize;
256 
257  /** the realtive gain with respect to the tile that this tile should be
258  * normalized to
259  */
261 
262  /** a stream reader object for the tile */
263  char * sreader;
264 
265  /** a read buffer object for the tile */
266  char * readBuf;
267  };
268 
269  /** detector consists of tiles */
270  struct detParams
271  {
272  /** intitalize to default values */
274  : normalize(false),
275  CASSID(-1),
276  notLoaded(true),
277  nCols(0),
278  nRows(0),
279  nPixels(0)
280  {}
281 
282  /** vector containing the tiles of this detector */
283  std::vector<detTileParams> tiles;
284 
285  /** flag to tell whether the individual tiles of this detector should be
286  * normalized to the first tile
287  */
288  bool normalize;
289 
290  /** the id of the detector within the CASSEvent */
291  int CASSID;
292 
293  /** flag to tell whether the non-changeing data of this tile has been loaded */
294  bool notLoaded;
295 
296  /** the total nbr of colums of the det */
297  size_t nCols;
298 
299  /** the total nbr of rows of the det */
300  size_t nRows;
301 
302  /** the total nbr of pixels of the det */
303  size_t nPixels;
304  };
305 
306  /** define the pixel detectors container type */
307  typedef std::vector<detParams> pixDets_t;
308 
309 private:
310  /** the list of requested machine values */
311  pixDets_t _pixelDetectors;
312 
313  /** the list of requested octal detectors */
314  pixDets_t _octalDetectors;
315 };
316 }//end namespace cass
317 #endif
uint64_t operator()(const int highTagNbr, const int tagNbr, CASSEvent &event)
read data from SaclaDataAccessUserAPI
detector consists of tiles
Event to store all LCLS Data.
Definition: cass_event.h:32
uint32_t xsize
the number of columns of the tile
size_t nPixels
the total nbr of pixels of the det
float gain
the absolute gain of the tile
Class for reading SACLA data.
void init(int runNbr, int blNbr)
init the tile reader
float posy_um
the position in y in lab space of the tile in um
SACLAConverter()
constructor
void cacheParameters(std::vector< int >::const_iterator first, std::vector< int >::const_iterator last, int blNbr, int runNbr, int highTagNbr)
retrieve requested beamline parameters in one go
std::string cassName
the name of the machine value within the cassevent
std::vector< detParams > pixDets_t
define the pixel detectors container type
void cache()
cache the non-changing data
size_t bytes_retrieved
the number of bytes retrieved for this tile
machineVals_t _machineVals
the list of requested machine values
std::vector< detTileParams > tiles
vector containing the tiles of this detector
void loadSettings()
load the settings of the reader
std::vector< MachineValue > machineVals_t
define the machine values
float relativeGain
the realtive gain with respect to the tile that this tile should be normalized to ...
bool normalize
flag to tell whether the data of this tile should be normalized to another tile
float angle_deg
the angle in degree in lab space of the tile
int datasize_bytes
the size of the frame in bytes
values_t values
map that contains the tag as key and value for the value associated with the tag
pixDets_t _octalDetectors
the list of requested octal detectors
int CASSID
the id of the detector within the CASSEvent
float posz_um
the position in z in lab space of the tile in um
float pixsizey_um
the y size of a pixel in um
uint32_t nPixels
the number of pixles of this tile
float pixsizex_um
the x size of a pixel in um
size_t nRows
the total nbr of rows of the det
std::string databaseName
the name of the machine value within the database
size_t nCols
the total nbr of colums of the det
file contains global definitions for project cass
~detTileParams()
destruct the tile parameter
void copyTo(pixeldetector::Detector::frame_t::iterator pos)
copy data to frame
detParams()
intitalize to default values
std::map< int, double > values_t
define map with tags as key and value and mapped type
float posx_um
the position in x in lab space of the tile in um
char * readBuf
a read buffer object for the tile
contains container for simple pixel detector data
std::string name
the name of the tile
pixDets_t _pixelDetectors
the list of requested machine values
bool notLoaded
flag to tell whether the non-changeing data of this tile has been loaded
uint32_t ysize
the number of rows of the tile
char * sreader
a stream reader object for the tile
non changeing parameters of a pixel detector tile
container for the cached machine value
void readFromStreamer(unsigned int tag)
retrieve data from streamer into buffer
bool normalize
flag to tell whether the individual tiles of this detector should be normalized to the first tile ...