CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/IOPool/Input/src/InputFile.cc

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------
00002 
00003 Holder for an input TFile.
00004 ----------------------------------------------------------------------*/
00005 #include "InputFile.h"
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "FWCore/ServiceRegistry/interface/Service.h"
00009 #include "FWCore/Utilities/interface/TimeOfDay.h"
00010 
00011 #include <iomanip>
00012 
00013 namespace edm {
00014   InputFile::InputFile(char const* fileName, char const* msg) : file_(), fileName_(fileName), reportToken_(0) {
00015     logFileAction(msg, fileName);
00016     file_.reset(TFile::Open(fileName));
00017     if(!file_) { 
00018       return;
00019     }
00020     if(file_->IsZombie()) { 
00021       file_.reset();
00022       return;
00023     }
00024     logFileAction("  Successfully opened file ", fileName);
00025   }
00026 
00027   InputFile::~InputFile() { 
00028     Close();
00029   }
00030 
00031   void
00032   InputFile::inputFileOpened(std::string const& logicalFileName,
00033                              std::string const& inputType,
00034                              std::string const& moduleName,
00035                              std::string const& label,
00036                              std::string const& fid,
00037                              std::vector<std::string> const& branchNames) {
00038     Service<JobReport> reportSvc;
00039     reportToken_ = reportSvc->inputFileOpened(fileName_,
00040                                               logicalFileName,
00041                                               std::string(),
00042                                               inputType,
00043                                               moduleName,
00044                                               label,
00045                                               fid,
00046                                               branchNames);
00047   }
00048 
00049   void
00050   InputFile::eventReadFromFile(unsigned int run, unsigned int event) const {
00051     Service<JobReport> reportSvc;
00052     reportSvc->eventReadFromFile(reportToken_, run, event);
00053   }
00054 
00055   void
00056   InputFile::reportInputRunNumber(unsigned int run) const {
00057     Service<JobReport> reportSvc;
00058     reportSvc->reportInputRunNumber(run);
00059   }
00060 
00061   void
00062   InputFile::reportInputLumiSection(unsigned int run, unsigned int lumi) const {
00063     Service<JobReport> reportSvc;
00064     reportSvc->reportInputLumiSection(run, lumi);
00065   }
00066 
00067   void
00068   InputFile::reportSkippedFile(std::string const& fileName, std::string const& logicalFileName) {
00069     Service<JobReport> reportSvc;
00070     reportSvc->reportSkippedFile(fileName, logicalFileName);
00071   }
00072 
00073   void
00074   InputFile::Close() {
00075     if(file_->IsOpen()) {
00076       file_->Close();
00077       try {
00078         logFileAction("  Closed file ", fileName_.c_str());
00079         Service<JobReport> reportSvc;
00080         reportSvc->inputFileClosed(reportToken_);
00081       } catch(...) {
00082         // If Close() called in a destructor after an exception throw, the services may no longer be active.
00083         // Therefore, we catch any new exception.
00084       }
00085     }
00086   }
00087 
00088   void
00089   InputFile::logFileAction(char const* msg, char const* fileName) const {
00090     LogAbsolute("fileAction") << std::setprecision(0) << TimeOfDay() << msg << fileName;
00091     FlushMessageLog();
00092   }
00093 }