Bayeux  3.4.1
Core Foundation library for SuperNEMO
io_common.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 : 2013-08-16
5  *
6  * Copyright (C) 2013 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  * Base class for I/O modules.
27  *
28  */
29 
30 #ifndef DPP_IO_COMMON_H
31 #define DPP_IO_COMMON_H 1
32 
33 // Standard library:
34 #include <string>
35 #include <vector>
36 
37 // Third party library:
38 // - Bayeux/datatools:
39 #include <datatools/logger.h>
42 
43 namespace dpp {
44 
45  class context_service;
46  class i_data_sink;
47  class i_data_source;
48 
50  class io_common
51  {
52  public:
53 
55  enum io_type {
56  IO_INVALID = -1,
57  IO_OUTPUT = 0,
59  };
60 
62  enum format_type {
66  };
67 
68  static format_type guess_format_from_filename(const std::string &);
69 
70  static i_data_source * allocate_reader(const std::string &,
72 
73  static i_data_sink * allocate_writer(const std::string &,
75 
76  static const std::string & metadata_key();
77 
78  static const std::string & metadata_meta();
79 
80  static const std::string & metadata_rank();
81 
82  static const std::string & metadata_topic();
83 
84  static const std::string & context_key();
85 
86  static const std::string & context_meta();
87 
88  static const std::string & context_rank();
89 
90  static const std::string & context_topic();
91 
93  const std::string & module_name_);
94 
95  virtual ~io_common();
96 
97  void set_module_name (const std::string &);
98 
99  const std::string & get_module_name() const;
100 
101  format_type get_format() const;
102 
103  void set_format(format_type);
104 
105  io_type get_io() const;
106 
107  void set_io(io_type);
108 
109  void set_context_label (const std::string &);
110 
111  const std::string & get_context_label() const;
112 
113  void set_context_service (dpp::context_service & context_service_,
114  const std::string & ctx_label_ = "Ctx");
115 
116  bool has_context_service() const;
117 
119 
121 
122  void add_context_metadata(const std::string &);
123 
124  void set_context_all(bool val_);
125 
126  void clear_context_metadata();
127 
128  void set_max_files (int max_files_);
129 
130  int get_max_files() const;
131 
132  void set_max_record_total (int max_record_total_);
133 
134  int get_max_record_total() const;
135 
136  void set_max_record_per_file (int max_record_per_file_);
137 
138  int get_max_record_per_file() const;
139 
140  void init_filenames (const datatools::properties & setup_);
141 
143 
145 
146  bool is_terminated () const;
147 
148  void set_terminated (bool);
149 
150  int get_file_record_counter() const;
151 
152  int get_record_counter() const;
153 
154  int get_file_index() const;
155 
156  void set_file_record_counter(int);
157 
158  void set_record_counter(int);
159 
160  void set_file_index(int);
161 
162  void initialize(const datatools::properties & config_,
163  datatools::service_manager & service_manager_);
164 
165  void reset();
166 
169 
172 
174  void clear_metadata_store();
175 
177  const std::vector<std::string> & get_context_metadata() const;
178 
180  bool is_context_all() const;
181 
182  virtual void tree_dump (std::ostream & out_ = std::clog,
183  const std::string & title_ = "",
184  const std::string & indent_ = "",
185  bool inherit_ = false) const;
186 
187  protected:
188 
189  void _set_defaults ();
190 
191  private:
192 
193  // Configuration attributes:
194  std::string _module_name_;
195  io_type _io_;
196  format_type _format_;
197  datatools::logger::priority * _logging_;
198  int _max_record_per_file_;
199  int _max_record_total_;
200  int _max_files_;
201  datatools::smart_filename _filenames_;
202 
203  // Running/dynamic attributes:
204  bool _terminated_;
205  int _file_record_counter_;
206  int _record_counter_;
207  int _file_index_;
208 
209  // Metadata support:
210  datatools::multi_properties _metadata_store_;
211 
212  // Context service (external metadata container):
213  std::string _Ctx_label_;
214  dpp::context_service * _Ctx_service_;
215  std::vector<std::string> _Ctx_metadata_;
216  bool _Ctx_metadata_all_;
217 
218  };
219 
220 } // namespace dpp
221 
222 #endif // DPP_IO_COMMON_H
223 
224 // Local Variables: --
225 // mode: c++ --
226 // c-file-style: "gnu" --
227 // tab-width: 2 --
228 // End: --
const datatools::multi_properties & get_metadata_store() const
Return an embedded metadata store (const reference)
void set_max_record_per_file(int max_record_per_file_)
static const std::string & context_topic()
datatools::smart_filename & grab_filenames()
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
void set_module_name(const std::string &)
virtual ~io_common()
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
dpp::context_service & grab_context_service()
Definition: io_common.h:58
io_type get_io() const
datatools::multi_properties & grab_metadata_store()
Return an embedded metadata store (mutable reference)
Top-level namespace of the Bayeux/dpp module library.
Definition: base_module.h:56
A service that handles a context object store implemented as a datatools::multi_properties container.
Definition: context_service.h:53
static const std::string & metadata_key()
bool has_context_service() const
bool is_terminated() const
void set_record_counter(int)
io_common(datatools::logger::priority &logging_, const std::string &module_name_)
void _set_defaults()
void add_context_metadata(const std::string &)
void set_context_all(bool val_)
void set_max_record_total(int max_record_total_)
void set_max_files(int max_files_)
bool is_context_all() const
Check if all context metadata are accepted.
static const std::string & metadata_rank()
static const std::string & metadata_topic()
void set_file_record_counter(int)
int get_max_files() const
void set_terminated(bool)
Definition: io_common.h:64
Definition: io_common.h:56
Some common data structure for I/O modules.
Definition: io_common.h:50
format_type get_format() const
Definition: io_common.h:63
void clear_metadata_store()
Clear the contents of the embedded metadata store.
void set_context_service(dpp::context_service &context_service_, const std::string &ctx_label_="Ctx")
void set_format(format_type)
int get_record_counter() const
Data source/reader abstract interface.
Definition: i_data_source.h:50
int get_max_record_total() const
static const std::string & context_rank()
void init_filenames(const datatools::properties &setup_)
static const std::string & context_key()
static i_data_source * allocate_reader(const std::string &, datatools::logger::priority)
int get_max_record_per_file() const
const dpp::context_service & get_context_service() const
const std::string & get_module_name() const
static i_data_sink * allocate_writer(const std::string &, datatools::logger::priority)
A class that builds an arbitrary list of filenames on user request. Supported modes are:
Definition: smart_filename.h:52
int get_file_record_counter() const
const datatools::smart_filename & get_filenames() const
Data sink/writer abstract interface.
Definition: i_data_sink.h:49
io_type
Input/output.
Definition: io_common.h:55
Utilities for logging information.
int get_file_index() const
void set_file_index(int)
static format_type guess_format_from_filename(const std::string &)
format_type
Format of the storage.
Definition: io_common.h:62
Definition: io_common.h:65
const std::string & get_context_label() const
void set_context_label(const std::string &)
void initialize(const datatools::properties &config_, datatools::service_manager &service_manager_)
static const std::string & context_meta()
void set_io(io_type)
void clear_context_metadata()
static const std::string & metadata_meta()
Service management class.
Definition: service_manager.h:57
Definition: io_common.h:57
const std::vector< std::string > & get_context_metadata() const
Return a const reference to the list of context metadata labels.
A dictionary of arbitrary properties.
Definition: properties.h:125