Belle II Software development
EventInfoPrinterModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/modules/core/EventInfoPrinterModule.h>
10
11#include <boost/format.hpp>
12#include <chrono>
13#include <ctime>
14
15using namespace std;
16using namespace Belle2;
17
18//-----------------------------------------------------------------
19// Register the Module
20//-----------------------------------------------------------------
21REG_MODULE(EventInfoPrinter);
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
28{
29 //Set module properties
30 setDescription("Prints the current event meta data information (exp, run, event numbers). LogLevel need to be set to INFO, at least for this module.");
31
32 addParam("printTime", m_printTime, "Print time in addition to exp/run/evt numbers.", false);
33}
34
36
38{
39 m_eventMetaData.isRequired();
40}
41
43{
44 B2INFO("========================================================================");
45 B2INFO(">>> Start new run: " << m_eventMetaData->getRun());
46 B2INFO("------------------------------------------------------------------------");
47}
48
49
51{
52 //Print event meta data information
53 if (!m_eventMetaData) return;
54 if (m_printTime) {
55 B2INFO(boost::format("EXP: %5d RUN: %6d EVT: %8d TIME: %s") % m_eventMetaData->getExperiment() % m_eventMetaData->getRun() %
56 m_eventMetaData->getEvent() % formatDateTime(m_eventMetaData->getTime()));
57 } else {
58 B2INFO(boost::format("EXP: %8d RUN: %8d EVT: %8d") % m_eventMetaData->getExperiment() % m_eventMetaData->getRun() %
59 m_eventMetaData->getEvent());
60 }
61}
62
63
65{
66 B2INFO("------------------------------------------------------------------------");
67 B2INFO("<<< End run: " << m_eventMetaData->getRun());
68 B2INFO("========================================================================");
69}
70
71std::string EventInfoPrinterModule::formatDateTime(unsigned long long int nsec)
72{
73 using namespace chrono;
74 high_resolution_clock::time_point time(duration_cast<high_resolution_clock::duration>(nanoseconds(nsec)));
75 time_t ttime = high_resolution_clock::to_time_t(time);
76 tm* tm = gmtime(&ttime);
77
78 char timeStr[32];
79 strftime(timeStr, 32, "%F %T", tm);
80 unsigned int sec_decimals = (nsec / 1000) % 1000000;
81
82 return str(boost::format("%s.%06d") % timeStr % sec_decimals);
83}
std::string formatDateTime(unsigned long long int)
Format date & time for output.
bool m_printTime
Print time in addition to exp/run/evt numbers.
virtual void initialize() override
initialization.
virtual void event() override
Prints the full information about the event, run and experiment number.
EventInfoPrinterModule()
Constructor of the module.
virtual void endRun() override
Prints a footer for each run which ended.
StoreObjPtr< EventMetaData > m_eventMetaData
EventMetaData.
virtual void beginRun() override
Prints a header for each new run.
virtual ~EventInfoPrinterModule()
Destructor of the module.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.