Quellcode durchsuchen

Finishes implementing TMVA integration

Caleb Fangmeier vor 7 Jahren
Ursprung
Commit
4427df6a66
3 geänderte Dateien mit 47 neuen und 9 gelöschten Zeilen
  1. 22 0
      api.hpp
  2. 13 0
      dataset.hpp
  3. 12 9
      value.hpp

+ 22 - 0
api.hpp

@@ -284,6 +284,28 @@ namespace fv{
         return combinations<T, Size>(lookup<std::vector<T>>(val_name), alias);
     }
 
+    template < typename T>
+    decltype(auto)
+    constant(const std::string name, T const_value, const std::string alias=""){
+        typedef T type;
+        const std::string& val_name = ConstantValue<T>::fmt_name(name);
+        if (check_exists<type>(val_name))
+            return lookup<type>(val_name);
+        else
+            return (Value<type>*)new ConstantValue<T>(val_name, const_value, alias);
+    }
+
+    template <typename T>
+    decltype(auto)
+    bound(Function<T()>& f, const std::string alias=""){
+        typedef T type;
+        const std::string& name = BoundValue<T>::fmt_name(f);
+        if (check_exists<type>(name))
+            return lookup<type>(name);
+        else
+            return (Value<type>*)new BoundValue<T>(f, alias);
+    }
+
     template <typename T>
     decltype(auto)
     filter(Function<bool(T)>& filter, Value<std::vector<T>>* val, const std::string alias=""){

+ 13 - 0
dataset.hpp

@@ -54,6 +54,7 @@ class DataSet{
             INFO(GenFunction::summary());
         }
 
+        Value<int>* current_event_number;
 
     protected:
         ContainerSet containers;
@@ -115,6 +116,18 @@ class DataSet{
             }
             return c;
         }
+
+        DataSet(){
+            auto& event_check = GenFunction::register_function<int()>("event_number",
+                FUNC(([ds=this](){
+                    return ds->get_current_event();
+                })));
+            current_event_number = new BoundValue<int>(event_check);
+        }
+
+        Value<int>* get_current_event_number(){
+            return current_event_number;
+        }
 };
 }
 #endif // dataset_hpp

+ 12 - 9
value.hpp

@@ -516,13 +516,7 @@ class DerivedValue : public Value<T>{
         }
 
         T& get_value(){
-            /* if (this->logging_enabled){ */
-            /*     std::cout <<  "Getting value for " << this->get_name() << std::endl; */
-            /* } */
             if (!this->value_valid){
-                /* if (this->logging_enabled){ */
-                /*     std::cout <<  "Updating value for " << this->get_name() << std::endl; */
-                /* } */
                 update_value();
                 this->value_valid = true;
                 this->log();
@@ -1196,9 +1190,14 @@ class BoundValue : public DerivedValue<T>{
         void update_value(){
             this->value = f();
         }
+
     public:
+        static std::string fmt_name(Function<T()> f){
+            return f.get_name()+"(<bound>)";
+        }
+
         BoundValue(Function<T()>& f, const std::string alias="")
-          :DerivedValue<T>(f.get_name()+"(<bound>)", alias),
+          :DerivedValue<T>(fmt_name(f), alias),
            f(f) { }
 };
 
@@ -1227,9 +1226,13 @@ class ConstantValue : public DerivedValue<T>{
         void update_value(){ }
 
     public:
+        static std::string fmt_name(const std::string& name){
+            return "const::"+name;
+        }
         ConstantValue(const std::string& name, T const_value, const std::string alias="")
-            :DerivedValue<T>("const::"+name, alias),
-             Value<T>::value(const_value) { }
+          :DerivedValue<T>(fmt_name(name), alias) {
+            this->value = const_value;
+        }
 };
 }
 #endif // value_hpp