Parcourir la source

Add internal variable values in before/after trace

Eric Ramat il y a 7 ans
Parent
commit
b64ef33ef5

+ 22 - 2
src/artis/kernel/AbstractAtomicModel.hpp

@@ -60,9 +60,19 @@ public:
         utils::Trace < utils::DoubleTime >::trace()
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
                                                          utils::KERNEL)
                                                          utils::KERNEL)
-            << " - AFTER - "
+            << "AFTER - "
             << AbstractAtomicModel < T, U, V >::path(this);
             << AbstractAtomicModel < T, U, V >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
         utils::Trace < utils::DoubleTime >::trace().flush();
+        for (size_t i = 0; i < Internals < T, U >::size(); ++i) {
+            if (not Internals < T, U >::get(i).is_null()) {
+                utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << i << " = " << Internals < T, U >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                utils::Trace < utils::DoubleTime >::trace().flush();
+            }
+        }
 #else
 #else
         (void) t;
         (void) t;
 #endif
 #endif
@@ -76,9 +86,19 @@ public:
         utils::Trace < utils::DoubleTime >::trace()
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
                                                          utils::KERNEL)
                                                          utils::KERNEL)
-            << " - BEFORE - "
+            << "BEFORE - "
             << AbstractAtomicModel < T, U, V >::path(this);
             << AbstractAtomicModel < T, U, V >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
         utils::Trace < utils::DoubleTime >::trace().flush();
+        for (size_t i = 0; i < Internals < T, U >::size(); ++i) {
+            if (not Internals < T, U >::get(i).is_null()) {
+                utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << i << " = " << Internals < T, U >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                utils::Trace < utils::DoubleTime >::trace().flush();
+            }
+        }
 #else
 #else
         (void) t;
         (void) t;
 #endif
 #endif

+ 22 - 2
src/artis/kernel/AbstractCoupledModel.hpp

@@ -70,9 +70,19 @@ public:
         utils::Trace < utils::DoubleTime >::trace()
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
                                                          utils::KERNEL)
                                                          utils::KERNEL)
-            << " - AFTER - "
+            << "AFTER - "
             << AbstractCoupledModel < T, U, V, W >::path(this);
             << AbstractCoupledModel < T, U, V, W >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
         utils::Trace < utils::DoubleTime >::trace().flush();
+                for (size_t i = 0; i < Internals < T, U >::size(); ++i) {
+            if (not Internals < T, U >::get(i).is_null()) {
+                utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << i << " = " << Internals < T, U >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                utils::Trace < utils::DoubleTime >::trace().flush();
+            }
+        }
 #else
 #else
         (void) t;
         (void) t;
 #endif
 #endif
@@ -98,9 +108,19 @@ public:
         utils::Trace < utils::DoubleTime >::trace()
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
                                                          utils::KERNEL)
                                                          utils::KERNEL)
-            << " - BEFORE - "
+            << "BEFORE - "
             << AbstractCoupledModel < T, U, V, W >::path(this);
             << AbstractCoupledModel < T, U, V, W >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
         utils::Trace < utils::DoubleTime >::trace().flush();
+                for (size_t i = 0; i < Internals < T, U >::size(); ++i) {
+            if (not Internals < T, U >::get(i).is_null()) {
+                utils::Trace < utils::DoubleTime >::trace()
+                    << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
+                                                                 utils::KERNEL)
+                    << i << " = " << Internals < T, U >::get(i).to_string(
+                        dynamic_cast < const T* >(this));
+                utils::Trace < utils::DoubleTime >::trace().flush();
+            }
+        }
 #else
 #else
         (void) t;
         (void) t;
 #endif
 #endif

+ 4 - 1
src/artis/kernel/Externals.hpp

@@ -70,7 +70,7 @@ public:
     void external(unsigned int index, V T::* var)
     void external(unsigned int index, V T::* var)
     {
     {
         if (externals.size() <= index) {
         if (externals.size() <= index) {
-            externals.resize(index + 1);
+            externals.resize(index + 1, std::make_pair(-1, Any()));
         }
         }
         externals[index] = std::make_pair(-1, var);
         externals[index] = std::make_pair(-1, var);
     }
     }
@@ -97,6 +97,9 @@ public:
         }
         }
     }
     }
 
 
+    unsigned int size() const
+    { return externals.size(); }
+
 protected:
 protected:
     bool updated;
     bool updated;
     std::vector < std::pair < typename U::type, Any > > externals;
     std::vector < std::pair < typename U::type, Any > > externals;

+ 4 - 1
src/artis/kernel/Internals.hpp

@@ -61,7 +61,7 @@ public:
     void internal(unsigned int index, V T::* var)
     void internal(unsigned int index, V T::* var)
     {
     {
         if (internals.size() <= index) {
         if (internals.size() <= index) {
-            internals.resize(index + 1);
+            internals.resize(index + 1, Any());
         }
         }
         internals[index] = Any(var);
         internals[index] = Any(var);
     }
     }
@@ -112,6 +112,9 @@ public:
         // }
         // }
     }
     }
 
 
+    unsigned int size() const
+    { return internals.size(); }
+
 private:
 private:
     std::vector < Any > internals;
     std::vector < Any > internals;
 };
 };

+ 21 - 18
src/artis/kernel/Value.hpp

@@ -82,6 +82,9 @@ public:
     V T::* get() const
     V T::* get() const
     { return dynamic_cast < data < T, V >* >(ptr_)->value_; }
     { return dynamic_cast < data < T, V >* >(ptr_)->value_; }
 
 
+    bool is_null() const
+    { return ptr_ == nullptr; }
+
     template < typename T, typename V >
     template < typename T, typename V >
     void put(T* o, const V& value )
     void put(T* o, const V& value )
     {
     {
@@ -94,24 +97,24 @@ public:
     std::string to_string(const T* o) const
     std::string to_string(const T* o) const
     {
     {
         if (ptr_) {
         if (ptr_) {
-            try {
-                double T::* p = dynamic_cast <
-                    data < T, double >* >(ptr_)->value_;
-
-                return std::to_string(o->*(p));
-            } catch(...) {
-                try {
-                    int T::* p = dynamic_cast <
-                        data < T, int >* >(this->ptr_)->value_;
-
-                    return std::to_string(o->*(p));
-                } catch(...) {
-                    try {
-                        bool T::* p = dynamic_cast <
-                            data < T, bool >* >(this->ptr_)->value_;
-
-                        return std::to_string(o->*(p));
-                    } catch(...) {
+            data < T, double >* q_double =
+                dynamic_cast < data < T, double >* >(ptr_);
+
+            if (q_double) {
+                return std::to_string(o->*(q_double->value_));
+            } else {
+                data < T, int >* q_int =
+                    dynamic_cast < data < T, int >* >(ptr_);
+
+                if (q_int) {
+                    return std::to_string(o->*(q_int->value_));
+                } else {
+                    data < T, bool >* q_bool =
+                        dynamic_cast < data < T, bool >* >(ptr_);
+
+                    if (q_bool) {
+                        return std::to_string(o->*(q_bool->value_));
+                    } else {
                         return "NA";
                         return "NA";
                     }
                     }
                 }
                 }

+ 2 - 0
src/test/test.cpp

@@ -119,6 +119,8 @@ int main()
     simulator.run(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
     simulator.run(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
                   artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
                   artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
 
 
+    std::cout << ::Trace::trace().elements().to_string() << std::endl;
+
     AnOutput output(simulator.observer());
     AnOutput output(simulator.observer());
 
 
     output();
     output();