CMS 3D CMS Logo

TFileService.h
Go to the documentation of this file.
1 #ifndef UtilAlgos_TFileService_h
2 #define UtilAlgos_TFileService_h
3 /* \class TFileService
4  *
5  * \author Luca Lista, INFN
6  *
7  * Modified to run properly in the multithreaded Framework.
8  * Any modules that use this service in multithreaded mode
9  * must be type "One" modules that declared a shared resource
10  * of type TFileService::kSharedResource.
11  *
12  */
13 
15 
16 #include <string>
17 
18 class TDirectory;
19 class TFile;
20 
21 namespace edm {
22  class ActivityRegistry;
23  class GlobalContext;
24  class ModuleCallingContext;
25  class ModuleDescription;
26  class ParameterSet;
27  class StreamContext;
28 }
29 
30 class TFileService {
31 public:
35  ~TFileService();
37  TFile & file() const { return * file_; }
38 
40  void afterBeginJob();
41 
42  TFileDirectory & tFileDirectory() { return tFileDirectory_; }
43 
44  // The next 6 functions do nothing more than forward function calls
45  // to the TFileDirectory data member.
46 
47  // cd()s to requested directory and returns true (if it is not
48  // able to cd, it throws exception).
49  bool cd() const { return tFileDirectory_.cd(); }
50 
51  // returns a TDirectory pointer
52  TDirectory *getBareDirectory (const std::string &subdir = "") const {
53  return tFileDirectory_.getBareDirectory(subdir);
54  }
55 
56  // reutrns a "T" pointer matched to objname
57  template< typename T > T* getObject (const std::string &objname,
58  const std::string &subdir = "") {
59  return tFileDirectory_.getObject<T>(objname, subdir);
60  }
61 
63  template<typename T, typename ... Args>
64  T* make(const Args& ... args) const {
65  return tFileDirectory_.make<T>(args ...);
66  }
67 
69  TFileDirectory mkdir( const std::string & dir, const std::string & descr = "" ) {
70  return tFileDirectory_.mkdir(dir, descr);
71  }
72 
74  std::string fullPath() const { return tFileDirectory_.fullPath(); }
75 
77 
78 private:
79  static thread_local TFileDirectory tFileDirectory_;
81  TFile * file_;
85 
86  // set current directory according to module name and prepair to create directory
87  void setDirectoryName( const edm::ModuleDescription & desc );
88  void preModuleEvent(edm::StreamContext const&, edm::ModuleCallingContext const&);
89  void postModuleEvent(edm::StreamContext const&, edm::ModuleCallingContext const&);
90  void preModuleGlobal(edm::GlobalContext const&, edm::ModuleCallingContext const&);
91  void postModuleGlobal(edm::GlobalContext const&, edm::ModuleCallingContext const&);
92 };
93 
94 namespace edm {
95  namespace service {
96  // This function is needed so that there will be only one instance
97  // of this service per process when "subprocesses" are being used.
98  inline
100  return true;
101  }
102  }
103 }
104 #endif
static const std::string kSharedResource
Definition: TFileService.h:76
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
TFile * file_
pointer to opened TFile
Definition: TFileService.h:81
std::string fullPath() const
return the full path of the stored histograms
Definition: TFileService.h:74
static thread_local TFileDirectory tFileDirectory_
Definition: TFileService.h:79
std::string fileName_
Definition: TFileService.h:82
TFileDirectory & tFileDirectory()
Definition: TFileService.h:42
bool cd() const
Definition: TFileService.h:49
TDirectory * getBareDirectory(const std::string &subdir="") const
Definition: TFileService.h:52
TFile & file() const
return opened TFile
Definition: TFileService.h:37
bool isProcessWideService(ZombieKillerService const *)
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
T * getObject(const std::string &objname, const std::string &subdir="")
Definition: TFileService.h:57
bool fileNameRecorded_
Definition: TFileService.h:83
HLT enums.
bool closeFileFast_
Definition: TFileService.h:84
dbl *** dir
Definition: mlp_gen.cc:35
long double T