Psyllid  v1.12.4
Project 8 Data Acquisisition Software
butterfly_house.hh
Go to the documentation of this file.
1 /*
2  * butterfly_house.hh
3  *
4  * Created on: Feb 11, 2016
5  * Author: nsoblath
6  *
7  * Monarch stages:
8  * - initialized
9  * - preparing
10  * - writing
11  * - finished
12  *
13  * Thread safety
14  * Thread-safe operations:
15  * - All butterfly_house function calls
16  * - Initializing an egg file
17  * - Accessing the Monarch header (can only be done by one thread at a time)
18  * - Writing data to a file (handled by HDF5's internal thread safety)
19  * - Finishing an egg file
20  *
21  * Non-thread-safe operations:
22  * - Stream function calls are not thread-safe other than HDF5's internal thread safety.
23  * It is highly (highly highly) recommended that you only access a given stream from one thread.
24  */
25 
26 #ifndef PSYLLID_BUTTERFLY_HOUSE_HH_
27 #define PSYLLID_BUTTERFLY_HOUSE_HH_
28 
29 #include "control_access.hh"
30 #include "monarch3_wrap.hh"
31 
32 #include "member_variables.hh"
33 #include "singleton.hh"
34 
35 namespace scarab
36 {
37  class param_node;
38 }
39 
40 namespace psyllid
41 {
42  class egg_writer;
43 
56  class butterfly_house : public scarab::singleton< butterfly_house >, public control_access
57  {
58  public:
59  mv_accessible( double, max_file_size_mb );
60 
61  public:
62  void register_file( unsigned a_file_num, const std::string& a_filename, const std::string& a_description, unsigned a_duration_ms );
63 
64  void prepare_files( const scarab::param_node& a_files_config );
65 
66  void start_files();
67 
68  void finish_files();
69 
70  void register_writer( egg_writer* a_writer, unsigned a_file_num );
71 
72  void unregister_writer( egg_writer* a_writer );
73 
74  void set_filename( const std::string& a_filename, unsigned a_file_num = 0 );
75  const std::string& get_filename( unsigned a_file_num );
76 
77  void set_description( const std::string& a_desc, unsigned a_file_num = 0 );
78  const std::string& get_description( unsigned a_file_num );
79 
80  private:
81  struct file_info
82  {
83  std::string f_filename;
84  std::string f_description;
85  };
86  typedef std::vector< file_info > file_infos_t;
87  typedef file_infos_t::const_iterator file_infos_cit;
88  typedef file_infos_t::iterator file_infos_it;
89  file_infos_t f_file_infos;
90 
91  std::vector< monarch_wrap_ptr > f_mw_ptrs;
92  std::multimap< egg_writer*, unsigned > f_writers;
93 
94  mutable std::mutex f_house_mutex;
95 
96  private:
97  friend class scarab::singleton< butterfly_house >;
98  friend class scarab::destroyer< butterfly_house >;
99 
100  butterfly_house();
101  virtual ~butterfly_house();
102 
103  };
104 
105 } /* namespace psyllid */
106 
107 #endif /* PSYLLID_BUTTERFLY_HOUSE_HH_ */
Base class for all writers.
Definition: egg_writer.hh:24
std::vector< file_info > file_infos_t
Responsible for starting files. Holds pointer to monarch.
Gives other classes access to daq_control.
file_infos_t::const_iterator file_infos_cit
std::vector< monarch_wrap_ptr > f_mw_ptrs
std::multimap< egg_writer *, unsigned > f_writers
file_infos_t::iterator file_infos_it