Explorar el Código

Adds VectorMany container class

Caleb Fangmeier hace 7 años
padre
commit
27cc0b9b63
Se han modificado 4 ficheros con 34 adiciones y 1 borrados
  1. 6 0
      container.hpp
  2. 1 1
      python/utils.py
  3. 3 0
      root/LinkDef.hpp
  4. 24 0
      root/container.hpp

+ 6 - 0
container.hpp

@@ -51,6 +51,8 @@ std::string get_type_name(const std::type_index& index){
     _map[typeid(double)]="double";
     _map[typeid(std::vector<int>)]="std::vector<int>";
     _map[typeid(std::vector<float>)]="std::vector<float>";
+    _map[typeid(std::pair<std::vector<float>,std::vector<float>>)]="std::pair<std::vector<float>,std::vector<float>>";
+    _map[typeid(std::vector<std::pair<float,int>>)]="std::vector<std::pair<float,int>>";
     _map[typeid(std::map<std::string,std::string>)] = "std::map<std::string,std::string>";
 
     if (_map[index] == ""){
@@ -141,6 +143,10 @@ class Container : public GenContainer{
            container(nullptr),
            value(value){ }
 
+        virtual ~Container(){
+            if (container != nullptr) delete container;
+        }
+
         virtual H* get_container(){
             return container;
         }

+ 1 - 1
python/utils.py

@@ -191,7 +191,7 @@ class ResultSet:
         for hist in objs:
             CANVAS.cd(i)
             try:
-                hist.SetStats(False)
+                hist.SetStats(True)
             except AttributeError:
                 pass
             if type(hist) in (ROOT.TH1I, ROOT.TH1F, ROOT.TH1D):

+ 3 - 0
root/LinkDef.hpp

@@ -1,6 +1,7 @@
 #ifndef linkdef_hpp
 #define linkdef_hpp
 #include <vector>
+#include <utility>
 #include <string>
 #include <map>
 
@@ -8,6 +9,8 @@
 #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::vector<std::pair<std::vector<float>,std::vector<float>>>+;
+#pragma link C++ class std::vector<std::pair<float,int>>+;
 #pragma link C++ class std::map<std::string,std::string>+;
 #endif
 

+ 24 - 0
root/container.hpp

@@ -291,6 +291,30 @@ class Vector : public Container<std::vector<V>,V>{
         }
 };
 
+template <typename V>
+class VectorMany : public Container<std::vector<V>,std::vector<V>>{
+    private:
+
+        void _fill(){
+            for(const V& val: this->value->get_value())
+                this->container->push_back(val);
+        }
+    public:
+        VectorMany(const std::string& name, Value<std::vector<V>>* value)
+          :Container<std::vector<V>,std::vector<V>>(name, value){
+            this->container = new std::vector<V>;
+        }
+
+        GenContainer* clone_as(const std::string& new_name){
+            return new VectorMany<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: