소스 검색

begins re-implementing old ipynb analysis/plots using new framework

Caleb Fangmeier 8 년 전
부모
커밋
7166060f01
2개의 변경된 파일28개의 추가작업 그리고 4개의 파일을 삭제
  1. 4 4
      dataset.hpp
  2. 24 0
      value.hpp

+ 4 - 4
dataset.hpp

@@ -20,20 +20,20 @@ class DataSet{
         virtual int get_current_event() = 0;
 
     public:
-        void process(){
+        void process(bool silent=false){
             int events, current_event;
             summary();
             events = get_events();
-            std::cout << std::endl;
+            if (!silent) std::cout << std::endl;
             while( load_next() ){
                 current_event = get_current_event();
-                std::cout << "\rprocessing event: " << current_event+1 << "/" << events << std::flush;
+                if (!silent) std::cout << "\rprocessing event: " << current_event+1 << "/" << events << std::flush;
                 GenValue::reset();
                 for(auto con : containers){
                     con.second->fill();
                 }
             }
-            std::cout << " Finished!" << std::endl;
+            if (!silent) std::cout << " Finished!" << std::endl;
         }
 
         virtual void save_all(){

+ 24 - 0
value.hpp

@@ -486,6 +486,30 @@ class ZipMapFour : public DerivedValue<std::vector<R> >{
                       alias){ }
 };
 
+/**
+ *
+ */
+template<typename T>
+class Count : public DerivedValue<int>{
+    private:
+        Function<bool(T)>& selector;
+        Value<std::vector<T> >* v;
+        void update_value(){
+            value = 0;
+            for(auto val : v->get_value()){
+                if(selector(val))
+                    value++;
+            }
+        }
+    public:
+        Count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string alias="")
+          :DerivedValue<int>("count("+selector.get_name()+":"+v->get_name()+")", alias),
+           selector(selector), v(v) { }
+
+        Count(Function<bool(T)>& selector, const std::string& v_name, const std::string alias="")
+          :Count(selector, dynamic_cast<Value<std::vector<T> >*>(GenValue::get_value(v_name)), alias) { }
+};
+
 
 /**
  * Reduce a Value of type vector<T> to just a T.