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