CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
TFileService Class Reference

#include <TFileService.h>

Public Member Functions

void afterBeginJob ()
 Hook for writing info into JR. More...
 
bool cd () const
 
TFile & file () const
 return opened TFile More...
 
std::string fullPath () const
 return the full path of the stored histograms More...
 
TDirectory * getBareDirectory (const std::string &subdir="") const
 
template<typename T >
TgetObject (const std::string &objname, const std::string &subdir="")
 
template<typename T , typename... Args>
Tmake (const Args &...args) const
 make new ROOT object More...
 
TFileDirectory mkdir (const std::string &dir, const std::string &descr="")
 create a new subdirectory More...
 
TFileDirectorytFileDirectory ()
 
 TFileService (const edm::ParameterSet &, edm::ActivityRegistry &)
 constructor More...
 
 ~TFileService ()
 destructor More...
 

Static Public Attributes

static const std::string kSharedResource = "TFileService"
 

Private Member Functions

void postModuleEvent (edm::StreamContext const &, edm::ModuleCallingContext const &)
 
void postModuleGlobal (edm::GlobalContext const &, edm::ModuleCallingContext const &)
 
void preModuleEvent (edm::StreamContext const &, edm::ModuleCallingContext const &)
 
void preModuleGlobal (edm::GlobalContext const &, edm::ModuleCallingContext const &)
 
void setDirectoryName (const edm::ModuleDescription &desc)
 

Private Attributes

bool closeFileFast_
 
TFile * file_
 pointer to opened TFile More...
 
std::string fileName_
 
bool fileNameRecorded_
 

Static Private Attributes

static thread_local TFileDirectory tFileDirectory_
 

Detailed Description

Definition at line 30 of file TFileService.h.

Constructor & Destructor Documentation

TFileService::TFileService ( const edm::ParameterSet cfg,
edm::ActivityRegistry r 
)

constructor

Definition at line 17 of file TFileService.cc.

References afterBeginJob(), file_, TFileDirectory::file_, fileName_, postModuleEvent(), postModuleGlobal(), preModuleEvent(), preModuleGlobal(), setDirectoryName(), tFileDirectory_, edm::ActivityRegistry::watchPostBeginJob(), edm::ActivityRegistry::watchPostModuleEvent(), edm::ActivityRegistry::watchPostModuleGlobalBeginLumi(), edm::ActivityRegistry::watchPostModuleGlobalBeginRun(), edm::ActivityRegistry::watchPostModuleGlobalEndLumi(), edm::ActivityRegistry::watchPostModuleGlobalEndRun(), edm::ActivityRegistry::watchPreModuleBeginJob(), edm::ActivityRegistry::watchPreModuleConstruction(), edm::ActivityRegistry::watchPreModuleEndJob(), edm::ActivityRegistry::watchPreModuleEvent(), edm::ActivityRegistry::watchPreModuleGlobalBeginLumi(), edm::ActivityRegistry::watchPreModuleGlobalBeginRun(), edm::ActivityRegistry::watchPreModuleGlobalEndLumi(), and edm::ActivityRegistry::watchPreModuleGlobalEndRun().

17  :
18  file_(nullptr),
19  fileName_(cfg.getParameter<std::string>("fileName")),
20  fileNameRecorded_(false),
21  closeFileFast_(cfg.getUntrackedParameter<bool>("closeFileFast", false))
22 {
24  "",
25  TFile::Open(fileName_.c_str(), "RECREATE"),
26  "");
28 
29  // activities to monitor in order to set the proper directory
35 
40 
45 
46  // delay writing into JobReport after BeginJob
48 }
void watchPostModuleGlobalEndLumi(PostModuleGlobalEndLumi::slot_type const &iSlot)
void postModuleGlobal(edm::GlobalContext const &, edm::ModuleCallingContext const &)
Definition: TFileService.cc:80
T getParameter(std::string const &) const
void watchPreModuleGlobalBeginRun(PreModuleGlobalBeginRun::slot_type const &iSlot)
T getUntrackedParameter(std::string const &, T const &) const
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
void watchPostModuleGlobalBeginLumi(PostModuleGlobalBeginLumi::slot_type const &iSlot)
TFile * file_
pointer to opened TFile
Definition: TFileService.h:81
void watchPreModuleGlobalEndRun(PreModuleGlobalEndRun::slot_type const &iSlot)
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
std::string fileName_
Definition: TFileService.h:82
void setDirectoryName(const edm::ModuleDescription &desc)
Definition: TFileService.cc:57
void watchPreModuleEndJob(PreModuleEndJob::slot_type const &iSlot)
void watchPreModuleBeginJob(PreModuleBeginJob::slot_type const &iSlot)
void watchPreModuleGlobalBeginLumi(PreModuleGlobalBeginLumi::slot_type const &iSlot)
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
Definition: TFileService.cc:67
void watchPostModuleGlobalEndRun(PostModuleGlobalEndRun::slot_type const &iSlot)
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
Definition: TFileService.cc:63
bool fileNameRecorded_
Definition: TFileService.h:83
bool closeFileFast_
Definition: TFileService.h:84
void watchPostModuleGlobalBeginRun(PostModuleGlobalBeginRun::slot_type const &iSlot)
void afterBeginJob()
Hook for writing info into JR.
Definition: TFileService.cc:87
void preModuleGlobal(edm::GlobalContext const &, edm::ModuleCallingContext const &)
Definition: TFileService.cc:75
void watchPreModuleGlobalEndLumi(PreModuleGlobalEndLumi::slot_type const &iSlot)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal
TFileService::~TFileService ( )

destructor

Definition at line 50 of file TFileService.cc.

References closeFileFast_, and file_.

50  {
51  file_->Write();
52  if(closeFileFast_) gROOT->GetListOfFiles()->Remove(file_);
53  file_->Close();
54  delete file_;
55 }
TFile * file_
pointer to opened TFile
Definition: TFileService.h:81
bool closeFileFast_
Definition: TFileService.h:84

Member Function Documentation

void TFileService::afterBeginJob ( )

Hook for writing info into JR.

Definition at line 87 of file TFileService.cc.

