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() [1/2]

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

Definition at line 18 of file InputFile.cc.

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  return;
38  }
39  if (file_->IsZombie()) {
40  file_ = nullptr; // propagate_const<T> has no reset() function
41  return;
42  }
43 
44  logFileAction(" Successfully opened file ", fileName);
45  }

References MillePedeFileConverter_cfg::e, file_, MillePedeFileConverter_cfg::fileName, edm::threadLocalException::getException(), logFileAction(), mps_check::msg, and edm::threadLocalException::setException().

◆ ~InputFile()

InputFile::~InputFile ( )

Definition at line 47 of file InputFile.cc.

47 { Close(); }

References Close().

◆ InputFile() [2/2]

edm::InputFile::InputFile ( InputFile const &  )
delete

Member Function Documentation

◆ Close()

void InputFile::Close ( )

Definition at line 87 of file InputFile.cc.

87  {
88  if (file_->IsOpen()) {
89  file_->Close();
90  try {
91  logFileAction(" Closed file ", fileName_.c_str());
92  Service<JobReport> reportSvc;
93  reportSvc->inputFileClosed(inputType_, reportToken_);
94  } catch (std::exception const&) {
95  // If Close() called in a destructor after an exception throw, the services may no longer be active.
96  // Therefore, we catch any reasonable new exception.
97  }
98  }
99  }

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

Referenced by ~InputFile().

◆ eventReadFromFile()

void InputFile::eventReadFromFile ( ) const

Definition at line 60 of file InputFile.cc.

60  {
61  Service<JobReport> reportSvc;
62  reportSvc->eventReadFromFile(inputType_, reportToken_);
63  }

References inputType_, and reportToken_.

◆ Get()

TObject* edm::InputFile::Get ( char const *  name)
inline

Definition at line 48 of file InputFile.h.

48 { return file_->Get(name); }

References file_, and Skims_PA_cff::name.

◆ GetCacheRead()

TFileCacheRead* edm::InputFile::GetCacheRead ( ) const
inline

Definition at line 49 of file InputFile.h.

49 { return file_->GetCacheRead(); }

References file_.

◆ inputFileOpened()

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 49 of file InputFile.cc.

54  {
55  Service<JobReport> reportSvc;
56  reportToken_ = reportSvc->inputFileOpened(
57  fileName_, logicalFileName, std::string(), inputType, moduleName, label, fid, branchNames);
58  }

References fileName_, label, edm::moduleName(), reportToken_, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ logFileAction()

void InputFile::logFileAction ( char const *  msg,
char const *  fileName 
) const

Definition at line 101 of file InputFile.cc.

101  {
102  LogAbsolute("fileAction") << std::setprecision(0) << TimeOfDay() << msg << fileName;
103  FlushMessageLog();
104  }

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

Referenced by Close(), and InputFile().

◆ operator=()

InputFile& edm::InputFile::operator= ( InputFile const &  )
delete

◆ reportFallbackAttempt()

void InputFile::reportFallbackAttempt ( std::string const &  pfn,
std::string const &  logicalFileName,
std::string const &  errorMessage 
)
static

Definition at line 80 of file InputFile.cc.

82  {
83  Service<JobReport> reportSvc;
84  reportSvc->reportFallbackAttempt(pfn, logicalFileName, errorMessage);
85  }

◆ reportInputLumiSection()

void InputFile::reportInputLumiSection ( unsigned int  run,
unsigned int  lumi 
) const

Definition at line 70 of file InputFile.cc.

70  {
71  Service<JobReport> reportSvc;
72  reportSvc->reportInputLumiSection(run, lumi);
73  }

References writedatasetfile::run.

◆ reportInputRunNumber()

void InputFile::reportInputRunNumber ( unsigned int  run) const

Definition at line 65 of file InputFile.cc.

65  {
66  Service<JobReport> reportSvc;
67  reportSvc->reportInputRunNumber(run);
68  }

References writedatasetfile::run.

◆ reportReadBranch()

void InputFile::reportReadBranch ( InputType  inputType,
std::string const &  branchname 
)
static

Definition at line 111 of file InputFile.cc.

111  {
112  Service<JobReport> reportSvc;
113  reportSvc->reportReadBranch(inputType, branchName);
114  }

References electrons_cff::branchName.

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

◆ reportReadBranches()

void InputFile::reportReadBranches ( )
static

Definition at line 106 of file InputFile.cc.

106  {
107  Service<JobReport> reportSvc;
108  reportSvc->reportReadBranches();
109  }

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

◆ reportSkippedFile()

void InputFile::reportSkippedFile ( std::string const &  fileName,
std::string const &  logicalFileName 
)
static

Definition at line 75 of file InputFile.cc.

75  {
76  Service<JobReport> reportSvc;
77  reportSvc->reportSkippedFile(fileName, logicalFileName);
78  }

References MillePedeFileConverter_cfg::fileName.

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

◆ SetCacheRead()

void edm::InputFile::SetCacheRead ( TFileCacheRead *  tfcr)
inline

Definition at line 50 of file InputFile.h.

50 { file_->SetCacheRead(tfcr, nullptr, TFile::kDoNotDisconnect); }

References file_.

Member Data Documentation

◆ file_

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().

◆ fileName_

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

Definition at line 55 of file InputFile.h.

Referenced by Close(), and inputFileOpened().

◆ inputType_

InputType edm::InputFile::inputType_
private

Definition at line 57 of file InputFile.h.

Referenced by Close(), and eventReadFromFile().

◆ reportToken_

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

Definition at line 56 of file InputFile.h.

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

edm::InputFile::logFileAction
void logFileAction(char const *msg, char const *fileName) const
Definition: InputFile.cc:101
edm::InputFile::fileName_
std::string fileName_
Definition: InputFile.h:55
electrons_cff.branchName
branchName
Definition: electrons_cff.py:492
mps_check.msg
tuple msg
Definition: mps_check.py:285
edm::threadLocalException::getException
std::exception_ptr getException()
Definition: ExceptionPropagate.cc:7
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
edm::InputFile::inputType_
InputType inputType_
Definition: InputFile.h:57
edm::threadLocalException::setException
void setException(std::exception_ptr e)
Definition: ExceptionPropagate.cc:6
Service
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::FlushMessageLog
void FlushMessageLog()
Definition: MessageLogger.cc:94
edm::InputFile::file_
edm::propagate_const< std::unique_ptr< TFile > > file_
Definition: InputFile.h:54
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::moduleName
std::string moduleName(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
lumi
Definition: LumiSectionData.h:20
edm::InputFile::Close
void Close()
Definition: InputFile.cc:87
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::InputFile::reportToken_
JobReport::Token reportToken_
Definition: InputFile.h:56
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37