26 f_max_file_size_mb( 500 ),
32 LDEBUG(
plog,
"Butterfly house has been built" );
47 if( a_daq_config.empty() )
53 f_file_infos.resize( a_daq_config.get_value(
"n-files", 1U ) );
54 set_max_file_size_mb( a_daq_config.get_value(
"max-file-size-mb", get_max_file_size_mb() ) );
60 std::stringstream t_filename_sstr;
62 t_filename_sstr <<
"psyllid_out_" << t_file_num <<
".egg";
63 fi_it->f_filename = t_filename_sstr.str();
64 fi_it->f_description =
"";
65 LPROG(
plog,
"Prepared file <" << t_file_num <<
">; default filename is <" << fi_it->f_filename <<
">" );
76 LERROR(
plog,
"Unable to get access to the DAQ control" );
77 throw error() <<
"Butterfly house is unable to get access to the DAQ control";
81 LINFO(
plog,
"Starting egg3 files" );
86 for(
unsigned t_file_num = 0; t_file_num <
f_file_infos.size(); ++t_file_num )
88 std::string t_filename(
f_file_infos[ t_file_num ].f_filename );
89 LDEBUG(
plog,
"Creating file <" << t_filename <<
">" );
91 f_mw_ptrs[ t_file_num ]->set_max_file_size( f_max_file_size_mb );
94 unique_lock t_header_lock( t_hwrap_ptr->get_lock() );
95 t_hwrap_ptr->header().Description() =
f_file_infos[ t_file_num ].f_description;
97 time_t t_raw_time = time(
nullptr );
98 struct tm* t_processed_time = gmtime( &t_raw_time );
99 char t_timestamp[ 512 ];
100 strftime( t_timestamp, 512, scarab::date_time_format, t_processed_time );
102 t_hwrap_ptr->header().Timestamp() = t_timestamp;
104 t_hwrap_ptr->header().SetRunDuration( t_run_duration );
107 LDEBUG(
plog,
"Setting up streams" );
110 if( it_writer->second == t_file_num )
112 it_writer->first->prepare_to_write(
f_mw_ptrs[ t_file_num ], t_hwrap_ptr );
117 t_header_lock.unlock();
121 LINFO(
plog,
"Done creating egg3 files" );
123 catch( std::exception& e )
138 (*file_it)->cancel();
139 (*file_it)->stop_using();
140 (*file_it)->finish_file();
145 catch( std::exception& e )
159 throw error() <<
"Currently configured number of files is <" <<
f_file_infos.size() <<
">, but file <" << a_file_num <<
"> was requested by a writer; please reconfigure for the appropriate number of files or assign the writer to the appropriate file number.";
162 bool t_has_already =
false;
163 auto t_range =
f_writers.equal_range( a_writer );
164 for(
auto t_it = t_range.first; t_it != t_range.second; ++t_it )
166 if( t_it->second == a_file_num )
168 t_has_already =
true;
174 throw error() <<
"Egg writer at <" << a_writer <<
"> is already registered for file number " << a_file_num;
176 f_writers.insert( std::pair< egg_writer*, unsigned >( a_writer, a_file_num ) );
183 auto t_range =
f_writers.equal_range( a_writer );
184 f_writers.erase( t_range.first, t_range.second );
191 if( a_file_num >
f_file_infos.size() )
throw error() <<
"Currently configured number of files is <" <<
f_file_infos.size() <<
">, but filename-set was for file <" << a_file_num <<
">.";
199 if( a_file_num >
f_file_infos.size() )
throw error() <<
"Currently configured number of files is <" <<
f_file_infos.size() <<
">, but filename-get was for file <" << a_file_num <<
">.";
206 if( a_file_num >
f_file_infos.size() )
throw error() <<
"Currently configured number of files is <" <<
f_file_infos.size() <<
">, but description-set was for file <" << a_file_num <<
">.";
214 if( a_file_num >
f_file_infos.size() )
throw error() <<
"Currently configured number of files is <" <<
f_file_infos.size() <<
">, but description-get was for file <" << a_file_num <<
">.";
std::shared_ptr< header_wrapper > header_wrap_ptr
Base class for all writers.
const std::string & get_filename(unsigned a_file_num)
void register_writer(egg_writer *a_writer, unsigned a_file_num)
static scarab::logger plog("batch_executor")
void unregister_writer(egg_writer *a_writer)
dc_ptr_t use_daq_control()
std::unique_lock< std::mutex > unique_lock
void set_filename(const std::string &a_filename, unsigned a_file_num=0)
void prepare_files(const scarab::param_node &a_files_config)
Gives other classes access to daq_control.
const std::string & get_description(unsigned a_file_num)
std::shared_ptr< monarch_wrapper > monarch_wrap_ptr
bool daq_control_expired()
LOGGER(plog, "egg_writer")
std::vector< monarch_wrap_ptr > f_mw_ptrs
file_infos_t f_file_infos
Wrapper class for a monarch3::M3Monarch object.
virtual ~butterfly_house()
void set_description(const std::string &a_desc, unsigned a_file_num=0)
std::multimap< egg_writer *, unsigned > f_writers
file_infos_t::iterator file_infos_it