Commit 71318e55 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Remove TStopWatch in favor of std::chrono in Analysis class

parent 986d3d7c
......@@ -18,6 +18,7 @@
#include "module/exceptions.h"
#include "utils/log.h"
#include <chrono>
#include <dlfcn.h>
#include <fstream>
#include <iomanip>
......@@ -366,6 +367,9 @@ void Analysis::run() {
// Run all modules
for(auto& module : m_modules) {
// Get current time
auto start = std::chrono::steady_clock::now();
// Set run module section header
std::string old_section_name = Log::getSection();
std::string section_name = "R:";
......@@ -375,20 +379,23 @@ void Analysis::run() {
auto old_settings = set_module_before(module->getName(), module->getConfig());
// Change to the output file directory
m_directory->cd(module->getName().c_str());
// Run the modules with timing enabled
module->getStopwatch()->Start(false);
StatusCode check = module->run(m_clipboard);
module->getStopwatch()->Stop();
// Reset logging
Log::setSection(old_section_name);
set_module_after(old_settings);
// Update execution time
auto end = std::chrono::steady_clock::now();
module_execution_time_[module] += static_cast<std::chrono::duration<long double>>(end - start).count();
if(check == NoData) {
noData = true;
skipped++;
break;
} // Nothing to be done in this event
if(check == Failure)
if(check == Failure) {
run = false;
}
}
// Print statistics:
......@@ -518,8 +525,8 @@ void Analysis::timing() {
LOG(STATUS) << "===============| Wall-clock timing (seconds) |================";
for(auto& module : m_modules) {
LOG(STATUS) << std::setw(25) << module->getName() << " -- " << std::fixed << std::setprecision(5)
<< module->getStopwatch()->RealTime() << " = " << std::setprecision(9)
<< module->getStopwatch()->RealTime() / m_events << " s/evt";
<< module_execution_time_[module] << " = " << std::setprecision(9)
<< module_execution_time_[module] / m_events << " s/evt";
}
LOG(STATUS) << "==============================================================";
}
......
......@@ -80,6 +80,8 @@ namespace corryvreckan {
Module* create_module(void* library, corryvreckan::Configuration config);
std::tuple<LogLevel, LogFormat> set_module_before(const std::string&, const Configuration& config);
void set_module_after(std::tuple<LogLevel, LogFormat> prev);
std::map<Module*, long double> module_execution_time_;
};
} // namespace corryvreckan
......
......@@ -14,7 +14,6 @@ Module::Module(Configuration config, std::vector<Detector*> detectors) {
m_name = config.getName();
m_config = config;
m_detectors = detectors;
m_stopwatch = new TStopwatch();
IFLOG(TRACE) {
std::stringstream det;
for(auto& d : m_detectors) {
......
......@@ -10,7 +10,7 @@
#define CORRYVRECKAN_MODULE_H
#include <string>
#include "TStopwatch.h"
#include "core/clipboard/Clipboard.hpp"
#include "core/config/Configuration.hpp"
#include "core/detector/Detector.hpp"
......@@ -47,8 +47,6 @@ namespace corryvreckan {
* - Module::initialise(): for initializing the module at the start
* - Module::run(Clipoard* Clipboard): for doing the job of every module for every event
* - Module::finalise(): for finalising the module at the end
*
* The module class also provides a few utility methods such as a stopwatch for timing measurements.
*/
class Module {
......@@ -103,7 +101,6 @@ namespace corryvreckan {
// Methods to get member variables
std::string getName() { return m_name; }
Configuration getConfig() { return m_config; }
TStopwatch* getStopwatch() { return m_stopwatch; }
protected:
// Member variables
......@@ -116,7 +113,6 @@ namespace corryvreckan {
bool has_detector(std::string name);
private:
TStopwatch* m_stopwatch;
std::vector<Detector*> m_detectors;
};
} // namespace corryvreckan
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment