LCOV - code coverage report
Current view: top level - include/crpropa/module - HDF5Output.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 0.0 % 1 0
Test Date: 2026-06-18 09:49:19 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 time;
      58              :                 double z;
      59              :                 uint64_t SN;
      60              :                 int32_t ID;
      61              :                 double E;
      62              :                 double X;
      63              :                 double Y;
      64              :                 double Z;
      65              :                 double Px;
      66              :                 double Py;
      67              :                 double Pz;
      68              :                 uint64_t SN0;
      69              :                 int32_t ID0;
      70              :                 double E0;
      71              :                 double X0;
      72              :                 double Y0;
      73              :                 double Z0;
      74              :                 double P0x;
      75              :                 double P0y;
      76              :                 double P0z;
      77              :                 uint64_t SN1;
      78              :                 int32_t ID1;
      79              :                 double E1;
      80              :                 double X1;
      81              :                 double Y1;
      82              :                 double Z1;
      83              :                 double P1x;
      84              :                 double P1y;
      85              :                 double P1z;
      86              :                 double weight;
      87              :                 std::string tag;
      88              :                 unsigned char propertyBuffer[propertyBufferSize];
      89              :         } OutputRow;
      90              : 
      91              :         std::string filename;
      92              : 
      93              :         hid_t file, sid;
      94              :         hid_t dset, dataspace;
      95              :         mutable std::vector<OutputRow> buffer;
      96              : 
      97              :         time_t lastFlush;
      98              :         unsigned int flushLimit;
      99              :         unsigned int candidatesSinceFlush;
     100              : public:
     101              :         /** Default constructor.
     102              :                 Does not run from scratch.
     103              :             At least open() has to be called in addition.
     104              :                 Units of energy and length are, by default, EeV and Mpc.
     105              :                 This can be changed with setEnergyScale and setLengthScale.
     106              :          */
     107              :         HDF5Output();
     108              :         /** Constructor with the default OutputType (everything).
     109              :                 @param filename string containing name of output hdf5 file
     110              :          */
     111              :         HDF5Output(const std::string &filename);
     112              :         /** Constructor
     113              :                 @param outputtype       type of output: Trajectory1D, Trajectory3D, Event1D, Event3D, Everything
     114              :                 @param filename string containing name of output hdf5 file
     115              :          */
     116              :         HDF5Output(const std::string &filename, OutputType outputtype);
     117              :         ~HDF5Output();
     118              : 
     119              :         void process(Candidate *candidate) const;
     120              :         herr_t insertStringAttribute(const std::string &key, const std::string &value);
     121              :         herr_t insertDoubleAttribute(const std::string &key, const double &value);
     122              :         std::string getDescription() const;
     123              : 
     124              :         /// Force flush after N events. In long running applications with scarse
     125              :         /// output this can be set to 1 or 0 to avoid data corruption. In applications
     126              :         /// with frequent output this should be set to a high number (default)
     127              :         void setFlushLimit(unsigned int N);
     128              : 
     129              :         /** Create and prepare a file as HDF5-file.
     130              :          */
     131              :         void open(const std::string &filename);
     132              :         void close();
     133              :         void flush() const;
     134              : 
     135              : };
     136              : /** @}*/
     137              : 
     138              : } // namespace crpropa
     139              : 
     140              : #endif // CRPROPA_HDF5OUTPUT_H
     141              : 
     142              : #endif // CRPROPA_HAVE_HDF5
        

Generated by: LCOV version 2.0-1