Browse Source

moves filval to submodules

Caleb Fangmeier 6 years ago
parent
commit
3eb6f64e5a

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "filval"]
+	path = filval
+	url = gogs@git.fangmeier.tech:caleb/filval.git

+ 1 - 0
filval

@@ -0,0 +1 @@
+Subproject commit 836549f3ab05b16cd5fb86747581345f5657cd03

+ 0 - 6
filval/README.md

@@ -1,6 +0,0 @@
-ROOT compatability layer for FilVal
-================================================
-See [FilVal](../filval/README.md) for details on FilVal. This layer provides
-container classes wrapping ROOT histograms and Graph objects. It also provides
-the ability to write these containers, as well as a variety of STL containers
-to ROOT files.

+ 0 - 357
filval/api.hpp

@@ -1,357 +0,0 @@
-/**
- * @file
- * @author  Caleb Fangmeier <caleb@fangmeier.tech>
- * @version 0.1
- *
- * @section LICENSE
- *
- *
- * MIT License
- *
- * Copyright (c) 2017 Caleb Fangmeier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * @section DESCRIPTION
- * This is the main api for FilVal. Users should try to avoid instantiating
- * Value objects directly, but rather use these functions. There are multiple
- * reasons for this. First of all, these functions do the extra work of making
- * sure that an identical Value doesn't already exist. If one does, it returns
- * the old Value object rather than creating a new one. The second reason is
- * that C++ allows type deduction for functions so one can often leave out the
- * type definitions to produce shorter, more readable, code. This cannot be
- * done when creating templated objects directly.
- */
-#ifndef API_HPP
-#define API_HPP
-#include <string>
-#include <vector>
-#include "filval/value.hpp"
-namespace fv{
-
-    template<typename T>
-    Value<T>* lookup(const std::string& name){
-        Value<T>* tv = GenValue::get_value<T>(name);
-        if (tv == nullptr){
-            CRITICAL("Could not find alias or value \"" << name << "\"."
-                     <<" I'll tell you the ones I know about." << std::endl
-                     << GenValue::summary(), -1);
-        }
-        return tv;
-    }
-
-    template<typename T>
-    bool check_exists(const std::string name){
-        Value<T>* tv = GenValue::get_value<T>(name);
-        return tv != nullptr;
-    }
-
-    ObsFilter* lookup_obs_filter(const std::string& name){
-        ObsFilter* f =  dynamic_cast<ObsFilter*>(GenValue::get_value<bool>(name));
-        if(f == nullptr){
-            CRITICAL("ObsFilter: "+f->get_name() + "has improper type.",-1);
-        }
-        return f;
-    }
-
-    template <typename T>
-    decltype(auto)
-    wrapper_vector(Value<int>* size, Value<T*>* data, const std::string& alias=""){
-        typedef std::vector<T> type;
-        const std::string& name = WrapperVector<T>::fmt_name(size, data);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new WrapperVector<T>(size, data, alias);
-    }
-
-    template <typename... ArgTypes>
-    decltype(auto)
-    zip(Value<std::vector<ArgTypes>>*... args, const std::string& alias=""){
-        typedef std::vector<std::tuple<ArgTypes...>> type;
-        std::string& name = Zip<ArgTypes...>::fmt_name(args...);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Zip<ArgTypes...>(args..., alias);
-    }
-
-    template <typename Ret, typename... ArgTypes>
-    decltype(auto)
-    map(Function<Ret(ArgTypes...)>& fn, Value<std::vector<std::tuple<ArgTypes...>>>* arg, const std::string& alias=""){
-        typedef std::vector<Ret> type;
-        const std::string& name = Map<Ret(ArgTypes...)>::fmt_name(fn, arg);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Map<Ret(ArgTypes...)>(fn, arg, alias);
-    }
-
-    template <typename... ArgTypes>
-    decltype(auto)
-    tuple(Value<ArgTypes>*... args){
-        typedef std::tuple<ArgTypes...> type;
-        const std::string& name = Tuple<ArgTypes...>::fmt_name(args...);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Tuple<ArgTypes...>(args..., "");
-    }
-
-    template <size_t N, typename... ArgTypes>
-    decltype(auto)
-    detup(Value<std::tuple<ArgTypes...>>* tup, const std::string& alias=""){
-        typedef typename std::tuple_element<N, std::tuple<ArgTypes...>>::type type;
-        const std::string& name = DeTup<N, ArgTypes...>::fmt_name(tup);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new DeTup<N, ArgTypes...>(tup, alias);
-    }
-
-    template <size_t N, typename... ArgTypes>
-    decltype(auto)
-    detup_vec(Value<std::vector<std::tuple<ArgTypes...>>>* tup, const std::string& alias=""){
-        typedef std::vector<typename std::tuple_element<N, std::tuple<ArgTypes...>>::type> type;
-        const std::string& name = DeTupVector<N, ArgTypes...>::fmt_name(tup);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new DeTupVector<N, ArgTypes...>(tup, alias);
-    }
-
-    template <typename Ret, typename... ArgTypes>
-    decltype(auto)
-    apply(Function<Ret(ArgTypes...)>& fn, Value<std::tuple<ArgTypes...>>* arg, const std::string& alias=""){
-        typedef Ret type;
-        const std::string& name = Apply<Ret(ArgTypes...)>::fmt_name(fn, arg);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Apply<Ret(ArgTypes...)>(fn, arg, alias);
-    }
-
-    template <typename T1, typename T2>
-    decltype(auto)
-    pair(Value<T1>* val1, Value<T2>* val2, const std::string& alias=""){
-        typedef std::pair<T1,T2> type;
-        const std::string& name = Pair<T1,T2>::fmt_name(val1, val2);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Pair<T1,T2>(val1, val2, alias);
-    }
-
-    template <typename T1, typename T2>
-    decltype(auto)
-    pair(const std::string& name1, const std::string& name2, const std::string& alias=""){
-        return pair<T1,T2>(lookup<T1>(name1), lookup<T2>(name2), alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    reduce(Function<T(std::vector<T>)>& fn, Value<std::vector<T>>* v, const std::string& alias=""){
-        typedef T type;
-        const std::string& name = Reduce<T>::fmt_name(fn, v);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Reduce<T>(fn, v, alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    max(Value<std::vector<T>>* v, const std::string& alias=""){
-        typedef T type;
-        const std::string& name = Max<T>::fmt_name(v);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Max<T>(v, alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    max(const std::string& v_name, const std::string& alias=""){
-        return max(lookup<std::vector<T>>(v_name), alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    min(Value<std::vector<T>>* v, const std::string& alias=""){
-        typedef T type;
-        const std::string& name = Min<T>::fmt_name(v);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Min<T>(v, alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    min(const std::string& v_name, const std::string& alias=""){
-        return min(lookup<std::vector<T>>(v_name), alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    range(Value<std::vector<T>>* v, const std::string& alias=""){
-        typedef T type;
-        const std::string& name = Range<T>::fmt_name(v);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Range<T>(v, alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    range(const std::string& v_name, const std::string& alias=""){
-        return range(lookup<std::vector<T>>(v_name), alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    mean(Value<std::vector<T>>* v, const std::string& alias=""){
-        typedef T type;
-        const std::string& name = Mean<T>::fmt_name(v);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Mean<T>(v, alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    mean(const std::string& v_name, const std::string& alias=""){
-        return mean(lookup<std::vector<T>>(v_name), alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string& alias=""){
-        typedef int type;
-        const std::string& name = Count<T>::fmt_name(selector, v);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Count<T>(selector, v, alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    count(Function<bool(T)>& selector, const std::string& v_name, const std::string& alias=""){
-        return count<T>(selector, lookup<std::vector<T>>(v_name), alias);
-    }
-
-    template <typename FST, typename SND>
-    decltype(auto)
-    cart_product(Value<std::vector<FST>>* val1, Value<std::vector<SND>>* val2, const std::string& alias=""){
-        typedef std::vector<std::tuple<FST,SND>> type;
-        const std::string& name = CartProduct<FST, SND>::fmt_name(val1, val2);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new CartProduct<FST, SND>(val1, val2, alias);
-    }
-
-    template <typename FST, typename SND>
-    decltype(auto)
-    cart_product(const std::string& val1_name, const std::string& val2_name, const std::string& alias=""){
-        return cart_product<FST,SND>(lookup<std::vector<FST>>(val1_name), lookup<std::vector<SND>>(val2_name), alias);
-    }
-
-    template <typename T, int Size>
-    decltype(auto)
-    combinations(Value<std::vector<T>>* val, const std::string& alias=""){
-        typedef std::vector<typename HomoTuple<T,Size>::type> type;
-        const std::string& name = Combinations<T, Size>::fmt_name(val);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Combinations<T, Size>(val, alias);
-    }
-
-    template <typename T, int Size>
-    decltype(auto)
-    combinations(const std::string& val_name, const std::string alias = ""){
-        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=""){
-        typedef std::vector<T> type;
-        const std::string& name = Filter<T>::fmt_name(filter, val);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new Filter<T>(filter, val, alias);
-    }
-
-    template <typename T>
-    decltype(auto)
-    filter(Function<bool(T)>& filter_func, const std::string& val_name, const std::string alias=""){
-        return filter<T>(filter_func, lookup<std::vector<T>>(val_name), alias);
-    }
-
-    template <typename... ArgTypes>
-    decltype(auto)
-    tup_filter(Function<bool(ArgTypes...)>& filter, Value<std::vector<std::tuple<ArgTypes...>>>* val, const std::string alias=""){
-        typedef std::vector<std::tuple<ArgTypes...>> type;
-        const std::string& name = TupFilter<ArgTypes...>::fmt_name(filter, val);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new TupFilter<ArgTypes...>(filter, val, alias);
-    }
-
-    template <typename... ArgTypes>
-    decltype(auto)
-    tup_filter(Function<bool(ArgTypes...)>& filter, const std::string& val_name, const std::string alias=""){
-        return tup_filter<ArgTypes...>(filter, lookup<std::vector<std::tuple<ArgTypes...>>>(val_name), alias);
-    }
-
-    ObsFilter* obs_filter(const std::string& name, std::function<bool()> filter_function, const std::string& impl=""){
-        return new ObsFilter(name, filter_function, impl);
-    }
-}
-#endif // API_HPP

+ 0 - 65
filval/argparse.hpp

@@ -1,65 +0,0 @@
-/**
- * @file
- * @author  Caleb Fangmeier <caleb@fangmeier.tech>
- * @version 0.1
- *
- * @section LICENSE
- *
- *
- * MIT License
- *
- * Copyright (c) 2017 Caleb Fangmeier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * @section DESCRIPTION
- * \see http://stackoverflow.com/questions/865668/how-to-parse-command-line-arguments-in-c#868894
- */
-#ifndef argparse_hpp
-#define argparse_hpp
-#include <algorithm>
-#include <string>
-#include <vector>
-namespace fv::util{
-class ArgParser{
-    private:
-        std::vector <std::string> tokens;
-        std::string empty_string;
-    public:
-        ArgParser (int &argc, char **argv){
-            for (int i=1; i < argc; ++i)
-                this->tokens.push_back(std::string(argv[i]));
-        }
-        /// @author iain
-        const std::string& getCmdOption(const std::string &option) const{
-            std::vector<std::string>::const_iterator itr;
-            itr =  std::find(this->tokens.begin(), this->tokens.end(), option);
-            if (itr != this->tokens.end() && ++itr != this->tokens.end()){
-                return *itr;
-            }
-            return empty_string;
-        }
-        /// @author iain
-        bool cmdOptionExists(const std::string &option) const{
-            return std::find(this->tokens.begin(), this->tokens.end(), option)
-                   != this->tokens.end();
-        }
-};
-}
-#endif // argparse_hpp

+ 0 - 192
filval/container.hpp

@@ -1,192 +0,0 @@
-/**
- * @file
- * @author  Caleb Fangmeier <caleb@fangmeier.tech>
- * @version 0.1
- *
- * @section LICENSE
- *
- *
- * MIT License
- *
- * Copyright (c) 2017 Caleb Fangmeier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#ifndef container_hpp
-#define container_hpp
-#include <typeindex>
-#include <vector>
-#include <map>
-
-#include "value.hpp"
-#include "filter.hpp"
-
-template class std::vector<std::vector<float> >;
-template class std::vector<std::vector<int> >;
-
-
-namespace fv::util{
-std::string get_type_name(const std::type_index& index){
-    std::map<std::type_index, std::string> _map;
-    // Add to this list as needed :)
-    _map[typeid(int)]="int";
-    _map[typeid(unsigned int)]="unsigned int";
-    _map[typeid(float)]="float";
-    _map[typeid(double)]="double";
-    _map[typeid(std::vector<int>)]="std::vector<int>";
-    _map[typeid(std::vector<float>)]="std::vector<float>";
-    _map[typeid(std::map<std::string,std::string>)] = "std::map<std::string,std::string>";
-
-    if (_map[index] == ""){
-        CRITICAL("Cannot lookup type name of \"" << index.name() << "\"",-1);
-    }
-    return _map[index];
-}
-}
-
-namespace fv{
-
-/**
- * Enumeration of different options that can be used to save Containers. Not
- * all options are allowed for all Containers.
- */
-enum SaveOption{
-    PNG = 0,
-    PDF = 1,
-    ROOT = 2
-};
-
-/**
- * Generic, untyped parent class of Container. Used to allow for placing
- * Containers of disparate types in common data structures.
- */
-class GenContainer{
-    private:
-        std::string name;
-        std::string desc;
-        std::vector<ObsFilter*> filters;
-    protected:
-        virtual void _fill() = 0;
-    public:
-        GenContainer(const std::string name, const std::string& desc)
-          :name(name),desc(desc) { }
-
-        GenContainer(const std::string name)
-          :GenContainer(name,"N/A"){ }
-
-        GenContainer* add_filter(GenValue* filter){
-            filters.push_back(dynamic_cast<ObsFilter*>(filter));
-            return this;
-        }
-
-        void fill(){
-            for (auto filter : filters){
-                if (!filter->get_value()) return;
-            }
-            _fill();
-        }
-
-        void set_description(const std::string& description){
-            desc = description;
-        }
-
-        const std::string& get_name(){
-            return name;
-        }
-
-        virtual const std::string get_value_name(){
-            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) {
-            save_as(get_name(), option);
-        }
-};
-
-/**
- * A class that is used to "hold" values. When an event is loaded, the
- * associated filters on this container are checked. If they all pass, the
- * \c _fill() method is called and the Container can access the stored Value
- * object to process it. For example, if the Container is a ROOT Histogram
- * object, it may call <tt>container->Fill(value->get_value())</tt>.
- */
-template <typename H, typename V>
-class Container : public GenContainer{
-    protected:
-        H* container;
-        Value<V> *value;
-    public:
-        Container(const std::string& name, Value<V>* value)
-          :GenContainer(name),
-           container(nullptr),
-           value(value){ }
-
-        virtual H* get_container(){
-            return container;
-        }
-
-        virtual const std::string get_value_name(){
-            return value->get_name();
-        }
-};
-
-/**
- * Calculate the Mean of a Value over a series of observations. This class is
- * given a value of some type that supports addition and division(eg. a \c
- * float) and yields the mean value. Note that this implementation does \i not
- * support serialization so it is not incredibly useful. See the ROOT
- * Containers for Containers that support serialization using ROOT's
- * facilities.
- */
-template <typename T>
-class ContainerMean : public Container<T,T>{
-    private:
-        int count;
-        T sum;
-
-        void _fill(){
-            count++;
-            sum += this->value->get_value();
-        }
-    public:
-        ContainerMean(const std::string& name, Value<T>* value)
-          :Container<std::vector<T>,T>(name, value){
-            this->container = new T();
-        }
-
-        T* get_container(){
-            *(this->container) = sum/count;
-            return (this->container);
-        }
-
-        GenContainer* clone_as(const std::string& new_name){
-            return new ContainerMean(new_name, this->value);
-        }
-
-        void save_as(const std::string&) {
-            WARNING("Saving of ContainerMean objects not supported");
-        }
-};
-
-}
-#endif // container_hpp

+ 0 - 147
filval/dataset.hpp

@@ -1,147 +0,0 @@
-/**
- * @file
- * @author  Caleb Fangmeier <caleb@fangmeier.tech>
- * @version 0.1
- *
- * @section LICENSE
- *
- *
- * MIT License
- *
- * Copyright (c) 2017 Caleb Fangmeier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#ifndef dataset_hpp
-#define dataset_hpp
-#include <iostream>
-#include "value.hpp"
-#include "container.hpp"
-#include "log.hpp"
-
-namespace fv{
-
-typedef std::map<std::string, GenContainer*> ContainerSet;
-
-/*
- * A DataSet is a generic source of data that is used to populate
- * ObservedValues. For each ObservedValue, it is recommened that the DataSet
- * have a field whose value is updated when the load_next() method is called. A
- * pointer to this value is then passed during the creation of the
- * ObservedValue. It is important, therefore, that the location in memory of
- * the data not change from event to event.
- */
-class DataSet{
-    private:
-        void summary(){
-            INFO(GenValue::summary());
-            INFO(GenFunction::summary());
-        }
-
-        Value<int>* current_event_number;
-
-    protected:
-        ContainerSet containers;
-        virtual bool load_next() = 0;
-        virtual int get_events() = 0;
-        virtual int get_current_event() = 0;
-
-        std::map<std::string,std::string> get_container_name_value_map(){
-            std::map<std::string, std::string> value_map;
-            for(auto container : containers)
-                value_map[container.first] = container.second->get_value_name();
-            return value_map;
-        }
-
-        std::map<std::string,std::string> get_function_name_impl_map(){
-            std::map<std::string, std::string> impl_map;
-            for(auto fn : GenFunction::function_registry)
-                if (fn.second != nullptr){
-                    impl_map[fn.first] = GenFunction::format_code(fn.second->get_impl());
-                }
-            return impl_map;
-        }
-    public:
-        DataSet(){
-            auto& event_check = GenFunction::reg_func<int()>("event_number",
-                FUNC(([ds=this](){
-                    return ds->get_current_event();
-                })));
-            current_event_number = new BoundValue<int>(event_check);
-        }
-
-        void process(bool silent=false){
-            int events, current_event;
-            summary();
-            events = get_events();
-            if (!silent) std::cout << std::endl;
-            while( load_next() ){
-                current_event = get_current_event();
-                if (!silent) std::cout << "\rprocessing event: " << current_event+1 << "/" << events << std::flush;
-                GenValue::reset();
-                for(auto con : containers){
-                    con.second->fill();
-                }
-            }
-            if (!silent) std::cout << " Finished!" << std::endl;
-        }
-
-        virtual void save_all(){
-            for(auto container : containers)
-                container.second->save();
-        }
-
-        template<typename C, typename... ArgTypes>
-        C* register_container(ArgTypes... args){
-            C* container = new C(args...);
-            if (containers[container->get_name()] != nullptr){
-                CRITICAL("Container with name \""+container->get_name()+"\" already exists.", -1);
-            }
-            containers[container->get_name()] = container;
-            return container;
-        }
-
-        void cut_set(GenContainer* base_container, std::vector<std::pair<Value<bool>*, std::string>> filters){
-            for(auto p : filters){
-                Value<bool>* filter;
-                std::string new_name;
-                std::tie(filter, new_name) = p;
-                if (containers[new_name] != nullptr){
-                    CRITICAL("Container with name \""<<new_name<<"\" already exists.", -1);
-                }
-                auto new_container = base_container->clone_as(new_name);
-                new_container->add_filter(filter);
-                containers[new_container->get_name()] = new_container;
-            }
-        }
-
-        GenContainer* get_container(std::string container_name){
-            GenContainer* c = containers[container_name];
-            if (c == nullptr){
-                CRITICAL("Request for container \"" << container_name << "\" failed. Doesn't exist.", -1);
-            }
-            return c;
-        }
-
-        Value<int>* get_current_event_number(){
-            return current_event_number;
-        }
-};
-}
-#endif // dataset_hpp

+ 0 - 97
filval/examples/example1.cpp

@@ -1,97 +0,0 @@
-/**
- * @file
- * @author  Caleb Fangmeier <caleb@fangmeier.tech>
- * @version 0.1
- *
- * @section LICENSE
- *
- *
- * MIT License
- *
- * Copyright (c) 2017 Caleb Fangmeier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * @section DESCRIPTION
- * A short example demonstrating some of the basic functionality of the FilVal
- * Value system.
- */
-
-#include <iostream>
-#include <utility>
-
-#include "filval/filval.hpp"
-
-int main(int argc, const char* argv[]){
-    // Initialize logging. Let's not worry about what is being logged right now
-    // and just redirect it to /dev/null so it doesn't appear on the screen.
-    fv::util::Log::init_logger("/dev/null", fv::util::LogPriority::kLogDebug);
-
-    // declare a helper function to print out a std::pair object
-    auto print_pair = [](fv::Value<std::pair<double, double>>* dp){
-        std::pair<double, double> p = dp->get_value();
-        std::cout << "(" << p.first << ", " << p.second << ")\n";
-    };
-
-    // These variables are the "Values" that will be observed. Think of these
-    // as sources of data that will be updated as new observations are loaded.
-    double x = 12;
-    double y = 13;
-
-    // This is where the fun begins. Here we declare a couple ObservedValue
-    // objects. these are basically just fancy wrappers around the x, and y
-    // variables declared above. They have the job of supplying the value
-    // stored by x and y when requested.
-    fv::ObservedValue<double> x_val("x", &x);
-    fv::ObservedValue<double> y_val("y", &y);
-
-    // Now that we have a few source values, let's compose them together into a
-    // pair. The fv api defines a function to do this: fv::pair. This function
-    // takes pointers to two Value objects and creates a new value that is a
-    // std::pair of these objects.
-    fv::Value<std::pair<double, double>>* dp = fv::pair(&x_val, &y_val);
-
-    // If we call the print_pair function that we declared earlier with the new
-    // value object, we can see that, indeed, we see the correct output
-    // (12, 13)
-    print_pair(dp);
-
-    // Now let's update the values of x and y to both be 2. Normally this job
-    // will be handled by a DataSet object which manages these variables, but
-    // we can do it here for now.
-    x = 2;
-    y = 2;
-
-    // Before we can access these new values through our value chain, we need
-    // to tell the values to "reset". One of the main features of FV is that
-    // each value is only calculated at most once per observation, regardless
-    // of how many times it is accessed. However, this means that we have to
-    // tell the objects when a new object has been loaded so it will actually
-    // do a re-calculation. In the case of dp, this means that it will
-    // re-access the values of x and y and create a new pair with the updated
-    // values.
-    fv::GenValue::reset();
-
-    // Call print_pair again just to verify that it gives the updated values,
-    // and indeed it does.
-    // (2, 2)
-    print_pair(dp);
-
-    return 0;
-}

+ 0 - 74
filval/examples/example2.cpp

@@ -1,74 +0,0 @@
-#include <iostream>
-#include <vector>
-#include <utility>
-
-#include "TFile.h"
-#include "TTree.h"
-#include "TCanvas.h"
-
-#include "filval/filval.hpp"
-
-#include "MiniTreeDataSet.hpp"
-
-void test2(){
-    double x = 12;
-    ObservedValue<double> x_val("x", &x);
-    ContainerTH1D hist("h1", "Hist", &x_val, 20, 0, 20);
-    hist.fill();
-    hist.fill();
-    hist.fill();
-    x = 11;
-    hist.fill();
-    hist.fill();
-    hist.fill();
-    hist.fill();
-    hist.fill();
-    hist.fill();
-
-    TH1D* h = (TH1D*) hist.get_container();
-    TCanvas can("c1");
-    h->Draw();
-    can.Draw();
-    can.SaveAs("outfile.png");
-}
-
-void test3(){
-    TFile *f = TFile::Open("./data/TTTT_ext_treeProducerSusyMultilepton_tree.root");
-    TTree *tree = (TTree*) f->Get("tree");
-    MiniTreeDataSet mtds(tree);
-    mtds.process();
-    TCanvas can("c1");
-    can.Clear();
-    TH1* hist = ((ContainerTH1I*)mtds.get_container("nLepGood"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("outfile.png");
-
-    can.Clear();
-    hist = ((ContainerTH1I*)mtds.get_container("nLepGood2"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("outfile2.png");
-
-    can.Clear();
-    hist = ((ContainerTH1I*)mtds.get_container("nLepGood3"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("outfile3.png");
-
-    can.Clear();
-    hist = ((ContainerTH1I*)mtds.get_container("avg_lepton_energy"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("lepton_energy.png");
-
-    can.Clear();
-    TGraph* graph= ((ContainerTGraph*)mtds.get_container("nLepvsnJet"))->get_container();
-    graph->Draw("A*");
-    can.Draw();
-    can.SaveAs("outfileGraph.png");
-
-    delete tree;
-    f->Close();
-    delete f;
-}

+ 0 - 52
filval/examples/example3.cpp

@@ -1,52 +0,0 @@
-#include <iostream>
-#include <vector>
-#include <utility>
-
-#include "TFile.h"
-#include "TTree.h"
-#include "TCanvas.h"
-
-#include "filval/filval.hpp"
-
-#include "MiniTreeDataSet.hpp"
-
-void test3(){
-    TFile *f = TFile::Open("./data/TTTT_ext_treeProducerSusyMultilepton_tree.root");
-    TTree *tree = (TTree*) f->Get("tree");
-    MiniTreeDataSet mtds(tree);
-    mtds.process();
-    TCanvas can("c1");
-    can.Clear();
-    TH1* hist = ((ContainerTH1I*)mtds.get_container("nLepGood"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("outfile.png");
-
-    can.Clear();
-    hist = ((ContainerTH1I*)mtds.get_container("nLepGood2"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("outfile2.png");
-
-    can.Clear();
-    hist = ((ContainerTH1I*)mtds.get_container("nLepGood3"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("outfile3.png");
-
-    can.Clear();
-    hist = ((ContainerTH1I*)mtds.get_container("avg_lepton_energy"))->get_container();
-    hist->Draw();
-    can.Draw();
-    can.SaveAs("lepton_energy.png");
-
-    can.Clear();
-    TGraph* graph= ((ContainerTGraph*)mtds.get_container("nLepvsnJet"))->get_container();
-    graph->Draw("A*");
-    can.Draw();
-    can.SaveAs("outfileGraph.png");
-
-    delete tree;
-    f->Close();
-    delete f;
-}

+ 0 - 89
filval/filter.hpp

@@ -1,89 +0,0 @@
-/**
- * @file
- * @author  Caleb Fangmeier <caleb@fangmeier.tech>
- * @version 0.1
- *
- * @section LICENSE
- *
- *
- * MIT License
- *
- * Copyright (c) 2017 Caleb Fangmeier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * @section DESCRIPTION
- * A Filter is a special type of derived value that can only return a boolean.
- * Container objects have a vector of filters that control if a "fill" call
- * actually places data into the container or not. This file contains a variety
- * of generic filters to aide in analysis.
- */
-#ifndef filter_h
-#define filter_h
-#include <iostream>
-#include <functional>
-#include "value.hpp"
-namespace fv {
-
-class ObsFilter : public DerivedValue<bool>{
-    private:
-        Function<bool()>& filter_function;
-
-        void update_value(){
-            value = filter_function();
-        }
-
-    public:
-        ObsFilter(const std::string& name, std::function<bool()> filter_function, const std::string& impl="")
-          :DerivedValue<bool>(name),
-           filter_function(GenFunction::reg_func<bool()>("filter::"+name, filter_function, impl)){ }
-};
-
-/** Return a new filter that is the conjuction of a vector of source filters
- */
-ObsFilter* all(const std::vector<ObsFilter*>&& fs){
-    if(fs.size() == 0){
-        return nullptr;
-    } else{
-        std::stringstream ss;
-        ss << fs[0]->get_name();
-        for(size_t i=1; i<fs.size(); i++) ss << "AND" << fs[i]->get_name();
-        return new ObsFilter(ss.str(), [fs](){
-                return std::all_of(std::begin(fs), std::end(fs), [](ObsFilter* f){return f->get_value();});
-        });
-    }
-}
-
-/** Return a new filter that is the disjunction of a vector of source filters
- */
-ObsFilter* any(const std::vector<ObsFilter*>&& fs){
-    if(fs.size() == 0){
-        return nullptr;
-    } else{
-        std::stringstream ss;
-        ss << fs[0]->get_name();
-        for(size_t i=1; i<fs.size(); i++) ss << "OR" << fs[i]->get_name();
-        return new ObsFilter(ss.str(), [fs](){
-                return std::any_of(std::begin(fs), std::end(fs), [](ObsFilter* f){return f->get_value();});
-        });
-    }
-}
-
-}
-#endif // filter_h

+ 0 - 12
filval/filval.hpp

@@ -1,12 +0,0 @@
-#ifndef filval_hpp
-#define filval_hpp
-#define FILVAL_VERSION_MAJOR @FILVAL_VERSION_MAJOR@
-#define FILVALTutorial_VERSION_MINOR @FILVAL_VERSION_MINOR@
-#include "value.hpp"
-#include "filter.hpp"
-#include "container.hpp"
-#include "dataset.hpp"
-#include "log.hpp"
-#include "argparse.hpp"
-#include "api.hpp"
-#endif // filval_hpp

+ 0 - 120
filval/log.hpp

@@ -1,120 +0,0 @@
-/**
- * @file
- * @author  Caleb Fangmeier <caleb@fangmeier.tech>
- * @version 0.1
- *
- * @section LICENSE
- *
- *
- * MIT License
- *
- * Copyright (c) 2017 Caleb Fangmeier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * @section DESCRIPTION
- */
-#ifndef log_hpp
-#define log_hpp
-
-#include <iostream>
-#include <fstream>
-#include <cstring>
-#include <map>
-
-namespace fv::util{
-enum LogPriority {
-    kLogEmergency = 7,  // system is unusable
-    kLogAlert     = 6,  // action must be taken immediately
-    kLogCritical  = 5,  // critical conditions
-    kLogError     = 4,  // error conditions
-    kLogWarning   = 3,  // warning conditions
-    kLogNotice    = 2,  // normal, but significant, condition
-    kLogInfo      = 1,  // informational message
-    kLogDebug     = 0   // debug-level message
-};
-
-#define CRITICAL(x,y) std::clog << fv::util::LogPriority::kLogCritical << __FILE__ << "@L" << __LINE__ << " :: " << x << std::flush; std::cout << "Errors encountered! See log file for details."<<std::endl;exit(y)
-#define ERROR(x) std::clog << fv::util::LogPriority::kLogError << __FILE__ << "@L" << __LINE__ << " :: " << x << std::flush
-#define WARNING(x) std::clog << fv::util::LogPriority::kLogWarning << x << std::flush
-#define INFO(x) std::clog << fv::util::LogPriority::kLogInfo << x << std::flush
-#define DEBUG(x) std::clog << fv::util::LogPriority::kLogDebug << __FILE__ << "@L" << __LINE__ << " :: " << x << std::flush
-
-/**
- * /see http://stackoverflow.com/questions/2638654/redirect-c-stdclog-to-syslog-on-unix
- */
-std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority);
-
-class Log : public std::basic_streambuf<char, std::char_traits<char> > {
-private:
-    std::string buffer_;
-    std::ofstream logfile;
-    LogPriority priority_curr;
-    LogPriority priority_set;
-    inline static Log* singleton = nullptr;
-    const std::map<LogPriority,std::string> name_map = {{kLogEmergency, "EMERGENCY"},
-                                                        {kLogAlert,     "ALERT"},
-                                                        {kLogCritical,  "CRITICAL"},
-                                                        {kLogError,     "ERROR"},
-                                                        {kLogWarning,   "WARNING"},
-                                                        {kLogNotice,    "NOTICE"},
-                                                        {kLogInfo,      "INFO"},
-                                                        {kLogDebug,     "DEBUG"}};
-
-    friend std::ostream& operator<< (std::ostream& os, const LogPriority& log_priority){
-        static_cast<Log *>(os.rdbuf())->priority_curr = log_priority;
-        return os;
-    }
-protected:
-    int sync(){
-        if (buffer_.length()) {
-            if (priority_curr >= priority_set){
-                logfile << name_map.at(priority_curr) << ": " <<  buffer_ << std::endl << std::flush;
-            }
-            buffer_.erase();
-            /* priority_curr = kLogDebug; // default to debug for each message */
-        }
-        return 0;
-    }
-    int overflow(int c){
-        if (c != EOF) {
-            buffer_ += static_cast<char>(c);
-        } else {
-            sync();
-        }
-        return c;
-    }
-public:
-    explicit Log(std::string filename, LogPriority priority)
-      :logfile(filename, std::ofstream::out){
-        priority_set = priority;
-        priority_curr = kLogDebug;
-    }
-
-    static Log& init_logger(std::string filename, LogPriority priority){
-        if (singleton == nullptr){
-            singleton = new Log(filename, priority);
-            std::cout << "Writing log data to " << filename << std::endl;
-            std::clog.rdbuf(singleton);
-        }
-        return *singleton;
-    }
-};
-}
-#endif // log_hpp

+ 0 - 14
filval/root/LinkDef.hpp

@@ -1,14 +0,0 @@
-#ifndef linkdef_hpp
-#define linkdef_hpp
-#include <vector>
-#include <string>
-#include <map>
-
-#ifdef __CLING__
-#pragma link C++ class std::vector<std::vector<int>>+;
-#pragma link C++ class std::vector<std::vector<unsigned int>>+;
-#pragma link C++ class std::vector<std::vector<float>>+;
-#pragma link C++ class std::map<std::string,std::string>+;
-#endif
-
-#endif // linkdev_hpp

+ 0 - 63
filval/root/root_api.hpp

@@ -1,63 +0,0 @@
-#ifndef ROOT_API_HPP
-#define ROOT_API_HPP
-#include <string>
-#include <vector>
-#include <tuple>
-#include "filval/api.hpp"
-#include "filval/root/root_value.hpp"
-namespace fv::root{
-
-    decltype(auto)
-    lorentz_vectors(Value<std::vector<float>>* pt, Value<std::vector<float>>* eta,
-                    Value<std::vector<float>>* phi, Value<std::vector<float>>* mass,
-                    const std::string& alias=""){
-        typedef std::vector<TLorentzVector> type;
-        const std::string& name = root::LorentzVectors::fmt_name(pt, eta, phi, mass);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new root::LorentzVectors(pt, eta, phi, mass, alias);
-    }
-
-    decltype(auto)
-    lorentz_vectors(const std::string& pt_name, const std::string& eta_name,
-                    const std::string& phi_name, const std::string& mass_name,
-                    const std::string& alias=""){
-        return lorentz_vectors(lookup<std::vector<float>>(pt_name), lookup<std::vector<float>>(eta_name),
-                               lookup<std::vector<float>>(phi_name), lookup<std::vector<float>>(mass_name),
-                               alias);
-    }
-
-    decltype(auto)
-    energies(Value<std::vector<TLorentzVector>>* vectors, const std::string& alias="") {
-        typedef std::vector<float> type;
-        const std::string& name = root::Energies::fmt_name(vectors);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new root::Energies(vectors, alias);
-    }
-
-    decltype(auto)
-    energies(const std::string& vectors_name, const std::string& alias="") {
-        return energies(lookup<std::vector<TLorentzVector>>(vectors_name), alias);
-    }
-
-    template<typename... DataTypes>
-    decltype(auto)
-    mva_data(Value<bool>* is_training, Value<bool>* is_signal, Value<double>* weight,
-             const std::pair<std::string, Value<DataTypes>*>&&... data_vals) {
-        typedef typename root::MVAData<DataTypes...> mva_type;
-        typedef typename mva_type::type type;
-        std::string alias="";
-        const std::string& name = mva_type::fmt_name(is_training, is_signal, weight,
-                                                     std::forward<const std::pair<std::string,Value<DataTypes>*>>(data_vals)...);
-        if (check_exists<type>(name))
-            return lookup<type>(name);
-        else
-            return (Value<type>*)new mva_type(is_training, is_signal, weight,
-                                                     std::forward<const std::pair<std::string,Value<DataTypes>*>>(data_vals)...);
-    }
-
-}
-#endif // ROOT_API_HPP

+ 0 - 444
filval/root/root_container.hpp

@@ -1,444 +0,0 @@
-#ifndef root_container_hpp
-#define root_container_hpp
-#include <iostream>
-#include <utility>
-#include <map>
-
-#include "TROOT.h"
-#include "TFile.h"
-#include "TCanvas.h"
-#include "TGraph.h"
-#include "TH1.h"
-#include "TH2.h"
-
-#include "TMVA/Factory.h"
-#include "TMVA/DataLoader.h"
-#include "TMVA/DataSetInfo.h"
-
-#include "filval/container.hpp"
-
-namespace fv::root::util{
-    /**
-     * Save a TObject. The TObject will typically be a Histogram or Graph object,
-     * but can really be any TObject. The SaveOption can be used to specify how to
-     * save the file.
-     */
-    void save_as(TObject* container, const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-
-        auto save_img = [](TObject* container, const std::string& fname){
-            TCanvas* c1 = new TCanvas("c1");
-            container->Draw();
-            c1->Draw();
-            c1->SaveAs(fname.c_str());
-            delete c1;
-        };
-
-        auto save_bin = [](TObject* container){
-            INFO("Saving object: " << container->GetName() << " into file " << gDirectory->GetName());
-            container->Write(container->GetName(), TObject::kOverwrite);
-        };
-
-        switch(option){
-            case PNG:
-                save_img(container, fname+".png"); break;
-            case PDF:
-                save_img(container, fname+".pdf"); break;
-            case ROOT:
-                save_bin(container); break;
-            default:
-                break;
-        }
-    }
-
-
-    /**
-     * Saves an STL container into a ROOT file. ROOT knows how to serialize STL
-     * containers, but it needs the *name* of the type of the container, eg.
-     * std::map<int,int> to be able to do this. In order to generate this name at
-     * run-time, the fv::util::get_type_name function uses RTTI to get type info
-     * and use it to look up the proper name.
-     *
-     * For nexted containers, it is necessary to generate the CLING dictionaries
-     * for each type at compile time to enable serialization. To do this, add the
-     * type definition into the LinkDef.hpp header file.
-     */
-    void save_as_stl(void* container, const std::string& type_name,
-                      const std::string& obj_name,
-                      const SaveOption& option = SaveOption::PNG) {
-        switch(option){
-            case PNG:
-                INFO("Cannot save STL container " << type_name <<" as png");
-                break;
-            case PDF:
-                INFO("Cannot save STL container " << type_name <<" as pdf");
-                break;
-            case ROOT:
-                /* DEBUG("Writing object \"" << obj_name << "\" of type \"" << type_name << "\"\n"); */
-                gDirectory->WriteObjectAny(container, type_name.c_str(), obj_name.c_str());
-                break;
-            default:
-                break;
-        }
-    }
-}
-
-namespace fv::root {
-
-template <typename V>
-class _ContainerTH1 : public Container<TH1,V>{
-    private:
-        void _fill(){
-            if (this->container == nullptr){
-                if (this->value == nullptr){
-                    CRITICAL("Container: \"" << this->get_name() << "\" has a null Value object. "
-                             << "Probably built with imcompatible type",-1);
-                }
-                this->container = new TH1D(this->get_name().c_str(), this->title.c_str(),
-                                           this->nbins, this->low, this->high);
-                this->container->SetXTitle(label_x.c_str());
-                this->container->SetYTitle(label_y.c_str());
-            }
-            _do_fill();
-        }
-
-    protected:
-        std::string title;
-        std::string label_x;
-        std::string label_y;
-        int nbins;
-        double low;
-        double high;
-
-        virtual void _do_fill() = 0;
-
-    public:
-        explicit _ContainerTH1(const std::string &name, const std::string& title, Value<V>* value,
-                               int nbins, double low, double high,
-                               const std::string& label_x = "",
-                               const std::string& label_y = "")
-          :Container<TH1,V>(name, value),
-           title(title), nbins(nbins), low(low), high(high),
-           label_x(label_x), label_y(label_y) { }
-
-        void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            util::save_as(this->get_container(), fname, option);
-        }
-};
-
-template <typename V>
-class ContainerTH1 : public _ContainerTH1<V>{
-    using _ContainerTH1<V>::_ContainerTH1;
-    void _do_fill(){
-        this->container->Fill(this->value->get_value());
-    }
-    public:
-        GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH1<V>(new_name, this->title, this->value, this->nbins, this->low, this->high, this->label_x, this->label_y);
-        }
-};
-
-template <typename V>
-class ContainerTH1Many : public _ContainerTH1<std::vector<V>>{
-    using _ContainerTH1<std::vector<V>>::_ContainerTH1;
-    void _do_fill(){
-        for(V x : this->value->get_value())
-            this->container->Fill(x);
-    }
-    public:
-        GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH1Many<V>(new_name, this->title, this->value, this->nbins, this->low, this->high, this->label_x, this->label_y);
-        }
-};
-
-
-
-template <typename V>
-class _ContainerTH2 : public Container<TH2,std::pair<V,V>>{
-    private:
-        void _fill(){
-            if (this->container == nullptr){
-                if (this->value == nullptr){
-                    CRITICAL("Container: \"" << this->get_name() << "\" has a null Value object. "
-                             << "Probably built with imcompatible type",-1);
-                }
-                this->container = new TH2D(this->get_name().c_str(), this->title.c_str(),
-                                           this->nbins_x, this->low_x, this->high_x,
-                                           this->nbins_y, this->low_y, this->high_y);
-                this->container->SetXTitle(label_x.c_str());
-                this->container->SetYTitle(label_y.c_str());
-            }
-            _do_fill(this->value->get_value());
-        }
-
-    protected:
-        std::string title;
-        std::string label_x;
-        std::string label_y;
-        int nbins_x;
-        int nbins_y;
-        double low_x;
-        double low_y;
-        double high_x;
-        double high_y;
-
-        virtual void _do_fill(std::pair<V,V>& val) = 0;
-
-    public:
-        explicit _ContainerTH2(const std::string& name, const std::string& title,
-                               Value<std::pair<V, V>>* value,
-                               int nbins_x, double low_x, double high_x,
-                               int nbins_y, double low_y, double high_y,
-                               const std::string& label_x = "",
-                               const std::string& label_y = "")
-          :Container<TH2,std::pair<V,V>>(name, value),
-           title(title),
-           nbins_x(nbins_x), low_x(low_x), high_x(high_x),
-           nbins_y(nbins_y), low_y(low_y), high_y(high_y),
-           label_x(label_x), label_y(label_y) { }
-
-        void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            util::save_as(this->get_container(), fname, option);
-        }
-};
-
-template <typename V>
-class ContainerTH2 : public _ContainerTH2<V>{
-    using _ContainerTH2<V>::_ContainerTH2;
-    void _do_fill(std::pair<V,V>& val){
-        this->container->Fill(val.first,val.second);
-    }
-    public:
-        GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH2<V>(new_name, this->title, this->value, this->nbins_x, this->low_x, this->high_x,
-                                       this->nbins_y, this->low_y, this->high_y, this->label_x, this->label_y);
-        }
-};
-
-template <typename V>
-class ContainerTH2Many : public _ContainerTH2<std::vector<V>>{
-    using _ContainerTH2<std::vector<V>>::_ContainerTH2;
-    void _do_fill(std::pair<std::vector<V>,std::vector<V>>& val){
-        int min_size = std::min(val.first.size(), val.second.size());
-        for(int i=0; i<min_size; i++)
-            this->container->Fill(val.first[i],val.second[i]);
-    }
-    public:
-        GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTH2Many<V>(new_name, this->title, this->value, this->nbins_x, this->low_x, this->high_x,
-                                           this->nbins_y, this->low_y, this->high_y, this->label_x, this->label_y);
-        }
-};
-
-template <typename V>
-class ContainerTGraph : public Container<TGraph,std::pair<V,V>>{
-    private:
-        std::vector<V> x_data;
-        std::vector<V> y_data;
-        std::string title;
-        bool data_modified;
-        void _fill(){
-            auto val = this->value->get_value();
-            x_data.push_back(val.first);
-            y_data.push_back(val.second);
-            data_modified = true;
-        }
-    public:
-        ContainerTGraph(const std::string& name, const std::string& title, Value<std::pair<V, V>>* value)
-          :Container<TGraph,std::pair<V,V>>(name, value),
-           data_modified(false){
-            this->container = new TGraph();
-           }
-
-        TGraph* get_container(){
-            if (data_modified){
-                delete this->container;
-                this->container = new TGraph(x_data.size(), x_data.data(), y_data.data());
-                this->container->SetName(this->get_name().c_str());
-                this->container->SetTitle(title.c_str());
-                data_modified = false;
-            }
-            return this->container;
-        }
-
-        GenContainer* clone_as(const std::string& new_name){
-            return new ContainerTGraph<V>(new_name, this->title, this->value);
-        }
-
-        void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            util::save_as(get_container(), fname, option);
-        }
-};
-
-template <typename V>
-class Vector : public Container<std::vector<V>,V>{
-    private:
-
-        void _fill(){
-            this->container->push_back(this->value->get_value());
-        }
-    public:
-        Vector(const std::string& name, Value<V>* value)
-          :Container<std::vector<V>,V>(name, value){
-            this->container = new std::vector<V>;
-        }
-
-        GenContainer* clone_as(const std::string& new_name){
-            return new Vector<V>(new_name, this->value);
-        }
-
-        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))+">";
-            util::save_as_stl(this->get_container(), type_name, this->get_name(), option);
-        }
-};
-
-template <typename V, typename D>
-class _Counter : public Container<std::map<D,int>,V>{
-    public:
-        explicit _Counter(const std::string& name, Value<V>* value)
-          :Container<std::map<D,int>,V>(name, value) {
-            this->container = new std::map<D,int>;
-        }
-
-        void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            std::string type_name = "std::map<"+fv::util::get_type_name(typeid(D))+",int>";
-            util::save_as_stl(this->get_container(), type_name, this->get_name(), option);
-        }
-};
-
-
-/**
- * A Counter that keeps a mapping of the number of occurances of each input
- * value.
- */
-template <typename V>
-class Counter : public _Counter<V,V>{
-    using _Counter<V,V>::_Counter;
-        void _fill(){
-            (*this->container)[this->value->get_value()]++;
-        }
-    public:
-        GenContainer* clone_as(const std::string& new_name){
-            return new Counter<V>(new_name, this->value);
-        }
-};
-
-/**
- * Same as Counter but accepts multiple values per fill.
- */
-template <typename V>
-class CounterMany : public _Counter<std::vector<V>,V>{
-    using _Counter<std::vector<V>,V>::_Counter;
-        void _fill(){
-            for(V& val : this->value->get_value())
-                (*this->container)[val]++;
-        }
-    public:
-        GenContainer* clone_as(const std::string& new_name){
-            return new CounterMany<V>(new_name, this->value);
-        }
-};
-
-class PassCount : public Container<int,bool>{
-    private:
-
-        void _fill(){
-            if(this->value->get_value()){
-                (*this->container)++;
-            }
-        }
-    public:
-        PassCount(const std::string& name, Value<bool>* value)
-          :Container<int,bool>(name, value){
-            this->container = new int(0);
-        }
-
-        GenContainer* clone_as(const std::string& new_name){
-            return new PassCount(new_name, this->value);
-        }
-
-        void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            //ROOT(hilariously) cannot serialize basic data types, we wrap this
-            //in a vector.
-            std::vector<int> v({*this->get_container()});
-            util::save_as_stl(&v, "std::vector<int>", this->get_name(), option);
-        }
-};
-
-
-template <typename... ArgTypes>
-class MVA : public Container<TMVA::DataLoader,typename MVAData<ArgTypes...>::type>{
-    private:
-        std::vector<std::pair<std::string,std::string>> methods;
-
-        std::string cut;
-        std::string opt;
-
-        void _fill(){
-            std::tuple<ArgTypes...> t;
-            typename MVAData<ArgTypes...>::type& event = this->value->get_value();
-            bool is_training, is_signal;
-            double weight;
-            std::tie(is_training, is_signal, weight, t) = event;
-            std::vector<double> v = t2v<double>(t);
-            if (is_signal){
-                if (is_training){
-                    this->container->AddSignalTrainingEvent(v, weight);
-                } else {
-                    this->container->AddSignalTestEvent(v, weight);
-                }
-            } else {
-                if (is_training){
-                    this->container->AddBackgroundTrainingEvent(v, weight);
-                } else {
-                    this->container->AddBackgroundTestEvent(v, weight);
-                }
-            }
-        }
-    public:
-        MVA(const std::string& name, MVAData<ArgTypes...>* value, const std::string& cut = "", const std::string& opt = "")
-          :Container<TMVA::DataLoader,typename MVAData<ArgTypes...>::type>(name, value),
-           cut(cut), opt(opt) {
-            this->container = new TMVA::DataLoader(name);
-            for (std::pair<std::string,char>& p : value->get_label_types()){
-                this->container->AddVariable(p.first, p.second);
-            }
-        }
-
-        void add_method(const std::string& method_name, const std::string& method_params) {
-            methods.push_back(std::make_pair(method_name, method_params));
-        }
-
-        GenContainer* clone_as(const std::string& new_name){
-            auto mva = new MVA<ArgTypes...>(new_name, (MVAData<ArgTypes...>*)this->value, this->cut, this->opt);
-            mva->methods = methods;
-            return mva;
-        }
-
-        void save_as(const std::string& fname, const SaveOption& option = SaveOption::PNG) {
-            TFile* outputFile = gDirectory->GetFile();
-
-            this->container->PrepareTrainingAndTestTree(cut.c_str(), opt.c_str());
-            TMVA::Factory *factory = new TMVA::Factory("TMVAClassification", outputFile,
-                                                       "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=Classification");
-
-            TMVA::Types& types = TMVA::Types::Instance();
-            for(auto& p : methods){
-                std::string method_name, method_params;
-                std::tie(method_name, method_params)  = p;
-                TMVA::Types::EMVA method_type = types.GetMethodType(method_name);
-                factory->BookMethod(this->container, method_type, method_name, method_params);
-            }
-
-            // Train MVAs using the set of training events
-            factory->TrainAllMethods();
-            // Evaluate all MVAs using the set of test events
-            factory->TestAllMethods();
-            // Evaluate and compare performance of all configured MVAs
-            factory->EvaluateAllMethods();
-
-            delete factory;
-        }
-};
-}
-#endif // root_container_hpp

+ 0 - 27
filval/root/root_filter.hpp

@@ -1,27 +0,0 @@
-#ifndef root_filter_hpp
-#define root_filter_hpp
-#include "value.hpp"
-#include "TLorentzVector.h"
-
-namespace fv::root{
-
-class MassFilter : public Filter {
-    private:
-        Value<TLorentzVector> *lorentz_vector;
-        Value<double> *mass_cut_low;
-        Value<double> *mass_cut_high;
-    void update_value(){
-        double m = lorentz_vector->get_value().M();
-        value = (m > mass_cut_low) && (m < mass_cut_high);
-    }
-    public:
-        FilterAnd(Value<TLorentzVector> *lorentz_vector,
-                  Value<double> *mass_cut_low,
-                  Value<double> *mass_cut_high)
-          :lorentz_vector(lorentz_vector),
-           mass_cut_low(mass_cut_low),
-           mass_cut_high(mass_cut_high){ }
-};
-
-}
-#endif // root_filter_hpp

+ 0 - 7
filval/root/root_filval.hpp

@@ -1,7 +0,0 @@
-#ifndef root_filval_hpp
-#define root_filval_hpp
-#include "filval/root/root_value.hpp"
-#include "filval/root/root_container.hpp"
-#include "filval/root/root_api.hpp"
-/* #include "dataset.hpp" */
-#endif // root_filval_hpp

+ 0 - 163
filval/root/root_value.hpp

@@ -1,163 +0,0 @@
-#ifndef root_value_hpp
-#define root_value_hpp
-#include "filval/value.hpp"
-#include "TLorentzVector.h"
-
-namespace fv::root{
-
-class LorentzVectors : public DerivedValue<std::vector<TLorentzVector>>{
-    protected:
-        Value<std::vector<float>> *pt_val;
-        Value<std::vector<float>> *eta_val;
-        Value<std::vector<float>> *phi_val;
-        Value<std::vector<float>> *mass_val;
-
-        void update_value(){
-            auto pt = pt_val->get_value();
-            auto eta = eta_val->get_value();
-            auto phi = phi_val->get_value();
-            auto mass = mass_val->get_value();
-            std::vector<int> sizes = {pt.size(), eta.size(), phi.size(), mass.size()};
-            int size = *std::min_element(sizes.begin(), sizes.end());
-            this->value.clear();
-            TLorentzVector lv;
-            for (int i =0; i<size; i++){
-                lv.SetPtEtaPhiM(pt[i], eta[i], phi[i], mass[i]);
-                this->value.push_back(lv);
-            }
-        }
-
-    public:
-        static std::string fmt_name(Value<std::vector<float>>* pt, Value<std::vector<float>>* eta,
-                                    Value<std::vector<float>>* phi, Value<std::vector<float>>* mass){
-            return "lorentz_vectors("+pt->get_name()+"," +eta->get_name()+","+
-                                      phi->get_name()+"," +mass->get_name()+")";
-        }
-
-        LorentzVectors(Value<std::vector<float>>* pt,
-                      Value<std::vector<float>>* eta,
-                      Value<std::vector<float>>* phi,
-                      Value<std::vector<float>>* mass,
-                      const std::string& alias)
-          :DerivedValue<std::vector<TLorentzVector>>(fmt_name(pt,eta,phi,mass), alias),
-           pt_val(pt), eta_val(eta), phi_val(phi), mass_val(mass) { }
-};
-
-class Energies : public DerivedValue<std::vector<float>>{
-    private:
-        Value<std::vector<TLorentzVector>> *vectors;
-        void update_value(){
-            std::vector<TLorentzVector>& vecs = vectors->get_value();
-            this->value.clear();
-            for (auto v : vecs){
-                this->value.push_back(v.Energy());
-            }
-        }
-
-    public:
-        static std::string fmt_name(Value<std::vector<TLorentzVector>> *vectors){
-            return "energies("+vectors->get_name()+")";
-        }
-
-        Energies(Value<std::vector<TLorentzVector>> *vectors,
-                 const std::string& alias)
-          :DerivedValue<std::vector<float>>(fmt_name(vectors), alias),
-           vectors(vectors) { }
-};
-
-
-namespace detail {
-    template<typename Tuple, std::size_t... Is>
-    decltype(auto) tuple_get_values_impl(const Tuple& t, std::index_sequence<Is...>){
-        return std::make_tuple(std::get<1>(std::get<Is>(t))->get_value()...);
-    }
-
-    template<typename Tuple, std::size_t... Is>
-    decltype(auto) tuple_get_labels_impl(const Tuple& t, std::index_sequence<Is...>){
-        return std::make_tuple(std::get<0>(std::get<Is>(t))...);
-    }
-}
-/**
- * Converts a tuple of pairs of label/Value objects to a tuple of the contained values
- */
-template<typename... ArgTypes>
-std::tuple<ArgTypes...> tuple_get_values(const std::tuple<std::pair<std::string,Value<ArgTypes>*>...>& t){
-    return detail::tuple_get_values_impl<std::tuple<std::pair<std::string,Value<ArgTypes>*>...>>(t, std::index_sequence_for<ArgTypes...>{});
-}
-
-/**
- * Converts a tuple of pairs of label/Value objects to a tuple of just the
- * labels
- */
-template<typename... ArgTypes>
-decltype(auto) tuple_get_labels(const std::tuple<std::pair<std::string,Value<ArgTypes>*>...>& t){
-    return detail::tuple_get_labels_impl<std::tuple<std::pair<std::string,Value<ArgTypes>*>...>>(t, std::index_sequence_for<ArgTypes...>{});
-}
-
-
-//-----------------------
-
-template <typename T>
-char type_lookup(){
-    return 0;
-}
-template <>
-char type_lookup<int>(){
-    return 'I';
-}
-template <>
-char type_lookup<float>(){
-    return 'F';
-}
-template <>
-char type_lookup<double>(){
-    return 'F';
-}
-
-
-template<typename... DataTypes>
-class MVAData : public DerivedValue<std::tuple<bool,bool,double,std::tuple<DataTypes...>>>{
-    private:
-        std::tuple<std::pair<std::string,Value<DataTypes>*>...> data;
-        Value<bool>* is_training;
-        Value<bool>* is_signal;
-        Value<double>* weight;
-
-        void update_value(){
-            this->value = std::make_tuple(is_training->get_value(), is_signal->get_value(), weight->get_value(),
-                                          tuple_get_values(data));
-        }
-
-        template <typename... Types>
-        static std::vector<std::pair<std::string, char>> get_label_types_impl(std::pair<std::string,Value<Types>*>... pairs){
-            return std::vector<std::pair<std::string, char>>({ std::make_pair(pairs.first,type_lookup<Types>())...});
-        }
-
-
-    public:
-        typedef std::tuple<bool, bool, double, std::tuple<DataTypes...>> type;
-
-
-        std::vector<std::pair<std::string, char>> get_label_types(){
-            return call(get_label_types_impl<DataTypes...>, data);
-        }
-
-        static std::string fmt_name(Value<bool>* is_training, Value<bool>* is_signal, Value<double>* weight,
-                                    const std::pair<std::string, Value<DataTypes>*>&&... data_vals){
-            //TODO: add data names
-            return "mva_data("+is_training->get_name()+","
-                              +is_signal->get_name()+","
-                              +weight->get_name()+")";
-        }
-
-        MVAData(Value<bool>* is_training, Value<bool>* is_signal,
-                Value<double>* weight, const std::pair<std::string, Value<DataTypes>*>&&... data_vals)
-          :DerivedValue<type>(fmt_name(is_training, is_signal, weight,
-                                       std::forward<const std::pair<std::string,Value<DataTypes>*>>(data_vals)...),""),
-           data(std::make_tuple(data_vals...)),
-           is_training(is_training),
-           is_signal(is_signal),
-           weight(weight) { }
-};
-}
-#endif // root_value_hpp

File diff suppressed because it is too large
+ 0 - 1242
filval/value.hpp