CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InputFile.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 Holder for an input TFile.
3 ----------------------------------------------------------------------*/
4 #include "InputFile.h"
5 
9 
10 #include <iomanip>
11 
12 namespace edm {
13  InputFile::InputFile(char const* fileName, char const* msg, InputType inputType) :
14  file_(), fileName_(fileName), reportToken_(0), inputType_(inputType) {
15 
16  logFileAction(msg, fileName);
17  file_.reset(TFile::Open(fileName));
18  if(!file_) {
19  return;
20  }
21  if(file_->IsZombie()) {
22  file_.reset();
23  return;
24  }
25  logFileAction(" Successfully opened file ", fileName);
26  }
27 
29  Close();
30  }
31 
32  void
33  InputFile::inputFileOpened(std::string const& logicalFileName,
34  std::string const& inputType,
35  std::string const& moduleName,
36  std::string const& label,
37  std::string const& fid,
38  std::vector<std::string> const& branchNames) {
39  Service<JobReport> reportSvc;
40  reportToken_ = reportSvc->inputFileOpened(fileName_,
41  logicalFileName,
42  std::string(),
43  inputType,
44  moduleName,
45  label,
46  fid,
47  branchNames);
48  }
49 
50  void
52  Service<JobReport> reportSvc;
53  reportSvc->eventReadFromFile(inputType_, reportToken_);
54  }
55 
56  void
57  InputFile::reportInputRunNumber(unsigned int run) const {
58  Service<JobReport> reportSvc;
59  reportSvc->reportInputRunNumber(run);
60  }
61 
62  void
63  InputFile::reportInputLumiSection(unsigned int run, unsigned int lumi) const {
64  Service<JobReport> reportSvc;
65  reportSvc->reportInputLumiSection(run, lumi);
66  }
67 
68  void
70  Service<JobReport> reportSvc;
71  reportSvc->reportSkippedFile(fileName, logicalFileName);
72  }
73 
74  void
75  InputFile::reportFallbackAttempt(std::string const& pfn, std::string const& logicalFileName, std::string const& errorMessage) {
76  Service<JobReport> reportSvc;
77  reportSvc->reportFallbackAttempt(pfn, logicalFileName, errorMessage);
78  }
79 
80  void
82  if(file_->IsOpen()) {
83  file_->Close();
84  try {
85  logFileAction(" Closed file ", fileName_.c_str());
86  Service<JobReport> reportSvc;
87  reportSvc->inputFileClosed(inputType_, reportToken_);
88  } catch(std::exception) {
89  // If Close() called in a destructor after an exception throw, the services may no longer be active.
90  // Therefore, we catch any reasonable new exception.
91  }
92  }
93  }
94 
95  void
96  InputFile::logFileAction(char const* msg, char const* fileName) const {
97  LogAbsolute("fileAction") << std::setprecision(0) << TimeOfDay() << msg << fileName;
99  }
100 
101  void
103  Service<JobReport> reportSvc;
104  reportSvc->reportReadBranches();
105  }
106 
107  void
108  InputFile::reportReadBranch(InputType inputType, std::string const& branchName) {
109  Service<JobReport> reportSvc;
110  reportSvc->reportReadBranch(inputType, branchName);
111  }
112 }
InputType
Definition: InputType.h:5
list pfn
Definition: dbtoconf.py:76
void reportInputLumiSection(unsigned int run, unsigned int lumi) const
Definition: InputFile.cc:63
void FlushMessageLog()
JobReport::Token reportToken_
Definition: InputFile.h:52
InputType inputType_
Definition: InputFile.h:53
tuple lumi
Definition: fjr2json.py:35
void inputFileOpened(std::string const &logicalFileName, std::string const &inputType, std::string const &moduleName, std::string const &label, std::string const &fid, std::vector< std::string > const &branchNames)
Definition: InputFile.cc:33
static void reportReadBranch(InputType inputType, std::string const &branchname)
Definition: InputFile.cc:108
void logFileAction(char const *msg, char const *fileName) const
Definition: InputFile.cc:96
static void reportSkippedFile(std::string const &fileName, std::string const &logicalFileName)
Definition: InputFile.cc:69
static void reportFallbackAttempt(std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
Definition: InputFile.cc:75
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
std::unique_ptr< TFile > file_
Definition: InputFile.h:50
void eventReadFromFile() const
Definition: InputFile.cc:51
std::string fileName_
Definition: InputFile.h:51
InputFile(char const *fileName, char const *msg, InputType inputType)
Definition: InputFile.cc:13
static void reportReadBranches()
Definition: InputFile.cc:102
void Close()
Definition: InputFile.cc:81
list fid
Definition: NewTree.py:51
void reportInputRunNumber(unsigned int run) const
Definition: InputFile.cc:57