CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
cond::persistency::Logger Class Reference

#include <Logger.h>

Public Member Functions

void end (int retCode)
 
std::iostream & log (const std::string &tag)
 
EchoedLogStream< edm::LogDebug_logDebug ()
 
EchoedLogStream< edm::LogErrorlogError ()
 
 Logger ()=delete
 
 Logger (const std::string &jobName)
 
EchoedLogStream< edm::LogInfologInfo ()
 
EchoedLogStream< edm::LogWarninglogWarning ()
 
void save ()
 
void saveOnDb ()
 
void saveOnFile ()
 
void setDbDestination (const std::string &connectionString, ConnectionPool &connectionPool)
 
void start ()
 
virtual ~Logger ()
 

Private Member Functions

void clearBuffer ()
 

Private Attributes

std::string m_connectionString
 
boost::posix_time::ptime m_endTime
 
std::string m_jobName
 
std::stringstream m_log
 
int m_retCode
 
ConnectionPoolm_sharedConnectionPool
 
bool m_started
 
boost::posix_time::ptime m_startTime
 

Detailed Description

Definition at line 84 of file Logger.h.

Constructor & Destructor Documentation

◆ Logger() [1/2]

cond::persistency::Logger::Logger ( )
delete

◆ Logger() [2/2]

Logger::Logger ( const std::string &  jobName)
explicit

Definition at line 45 of file Logger.cc.

46  : m_jobName(jobName),
48  m_sharedConnectionPool(nullptr),
49  m_started(false),
50  m_startTime(),
51  m_endTime(),
52  m_retCode(0),
53  m_log() {}

◆ ~Logger()

Logger::~Logger ( )
virtual

Definition at line 56 of file Logger.cc.

56 {}

Member Function Documentation

◆ clearBuffer()

void Logger::clearBuffer ( )
private

Definition at line 40 of file Logger.cc.

40  {
41  m_log.str("");
42  m_log.clear();
43  }

References m_log.

Referenced by end(), and start().

◆ end()

void Logger::end ( int  retCode)

Definition at line 75 of file Logger.cc.

75  {
76  if (m_started) {
77  m_endTime = boost::posix_time::microsec_clock::universal_time();
78  m_started = false;
79  m_retCode = retCode;
80  log("END_JOB") << ": return code:" << retCode;
81  save();
82  clearBuffer();
83  }
84  }

References clearBuffer(), log(), m_endTime, m_retCode, m_started, and save().

Referenced by Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), BeamMonitor::endLuminosityBlock(), and FakeBeamMonitor::endLuminosityBlock().

◆ log()

std::iostream & Logger::log ( const std::string &  tag)

◆ logDebug()

EchoedLogStream< edm::LogDebug_ > Logger::logDebug ( )

Definition at line 157 of file Logger.cc.

157  {
158  log("DEBUG");
159  return EchoedLogStream<edm::LogDebug_>(m_jobName, m_log);
160  }

References log(), m_jobName, and m_log.

◆ logError()

EchoedLogStream< edm::LogError > Logger::logError ( )

Definition at line 161 of file Logger.cc.

161  {
162  log("ERROR");
163  return EchoedLogStream<edm::LogError>(m_jobName, m_log);
164  }

References log(), m_jobName, and m_log.

Referenced by BeamMonitor::FitAndFill(), FakeBeamMonitor::FitAndFill(), and saveOnDb().

◆ logInfo()

EchoedLogStream< edm::LogInfo > Logger::logInfo ( )

◆ logWarning()

EchoedLogStream< edm::LogWarning > Logger::logWarning ( )

Definition at line 165 of file Logger.cc.

165  {
166  log("WARNING");
167  return EchoedLogStream<edm::LogWarning>(m_jobName, m_log);
168  }

References log(), m_jobName, and m_log.

Referenced by cond::service::OnlineDBOutputService::writeForNextLumisection(), and cond::service::PoolDBOutputService::writeOne().

◆ save()

void Logger::save ( )

Definition at line 139 of file Logger.cc.

139  {
140  if (!m_connectionString.empty())
141  saveOnDb();
142  else
143  saveOnFile();
144  }

References m_connectionString, saveOnDb(), and saveOnFile().

Referenced by end(), and SpecificationBuilder_cfi.Specification::saveAll().

◆ saveOnDb()

void Logger::saveOnDb ( )

Definition at line 115 of file Logger.cc.

115  {
116  if (!m_log.str().empty()) {
117  if (m_sharedConnectionPool == nullptr) {
118  throwException("Connection pool handle has not been provided.", "Logger::saveOnDb");
119  }
120  if (m_connectionString.empty()) {
121  throwException("Connection string for destination database has not been provided.", "Logger::saveOnDb");
122  }
124  coralSession->transaction().start(false);
125  try {
126  O2O_RUN::Table destinationTable(coralSession->nominalSchema());
127  destinationTable.insert(m_jobName, m_startTime, m_endTime, m_retCode, m_log.str());
128  coralSession->transaction().commit();
129  } catch (const std::exception& e) {
130  coralSession->transaction().rollback();
131  // dump on file on this circumstance...
132  logError() << e.what();
133  saveOnFile();
134  throwException(std::string("Failure while saving log on database:") + e.what(), "Logger::saveOnDb");
135  }
136  }
137  }

