TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
FichierHDF.h
1/****************************************************************************
2* Copyright (c) 2022, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15#ifndef FichierHDF_included
16#define FichierHDF_included
17
18
19#include <Entree_Brute.h>
20#include <Sortie_Brute.h>
21#include <Nom.h>
22#include <Noms.h>
23#include <SChaine.h>
24
25#include <med.h>
26#ifdef MED_H
27#ifndef MED_
28#define MED_
29#endif
30#else
31#undef MED_
32#endif
33
34#ifdef MED_
35#include <hdf5.h>
36#endif
37
38
39/*! @brief This abstract class provides all the functionalities to open and manipulate HDF files and related concepts (datasets, groups, etc .
40 *
41 * ..)
42 * It intentionally does not place itself in the Sortie_Fichier_base or Entree_Fichier_base hierarchy
43 * since it is rather the datasets inside the HDF file that are regarded as TRUST Fichier objects.
44 *
45 */
47{
48public:
49 FichierHDF();
50 virtual ~FichierHDF();
51
52 // Creates (and open) the HDF file.
53 virtual void create(Nom filename);
54 virtual void open(Nom filename, bool readOnly);
55 virtual void close();
56
57 // Multiple Writer methods:
58 // every processor writes their own dataset into the file
59 virtual void create_and_fill_dataset_MW(Nom dataset_basename, Sortie_Brute& sortie);
60 virtual void create_and_fill_dataset_MW(Nom dataset_basename, SChaine& sortie);
61
62 // Method to write the dataset owned by proc #proc_rank in the given file
63 // (to use when a single proc writes all the datasets for example)
64 virtual void create_and_fill_dataset_SW(Nom datasetname, Sortie_Brute& sortie);
65
66 // Method to read the dataset owned by proc #proc_rank in the given file
67 virtual void read_dataset(Nom dataset_basename, int proc_rank, Entree_Brute& entree);
68
69 // Method to create datasets of size length and whose names are given by dataset_names
70 // to use when a process has multiple datasets to write
71#ifdef MED_
72 void create_datasets(Noms dataset_names, hsize_t length);
73#else
74 void create_datasets(Noms dataset_names, long length) { throw; }
75#endif
76
77 // Method to write sortie into the specified dataset
78 void fill_dataset(Nom dataset_name, Sortie_Brute& sortie);
79
80 // checks if a dataset named dataset_name exists in the file
81 virtual bool exists(const char* dataset_name);
82 //check if the file file_name is in the HDF5 format
83 static bool is_hdf5(const char *file_name);
84 // Checks if HDF file was written in int32 or int64, and sets 'is_different_int_size_' accordingly
85 void check_int_size(Nom filename);
87
88protected:
89 virtual void prepare_file_props();
90 virtual void prepare_dataset_props();
91#ifdef MED_
92 void create_and_fill_dataset_MW(Nom dataset_basename, const char* data, hsize_t lenData, hid_t datatype);
93
94 hid_t file_id_;
95 hid_t file_access_plst_;
96 hid_t dataset_transfer_plst_;
97 bool is_different_int_size_=false; // File with int32 (or int64) whereas version is int64 (or int32)
98#endif
99
100private:
101 // Forbid copy:
102 FichierHDF& operator=(const FichierHDF&);
103 FichierHDF(const FichierHDF&);
104
105};
106#endif
An Entree whose main source of data is an arbitrary binary buffer set using the set_data() method.
void check_int_size(Nom filename)
static bool is_hdf5(const char *file_name)
virtual void create_and_fill_dataset_MW(Nom dataset_basename, Sortie_Brute &sortie)
virtual void prepare_file_props()
void fill_dataset(Nom dataset_name, Sortie_Brute &sortie)
virtual void read_dataset(Nom dataset_basename, int proc_rank, Entree_Brute &entree)
virtual void open(Nom filename, bool readOnly)
virtual bool exists(const char *dataset_name)
virtual void create_and_fill_dataset_SW(Nom datasetname, Sortie_Brute &sortie)
void set_int_size()
virtual void prepare_dataset_props()
void create_datasets(Noms dataset_names, long length)
Definition FichierHDF.h:74
virtual ~FichierHDF()
virtual void close()
virtual void create(Nom filename)
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Un tableau de chaine de caracteres (VECT(Nom)).
Definition Noms.h:26
Cette classe derivee de Sortie empile ce qu'on lui envoie dans une chaine de caracteres.
Definition SChaine.h:26
This derived class of Sortie stacks whatever it receives in an internal binary buffer.