LCOV - code coverage report
Current view: top level - include/crpropa/module - HDF5Output.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 1 0.0 %
Date: 2024-04-29 14:43:01 Functions: 0 0 -

          Line data    Source code
       1             : #ifdef CRPROPA_HAVE_HDF5
       2             : 
       3             : #ifndef CRPROPA_HDF5OUTPUT_H
       4             : #define CRPROPA_HDF5OUTPUT_H
       5             : 
       6             : 
       7             : #include "crpropa/module/Output.h"
       8             : #include <stdint.h>
       9             : #include <ctime>
      10             : 
      11             : #include <H5Ipublic.h>
      12             : 
      13             : namespace crpropa {
      14             : 
      15             : const size_t propertyBufferSize = 1024;
      16             : 
      17             : /**
      18             :  * \addtogroup Output
      19             :  * @{
      20             :  */
      21             : 
      22             : /**
      23             :  @class HDF5Output
      24             :  @brief Output to HDF5 Format.
      25             : The base class gives an overview of possible columns
      26             : 
      27             : HDF5 structure:
      28             : ```
      29             : HDF5 "FILENAME.h5" {
      30             : GROUP "/" {
      31             : DATASET "OUTPUTTYPE" {
      32             :   DATATYPE  H5T_COMPOUND {
      33             :   ...
      34             :  }
      35             :  DATASPACE  SIMPLE { ( 1 ) / ( H5S_UNLIMITED ) }
      36             :  DATA {
      37             :   ...
      38             :  }
      39             :   ATTRIBUTE "Version" {
      40             :   DATATYPE  H5T_STRING {
      41             :       STRSIZE 100;
      42             :       STRPAD H5T_STR_NULLTERM;
      43             :       CSET H5T_CSET_ASCII;
      44             :       CTYPE H5T_C_S1;
      45             :       }
      46             :   DATASPACE  SCALAR
      47             :   DATA { (0): "VERSION" }
      48             :  }
      49             : } } }
      50             : ```
      51             : 
      52             :  */
      53             : class HDF5Output: public Output {
      54             : 
      55           0 :         typedef struct OutputRow {
      56             :                 double D;
      57             :                 double z;
      58             :                 uint64_t SN;
      59             :                 int32_t ID;
      60             :                 double E;
      61             :                 double X;
      62             :                 double Y;
      63             :                 double Z;
      64             :                 double Px;
      65             :                 double Py;
      66             :                 double Pz;
      67             :                 uint64_t SN0;
      68             :                 int32_t ID0;
      69             :                 double E0;
      70             :                 double X0;
      71             :                 double Y0;
      72             :                 double Z0;
      73             :                 double P0x;
      74             :                 double P0y;
      75             :                 double P0z;
      76             :                 uint64_t SN1;
      77             :                 int32_t ID1;
      78             :                 double E1;
      79             :                 double X1;
      80             :                 double Y1;
      81             :                 double Z1;
      82             :                 double P1x;
      83             :                 double P1y;
      84             :                 double P1z;
      85             :                 double weight;
      86             :                 std::string tag;
      87             :                 unsigned char propertyBuffer[propertyBufferSize];
      88             :         } OutputRow;
      89             : 
      90             :         std::string filename;
      91             : 
      92             :         hid_t file, sid;
      93             :         hid_t dset, dataspace;
      94             :         mutable std::vector<OutputRow> buffer;
      95             : 
      96             :         time_t lastFlush;
      97             :         unsigned int flushLimit;
      98             :         unsigned int candidatesSinceFlush;
      99             : public:
     100             :         /** Default constructor.
     101             :                 Does not run from scratch.
     102             :             At least open() has to be called in addition.
     103             :                 Units of energy and length are, by default, EeV and Mpc.
     104             :                 This can be changed with setEnergyScale and setLengthScale.
     105             :          */
     106             :         HDF5Output();
     107             :         /** Constructor with the default OutputType (everything).
     108             :                 @param filename string containing name of output hdf5 file
     109             :          */
     110             :         HDF5Output(const std::string &filename);
     111             :         /** Constructor
     112             :                 @param outputtype       type of output: Trajectory1D, Trajectory3D, Event1D, Event3D, Everything
     113             :                 @param filename string containing name of output hdf5 file
     114             :          */
     115             :         HDF5Output(const std::string &filename, OutputType outputtype);
     116             :         ~HDF5Output();
     117             : 
     118             :         void process(Candidate *candidate) const;
     119             :         herr_t insertStringAttribute(const std::string &key, const std::string &value);
     120             :         herr_t insertDoubleAttribute(const std::string &key, const double &value);
     121             :         std::string getDescription() const;
     122             : 
     123             :         /// Force flush after N events. In long running applications with scarse
     124             :         /// output this can be set to 1 or 0 to avoid data corruption. In applications
     125             :         /// with frequent output this should be set to a high number (default)
     126             :         void setFlushLimit(unsigned int N);
     127             : 
     128             :         /** Create and prepare a file as HDF5-file.
     129             :          */
     130             :         void open(const std::string &filename);
     131             :         void close();
     132             :         void flush() const;
     133             : 
     134             : };
     135             : /** @}*/
     136             : 
     137             : } // namespace crpropa
     138             : 
     139             : #endif // CRPROPA_HDF5OUTPUT_H
     140             : 
     141             : #endif // CRPROPA_HAVE_HDF5

Generated by: LCOV version 1.14