CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DbFileHandler.cc
Go to the documentation of this file.
1 // $Id: DbFileHandler.cc,v 1.11 2012/04/04 12:17:00 mommsen Exp $
3 
6 
7 #include <iomanip>
8 
9 
10 namespace stor {
11 
13  runNumber_(0)
14  {}
15 
16 
17  void DbFileHandler::writeOld(const utils::TimePoint_t& timestamp, const std::string& str)
18  {
19  std::ofstream outputFile;
20  openFile(outputFile, timestamp);
21  outputFile << str.c_str();
22  outputFile << std::endl;
23  outputFile.close();
24  }
25 
26 
27  void DbFileHandler::write(const std::string& str)
28  {
30 
31  std::ofstream outputFile;
32  openFile(outputFile, timestamp);
33  addReportHeader(outputFile, timestamp);
34  outputFile << str.c_str();
35  outputFile << std::endl;
36  outputFile.close();
37  }
38 
39 
40  void DbFileHandler::configure(const unsigned int runNumber, const DiskWritingParams& params)
41  {
42  dwParams_ = params;
44 
45  write("BoR");
46  }
47 
48 
50  (
51  std::ofstream& outputFile,
53  ) const
54  {
55  utils::checkDirectory(dwParams_.dbFilePath_);
56 
57  std::ostringstream dbfilename;
58  dbfilename
59  << dwParams_.dbFilePath_
60  << "/"
61  << utils::dateStamp(timestamp)
62  << "-" << dwParams_.hostName_
63  << "-" << dwParams_.smInstanceString_
64  << ".log";
65 
66  outputFile.open( dbfilename.str().c_str(), std::ios_base::ate | std::ios_base::out | std::ios_base::app );
67  if (! outputFile.is_open() )
68  {
69  std::ostringstream msg;
70  msg << "Failed to open db log file " << dbfilename.str();
71  XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
72  }
73  }
74 
75 
77  (
78  std::ostream& msg,
79  const utils::TimePoint_t& timestamp
80  ) const
81  {
82  msg << "Timestamp:" << utils::secondsSinceEpoch(timestamp)
83  << "\trun:" << runNumber_
84  << "\thost:" << dwParams_.hostName_
85  << "\tinstance:" << dwParams_.smInstanceString_
86  << "\t";
87  }
88 
89 } // namespace stor
90 
91 
TimePoint_t getCurrentTime()
Definition: Utils.h:158
unsigned int runNumber_
Definition: DbFileHandler.h:68
static const char runNumber_[]
std::string dateStamp(TimePoint_t)
Definition: Utils.cc:60
void configure(const unsigned int runNumber, const DiskWritingParams &)
long secondsSinceEpoch(TimePoint_t const &)
Definition: Utils.h:152
void writeOld(const utils::TimePoint_t &, const std::string &)
void addReportHeader(std::ostream &, const utils::TimePoint_t &) const
DiskWritingParams dwParams_
Definition: DbFileHandler.h:67
void write(const std::string &)
boost::posix_time::ptime TimePoint_t
Definition: Utils.h:35
void checkDirectory(const std::string &)
Definition: Utils.cc:80
tuple out
Definition: dbtoconf.py:99
void openFile(std::ofstream &, const utils::TimePoint_t &) const