CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/EventFilter/StorageManager/src/DbFileHandler.cc

Go to the documentation of this file.
00001 // $Id: DbFileHandler.cc,v 1.11 2012/04/04 12:17:00 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 << std::endl;
00023     outputFile.close();
00024   }
00025   
00026   
00027   void DbFileHandler::write(const std::string& str)
00028   {
00029     const utils::TimePoint_t timestamp = utils::getCurrentTime();
00030     
00031     std::ofstream outputFile;
00032     openFile(outputFile, timestamp);
00033     addReportHeader(outputFile, timestamp);
00034     outputFile << str.c_str();
00035     outputFile << std::endl;
00036     outputFile.close();
00037   }
00038   
00039   
00040   void DbFileHandler::configure(const unsigned int runNumber, const DiskWritingParams& params)
00041   { 
00042     dwParams_ = params;
00043     runNumber_ = runNumber;
00044     
00045     write("BoR");
00046   }
00047   
00048   
00049   void DbFileHandler::openFile
00050   (
00051     std::ofstream& outputFile,
00052     const utils::TimePoint_t& timestamp
00053   ) const
00054   {
00055     utils::checkDirectory(dwParams_.dbFilePath_);
00056     
00057     std::ostringstream dbfilename;
00058     dbfilename
00059       << dwParams_.dbFilePath_
00060         << "/"
00061         << utils::dateStamp(timestamp)
00062         << "-" << dwParams_.hostName_
00063         << "-" << dwParams_.smInstanceString_
00064         << ".log";
00065     
00066     outputFile.open( dbfilename.str().c_str(), std::ios_base::ate | std::ios_base::out | std::ios_base::app );
00067     if (! outputFile.is_open() )
00068     {
00069       std::ostringstream msg;
00070       msg << "Failed to open db log file " << dbfilename.str();
00071       XCEPT_RAISE(stor::exception::DiskWriting, msg.str());
00072     }
00073   }
00074   
00075   
00076   void DbFileHandler::addReportHeader
00077   (
00078     std::ostream& msg,
00079     const utils::TimePoint_t& timestamp
00080   ) const
00081   {
00082     msg << "Timestamp:" << utils::secondsSinceEpoch(timestamp)
00083       << "\trun:" << runNumber_
00084       << "\thost:" << dwParams_.hostName_
00085       << "\tinstance:" << dwParams_.smInstanceString_
00086       << "\t";
00087   }
00088   
00089 } // namespace stor
00090 
00091