observables.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2020 by
  4. * The Salk Institute for Biological Studies
  5. *
  6. * Use of this source code is governed by an MIT-style
  7. * license that can be found in the LICENSE file or at
  8. * https://opensource.org/licenses/MIT.
  9. *
  10. ******************************************************************************/
  11. #ifndef API_OBSERVABLES_H
  12. #define API_OBSERVABLES_H
  13. #include "generated/gen_observables.h"
  14. #include "api/api_common.h"
  15. #include "api/api_utils.h"
  16. #include "api/viz_output.h"
  17. #include "api/count.h"
  18. namespace BNG {
  19. class Observable;
  20. class BNGData;
  21. }
  22. namespace MCell {
  23. namespace API {
  24. class Observables: public GenObservables {
  25. public:
  26. OBSERVABLES_CTOR()
  27. // TODO: add checks that each observable writes to a different file
  28. void add_viz_output(std::shared_ptr<VizOutput> viz_output) override {
  29. append_to_vec(viz_outputs, viz_output, true);
  30. };
  31. void add_count(std::shared_ptr<Count> count) override {
  32. append_to_vec(counts, count, true);
  33. };
  34. // throws error if viz_output is not present or if its output_files_prefix is not set
  35. // uses argument method_name for this error report
  36. std::string get_first_viz_output_files_prefix(const char* method_name);
  37. std::shared_ptr<Count> find_count(const std::string& name) override {
  38. return vec_find_by_name(counts, name);
  39. }
  40. void load_bngl_observables(
  41. const std::string& file_name,
  42. const std::string& observables_path_or_file = "",
  43. const std::map<std::string, double>& parameter_overrides = std::map<std::string, double>(),
  44. const CountOutputFormat observables_output_format = CountOutputFormat::AUTOMATIC_FROM_EXTENSION
  45. ) override;
  46. // added manually
  47. void dump() const;
  48. protected:
  49. void convert_bng_data_to_observables_data(
  50. const BNG::BNGData& bng_data,
  51. const CountOutputFormat observables_output_format,
  52. const std::string& output_files_prefix
  53. );
  54. CountOutputFormat get_count_output_format(
  55. const CountOutputFormat observables_output_format,
  56. const std::string& observables_path_or_file
  57. );
  58. private:
  59. void convert_observable(
  60. const BNG::Observable& o,
  61. const BNG::BNGData& bng_data,
  62. const std::string& observables_path_or_file,
  63. const CountOutputFormat observables_output_format
  64. );
  65. CountOutputFormat count_output_format_from_path_or_file(const std::string& path_or_file);
  66. };
  67. } // namespace API
  68. } // namespace MCell
  69. #endif // API_OBSERVABLES_H