References fileName_, fileNameRecorded_, newFWLiteAna::fullName, edm::JobReport::reportAnalysisFile(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TFileService().

87  {
88 
89  if(!fileName_.empty()) {
90  if(!fileNameRecorded_) {
92  fullName.reserve(1024);
93  fullName = getcwd(&fullName[0],1024);
94  fullName += "/" + fileName_;
95 
96  std::map<std::string, std::string> fileData;
97  fileData.insert(std::make_pair("Source","TFileService"));
98 
100  reportSvc->reportAnalysisFile(fullName,fileData);
101  fileNameRecorded_ = true;
102  }
103  }
104 }
std::string fileName_
Definition: TFileService.h:82
string fullName
bool fileNameRecorded_
Definition: TFileService.h:83
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:564
bool TFileService::cd ( ) const
inline

Definition at line 49 of file TFileService.h.

References TFileDirectory::cd(), and tFileDirectory_.

49 { return tFileDirectory_.cd(); }
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
bool cd() const
TFile& TFileService::file ( ) const
inline

return opened TFile

Definition at line 37 of file TFileService.h.

References file_.

Referenced by BTagPerformaceRootProducerFromSQLITE::analyze(), HcalForwardLibWriter::endJob(), HcalForwardLibWriter::HcalForwardLibWriter(), and VariableNTupler::registerleaves().

37 { return * file_; }
TFile * file_
pointer to opened TFile
Definition: TFileService.h:81
std::string TFileService::fullPath ( ) const
inline

return the full path of the stored histograms

Definition at line 74 of file TFileService.h.

References TFileDirectory::fullPath(), and tFileDirectory_.

74 { return tFileDirectory_.fullPath(); }
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
std::string fullPath() const
return the full path of the stored histograms
TDirectory* TFileService::getBareDirectory ( const std::string &  subdir = "") const
inline

Definition at line 52 of file TFileService.h.

References TFileDirectory::getBareDirectory(), and tFileDirectory_.

Referenced by FFTJetImageRecorder::analyze().

52  {
53  return tFileDirectory_.getBareDirectory(subdir);
54  }
TDirectory * getBareDirectory(const std::string &subdir="") const
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
template<typename T >
T* TFileService::getObject ( const std::string &  objname,
const std::string &  subdir = "" 
)
inline

Definition at line 57 of file TFileService.h.

References TFileDirectory::getObject(), and tFileDirectory_.

58  {
59  return tFileDirectory_.getObject<T>(objname, subdir);
60  }
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
T * getObject(const std::string &objname, const std::string &subdir="")
long double T
template<typename T , typename... Args>
T* TFileService::make ( const Args &...  args) const
inline

make new ROOT object

Definition at line 64 of file TFileService.h.

References TFileDirectory::make(), and tFileDirectory_.

Referenced by PatZjetsElectronAnalyzer::beginJob(), PatZjetsJetAnalyzer::beginJob(), PatTriggerTagAndProbe::beginJob(), PatBJetTagAnalyzer::beginJob(), PatMCMatching::beginJob(), PatMCMatchingExtended::beginJob(), myRawAna::beginJob(), PatTopSelectionAnalyzer::beginJob(), PatBasicAnalyzer::beginJob(), PatVertexAnalyzer::beginJob(), FFTJetImageRecorder::beginJob(), IsolatedParticlesGeneratedJets::BookHistograms(), CMSDAS11DijetTestAnalyzer::CMSDAS11DijetTestAnalyzer(), CSCOverlapsBeamSplashCut::CSCOverlapsBeamSplashCut(), DuplicateRecHits::DuplicateRecHits(), HcalTB02Histo::HcalTB02Histo(), HcalTB04Histo::HcalTB04Histo(), HcalTB06Histo::HcalTB06Histo(), HcalTestHistoManager::HcalTestHistoManager(), HLTCSCOverlapFilter::HLTCSCOverlapFilter(), L1EventTreeProducer::L1EventTreeProducer(), L1MenuTreeProducer::L1MenuTreeProducer(), L1RCTRelValAnalyzer::L1RCTRelValAnalyzer(), L1RecoTreeProducer::L1RecoTreeProducer(), L1uGTTreeProducer::L1uGTTreeProducer(), L1UpgradeTreeProducer::L1UpgradeTreeProducer(), OverlapProblemTSOSAnalyzer::OverlapProblemTSOSAnalyzer(), PatJetAnalyzer::PatJetAnalyzer(), PDFWeightsTest::PDFWeightsTest(), CSCAlignmentCorrections::plot(), VariableNTupler::registerleaves(), TopElecAnalyzer::TopElecAnalyzer(), TopGenEventAnalyzer::TopGenEventAnalyzer(), TopJetAnalyzer::TopJetAnalyzer(), TopMuonAnalyzer::TopMuonAnalyzer(), TopTauAnalyzer::TopTauAnalyzer(), TrackCategoriesAnalyzer::TrackCategoriesAnalyzer(), TrackingParticleCategoriesAnalyzer::TrackingParticleCategoriesAnalyzer(), TreeWriterForEcalCorrection::TreeWriterForEcalCorrection(), ZMassHistogrammer::ZMassHistogrammer(), and ZMuMuSaMassHistogram::ZMuMuSaMassHistogram().

64  {
65  return tFileDirectory_.make<T>(args ...);
66  }
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
T * make(const Args &...args) const
make new ROOT object
long double T
TFileDirectory TFileService::mkdir ( const std::string &  dir,
const std::string &  descr = "" 
)
inline

create a new subdirectory

Definition at line 69 of file TFileService.h.

References TFileDirectory::mkdir(), and tFileDirectory_.

Referenced by AlignmentMonitorBase::AlignmentMonitorBase(), BjetAnalysis::BjetAnalysis(), DigiVtxPosCorrHistogramMaker::book(), DigiVertexCorrHistogramMaker::book(), TrackCategoriesAnalyzer::TrackCategoriesAnalyzer(), TrackingParticleCategoriesAnalyzer::TrackingParticleCategoriesAnalyzer(), and TSOSHistogramMaker::TSOSHistogramMaker().

69  {
70  return tFileDirectory_.mkdir(dir, descr);
71  }
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
dbl *** dir
Definition: mlp_gen.cc:35
void TFileService::postModuleEvent ( edm::StreamContext const &  ,
edm::ModuleCallingContext const &  mcc 
)
private

Definition at line 67 of file TFileService.cc.

References edm::ModuleCallingContext::moduleDescription(), edm::ModuleCallingContext::previousModuleOnThread(), and setDirectoryName().

Referenced by TFileService().

67  {
68  edm::ModuleCallingContext const* previous_mcc = mcc.previousModuleOnThread();
69  if(previous_mcc) {
70  setDirectoryName(*previous_mcc->moduleDescription());
71  }
72 }
void setDirectoryName(const edm::ModuleDescription &desc)
Definition: TFileService.cc:57
ModuleDescription const * moduleDescription() const
ModuleCallingContext const * previousModuleOnThread() const
void TFileService::postModuleGlobal ( edm::GlobalContext const &  ,
edm::ModuleCallingContext const &  mcc 
)
private

Definition at line 80 of file TFileService.cc.

References edm::ModuleCallingContext::moduleDescription(), edm::ModuleCallingContext::previousModuleOnThread(), and setDirectoryName().

Referenced by TFileService().

80  {
81  edm::ModuleCallingContext const* previous_mcc = mcc.previousModuleOnThread();
82  if(previous_mcc) {
83  setDirectoryName(*previous_mcc->moduleDescription());
84  }
85 }
void setDirectoryName(const edm::ModuleDescription &desc)
Definition: TFileService.cc:57
ModuleDescription const * moduleDescription() const
ModuleCallingContext const * previousModuleOnThread() const
void TFileService::preModuleEvent ( edm::StreamContext const &  ,
edm::ModuleCallingContext const &  mcc 
)
private

Definition at line 63 of file TFileService.cc.

References edm::ModuleCallingContext::moduleDescription(), and setDirectoryName().

Referenced by TFileService().

63  {
64  setDirectoryName(*mcc.moduleDescription());
65 }
void setDirectoryName(const edm::ModuleDescription &desc)
Definition: TFileService.cc:57
void TFileService::preModuleGlobal ( edm::GlobalContext const &  ,
edm::ModuleCallingContext const &  mcc 
)
private

Definition at line 75 of file TFileService.cc.

References edm::ModuleCallingContext::moduleDescription(), and setDirectoryName().

Referenced by TFileService().

75  {
76  setDirectoryName(*mcc.moduleDescription());
77 }
void setDirectoryName(const edm::ModuleDescription &desc)
Definition: TFileService.cc:57
void TFileService::setDirectoryName ( const edm::ModuleDescription desc)
private

Definition at line 57 of file TFileService.cc.

References TFileDirectory::descr_, TFileDirectory::dir_, file_, TFileDirectory::file_, edm::ModuleDescription::moduleLabel(), edm::ModuleDescription::moduleName(), and tFileDirectory_.

Referenced by postModuleEvent(), postModuleGlobal(), preModuleEvent(), preModuleGlobal(), and TFileService().

57  {
60  tFileDirectory_.descr_ = (tFileDirectory_.dir_ + " (" + desc.moduleName() + ") folder").c_str();
61 }
std::string const & moduleName() const
TFile * file_
pointer to opened TFile
Definition: TFileService.h:81
std::string const & moduleLabel() const
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
std::string dir_
std::string descr_
TFileDirectory& TFileService::tFileDirectory ( )
inline

Definition at line 42 of file TFileService.h.

References tFileDirectory_.

Referenced by edm::AnalyzerWrapper< T >::AnalyzerWrapper(), RunHistogramManager::beginRun(), and HistoAnalyzer< C >::HistoAnalyzer().

42 { return tFileDirectory_; }
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79

Member Data Documentation

bool TFileService::closeFileFast_
private

Definition at line 84 of file TFileService.h.

Referenced by ~TFileService().

TFile* TFileService::file_
private

pointer to opened TFile

Definition at line 81 of file TFileService.h.

Referenced by file(), setDirectoryName(), TFileService(), and ~TFileService().

std::string TFileService::fileName_
private

Definition at line 82 of file TFileService.h.

Referenced by afterBeginJob(), and TFileService().

bool TFileService::fileNameRecorded_
private

Definition at line 83 of file TFileService.h.

Referenced by afterBeginJob().

const std::string TFileService::kSharedResource = "TFileService"
static

Definition at line 76 of file TFileService.h.

thread_local TFileDirectory TFileService::tFileDirectory_
staticprivate