Skip to content

Commit

Permalink
add timestap dates in human readable form in the BeamSpot DisplayPara…
Browse files Browse the repository at this point in the history
…meters template class
  • Loading branch information
mmusich committed Jun 23, 2023
1 parent c34a318 commit eacba5a
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"

// system includes
#include <ctime>
#include <fmt/printf.h>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -60,6 +61,26 @@ namespace beamSpotPI {
END_OF_TYPES = 25,
};

/************************************************/
// Function to convert cond::Time_t (in microseconds) to human-readable date string
std::string convertTimeToDateString(cond::Time_t timeValue, bool hasMicros = false, bool toUTC = true) {
// Convert microseconds to seconds
std::time_t unixTime = static_cast<std::time_t>(hasMicros ? timeValue / 1000000 : timeValue);

// Convert std::time_t to struct tm (to UTC, or not)
std::tm* timeInfo = toUTC ? std::gmtime(&unixTime) : std::localtime(&unixTime);

// Convert struct tm to human-readable string format
char buffer[80];
std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", timeInfo);

// Append microseconds to the string
std::string dateString(buffer);
//dateString += "." + std::to_string(timeValue % 1000000);

return dateString;
}

/************************************************/
inline std::string getStringFromParamEnum(const parameters& parameter,
const bool addUnits = false /*not used by default*/) {
Expand Down Expand Up @@ -432,6 +453,29 @@ namespace beamSpotPI {
(tagname + " IOV: #color[4]{" + std::to_string(runLS.first) + "," + std::to_string(runLS.second) + "}")
.c_str());

if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
canvas.cd(2);
ltx.SetTextSize(0.025);
ltx.DrawLatexNDC(
gPad->GetLeftMargin() + 0.01,
gPad->GetBottomMargin() + 0.15,
("#color[2]{(" + beamSpotPI::convertTimeToDateString(m_payload->creationTime(), /*has us*/ true) + ")}")
.c_str());

ltx.DrawLatexNDC(
gPad->GetLeftMargin() + 0.01,
gPad->GetBottomMargin() + 0.085,
("#color[2]{(" + beamSpotPI::convertTimeToDateString(m_payload->startTimeStamp()) + ")}").c_str());

ltx.DrawLatexNDC(
gPad->GetLeftMargin() + 0.01,
gPad->GetBottomMargin() + 0.025,
("#color[2]{(" + beamSpotPI::convertTimeToDateString(m_payload->endTimeStamp()) + ")}").c_str());

ltx.DrawLatexNDC(
gPad->GetLeftMargin(), gPad->GetBottomMargin() - 0.05, "#color[4]{N.B.} TimeStamps are in UTC");
}

std::string fileName(this->m_imageFileName);
canvas.SaveAs(fileName.c_str());

Expand Down

0 comments on commit eacba5a

Please sign in to comment.