Explorar el Código

Added filters on kernelInfo

gbeurier hace 7 años
padre
commit
4f3dc47a21
Se han modificado 2 ficheros con 26 adiciones y 7 borrados
  1. 25 5
      src/artis/utils/Trace.hpp
  2. 1 2
      src/test/test-context.cpp

+ 25 - 5
src/artis/utils/Trace.hpp

@@ -66,10 +66,10 @@ class KernelInfo
 {
 public:
     const std::string& var() const {return _var;}
-    std::string value() const {return _value;}
-    std::string tgt_model() const {return _tgt_model;}
-    std::string tgt_internal_var() const {return _tgt_internal_var;}
-    bool internal_var() const {return _internal_var;}
+    const std::string& value() const {return _value;}
+    const std::string& tgt_model() const {return _tgt_model;}
+    const std::string& tgt_internal_var() const {return _tgt_internal_var;}
+    bool is_internal_var() const {return _internal_var;}
     bool empty() const {return _empty;}
 
     KernelInfo() :
@@ -221,7 +221,11 @@ public:
         std::copy_if(TraceElements < Time >::begin(),
                      TraceElements < Time >::end(), std::back_inserter(result),
                      [model_name](TraceElement < Time > const & x)
-        { return x.get_model_name() == model_name; });
+        { if(not x.get_kernel_info().empty())
+            if( x.get_kernel_info().tgt_model() == model_name)
+                    return true;
+            return x.get_model_name() == model_name;
+        });
         return result;
     }
 
@@ -247,6 +251,22 @@ public:
         return result;
     }
 
+    TraceElements filter_variable(const std::string& var_name) const
+    {
+        TraceElements result;
+
+        std::copy_if(TraceElements < Time >::begin(),
+                     TraceElements < Time >::end(), std::back_inserter(result),
+                     [var_name](TraceElement < Time > const & x)
+        {   if(x.get_kernel_info().empty())
+                return false;
+            return ((x.get_kernel_info().var() == var_name)
+                    or (x.get_kernel_info().tgt_internal_var() == var_name));
+        });
+        return result;
+    }
+
+
     std::string to_string(artis::utils::DateFormat date_format = artis::utils::DATE_FORMAT_EXTENDED) const
     {
         std::ostringstream ss;

+ 1 - 2
src/test/test-context.cpp

@@ -58,7 +58,7 @@ int main()
                        modelParameters);
         simulator.run(context);
 
-        std::cout << ::Trace::trace().elements().to_string(artis::utils::DATE_FORMAT_YMD) << std::endl;
+        std::cout << ::Trace::trace().elements().filter_variable("BX").to_string(artis::utils::DATE_FORMAT_YMD) << std::endl;
 
         simulator.save(context);
 
@@ -68,7 +68,6 @@ int main()
         oa << context;
     }
 
-    exit(0);
 
     std::cout << "==== PAUSE ====" << std::endl;