CMS 3D CMS Logo

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

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