LCOV - code coverage report
Current view: top level - include/crpropa/module - Output.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 0.0 % 6 0
Test Date: 2026-06-18 09:49:19 Functions: 0.0 % 1 0

            Line data    Source code
       1              : #ifndef CRPROPA_OUTPUT_H
       2              : #define CRPROPA_OUTPUT_H
       3              : 
       4              : #include "crpropa/Module.h"
       5              : #include "crpropa/Variant.h"
       6              : 
       7              : #include <bitset>
       8              : #include <vector>
       9              : #include <string>
      10              : 
      11              : namespace crpropa {
      12              : 
      13              : /**
      14              :  * \addtogroup Output
      15              :  * @{
      16              :  */
      17              : 
      18              : /**
      19              :  @class Output
      20              :  @brief Configurable output base class.
      21              :  The names of each quantity are provided in the table below.
      22              :  The left column corresponds to the labels of each quantity. 
      23              :  They are printed in the output files either as comments (in a text file) 
      24              :  or as columns (in a HDF5 file). The right columns are the names of each
      25              :  column for internal access.
      26              :  . D                     TrajectoryLengthColumn
      27              :  . SN                    SerialNumberColumn
      28              :  . ID                    CurrentIdColumn
      29              :  . E                     CurrentEnergyColumn
      30              :  . X/Y/Z                 CurrentPositionColumn
      31              :  . Px/Py/Pz              CurrentDirectionColumn
      32              :  . SN0                   SourceSerialNumberColumn
      33              :  . ID0                   SourceIdColumn
      34              :  . E0                    SourceEnergyColumn
      35              :  . X0/Y0/Z0              SourcePositionColumn
      36              :  . P0x/P0y/P0z   SourceDirectionColumn
      37              :  . SN1                   CreatedSerialNumberColumn
      38              :  . ID1                   CreatedIdColumn
      39              :  . E1                    CreatedEnergyColumn
      40              :  . X1/Y1/Z1              CreatedPositionColumn
      41              :  . P1x/P1y/P1z   CreatedDirectionColumn
      42              :  . z                     RedshiftColumn
      43              :  . tag                   CandidateTagColumn
      44              :  . weight                WeightColumn
      45              :  . time                  TimeColumn
      46              : 
      47              :  Some output types are pre-defined: 
      48              :  . Trajectory1D
      49              :  . Trajectory3D
      50              :  . Event1D
      51              :  . Event3D
      52              :  . Everything
      53              :  They can be easily customised by enabling/disabling specific columns.
      54              :  */
      55              : class Output: public Module {
      56              : public: 
      57              :         struct Property
      58              :         {
      59              :                 std::string name;
      60              :                 std::string comment;
      61              :                 Variant defaultValue;
      62              :         };
      63              : 
      64              : protected:
      65              :         double lengthScale, timeScale, energyScale;
      66              :         std::bitset<64> fields;
      67              : 
      68              :         std::vector<Property> properties;
      69              : 
      70              :         bool oneDimensional;
      71              :         mutable size_t count;
      72              : 
      73              :         void modify();
      74              : 
      75              : public:
      76              :         enum OutputColumn {
      77              :                 TrajectoryLengthColumn,
      78              :                 ColumnDensityColumn,
      79              :                 RedshiftColumn,
      80              :                 CurrentIdColumn,
      81              :                 CurrentEnergyColumn,
      82              :                 CurrentPositionColumn,
      83              :                 CurrentDirectionColumn,
      84              :                 SourceIdColumn,
      85              :                 SourceEnergyColumn,
      86              :                 SourcePositionColumn,
      87              :                 SourceDirectionColumn,
      88              :                 CreatedIdColumn,
      89              :                 CreatedEnergyColumn,
      90              :                 CreatedPositionColumn,
      91              :                 CreatedDirectionColumn,
      92              :                 CandidateTagColumn,
      93              :                 SerialNumberColumn,
      94              :                 WeightColumn,
      95              :                 TimeColumn
      96              :         };
      97              :         enum OutputType {
      98              :                 Trajectory1D,
      99              :                 Trajectory3D,
     100              :                 Event1D,
     101              :                 Event3D,
     102              :                 Everything
     103              :         };
     104              : 
     105              :         std::string OutputTypeName(OutputType outputtype);
     106              :         const std::string outputName;
     107              :         
     108              :         /** Default constructor. Output contains all the information available.
     109              :          Units of energy and length are, by default, EeV and Mpc.
     110              :          This can be changed with setEnergyScale and setLengthScale.
     111              :          */
     112              :         Output();
     113              :         /** General constructor.
     114              :          Units of energy and length are, by default, EeV and Mpc.
     115              :          This can be changed with setEnergyScale and setLengthScale.
     116              :          @param outputType      type of output: Trajectory1D, Trajectory3D, Event1D, Event3D, Everything
     117              :          */
     118              :         Output(OutputType outputType);
     119              : 
     120              :         /** Set energy scale.
     121              :          @param scale   energy scale (scale = 1 corresponds to 1 Joule)
     122              :          */
     123              :         void setEnergyScale(double scale);
     124              :         double getEnergyScale() const;
     125              :         /** Set length scale.
     126              :          @param scale   length scale (scale = 1 corresponds to 1 meter)
     127              :          */
     128              :         void setLengthScale(double scale);
     129              :         double getLengthScale() const;
     130              :         /** Set time scale.
     131              :          @param scale   time scale (scale = 1 corresponds to 1 second)
     132              :          */
     133              :         void setTimeScale(double scale);
     134              :         double getTimeScale() const;
     135              :         /** Set type of output.
     136              :          @param outputType      type of output: Trajectory1D, Trajectory3D, Event1D, Event3D, Everything
     137              :          */
     138              :         void setOutputType(OutputType outputType);
     139              :         /** Determines whether a given column will be displayed in the output.
     140              :          @param field   name of the field to be added/removed from output
     141              :          @param value   boolean flag adding (true) or removing (false) the field
     142              :          */
     143              :         void set(OutputColumn field, bool value);
     144              :         /** Add a property to output. 
     145              :          Default value is required to assign a type in the output.
     146              :          @param property                string containing name of property
     147              :          @param defaultValue    default value of property
     148              :          @param comment                 string with a comment
     149              :          */
     150              :         void enableProperty(const std::string &property, const Variant& defaultValue, const std::string &comment = "");
     151              :         /** Enable specific column in the output.
     152              :          @param field   name of the field to be enabled
     153              :          */
     154              :         void enable(OutputColumn field);
     155              :         /** Disable specific column in the output.
     156              :          @param field   name of the field to be disabled
     157              :          */
     158              :         void disable(OutputColumn field);
     159              :         /** Enable all fields.
     160              :          Essentially a wrapper for set(field, true).
     161              :          */
     162              :         void enableAll();
     163              :         /** Disable all fields.
     164              :          Essentially a wrapper for set(field, false). 
     165              :          */
     166              :         void disableAll();
     167              :         /** If true, output is of 1D type. 
     168              :          3D quantities such as vectors will be reduced to the relevant components (x, by default).
     169              :          @param value   boolean flag
     170              :          */
     171              :         void set1D(bool value);
     172              :         /** Returns the size of the output
     173              :          */
     174              :         size_t size() const;
     175              : 
     176              :         void process(Candidate *) const;
     177              : 
     178              :         /**     
     179              :          * write the indices of not started candidates into the output file. 
     180              :          * Used for interrupting the simulation
     181              :          * @param indices list of not started indices
     182              :          */
     183            0 :         virtual void dumpIndexList(std::vector<int> indices) {
     184            0 :                 std::cout << "indices:\t"; 
     185            0 :                 for (int i = 0; i < indices.size(); i++) 
     186            0 :                         std::cout << indices[i] << ", ";
     187            0 :                 std::cout << "\n";
     188            0 :         };
     189              : };
     190              : 
     191              : /** @}*/
     192              : 
     193              : } // namespace crpropa
     194              : 
     195              : #endif // CRPROPA_OUTPUT_H
        

Generated by: LCOV version 2.0-1