Bayeux  3.4.1
Core Foundation library for SuperNEMO
output_module.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2013-08-16
4  * Last modified : 2014-01-15
5  *
6  * Copyright (C) 2013-2014 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  *
24  * Description:
25  *
26  * An output data processing module.
27  *
28  */
29 
30 #ifndef DPP_OUTPUT_MODULE_H
31 #define DPP_OUTPUT_MODULE_H 1
32 
33 // Third party:
34 // - Boost:
35 #include <boost/scoped_ptr.hpp>
36 // - Bayeux/datatools:
38 
39 // This project:
40 #include <dpp/base_module.h>
41 
42 namespace dpp {
43 
44  // Forward declarations
45  class i_data_sink;
46  class io_common;
47 
50  : public base_module
51  {
52  public:
53 
56 
58  virtual ~output_module();
59 
61  virtual void initialize(const ::datatools::properties & /* config_ */,
62  datatools::service_manager & /* service_mgr_ */,
63  dpp::module_handle_dict_type & /* modules_map_ */);
64 
66  virtual void reset();
67 
69  virtual process_status process(::datatools::things & /* data_ */);
70 
72  void set_limits(int max_record_total_,
73  int max_record_per_file_ = 0,
74  int max_files_ = -1);
75 
77  void set_single_output_file(const std::string & filepath_);
78 
80  void set_list_of_output_files(const std::vector<std::string> & filepaths_,
81  bool allow_duplicate_ = false);
82 
84  void set_incremental_output_files(const std::string & path_,
85  const std::string & prefix_,
86  const std::string & extension_,
87  unsigned int stop_,
88  unsigned int start_ = 0,
89  int increment_ = 1);
90 
92  void set_preserve_existing_output(bool preserve_existing_output);
93 
95  bool has_metadata_store() const;
96 
99 
102 
104  void clear_metadata_store();
105 
107  virtual void tree_dump(std::ostream & out_ = std::clog,
108  const std::string & title_ = "",
109  const std::string & indent_ = "",
110  bool inherit_ = false) const;
111 
113  bool is_terminated() const;
114 
116  const io_common & get_common() const;
117 
119  void set_context_label(const std::string &);
120 
122  void export_context_metadata(const std::string &);
123 
125  void set_export_context_all(bool);
126 
127  protected:
128 
130  process_status _store(const datatools::things & data_record_);
131 
133  void _set_defaults();
134 
137 
138  private:
139 
141  base_module::process_status _open_sink_();
142 
144  void _store_metadata_();
145 
146  private:
147 
148  bool _preserve_existing_output_;
149  boost::scoped_ptr<io_common> _common_;
150  i_data_sink * _sink_ = nullptr;
151 
152  // Macro to automate the registration of the module :
154 
155  };
156 
157 } // namespace dpp
158 
159 #endif // DPP_OUTPUT_MODULE_H
160 
161 // Local Variables: --
162 // mode: c++ --
163 // c-file-style: "gnu" --
164 // tab-width: 2 --
165 // End: --
A generic serializable and noncopyable container for arbitrary serializable objects.
Definition: things.h:85
void set_single_output_file(const std::string &filepath_)
Set the filename of a single output file.
output_module(datatools::logger::priority=datatools::logger::PRIO_FATAL)
Constructor.
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
A container of mapped properties objects.
Definition: multi_properties.h:99
virtual ~output_module()
Destructor.
virtual void reset()
Reset.
Top-level namespace of the Bayeux/dpp module library.
Definition: base_module.h:56
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
void _set_defaults()
Set default values before explicit settings and initialization.
process_status
Processing status flags used as the returned value of data processing methods through the pipeline.
Definition: base_module.h:65
datatools::multi_properties & grab_metadata_store()
Return a mutable reference to the embedded metadata store, create it if it does not exist.
void set_context_label(const std::string &)
Set the label/name of the context service to be used.
void set_preserve_existing_output(bool preserve_existing_output)
Set the flag for preserving existing output file (prevent from file overwriting)
io_common & _grab_common()
Return a reference to the mutable internal I/O data structure.
const io_common & get_common() const
Return a reference to the non mutable internal I/O data structure.
bool is_terminated() const
Check output termination.
void set_limits(int max_record_total_, int max_record_per_file_=0, int max_files_=-1)
Set limits.
Some common data structure for I/O modules.
Definition: io_common.h:50
virtual void initialize(const ::datatools::properties &, datatools::service_manager &, dpp::module_handle_dict_type &)
Initialization.
void export_context_metadata(const std::string &)
Export a metadata section with a given name from the context service to the output stream.
void set_list_of_output_files(const std::vector< std::string > &filepaths_, bool allow_duplicate_=false)
Set the filenames of a list of output files.
std::map< std::string, module_entry_type > module_handle_dict_type
Definition: module_tools.h:141
Base processing module (abstract interface)
Definition: base_module.h:59
process_status _store(const datatools::things &data_record_)
Store a data record.
#define DPP_MODULE_REGISTRATION_INTERFACE(T)
Definition: base_module.h:231
bool has_metadata_store() const
Check if an embedded metadata store exists.
A output data processing module for automated I/O operations.
Definition: output_module.h:49
Data sink/writer abstract interface.
Definition: i_data_sink.h:49
void set_incremental_output_files(const std::string &path_, const std::string &prefix_, const std::string &extension_, unsigned int stop_, unsigned int start_=0, int increment_=1)
Set the incremented filenames of output files.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
const datatools::multi_properties & get_metadata_store() const
Return a const reference to the existing embedded metadata store.
void clear_metadata_store()
Clear the embedded metadata store.
void set_export_context_all(bool)
Export all metadata sections from the context service to the output stream.
virtual process_status process(::datatools::things &)
Data record processing.
Service management class.
Definition: service_manager.h:57