Psi4
psio.hpp
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2018 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_lib_libpsio_psio_hpp_
30 #define _psi_src_lib_libpsio_psio_hpp_
31 
32 #include <string>
33 #include <map>
34 #include <set>
35 #include <queue>
36 #include <memory>
37 
38 #include "psi4/libpsio/config.h"
39 
40 namespace psi {
41 
42 class PSIO;
43 class PSIOManager;
44 extern PSI_API std::shared_ptr<PSIO> _default_psio_lib_;
45 extern PSI_API std::shared_ptr<PSIOManager> _default_psio_manager_;
46 
55 private:
57  std::string default_path_;
59  std::map<int, std::string> specific_paths_;
61  std::set<int> specific_retains_;
62 
64  std::map<std::string, bool> files_;
66  std::set<std::string> retained_files_;
67 
68  std::string pid_;
69 public:
71  PSIOManager();
73  ~PSIOManager();
74 
78  void mirror_to_disk();
82  void build_from_disk();
83 
88  void set_default_path(const std::string& path);
94  void set_specific_path(int fileno, const std::string& path);
100  void set_specific_retention(int fileno, bool retain);
106  bool get_specific_retention(int fileno);
107 
113  std::string get_file_path(int fileno);
114 
119  std::string get_default_path() { return default_path_; }
120 
126  void write_scratch_file(const std::string &full_path, const std::string &text);
127 
132  void open_file(const std::string & full_path, int fileno);
140  void close_file(const std::string & full_path, int fileno, bool keep);
147  void move_file(const std::string & old_full_path, const std::string & new_full_path);
154  void mark_file_for_retention(const std::string & full_path, bool retain);
159  void print(std::string out = "outfile");
163  void print_out() { print("outfile"); }
174  void psiclean();
179  void crashclean();
181  static std::shared_ptr<PSIOManager> shared_object();
182 };
183 
195 class PSI_API PSIO {
196 public:
197  PSIO();
198  ~PSIO();
199 
201  int state() {
202  return state_;
203  }
216  void filecfg_kwd(const char* kwdgrp, const char* kwd, int unit,
217  const char* kwdval);
219  const std::string& filecfg_kwd(const char* kwdgrp, const char* kwd,
220  int unit);
221 
223  void rename_file(size_t old_unit,size_t new_unit);
224 
226  bool exists(size_t unit);
228  void open(size_t unit, int status);
230  void close(size_t unit, int keep);
232  std::string getpid(void);
234  void rehash(size_t unit);
236  int open_check(size_t unit);
248  void read(size_t unit, const char *key, char *buffer, size_t size,
249  psio_address start, psio_address *end);
261  void write(size_t unit, const char *key, char *buffer, size_t size,
262  psio_address start, psio_address *end);
263 
264  void read_entry(size_t unit, const char *key, char *buffer, size_t size);
265  void write_entry(size_t unit, const char *key, char *buffer, size_t size);
266 
278  void zero_disk(size_t unit, const char *key, size_t rows, size_t cols);
279 
289  void rw(size_t unit, char *buffer, psio_address address, size_t size,
290  int wrt);
291 
293  void tocclean(size_t unit, const char *key);
295  void tocprint(size_t unit);
297  psio_tocentry* tocscan(size_t unit, const char *key);
299  bool tocentry_exists(size_t unit, const char *key);
301  void tocwrite(size_t unit);
302 
304  static int _error_exit_code_;
305 
307  static void set_default_namespace(const std::string &_ns) { default_namespace_ = _ns; }
308 
310  static std::string get_default_namespace() { return default_namespace_; }
311 
313  static void change_file_namespace(size_t fileno, const std::string & ns1, const std::string & ns2);
314 
316  static std::shared_ptr<PSIO> shared_object();
317 
328  size_t rd_toclen(size_t unit);
329 
331  void get_filename(size_t unit, char **name, bool remove_namespace = false);
332 
334  bool tocdel(size_t unit, const char *key);
335 
336 private:
339 
341  std::string pid_;
342 
343 
345  static std::string default_namespace_;
346 
347  typedef std::map<std::string,std::string> KWDMap;
350 
351 #ifdef PSIO_STATS
352  size_t *psio_readlen;
353  size_t *psio_writlen;
354 #endif
355 
357  int state_;
359  size_t get_numvols(size_t unit);
361  void get_volpath(size_t unit, size_t volume, char **path);
363  psio_tocentry* toclast(size_t unit);
365  size_t toclen(size_t unit);
372  void wt_toclen(size_t unit, size_t toclen);
374  void tocread(size_t unit);
375 
376  friend class AIO_Handler;
377 
378 public:
379  void set_pid(const std::string &pid) { pid_ = pid; }
380 };
381 
382 }
383 
384 #endif /* header guard */
void status(const char *, std::string)
Definition: cchbar/status.cc:39
std::string pid_
Definition: psio.hpp:68
std::string get_default_path()
Definition: psio.hpp:119
std::map< std::string, std::string > KWDMap
Definition: psio.hpp:347
std::map< std::string, bool > files_
Map of files, bool denotes open or closed.
Definition: psio.hpp:64
static int _error_exit_code_
Upon catastrophic failure, the library will exit() with this code. The default is 1...
Definition: psio.hpp:304
static std::string get_default_namespace()
Get the default namespace (for PREFIX.NAMESPACE.UNIT file numbering)
Definition: psio.hpp:310
void psiclean(void)
int state()
return 1 if activated
Definition: psio.hpp:201
Definition: libpsio/config.h:65
std::shared_ptr< PSIOManager > _default_psio_manager_
Definition: libpsio/init.cc:51
void print_out()
Definition: psio.hpp:163
int state_
Library state variable.
Definition: psio.hpp:357
KWDMap files_keywords_
library configuration is described by a set of keywords
Definition: psio.hpp:349
static void set_default_namespace(const std::string &_ns)
Set the current namespace (for PREFIX.NAMESPACE.UNIT file numbering)
Definition: psio.hpp:307
Definition: libpsio/config.h:75
std::map< int, std::string > specific_paths_
Specific paths for arbitrary file numbers.
Definition: psio.hpp:59
Definition: psio.hpp:54
std::set< std::string > retained_files_
Set of files to retain after psiclean.
Definition: psio.hpp:66
std::string pid_
Process ID.
Definition: psio.hpp:341
#define PSI_API
Definition: pragma.h:155
psio_ud * psio_unit
vector of units
Definition: psio.hpp:338
std::string default_path_
Default path for unspec&#39;d file numbers. Defaults to /tmp/.
Definition: psio.hpp:57
std::set< int > specific_retains_
Default retained files.
Definition: psio.hpp:61
std::shared_ptr< PSIO > _default_psio_lib_
Definition: libpsio/init.cc:50
static std::string default_namespace_
Current default namespace (for PREFIX.NAMESPACE.UNIT numbering)
Definition: psio.hpp:345
void set_pid(const std::string &pid)
Definition: psio.hpp:379
Definition: libpsio/config.h:83
Definition: psio.hpp:195