CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/StorageManager/src/DbFileHandler.cc

Go to the documentation of this file.
00001 // $Id: DbFileHandler.cc,v 1.10 2011/03/07 15:31:32 mommsen Exp $
00003 
00004 #include "EventFilter/StorageManager/interface/DbFileHandler.h"
00005 #include "EventFilter/StorageManager/interface/Exception.h"
00006 
00007 #include <iomanip>
00008 
00009 
00010 namespace stor {
00011   
00012   DbFileHandler::DbFileHandler() :
00013   runNumber_(0)
00014   {}
00015   
00016   
00017   void DbFileHandler::writeOld(const utils::TimePoint_t& timestamp, const std::string& str)
00018   {
00019     std::ofstream outputFile;
00020     openFile(outputFile, timestamp);
00021     outputFile << str.c_str();
00022     outputFile.close();
00023   }
00024   
00025   
00026   void DbFileHandler::write(const std::string& str)
00027   {
00028     const utils::TimePoint_t timestamp = utils::getCurrentTime();
00029     
00030     std::ofstream outputFile;
00031     openFile(outputFile, timestamp);
00032     addReportHeader(outputFile, timestamp);
00033     outputFile << str.c_str();
00034     outputFile << std::endl;
00035     outputFile.close();
00036   }
00037   
00038   
00039   void DbFileHandler::configure(const unsigned int runNumber, const DiskWritingParams& params)
00040   { 
00041     dwParams_ = params;
00042     runNumber_ = runNumber;
00043     
00044     write("BoR");
00045   }
00046   
00047   
00048   void DbFileHandler::openFile
00049   (
00050     std::ofstream& outputFile,
00051     const utils::TimePoint_t& timestamp
00052   ) const
00053   {
00054     utils::checkDirectory(dwParams_.dbFilePath_);
00055     
00056     std::ostringstream dbfilename;
00057     dbfilename
00058       << dwParams_.dbFilePath_
00059         << "/"
00060         << utils::dateStamp(timestamp)
00061         << "-" << dwParams_.hostName_
00062         << "-" << dwParams_.smInstanceString_
00063         << ".log";
00064     
00065     outputFile.open( dbfilename.str().c_str(), std::ios_base::ate | std::ios_base::out | std::ios_base::app );
00066     if (! outputFile.is_open() )
00067     {
00068       std::ostringstream msg;
00069       msg << "Failed to open db log file " << dbfilename.str();
00070       XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
00071     }
00072   }
00073   
00074   
00075   void DbFileHandler::addReportHeader
00076   (
00077     std::ostream& msg,
00078     const utils::TimePoint_t& timestamp
00079   ) const
00080   {
00081     msg << "Timestamp:" << utils::secondsSinceEpoch(timestamp)
00082       << "\trun:" << runNumber_
00083       << "\thost:" << dwParams_.hostName_
00084       << "\tinstance:" << dwParams_.smInstanceString_
00085       << "\t";
00086   }
00087   
00088 } // namespace stor
00089 
00090