CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
edm::InputFile Class Reference

#include <InputFile.h>

Public Member Functions

void Close ()
 
void eventReadFromFile () const
 
TObject * Get (char const *name)
 
TFileCacheRead * GetCacheRead () const
 
 InputFile (char const *fileName, char const *msg, InputType inputType)
 
 InputFile (InputFile const &)=delete
 
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)
 
void logFileAction (char const *msg, char const *fileName) const
 
InputFileoperator= (InputFile const &)=delete
 
void reportInputLumiSection (unsigned int run, unsigned int lumi) const
 
void reportInputRunNumber (unsigned int run) const
 
void SetCacheRead (TFileCacheRead *tfcr)
 
 ~InputFile ()
 

Static Public Member Functions

static void reportFallbackAttempt (std::string const &pfn, std::string const &logicalFileName, std::string const &errorMessage)
 
static void reportReadBranch (InputType inputType, std::string const &branchname)
 
static void reportReadBranches ()
 
static void reportSkippedFile (std::string const &fileName, std::string const &logicalFileName)
 

Private Attributes

edm::propagate_const< std::unique_ptr< TFile > > file_
 
std::string fileName_
 
InputType inputType_
 
JobReport::Token reportToken_
 

Detailed Description

Definition at line 21 of file InputFile.h.

Constructor & Destructor Documentation

InputFile::InputFile ( char const *  fileName,
char const *  msg,
InputType  inputType 
)
explicit

Definition at line 18 of file InputFile.cc.

References MillePedeFileConverter_cfg::e, Exception, file_, edm::errors::FileOpenError, edm::threadLocalException::getException(), logFileAction(), and edm::threadLocalException::setException().

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  }
JobReport::Token reportToken_
Definition: InputFile.h:56
InputType inputType_
Definition: InputFile.h:57
void logFileAction(char const *msg, char const *fileName) const
Definition: InputFile.cc:100
edm::propagate_const< std::unique_ptr< TFile > > file_
Definition: InputFile.h:54
std::string fileName_
Definition: InputFile.h:55
tuple msg
Definition: mps_check.py:285
void setException(std::exception_ptr e)
std::exception_ptr getException()
InputFile::~InputFile ( )

Definition at line 46 of file InputFile.cc.

References Close().

46 { Close(); }
void Close()
Definition: InputFile.cc:86
edm::InputFile::InputFile ( InputFile const &  )
delete

Member Function Documentation

void InputFile::Close ( )

Definition at line 86 of file InputFile.cc.

References cppFunctionSkipper::exception, file_, fileName_, inputType_, logFileAction(), and reportToken_.

Referenced by ~InputFile().

86  {
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  }
JobReport::Token reportToken_
Definition: InputFile.h:56
InputType inputType_
Definition: InputFile.h:57
void logFileAction(char const *msg, char const *fileName) const
Definition: InputFile.cc:100
edm::propagate_const< std::unique_ptr< TFile > > file_
Definition: InputFile.h:54
std::string fileName_
Definition: InputFile.h:55
void InputFile::eventReadFromFile ( ) const

Definition at line 59 of file InputFile.cc.

References inputType_, and reportToken_.

59  {
60  Service<JobReport> reportSvc;
61  reportSvc->eventReadFromFile(inputType_, reportToken_);
62  }
JobReport::Token reportToken_
Definition: InputFile.h:56
InputType inputType_
Definition: InputFile.h:57
TObject* edm::InputFile::Get ( char const *  name)
inline

Definition at line 48 of file InputFile.h.

References file_.

48 { return file_->Get(name); }
edm::propagate_const< std::unique_ptr< TFile > > file_
Definition: InputFile.h:54
TFileCacheRead* edm::InputFile::GetCacheRead ( ) const
inline

Definition at line 49 of file InputFile.h.

References file_.

Referenced by edm::roottree::trainCache().

49 { return file_->GetCacheRead(); }
edm::propagate_const< std::unique_ptr< TFile > > file_
Definition: InputFile.h:54
void InputFile::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 at line 48 of file InputFile.cc.

