LCOV - code coverage report
Current view: top level - src/module - Output.cpp (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 86.4 % 103 89
Test Date: 2026-06-18 09:49:19 Functions: 85.0 % 20 17

            Line data    Source code
       1              : #include "crpropa/module/Output.h"
       2              : #include "crpropa/Units.h"
       3              : 
       4              : #include <stdexcept>
       5              : 
       6              : namespace crpropa {
       7              : 
       8            5 : Output::Output() : outputName(OutputTypeName(Everything)), lengthScale(Mpc), timeScale(Myr), energyScale(EeV), oneDimensional(false), count(0) {
       9            5 :         enableAll();
      10            5 : }
      11              : 
      12            8 : Output::Output(OutputType outputType) : outputName(OutputTypeName(outputType)), lengthScale(Mpc), timeScale(Myr), energyScale(EeV), oneDimensional(false), count(0) {
      13            8 :         setOutputType(outputType);
      14            8 : }
      15              : 
      16           13 : std::string Output::OutputTypeName(OutputType outputType) {
      17           13 :         if (outputType == Trajectory1D)
      18            1 :                 return "Trajectory1D";
      19           12 :         if (outputType == Event1D)
      20            4 :                 return "Event1D";
      21            8 :         if (outputType == Trajectory3D)
      22            1 :                 return "Trajectory3D";
      23            7 :         if (outputType == Event3D)
      24            1 :                 return "Event3D";
      25            6 :         return "Everything";
      26              : }
      27              : 
      28           67 : void Output::modify() {
      29           67 :         if (count > 0)
      30            0 :                 throw std::runtime_error("Output: cannot change Output parameters after data has been written to file.");
      31           67 : }
      32              : 
      33           27 : void Output::process(Candidate *c) const {
      34           27 :         count++;
      35           27 : }
      36              : 
      37            8 : void Output::setOutputType(OutputType outputtype) {
      38            8 :         modify();
      39              :         if (outputtype == Trajectory1D) {
      40              :                 // X, ID, E
      41            1 :                 set(CurrentPositionColumn, true);
      42            1 :                 set(CurrentIdColumn, true);
      43            1 :                 set(CurrentEnergyColumn, true);
      44            1 :                 set1D(true);
      45              :         } else if (outputtype == Event1D) {
      46              :                 // D, ID, E, ID0, E0
      47            4 :                 set(TrajectoryLengthColumn, true);
      48            4 :                 set(CurrentIdColumn, true);
      49            4 :                 set(CurrentEnergyColumn, true);
      50            4 :                 set(SourceIdColumn, true);
      51            4 :                 set(SourceEnergyColumn, true);
      52            4 :                 set1D(true);
      53              :         } else if (outputtype == Trajectory3D) {
      54              :                 // D, ID, E, X, Y, Z, Px, Py, Pz
      55            1 :                 set(TrajectoryLengthColumn, true);
      56            1 :                 set(CurrentIdColumn, true);
      57            1 :                 set(CurrentEnergyColumn, true);
      58            1 :                 set(CurrentPositionColumn, true);
      59            1 :                 set(CurrentDirectionColumn, true);
      60            1 :                 set1D(false);
      61              :         } else if (outputtype == Event3D) {
      62              :                 // D, ID, E, X, Y, Z, Px, Py, Pz, ID0, E0, X0, Y0, Z0, P0x, P0y, P0z
      63            1 :                 set(TrajectoryLengthColumn, true);
      64            1 :                 set(CurrentIdColumn, true);
      65            1 :                 set(CurrentEnergyColumn, true);
      66            1 :                 set(CurrentPositionColumn, true);
      67            1 :                 set(CurrentDirectionColumn, true);
      68            1 :                 set(SourceIdColumn, true);
      69            1 :                 set(SourceEnergyColumn, true);
      70            1 :                 set(SourcePositionColumn, true);
      71            1 :                 set(SourceDirectionColumn, true);
      72            1 :                 set1D(false);
      73              :         } else if (outputtype == Everything) {
      74            1 :                 enableAll();
      75            1 :                 set1D(false);
      76              :         } else {
      77            0 :                 throw std::runtime_error("Output: unknown output type");
      78              :         }
      79            8 : }
      80              : 
      81            0 : void Output::setEnergyScale(double scale) {
      82            0 :         modify();
      83            0 :         energyScale = scale;
      84            0 : }
      85              : 
      86            1 : double Output::getEnergyScale() const {
      87            1 :         return energyScale;
      88              : }
      89              : 
      90            0 : void Output::setLengthScale(double scale) {
      91            0 :         modify();
      92            0 :         lengthScale = scale;
      93            0 : }
      94              : 
      95            1 : double Output::getLengthScale() const {
      96            1 :         return lengthScale;
      97              : }
      98              : 
      99            0 : void Output::setTimeScale(double scale) {
     100            0 :         modify();
     101            0 :         timeScale = scale;
     102            0 : }
     103              : 
     104            1 : double Output::getTimeScale() const {
     105            1 :         return timeScale;
     106              : }
     107              : 
     108            9 : void Output::set1D(bool value) {
     109            9 :         modify();
     110            9 :         oneDimensional = value;
     111            9 : }
     112              : 
     113            3 : void Output::enable(OutputColumn field) {
     114            3 :         modify();
     115            3 :         fields.set(field, true);
     116            3 : }
     117              : 
     118            1 : void Output::disable(OutputColumn field) {
     119            1 :         modify();
     120            1 :         fields.set(field, false);
     121            1 : }
     122              : 
     123           38 : void Output::set(OutputColumn field, bool value) {
     124           38 :         modify();
     125           38 :         fields.set(field, value);
     126           38 : }
     127              : 
     128            6 : void Output::enableAll() {
     129            6 :         modify();
     130              :         fields.set();
     131            6 : }
     132              : 
     133            1 : void Output::disableAll() {
     134            1 :         modify();
     135              :         fields.reset();
     136            1 : }
     137              : 
     138            1 : size_t Output::size() const {
     139            1 :         return count;
     140              : }
     141              : 
     142            1 : void Output::enableProperty(const std::string &property, const Variant &defaultValue, const std::string &comment) {
     143            1 :         modify();
     144            1 :         Property prop;
     145              :         prop.name = property;
     146              :         prop.comment = comment;
     147            1 :         prop.defaultValue = defaultValue;
     148            1 :         properties.push_back(prop);
     149            1 : };
     150              : 
     151              : } // namespace crpropa
        

Generated by: LCOV version 2.0-1