Bladeren bron

Adds saving of configuration to output file

  - Eliminates clone_as
  - Adds simplified THX Container constructor
Caleb Fangmeier 6 jaren geleden
bovenliggende
commit
7805222983
5 gewijzigde bestanden met toevoegingen van 28 en 26 verwijderingen
  1. 11 0
      include/config.hpp
  2. 0 6
      include/container.hpp
  3. 3 0
      include/dataset.hpp
  4. 6 20
      root/include/root_container.hpp
  5. 8 0
      root/include/root_dataset.hpp

+ 11 - 0
include/config.hpp

@@ -32,6 +32,8 @@
 #ifndef config_hpp
 #define config_hpp
 #include <string>
+#include <fstream>
+#include <sstream>
 
 #include "yaml-cpp/yaml.h"
 
@@ -100,6 +102,15 @@ class Config{
             return val;
         }
 
+        std::string as_string() {
+            std::stringstream config;
+            std::ifstream s(input_filename);
+            for (std::string line; std::getline(s, line);) {
+                config << line << std::endl;
+            }
+            return config.str();
+        }
+
         size_t get_max_events() {
             YAML::Node max_events = root["max-events"];
             if(!max_events) {

+ 0 - 6
include/container.hpp

@@ -104,8 +104,6 @@ namespace fv {
             return "N/A";
         }
 
-        virtual GenContainer *clone_as(const std::string &new_name) = 0;
-
         virtual void save_as(const std::string &fname, const SaveOption &option) = 0;
 
         virtual void save(const SaveOption &option = SaveOption::PNG) {
@@ -175,10 +173,6 @@ namespace fv {
             return this->container;
         }
 
-        GenContainer *clone_as(const std::string &new_name) {
-            return new Logger(this->container, logger_name, value_to_string);
-        }
-
         void save_as(const std::string &, const SaveOption &) {}
     };
 

+ 3 - 0
include/dataset.hpp

@@ -75,6 +75,8 @@ namespace fv {
 
         virtual bool load_next() = 0;
 
+        virtual void save_config() = 0;
+
     public:
         bool next(bool print_status=true) {
             if(print_status) {
@@ -100,6 +102,7 @@ namespace fv {
         virtual void save_all() {
             for (auto container : containers)
                 container.second->save();
+            save_config();
         }
 
         template<typename C, typename... ArgTypes>

+ 6 - 20
root/include/root_container.hpp

@@ -131,6 +131,9 @@ namespace fv_root {
             this->container->SetYTitle(params.label_y.c_str());
         }
 
+        ContainerTH1(const std::string &name, const TH1Params &params)
+                : ContainerTH1<V>(name, name, params) { }
+
         void fill(const V &v) {
             this->container->Fill(v);
         }
@@ -152,10 +155,6 @@ namespace fv_root {
                 fv_root_util::save_as(this->get_container(), fname, option);
             }
         }
-
-        GenContainer *clone_as(const std::string &new_name) {
-            return new ContainerTH1<V>(new_name, this->title, this->params);
-        }
     };
 
     struct TH2Params {
@@ -205,6 +204,9 @@ namespace fv_root {
             this->container->SetYTitle(params.label_y.c_str());
         }
 
+        ContainerTH2(const std::string &name, const TH2Params &params)
+                : ContainerTH2<V>(name, name, params) { }
+
         void fill(const V& x, const V& y) {
             this->container->Fill(x, y);
         }
@@ -245,10 +247,6 @@ namespace fv_root {
             return this->container;
         }
 
-        GenContainer *clone_as(const std::string &new_name) {
-            return new ContainerTGraph<V>(new_name, this->title);
-        }
-
         void save_as(const std::string &fname, const SaveOption &option = SaveOption::PNG) {
             fv_root_util::save_as(get_container(), fname, option);
         }
@@ -272,10 +270,6 @@ namespace fv_root {
             this->container->push_back(v);
         }
 
-        GenContainer *clone_as(const std::string &new_name) {
-            return new Vector<V>(new_name);
-        }
-
         void save_as(const std::string &fname, const SaveOption &option = SaveOption::PNG) {
             std::string type_name = "std::vector<" + fv::util::get_type_name(typeid(V)) + ">";
             fv_root_util::save_as_stl(this->get_container(), type_name, this->get_name(), option);
@@ -302,10 +296,6 @@ namespace fv_root {
         void fill(const V& v) {
             (*this->container)[v]++;
         }
-
-        GenContainer *clone_as(const std::string &new_name) {
-            return new Counter<V>(new_name);
-        }
     };
 
 
@@ -349,10 +339,6 @@ namespace fv_root {
             den.Fill(v);
             if (pass) num.Fill(v);
         }
-
-        GenContainer *clone_as(const std::string &new_name) {
-            return new EfficiencyContainer<V>(new_name, this->params);
-        }
     };
 
 }

+ 8 - 0
root/include/root_dataset.hpp

@@ -198,6 +198,13 @@ namespace fv_root {
             return new ObjectValue<T>(bname, bref);
         }
 
+        void save_config() {
+            if (the_config == nullptr) return;
+            TObjString config(the_config->as_string().c_str());
+            output_file->cd();
+            config.Write("_config");
+        }
+
         void save_all() {
             output_file->cd();
 
@@ -209,6 +216,7 @@ namespace fv_root {
             for (auto container : containers) {
                 container.second->save_as("outfile", SaveOption::ROOT);
             }
+            save_config();
         }
     };
 }