CMS 3D CMS Logo

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) {
21  {
22  // ROOT's context management implicitly assumes that a file is opened and
23  // closed on the same thread. To avoid the problem, we declare a local
24  // TContext object; when it goes out of scope, its destructor unregisters
25  // the context, guaranteeing the context is unregistered in the same thread
26  // it was registered in. Fixes issue #15524.
27  TDirectory::TContext contextEraser;
28 
29  file_ = std::unique_ptr<TFile>(TFile::Open(fileName)); // propagate_const<T> has no reset() function
30  }
31  std::exception_ptr e = edm::threadLocalException::getException();
32  if (e != std::exception_ptr()) {
33  edm::threadLocalException::setException(std::exception_ptr());
34  std::rethrow_exception(e);
35  }
36  if (!file_) {
37  throw edm::Exception(errors::FileOpenError) << "TFile::Open failed.";
38  }
39  if (file_->IsZombie()) {
40  throw edm::Exception(errors::FileOpenError) << "TFile::Open returned zombie.";
41  }
42 
43  logFileAction(" Successfully opened file ", fileName);
44  }
45 
47 
48  void InputFile::inputFileOpened(std::string const& logicalFileName,
49  std::string const& inputType,
50  std::string const& moduleName,
51  std::string const& label,
52  std::string const& fid,
53  std::vector<std::string> const& branchNames) {
54  Service<JobReport> reportSvc;
55  reportToken_ = reportSvc->inputFileOpened(
56  fileName_, logicalFileName, std::string(), inputType, moduleName, label, fid, branchNames);
57  }
58 
60  Service<JobReport> reportSvc;
61  reportSvc->eventReadFromFile(inputType_, reportToken_);
62  }
63 
64  void InputFile::reportInputRunNumber(unsigned int run) const {
65  Service<JobReport> reportSvc;
66  reportSvc->reportInputRunNumber(run);
67  }
68 
69  void InputFile::reportInputLumiSection(unsigned int run, unsigned int lumi) const {
70  Service<JobReport> reportSvc;
71  reportSvc->reportInputLumiSection(run, lumi);
72  }
73 
74  void InputFile::reportSkippedFile(std::string const& fileName, std::string const& logicalFileName) {
75  Service<JobReport> reportSvc;
76  reportSvc->reportSkippedFile(fileName, logicalFileName);
77  }
78 
80  std::string const& logicalFileName,
81  std::string const& errorMessage) {
82  Service<JobReport> reportSvc;
83  reportSvc->reportFallbackAttempt(pfn, logicalFileName, errorMessage);
84  }
85 
87  if (file_->IsOpen()) {
88  file_->Close();
89  try {
90  logFileAction(" Closed file ", fileName_.c_str());
91  Service<JobReport> reportSvc;
92  reportSvc->inputFileClosed(inputType_, reportToken_);
93  } catch (std::exception const&) {
94  // If Close() called in a destructor after an exception throw, the services may no longer be active.
95  // Therefore, we catch any reasonable new exception.
96  }
97  }
98  }
99 
100  void InputFile::logFileAction(char const* msg, char const* fileName) const {
101  LogAbsolute("fileAction") << std::setprecision(0) << TimeOfDay() << msg << fileName;
102  FlushMessageLog();
103  }
104 
106  Service<JobReport> reportSvc;
107  reportSvc->reportReadBranches();
108  }
109 
111  Service<JobReport> reportSvc;
112  reportSvc->reportReadBranch(inputType, branchName);
113  }
114 } // namespace edm
void Close()
Definition: InputFile.cc:86
InputType
Definition: InputType.h:5
void FlushMessageLog()
JobReport::Token reportToken_
Definition: InputFile.h:56
void logFileAction(char const *msg, char const *fileName) const
Definition: InputFile.cc:100
InputType inputType_
Definition: InputFile.h:57
void eventReadFromFile() const
Definition: InputFile.cc:59
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:48
static void reportReadBranch(InputType inputType, std::string const &branchname)
Definition: InputFile.cc:110
char const * label
static void reportFallbackAttempt(std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
Definition: InputFile.cc:79
static void reportReadBranches()
Definition: InputFile.cc:105
static void reportSkippedFile(std::string const &fileName, std::string const &logicalFileName)
Definition: InputFile.cc:74
edm::propagate_const< std::unique_ptr< TFile > > file_
Definition: InputFile.h:54
std::string fileName_
Definition: InputFile.h:55
void reportInputLumiSection(unsigned int run, unsigned int lumi) const
Definition: InputFile.cc:69
tuple msg
Definition: mps_check.py:286
void reportInputRunNumber(unsigned int run) const
Definition: InputFile.cc:64
void setException(std::exception_ptr e)
std::string moduleName(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
HLT enums.
std::exception_ptr getException()
Log< level::System, true > LogAbsolute
InputFile(char const *fileName, char const *msg, InputType inputType)
Definition: InputFile.cc:18
branchNames
Definition: haddnano.py:54