References fileName_, reportToken_, and AlCaHLTBitMon_QueryRunRegistry::string.

53  {
54  Service<JobReport> reportSvc;
55  reportToken_ = reportSvc->inputFileOpened(
56  fileName_, logicalFileName, std::string(), inputType, moduleName, label, fid, branchNames);
57  }
JobReport::Token reportToken_
Definition: InputFile.h:56
char const * label
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
std::string fileName_
Definition: InputFile.h:55
branchNames
Definition: haddnano.py:54
void InputFile::logFileAction ( char const *  msg,
char const *  fileName 
) const

Definition at line 100 of file InputFile.cc.

References MillePedeFileConverter_cfg::fileName, and edm::FlushMessageLog().

Referenced by Close(), InputFile(), and SetCacheRead().

100  {
101  LogAbsolute("fileAction") << std::setprecision(0) << TimeOfDay() << msg << fileName;
102  FlushMessageLog();
103  }
void FlushMessageLog()
tuple msg
Definition: mps_check.py:285
InputFile& edm::InputFile::operator= ( InputFile const &  )
delete
void InputFile::reportFallbackAttempt ( std::string const &  pfn,
std::string const &  logicalFileName,
std::string const &  errorMessage 
)
static

Definition at line 79 of file InputFile.cc.

Referenced by edm::RootInputFileSequence::initTheFile().

81  {
82  Service<JobReport> reportSvc;
83  reportSvc->reportFallbackAttempt(pfn, logicalFileName, errorMessage);
84  }
void InputFile::reportInputLumiSection ( unsigned int  run,
unsigned int  lumi 
) const

Definition at line 69 of file InputFile.cc.

69  {
70  Service<JobReport> reportSvc;
71  reportSvc->reportInputLumiSection(run, lumi);
72  }
void InputFile::reportInputRunNumber ( unsigned int  run) const

Definition at line 64 of file InputFile.cc.

64  {
65  Service<JobReport> reportSvc;
66  reportSvc->reportInputRunNumber(run);
67  }
void InputFile::reportReadBranch ( InputType  inputType,
std::string const &  branchname 
)
static

Definition at line 110 of file InputFile.cc.

Referenced by edm::RootDelayedReader::getProduct_().

110  {
111  Service<JobReport> reportSvc;
112  reportSvc->reportReadBranch(inputType, branchName);
113  }
void InputFile::reportReadBranches ( )
static

Definition at line 105 of file InputFile.cc.

Referenced by edm::EmbeddedRootSource::endJob(), and edm::PoolSource::endJob().

105  {
106  Service<JobReport> reportSvc;
107  reportSvc->reportReadBranches();
108  }
void InputFile::reportSkippedFile ( std::string const &  fileName,
std::string const &  logicalFileName 
)
static

Definition at line 74 of file InputFile.cc.

Referenced by edm::RootInputFileSequence::initTheFile().

74  {
75  Service<JobReport> reportSvc;
76  reportSvc->reportSkippedFile(fileName, logicalFileName);
77  }
void edm::InputFile::SetCacheRead ( TFileCacheRead *  tfcr)
inline

Definition at line 50 of file InputFile.h.

References file_, and logFileAction().

Referenced by edm::roottree::trainCache().

50 { file_->SetCacheRead(tfcr, nullptr, TFile::kDoNotDisconnect); }
edm::propagate_const< std::unique_ptr< TFile > > file_
Definition: InputFile.h:54

Member Data Documentation

edm::propagate_const<std::unique_ptr<TFile> > edm::InputFile::file_
private

Definition at line 54 of file InputFile.h.

Referenced by Close(), Get(), GetCacheRead(), InputFile(), and SetCacheRead().

std::string edm::InputFile::fileName_
private

Definition at line 55 of file InputFile.h.

Referenced by Close(), and inputFileOpened().

InputType edm::InputFile::inputType_
private

Definition at line 57 of file InputFile.h.

Referenced by Close(), and eventReadFromFile().

JobReport::Token edm::InputFile::reportToken_
private

Definition at line 56 of file InputFile.h.

Referenced by Close(), eventReadFromFile(), and inputFileOpened().