LCOV - code coverage report
Current view: top level - src/interfaces - DataFileInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 25 25 100.0 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "DataFileInterface.h"
      11             : #include "MooseError.h"
      12             : #include "ParallelParamObject.h"
      13             : #include "DataFileUtils.h"
      14             : #include "MooseUtils.h"
      15             : 
      16             : #include <optional>
      17             : 
      18     5213724 : DataFileInterface::DataFileInterface(const ParallelParamObject & parent) : _parent(parent) {}
      19             : 
      20             : std::string
      21          10 : DataFileInterface::getDataFileName(const std::string & param) const
      22             : {
      23          10 :   _parent.mooseDeprecated("getDataFileName() is deprecated. The file path is now directly set "
      24             :                           "within the InputParameters.\nUse getParam<DataFileName>(\"",
      25             :                           param,
      26             :                           "\") instead.");
      27          10 :   return _parent.getParam<DataFileName>(param);
      28             : }
      29             : 
      30             : std::string
      31          10 : DataFileInterface::getDataFileNameByName(const std::string & relative_path) const
      32             : {
      33          10 :   _parent.mooseDeprecated("getDataFileNameByName() is deprecated. Use getDataFilePath(\"",
      34             :                           relative_path,
      35             :                           "\") instead.");
      36          10 :   return getDataFilePath(relative_path);
      37             : }
      38             : 
      39             : std::string
      40          28 : DataFileInterface::getDataFilePath(const std::string & relative_path) const
      41             : {
      42             :   // This should only ever be used with relative paths. There is no point to
      43             :   // use this search path with an absolute path.
      44          28 :   if (std::filesystem::path(relative_path).is_absolute())
      45           4 :     _parent.mooseWarning("While using getDataFilePath(\"",
      46             :                          relative_path,
      47             :                          "\"): This API should not be used for absolute paths.");
      48             : 
      49             :   // Throw on error so that if getPath() fails, we can throw an error
      50             :   // with the context of _parent.mooseError()
      51          24 :   const auto throw_on_error_before = Moose::_throw_on_error;
      52          24 :   Moose::_throw_on_error = true;
      53          24 :   std::optional<std::string> error;
      54             : 
      55             :   // This will search the data paths for this relative path
      56          24 :   Moose::DataFileUtils::Path found_path;
      57             :   try
      58             :   {
      59          32 :     found_path = Moose::DataFileUtils::getPath(relative_path);
      60             :   }
      61           4 :   catch (std::exception & e)
      62             :   {
      63           4 :     error = e.what();
      64           4 :   }
      65             : 
      66          24 :   Moose::_throw_on_error = throw_on_error_before;
      67          24 :   if (error)
      68           4 :     _parent.mooseError(*error);
      69             : 
      70             :   mooseAssert(found_path.context == Moose::DataFileUtils::Context::DATA,
      71             :               "Should only ever obtain data");
      72             :   mooseAssert(found_path.data_name, "Should be set");
      73             : 
      74             :   const std::string msg =
      75          20 :       "Using data file '" + found_path.path + "' from " + *found_path.data_name + " data";
      76          20 :   _parent.mooseInfo(msg);
      77             : 
      78          40 :   return found_path.path;
      79          20 : }

Generated by: LCOV version 1.14