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)
 
void start ()
 
void subscribeCoralMessages (const std::weak_ptr< MsgDispatcher > &dispatcher)
 
virtual ~Logger ()
 

Private Member Functions

void clearBuffer ()
 

Private Attributes

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

Detailed Description

Definition at line 85 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 48 of file Logger.cc.

49  : m_jobName(jobName),
51  m_started(false),
52  m_startTime(),
53  m_endTime(),
54  m_retCode(0),
55  m_log() {}

◆ ~Logger()

Logger::~Logger ( )
virtual

Definition at line 58 of file Logger.cc.

58  {
59  auto dispatcher = m_dispatcher.lock();
60  if (dispatcher.get())
61  dispatcher->unsubscribe();
62  }

References m_dispatcher.

Member Function Documentation

◆ clearBuffer()

void Logger::clearBuffer ( )
private

Definition at line 43 of file Logger.cc.

43  {
44  m_log.str("");
45  m_log.clear();
46  }

References m_log.

Referenced by end(), and start().

◆ end()

void Logger::end ( int  retCode)

Definition at line 80 of file Logger.cc.

80  {
81  if (m_started) {
82  m_endTime = boost::posix_time::microsec_clock::universal_time();
83  m_started = false;
84  m_retCode = retCode;
85  log("END_JOB") << ": return code:" << retCode;
86  save();
87  clearBuffer();
88  }
89  }

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 161 of file Logger.cc.

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

References log(), m_jobName, and m_log.

Referenced by reportToRecipient().

◆ logError()

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

Definition at line 165 of file Logger.cc.

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

References log(), m_jobName, and m_log.

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

◆ logInfo()

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

◆ logWarning()

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

Definition at line 169 of file Logger.cc.

169  {
170  log("WARNING");
171  return EchoedLogStream<edm::LogWarning>(m_jobName, m_log);
172  }

References log(), m_jobName, and m_log.

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

◆ save()

void Logger::save ( )

Definition at line 143 of file Logger.cc.

143  {
144  if (!m_connectionString.empty())
145  saveOnDb();
146  else
147  saveOnFile();
148  }

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

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

◆ saveOnDb()

void Logger::saveOnDb ( )

Definition at line 120 of file Logger.cc.

120  {
121  if (!m_log.str().empty()) {
122  if (m_connectionString.empty()) {
123  throwException("Connection string for destination database has not been provided.", "Logger::saveOnDb");
124  }
125  coral::ConnectionService connServ;
126  std::unique_ptr<coral::ISessionProxy> coralSession(
127  connServ.connect(m_connectionString, auth::COND_WRITER_ROLE, coral::Update));
128  coralSession->transaction().start(false);
129  try {
130  O2O_RUN::Table destinationTable(coralSession->nominalSchema());
131  destinationTable.insert(m_jobName, m_startTime, m_endTime, m_retCode, m_log.str());
132  coralSession->transaction().commit();
133  } catch (const std::exception& e) {
134  coralSession->transaction().rollback();
135  // dump on file on this circumstance...
136  logError() << e.what();
137  saveOnFile();
138  throwException(std::string("Failure while saving log on database:") + e.what(), "Logger::saveOnDb");
139  }
140  }
141  }

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

Referenced by save().

◆ saveOnFile()

void Logger::saveOnFile ( )

Definition at line 110 of file Logger.cc.

110  {
111  if (!m_log.str().empty()) {
113  std::ofstream fout(fileName, std::ofstream::app);
114  fout << m_log.str() << std::endl;
115  fout.close();
116  }
117  }

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)

◆ start()

void Logger::start ( )

Definition at line 69 of file Logger.cc.

69  {
70  if (!m_started) {
71  if (!m_log.str().empty())
72  clearBuffer();
73  m_startTime = boost::posix_time::microsec_clock::universal_time();
74  m_started = true;
75  log("START_JOB") << " " << m_jobName;
76  }
77  }

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().

◆ subscribeCoralMessages()

void Logger::subscribeCoralMessages ( const std::weak_ptr< MsgDispatcher > &  dispatcher)

Definition at line 64 of file Logger.cc.

64 { m_dispatcher = dispatcher; }

References m_dispatcher.

Member Data Documentation

◆ m_connectionString

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

Definition at line 130 of file Logger.h.

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

◆ m_dispatcher

std::weak_ptr<MsgDispatcher> cond::persistency::Logger::m_dispatcher
private

Definition at line 136 of file Logger.h.

Referenced by subscribeCoralMessages(), and ~Logger().

◆ m_endTime

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

Definition at line 133 of file Logger.h.

Referenced by end(), and saveOnDb().

◆ m_jobName

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

Definition at line 129 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 135 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 134 of file Logger.h.

Referenced by end(), and saveOnDb().

◆ m_started

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

Definition at line 131 of file Logger.h.

Referenced by end(), and start().

◆ m_startTime

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

Definition at line 132 of file Logger.h.

Referenced by saveOnDb(), and start().

cond::persistency::Logger::m_jobName
std::string m_jobName
Definition: Logger.h:129
cond::persistency::Logger::log
std::iostream & log(const std::string &tag)
Definition: Logger.cc:150
cond::persistency::get_timestamp
std::string get_timestamp()
Definition: Logger.cc:100
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
cond::persistency::Logger::m_startTime
boost::posix_time::ptime m_startTime
Definition: Logger.h:132
cond::persistency::Logger::save
void save()
Definition: Logger.cc:143
cond::auth::COND_WRITER_ROLE
static constexpr const char *const COND_WRITER_ROLE
Definition: Auth.h:17
cond::persistency::Logger::clearBuffer
void clearBuffer()
Definition: Logger.cc:43
cond::persistency::Logger::m_started
bool m_started
Definition: Logger.h:131
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
submitPVValidationJobs.jobName
list jobName
Initialize all the variables.
Definition: submitPVValidationJobs.py:657
cond::persistency::Logger::saveOnFile
void saveOnFile()
Definition: Logger.cc:110
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:120
cond::persistency::get_timestamp_for_filename
std::string get_timestamp_for_filename()
Definition: Logger.cc:104
cond::persistency::Logger::m_endTime
boost::posix_time::ptime m_endTime
Definition: Logger.h:133
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:135
cond::persistency::Logger::logError
EchoedLogStream< edm::LogError > logError()
Definition: Logger.cc:165
cond::persistency::Logger::m_connectionString
std::string m_connectionString
Definition: Logger.h:130
cond::persistency::Logger::m_dispatcher
std::weak_ptr< MsgDispatcher > m_dispatcher
Definition: Logger.h:136
cond::persistency::Logger::m_retCode
int m_retCode
Definition: Logger.h:134
l1RCTOmdsFedVectorProducer_cfi.connectionString
connectionString
Definition: l1RCTOmdsFedVectorProducer_cfi.py:4
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37