소스 검색

Adds simple debugging which can just print out the values as they are
bgin calculated to find what is causing crashes. Fixes bug in Hist2d
code.

Caleb Fangmeier 7 년 전
부모
커밋
6d3fc567de
5개의 변경된 파일25개의 추가작업 그리고 8개의 파일을 삭제
  1. 10 0
      config.hpp
  2. 5 4
      python/filval/histogram_utils.py
  3. 1 1
      python/filval/plotter.py
  4. 0 2
      python/setup.py
  5. 9 1
      value.hpp

+ 10 - 0
config.hpp

@@ -105,6 +105,14 @@ class Config{
             return max_events.as<size_t>();
         }
 
+        bool get_debug() {
+            YAML::Node debug_node = root["debug"];
+            if(!debug_node) {
+                return false;
+            }
+            return debug_node.as<bool>();
+        }
+
         std::string get_output_filename() {
             YAML::Node output_file = root["output-file"];
             if(output_file) {
@@ -130,9 +138,11 @@ class Config{
 };
 
 Config* the_config = nullptr;
+bool debug_on = false;
 void init_config(const std::string& input_filename){
     if(the_config) delete the_config;
     the_config = new Config(input_filename);
+    debug_on = the_config->get_debug();
 }
 
 }

+ 5 - 4
python/filval/histogram_utils.py

@@ -42,6 +42,7 @@ def hist2d(th2, rescale_x=1.0, rescale_y=1.0, rescale_z=1.0):
     """
     nbins_x = th2.GetNbinsX()
     nbins_y = th2.GetNbinsY()
+    print(nbins_x, nbins_y)
     xs = np.zeros((nbins_y+1, nbins_x+1), np.float32)
     ys = np.zeros((nbins_y+1, nbins_x+1), np.float32)
     values = np.zeros((nbins_y, nbins_x), np.float32)
@@ -52,11 +53,11 @@ def hist2d(th2, rescale_x=1.0, rescale_y=1.0, rescale_z=1.0):
             ys[j][i] = th2.GetYaxis().GetBinLowEdge(j+1)
             values[j][i] = th2.GetBinContent(i+1, j+1)
             errors[j][i] = th2.GetBinError(i+1, j+1)
-        xs[nbins_y][i] = th2.GetXaxis().GetBinUpEdge(i+1)
-        ys[nbins_y][i] = th2.GetYaxis().GetBinUpEdge(nbins_y+1)
+        xs[nbins_y][i] = th2.GetXaxis().GetBinUpEdge(i)
+        ys[nbins_y][i] = th2.GetYaxis().GetBinUpEdge(nbins_y)
     for j in range(nbins_y+1):
-        xs[j][nbins_x] = th2.GetXaxis().GetBinUpEdge(nbins_x+1)
-        ys[j][nbins_x] = th2.GetYaxis().GetBinUpEdge(j+1)
+        xs[j][nbins_x] = th2.GetXaxis().GetBinUpEdge(nbins_x)
+        ys[j][nbins_x] = th2.GetYaxis().GetBinUpEdge(j)
 
     xs *= rescale_x
     ys *= rescale_y

+ 1 - 1
python/filval/plotter.py

@@ -200,7 +200,7 @@ def render_plots(plots, exts=('png',), scale=1.0, to_disk=True):
         print(f'Building plot {plot.name}')
         plot.data = None
         if to_disk:
-            with lp.figure(plot.name, directory='output/figures',
+            with lp.figure(plot.name.replace(' ', '_'), directory='output/figures',
                            exts=exts,
                            size=(scale * 10, scale * 10)):
                 argdicts, docs = grid_plot(plot.subplots)

+ 0 - 2
python/setup.py

@@ -3,8 +3,6 @@ from setuptools import setup
 with open('requirements.txt') as req:
     install_requires = [l.strip() for l in req.readlines()]
 
-print(install_requires)
-
 setup(
     name='filval',
     version='0.1',

+ 9 - 1
value.hpp

@@ -55,6 +55,7 @@
 #include <vector>
 
 #include "log.hpp"
+#include "config.hpp"
 
 /**
  * The namespace containing all filval classes and functions.
@@ -334,7 +335,7 @@ class GenValue{
         /**
          * If logging is enabled for this value, this function should be
          * implemented to format the value to a string and place it as an INFO
-         * entry in the log file. Useful for debugging, but may produce alot of
+         * entry in the log file. Useful for debugging, but may produce a lot of
          * output.
          */
         virtual void log() = 0;
@@ -423,6 +424,7 @@ class Value : public GenValue{
         Value(const std::string& name, const std::string& alias="")
           :value_to_string([](T){return "";}),
            GenValue(typeid(T), name, alias){ }
+
         /** Calculate, if necessary, and return the value held by this object.
          */
         virtual T& get_value() = 0;
@@ -458,6 +460,9 @@ class ObservedValue : public Value<T>{
            val_ref(val_ref){ }
 
         void log(){
+            if (util::debug_on) {
+                std::cout << "Calculating Value: " << this->get_name() << std::endl;
+            }
             if(this->logging_enabled){
                 INFO(this->get_name() << ": " << this->value_to_string(*val_ref));
             }
@@ -511,6 +516,9 @@ class DerivedValue : public Value<T>{
           :Value<T>(name, alias){ }
 
         void log(){
+            if (util::debug_on) {
+                std::cout << "Calculating Value: " << this->get_name() << std::endl;
+            }
             if(this->logging_enabled){
                 INFO(this->get_name() << ": " << this->value_to_string(value));
             }