CFEL - ASG Software Suite  2.5.0
CASS
hdf5_converter.h
Go to the documentation of this file.
1 // Copyright (C) 2010 Lutz Foucar
2 
3 /**
4  * @file hdf5_converter.h declaration of pp1001 (hdf5_converter)
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _HDF5_CONVERTER_H_
10 #define _HDF5_CONVERTER_H_
11 
12 #include <string>
13 #include <list>
14 #include <hdf5.h>
15 
16 #include "processor.h"
17 
18 namespace cass
19 {
20 
21 namespace hdf5
22 {
23 class WriteEntry;
24 }//end namespace hdf5
25 
26 /** saves a selected 2d histogram to hdf5
27  *
28  * @PPList "1002": saves a selected 2d histogram to hdf5
29  *
30  * it will just save one histogram in a file and then write the next into the
31  * next hdf5 file. Inside the hdf5 it uses the same layout that the Chapman
32  * crew is using to be able to read and process the hdf5 with crystfel
33  *
34  * @cassttng Processor/\%name\%/{CompressLevel} \n
35  * The compression level. Default is 2
36  * @cassttng Processor/\%name\%/{FileBaseName} \n
37  * Base Name of the Files to be written. In case of writing mutiple
38  * Events to the same file an alpha counter will be added to the file
39  * name. In case of writing an event to a single file the event id
40  * Will be appended to the file name.
41  * @cassttng Processor/\%name\%/{WriteMultipleEventsInOneFile} \n
42  * Flag to tell whether to write multiple events to the same file
43  * (true) or each event into a single file (false). Default is false.
44  * @cassttng Processor/\%name\%/{WriteToSingleDatasets} \n
45  * In case one writes multiple events into the same file, this flag
46  * allows to tell, that the data will be written into a single dataset.
47  * The dataset will have an additional dimension in the slowest axis
48  * that holds the data of all the events. In addition to that a
49  * dataset is written that lists all the eventids of the events that
50  * are written.
51  * Default is false.
52  * @cassttng Processor/\%name\%/{MaximumNbrFilesPerDir} \n
53  * In case of single files per event, distribute the files over
54  * subdirectories where each subdir contains this amount of files.
55  * If -1 it will not distribute the files. Default is -1.
56  * @cassttng Processor/\%name\%/{MaximumFileSize_GB} \n
57  * In case of multiple events per file, this is the maximum file size
58  * before the alpha counter of the filename will be increased and a
59  * the events will be written to the new file. Default is 200
60  * @cassttng Processor/\%name\%/Processor/{size} \n
61  * How many Processors should be written to the h5 file.
62  * @cassttng Processor/\%name\%/Processor/\%id\%/{Name} \n
63  * Name of the Processor that should be written into the h5 file.
64  * Default is "unknown"
65  * @cassttng Processor/\%name\%/Processor/\%id\%/{GroupName} \n
66  * Name of the group in the h5 file into which the Processor
67  * should be written into. Default is "/"
68  * @cassttng Processor/\%name\%/Processor/\%id\%/{ValName} \n
69  * Name that the data should have in the h5 file. Default is the
70  * name of the Processor.
71  * @cassttng Processor/\%name\%/ProcessorSummary/{size} \n
72  * How many Processors should be written to the h5 file.
73  * @cassttng Processor/\%name\%/ProcessorSummary/\%id\%/{Name} \n
74  * Name of the Processor that should be written into the h5 file.
75  * Default is "unknown"
76  * @cassttng Processor/\%name\%/ProcessorSummary/\%id\%/{GroupName} \n
77  * Name of the group in the h5 file into which the Processor
78  * should be written into. Default is "/"
79  * @cassttng Processor/\%name\%/ProcessorSummary/\%id\%/{ValName} \n
80  * Name that the data should have in the h5 file. Default is the
81  * name of the Processor.
82  *
83  * @todo enable that one can write into just one h5 file multiple events
84  *
85  * @author Lutz Foucar
86  */
87 class pp1002 : public Processor
88 {
89 public:
90  /** struct bundleing info for writing an entry to file
91  *
92  * @author Lutz Foucar
93  */
94  struct entry_t
95  {
96  /** constructor
97  *
98  * @param _name the name of the value in the file
99  * @param _groupname the group where the data will be written to
100  * @param _options the options for writing
101  * @param _proc the processor holding the data to be written
102  */
103  entry_t(const std::string &_name,
104  const std::string &_groupname,
105  const uint32_t _options,
106  shared_pointer _proc)
107  : name(_name), groupname(_groupname), options(_options),proc(_proc)
108  {}
109 
110  /** name of the value in the file */
111  std::string name;
112 
113  /** group where the data will be written to */
114  std::string groupname;
115 
116  /** options for writing */
117  uint32_t options;
118 
119  /** processor holding the data to be written */
121  };
122 
123  /** constructor */
124  pp1002(const name_t &);
125 
126  /** process the event */
127  virtual void processEvent(const CASSEvent&);
128 
129  /** dump all pp histograms to summary group just before quitting */
130  virtual void aboutToQuit();
131 
132  /** load the settings of this pp */
133  virtual void loadSettings(size_t);
134 
135  /** overwrite the retrieval of an histogram */
136  virtual const result_t& result(const CASSEvent::id_t eventid=0);
137 
138  /** overwrite the release */
139  virtual void releaseEvent(const CASSEvent &){}
140 
141 protected:
142  /** write the summary to a file that contains multiple events */
144 
145  /** function to write the events to a file that contains multiple events
146  *
147  * @param evt The event containg the data to write
148  */
149  void writeEventToMultipleEventsFile(const CASSEvent &evt);
150 
151  /** function to write the events to a file that contains multiple events
152  *
153  * append the static size results to a single dataset with one more dimension
154  *
155  * @param evt The event containg the data to write
156  */
158 
159  /** function to write the summary to a single file */
161 
162  /** function to write the events to a single file
163  *
164  * @param evt The event containg the data to write
165  */
166  void writeEventToSingleFile(const CASSEvent &evt);
167 
168 protected:
169  /** the filename that the data will be written to */
170  std::string _basefilename;
171 
172  /** container with all pps that contain the histograms to dump to hdf5 */
173  std::list<entry_t> _procList;
174 
175  /** container for all pps that should be written when program quits */
176  std::list<entry_t> _procSummaryList;
177 
178  /** the number of files in each subdir */
180 
181  /** counter to count how many files have been written */
183 
184  /** define pointer to the entry writer */
185  typedef std::tr1::shared_ptr<hdf5::WriteEntry> entryWriter_t;
186 
187  /** the entry writer */
188  entryWriter_t _entryWriter;
189 
190  /** the maximum file size of the single file */
191  size_t _maxFileSize;
192 
193  /** write summary to file */
194  std::tr1::function<void(void)> _writeSummary;
195 
196  /** write event to file */
197  std::tr1::function<void(const CASSEvent&)> _writeEvent;
198 
199 private:
200  /** a lock to make the process reentrant */
202 };
203 }//end namespace cass
204 #endif
std::string name
name of the value in the file
Event to store all LCLS Data.
Definition: cass_event.h:32
virtual void loadSettings(size_t)
load the settings of this pp
std::list< entry_t > _procSummaryList
container for all pps that should be written when program quits
check if FEL is off by checking for bykick which is eventid
pp1002(const name_t &)
constructor
std::tr1::shared_ptr< hdf5::WriteEntry > entryWriter_t
define pointer to the entry writer
size_t _maxFileSize
the maximum file size of the single file
void writeEventToSingleFile(const CASSEvent &evt)
function to write the events to a single file
virtual void processEvent(const CASSEvent &)
process the event
uint64_t id_t
define the id type
Definition: cass_event.h:52
void writeEventToMultipleEventsFile(const CASSEvent &evt)
function to write the events to a file that contains multiple events
std::tr1::function< void(const CASSEvent &)> _writeEvent
write event to file
std::tr1::function< void(void)> _writeSummary
write summary to file
entry_t(const std::string &_name, const std::string &_groupname, const uint32_t _options, shared_pointer _proc)
constructor
base class for processors.
Definition: processor.h:39
void writeSummaryToSingleFile()
function to write the summary to a single file
int _maxFilePerSubDir
the number of files in each subdir
std::string groupname
group where the data will be written to
struct bundleing info for writing an entry to file
void appendEventToMultipleEventsFile(const CASSEvent &evt)
function to write the events to a file that contains multiple events
void writeSummaryToMultipleEventsFile()
write the summary to a file that contains multiple events
std::list< entry_t > _procList
container with all pps that contain the histograms to dump to hdf5
uint32_t options
options for writing
virtual void releaseEvent(const CASSEvent &)
overwrite the release
file contains processors baseclass declaration
saves a selected 2d histogram to hdf5
entryWriter_t _entryWriter
the entry writer
const name_t _name
the processors name
Definition: processor.h:259
shared_pointer proc
processor holding the data to be written
virtual const result_t & result(const CASSEvent::id_t eventid=0)
overwrite the retrieval of an histogram
QMutex _lock
a lock to make the process reentrant
std::string name_t
define the name type
Definition: processor.h:46
virtual void aboutToQuit()
dump all pp histograms to summary group just before quitting
std::tr1::shared_ptr< Processor > shared_pointer
a shared pointer of this
Definition: processor.h:43
int _filecounter
counter to count how many files have been written
std::string _basefilename
the filename that the data will be written to