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