References cond::persistency::ConnectionPool::createCoralSession(), MillePedeFileConverter_cfg::e, cppFunctionSkipper::exception, cond::persistency::O2O_RUN::Table::insert(), logError(), m_connectionString, m_endTime, m_jobName, m_log, m_retCode, m_sharedConnectionPool, m_startTime, saveOnFile(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::persistency::throwException().

Referenced by save().

◆ saveOnFile()

void Logger::saveOnFile ( )

Definition at line 105 of file Logger.cc.

105  {
106  if (!m_log.str().empty()) {
108  std::ofstream fout(fileName, std::ofstream::app);
109  fout << m_log.str() << std::endl;
110  fout.close();
111  }
112  }

References MillePedeFileConverter_cfg::fileName, groupFilesInBlocks::fout, cond::persistency::get_timestamp_for_filename(), m_log, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by save(), and saveOnDb().

◆ setDbDestination()

void Logger::setDbDestination ( const std::string &  connectionString,
ConnectionPool connectionPool 
)

◆ start()

void Logger::start ( )

Definition at line 64 of file Logger.cc.

64  {
65  if (!m_started) {
66  if (!m_log.str().empty())
67  clearBuffer();
68  m_startTime = boost::posix_time::microsec_clock::universal_time();
69  m_started = true;
70  log("START_JOB") << " " << m_jobName;
71  }
72  }

References clearBuffer(), log(), m_jobName, m_log, m_started, and m_startTime.

Referenced by progressbar.ProgressBar::__next__(), BeamMonitor::beginLuminosityBlock(), FakeBeamMonitor::beginLuminosityBlock(), Types.LuminosityBlockRange::cppID(), and Types.EventRange::cppID().

Member Data Documentation

◆ m_connectionString

std::string cond::persistency::Logger::m_connectionString
private

Definition at line 126 of file Logger.h.

Referenced by save(), saveOnDb(), and setDbDestination().

◆ m_endTime

boost::posix_time::ptime cond::persistency::Logger::m_endTime
private

Definition at line 130 of file Logger.h.

Referenced by end(), and saveOnDb().

◆ m_jobName

std::string cond::persistency::Logger::m_jobName
private

Definition at line 125 of file Logger.h.

Referenced by logDebug(), logError(), logInfo(), logWarning(), saveOnDb(), and start().

◆ m_log

std::stringstream cond::persistency::Logger::m_log
private

Definition at line 132 of file Logger.h.

Referenced by clearBuffer(), log(), logDebug(), logError(), logInfo(), logWarning(), saveOnDb(), saveOnFile(), and start().

◆ m_retCode

int cond::persistency::Logger::m_retCode
private

Definition at line 131 of file Logger.h.

Referenced by end(), and saveOnDb().

◆ m_sharedConnectionPool

ConnectionPool* cond::persistency::Logger::m_sharedConnectionPool
private

Definition at line 127 of file Logger.h.

Referenced by saveOnDb(), and setDbDestination().

◆ m_started

bool cond::persistency::Logger::m_started
private

Definition at line 128 of file Logger.h.

Referenced by end(), and start().

◆ m_startTime

boost::posix_time::ptime cond::persistency::Logger::m_startTime
private

Definition at line 129 of file Logger.h.

Referenced by saveOnDb(), and start().

cond::persistency::Logger::m_jobName
std::string m_jobName
Definition: Logger.h:125
cond::persistency::Logger::log
std::iostream & log(const std::string &tag)
Definition: Logger.cc:146
beam_dqm_sourceclient-live_cfg.jobName
jobName
Definition: beam_dqm_sourceclient-live_cfg.py:372
cond::persistency::ConnectionPool::createCoralSession
std::shared_ptr< coral::ISessionProxy > createCoralSession(const std::string &connectionString, bool writeCapable=false)
Definition: ConnectionPool.cc:167
cond::persistency::get_timestamp
std::string get_timestamp()
Definition: Logger.cc:95
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
cond::persistency::Logger::m_startTime
boost::posix_time::ptime m_startTime
Definition: Logger.h:129
cond::persistency::Logger::save
void save()
Definition: Logger.cc:139
cond::persistency::Logger::clearBuffer
void clearBuffer()
Definition: Logger.cc:40
std::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: cuda_cxx17.h:13
cond::persistency::Logger::m_started
bool m_started
Definition: Logger.h:128
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
cond::persistency::Logger::saveOnFile
void saveOnFile()
Definition: Logger.cc:105
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
groupFilesInBlocks.fout
fout
Definition: groupFilesInBlocks.py:162
cond::persistency::Logger::saveOnDb
void saveOnDb()
Definition: Logger.cc:115
cond::persistency::get_timestamp_for_filename
std::string get_timestamp_for_filename()
Definition: Logger.cc:99
cond::persistency::Logger::m_endTime
boost::posix_time::ptime m_endTime
Definition: Logger.h:130
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::persistency::Logger::m_log
std::stringstream m_log
Definition: Logger.h:132
cond::persistency::Logger::logError
EchoedLogStream< edm::LogError > logError()
Definition: Logger.cc:161
cond::persistency::Logger::m_sharedConnectionPool
ConnectionPool * m_sharedConnectionPool
Definition: Logger.h:127
cond::persistency::Logger::m_connectionString
std::string m_connectionString
Definition: Logger.h:126
cond::persistency::Logger::m_retCode
int m_retCode
Definition: Logger.h:131
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37