Skip to content

Commit eacba5a

Browse files
committed
add timestap dates in human readable form in the BeamSpot DisplayParameters template class
1 parent c34a318 commit eacba5a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h

+44
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "FWCore/MessageLogger/interface/MessageLogger.h"
1010

1111
// system includes
12+
#include <ctime>
1213
#include <fmt/printf.h>
1314
#include <memory>
1415
#include <sstream>
@@ -60,6 +61,26 @@ namespace beamSpotPI {
6061
END_OF_TYPES = 25,
6162
};
6263

64+
/************************************************/
65+
// Function to convert cond::Time_t (in microseconds) to human-readable date string
66+
std::string convertTimeToDateString(cond::Time_t timeValue, bool hasMicros = false, bool toUTC = true) {
67+
// Convert microseconds to seconds
68+
std::time_t unixTime = static_cast<std::time_t>(hasMicros ? timeValue / 1000000 : timeValue);
69+
70+
// Convert std::time_t to struct tm (to UTC, or not)
71+
std::tm* timeInfo = toUTC ? std::gmtime(&unixTime) : std::localtime(&unixTime);
72+
73+
// Convert struct tm to human-readable string format
74+
char buffer[80];
75+
std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", timeInfo);
76+
77+
// Append microseconds to the string
78+
std::string dateString(buffer);
79+
//dateString += "." + std::to_string(timeValue % 1000000);
80+
81+
return dateString;
82+
}
83+
6384
/************************************************/
6485
inline std::string getStringFromParamEnum(const parameters& parameter,
6586
const bool addUnits = false /*not used by default*/) {
@@ -432,6 +453,29 @@ namespace beamSpotPI {
432453
(tagname + " IOV: #color[4]{" + std::to_string(runLS.first) + "," + std::to_string(runLS.second) + "}")
433454
.c_str());
434455

456+
if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
457+
canvas.cd(2);
458+
ltx.SetTextSize(0.025);
459+
ltx.DrawLatexNDC(
460+
gPad->GetLeftMargin() + 0.01,
461+
gPad->GetBottomMargin() + 0.15,
462+
("#color[2]{(" + beamSpotPI::convertTimeToDateString(m_payload->creationTime(), /*has us*/ true) + ")}")
463+
.c_str());
464+
465+
ltx.DrawLatexNDC(
466+
gPad->GetLeftMargin() + 0.01,
467+
gPad->GetBottomMargin() + 0.085,
468+
("#color[2]{(" + beamSpotPI::convertTimeToDateString(m_payload->startTimeStamp()) + ")}").c_str());
469+
470+
ltx.DrawLatexNDC(
471+
gPad->GetLeftMargin() + 0.01,
472+
gPad->GetBottomMargin() + 0.025,
473+
("#color[2]{(" + beamSpotPI::convertTimeToDateString(m_payload->endTimeStamp()) + ")}").c_str());
474+
475+
ltx.DrawLatexNDC(
476+
gPad->GetLeftMargin(), gPad->GetBottomMargin() - 0.05, "#color[4]{N.B.} TimeStamps are in UTC");
477+
}
478+
435479
std::string fileName(this->m_imageFileName);
436480
canvas.SaveAs(fileName.c_str());
437481

0 commit comments

Comments
 (0)