ATLAS Offline Software
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
D3PD::RootD3PDSvc Class Reference

Service to create a root-based D3PD. More...

#include <RootD3PDSvc.h>

Inheritance diagram for D3PD::RootD3PDSvc:
Collaboration diagram for D3PD::RootD3PDSvc:

Public Member Functions

 RootD3PDSvc (const std::string &name, ISvcLocator *svcloc)
 Constructor. More...
 
virtual StatusCode initialize () override
 Standard Gaudi initialize method. More...
 
virtual StatusCode finalize () override
 Standard Gaudi finalize method. More...
 
virtual StatusCode stop () override
 Standard Gaudi stop method. More...
 
virtual StatusCode make (const std::string &name, ID3PD *&d3pd) override
 Create a new D3PD tree. More...
 

Private Member Functions

 RootD3PDSvc (const RootD3PDSvc &)
 
RootD3PDSvcoperator= (const RootD3PDSvc &)
 

Static Private Member Functions

static void cleanup ()
 Make sure all files are closed before exiting, to prevent crashes. More...
 

Private Attributes

bool m_doBranchRef
 Property: If true, then add BranchRef info to the tuple. More...
 
std::string m_masterTree
 Property: Name of the master tree. More...
 
std::string m_indexMajor
 Property: Major variable name for index making, or null. More...
 
std::string m_indexMinor
 Property: Minor variable name for index making, or null. More...
 
int m_basketSize
 Property: Basket buffer size, or -1 to use the Root default. More...
 
int m_entryOffsetLen
 Property: Basket entry offset buffer size, or -1 to use the Root default. More...
 
long long m_autoFlush
 Property: Value to set for ROOT's AutoFlush parameter. More...
 
std::vector< std::string > m_allowedNames
 Property: Allowed names for the created D3PD. More...
 
std::vector< std::string > m_vetoedNames
 Property: Vetoed names for the created D3PD. More...
 
ServiceHandle< ITHistSvc > m_histSvc
 Property: Gaudi THistSvc. More...
 
std::vector< std::unique_ptr< RootD3PD > > m_d3pds
 Remember all the tuples we've made. More...
 

Detailed Description

Service to create a root-based D3PD.

Definition at line 37 of file RootD3PDSvc.h.

Constructor & Destructor Documentation

◆ RootD3PDSvc() [1/2]

D3PD::RootD3PDSvc::RootD3PDSvc ( const std::string &  name,
ISvcLocator *  svcloc 
)

Constructor.

Parameters
nameService name.
svclocService locator.

Definition at line 32 of file RootD3PDSvc.cxx.

34  : base_class (name, svcloc),
35  m_histSvc ("THistSvc", name)
36 {
37  // See comments on cleanup().
38  std::atexit (cleanup);
39 
40  declareProperty ("HistSvc", m_histSvc);
41  declareProperty ("DoBranchRef", m_doBranchRef = true);
42  declareProperty ("MasterTree", m_masterTree = "CollectionTree");
43  declareProperty ("IndexMajor", m_indexMajor = "RunNumber");
44  declareProperty ("IndexMinor", m_indexMinor = "EventNumber");
45  declareProperty ("BasketSize", m_basketSize = 32768);
46  declareProperty ("EntryOffsetLen", m_entryOffsetLen = 512);
47  declareProperty ("AutoFlush", m_autoFlush = -1,
48  "Value to set for ROOT's AutoFlush parameter. "
49  "(Tells how often the tree baskets will be flushed.) "
50  "0 disables flushing. "
51  "-1 (default) makes no changes to what THistSvc did. "
52  "Any other negative number gives the number of bytes "
53  "after which to flush. "
54  "A positive number gives the number of entries after which "
55  "to flush.");
56  declareProperty ("AllowedNames", m_allowedNames,
57  "Variable names allowed in the output D3PDs. An empty list "
58  "means that all variable names are allowed. Regular expressions "
59  "are allowed.");
60  declareProperty ("VetoedNames", m_vetoedNames,
61  "Variable names that are not allowed to end up in the "
62  "created D3PDs. Regular expressions are allowed.");
63 }

◆ RootD3PDSvc() [2/2]

D3PD::RootD3PDSvc::RootD3PDSvc ( const RootD3PDSvc )
private

Member Function Documentation

◆ cleanup()

void D3PD::RootD3PDSvc::cleanup ( )
staticprivate

Make sure all files are closed before exiting, to prevent crashes.

Root files are normally closed by THistSvc::finalize().

However, if we get an error during initialization, then the program will exit without running the finalize() methods. In that case, the root files will get closed when global destructors are run. But by that time, some of the root objects needed to perform the close may have already been deleted, leading to a crash.

To avoid this, we register this method with atexit(); we just loop through all existing root files and try to close them all.

Definition at line 80 of file RootD3PDSvc.cxx.

81 {
82  // Sometimes gDirectory is invalid at this point...
83  gDirectory = gROOT;
84  TIter it (gROOT->GetListOfFiles());
85  while (TObject* o = it.Next()) {
86  if (TFile* f = dynamic_cast<TFile*> (o))
87  f->Close();
88  }
89 }

◆ finalize()

StatusCode D3PD::RootD3PDSvc::finalize ( )
overridevirtual

Standard Gaudi finalize method.

Definition at line 106 of file RootD3PDSvc.cxx.

107 {
108  return StatusCode::SUCCESS;
109 }

◆ initialize()

StatusCode D3PD::RootD3PDSvc::initialize ( )
overridevirtual

Standard Gaudi initialize method.

Definition at line 95 of file RootD3PDSvc.cxx.

96 {
98  CHECK( m_histSvc.retrieve() );
99  return StatusCode::SUCCESS;
100 }

◆ make()

StatusCode D3PD::RootD3PDSvc::make ( const std::string &  name,
ID3PD *&  d3pd 
)
overridevirtual

Create a new D3PD tree.

Parameters
nameThe name of the new tree. If the name contains a slash, it is interpreted as STREAM/NAME. If the stream name contains a colon, then the part of the name before the colon is the ‘parent’ stream name; this is used to locate the master tree.
d3pd[out]The created tree.
nameThe name of the new tree. If the name contains a slash, it is interpreted as STREAM/NAME. If the stream name is of the form ‘pool:FILE’, then this is a request to put the new tree in the given pool file. If the the stream name otherwise contains a colon, then the part of the name before the colon is the ‘parent’ stream name; this is used to locate the master tree.
d3pd[out]The created tree.

Definition at line 175 of file RootD3PDSvc.cxx.

176 {
177  std::string tname = name;
178  std::string::size_type ipos = name.rfind ('/');
179  std::string master = m_masterTree;
180  std::string poolfile;
181  if (ipos != std::string::npos) {
182  tname = name.substr (ipos+1);
183  if (!master.empty()) {
184  std::string sname = name.substr (0, ipos+1);
185  std::string::size_type jpos = sname.find (':');
186  if (sname.substr (0, jpos) == "pool" ||
187  sname.substr (0, jpos) == "/pool")
188  {
189  poolfile = sname.substr (jpos+1, std::string::npos);
190  if (!poolfile.empty() && poolfile[poolfile.size()-1] == '/')
191  poolfile.erase (poolfile.size()-1);
192  }
193  else {
194  if (jpos != std::string::npos){
195  sname.erase(jpos,sname.size()-jpos-1);
196  }
197  master = sname + master;
198  }
199  }
200  }
201  TTree* tree = new TTree (tname.c_str(), tname.c_str());
202 
203  if (m_doBranchRef)
204  tree->BranchRef();
205  if (m_autoFlush != -1)
206  tree->SetAutoFlush (m_autoFlush);
207  auto rd3pd = std::make_unique<RootD3PD>
208  (tree, master,
211 
212  if (!poolfile.empty())
213  rd3pd->setPoolFile (poolfile);
214  else
215  CHECK( m_histSvc->regTree (name, tree) );
216 
217  d3pd = rd3pd.get();
218  m_d3pds.push_back (std::move (rd3pd));
219  return StatusCode::SUCCESS;
220 }

◆ operator=()

RootD3PDSvc& D3PD::RootD3PDSvc::operator= ( const RootD3PDSvc )
private

◆ stop()

StatusCode D3PD::RootD3PDSvc::stop ( )
overridevirtual

Standard Gaudi stop method.

Definition at line 115 of file RootD3PDSvc.cxx.

116 {
117  // Run through all the trees we've made.
118  for (size_t i = 0; i < m_d3pds.size(); i++) {
119  RootD3PD* d3pd = m_d3pds[i].get();
120 
121  // Make an index if requested.
122  if (!m_indexMajor.empty())
123  d3pd->tree()->BuildIndex (m_indexMajor.c_str(), m_indexMinor.c_str());
124 
125  // Was there a master tree specified?
126  if (!d3pd->master().empty()) {
127  // Yes --- try to find it
128  TDirectory* dir = d3pd->tree()->GetDirectory();
129  TTree* master =
130  dynamic_cast<TTree*> (dir->Get (d3pd->master().c_str()));
131  if (!master && d3pd->tree()->GetEntries() > 0)
132  CHECK( m_histSvc->getTree (d3pd->master(), master) );
133  if (master) {
134  // Make an index for the master if needed.
135  if (!master->GetTreeIndex()) {
136  // AANTupleStream will leave branch addresses in the master
137  // tree pointing at dead objects.
138  master->ResetBranchAddresses();
139 
140  master->BuildIndex (m_indexMajor.c_str(), m_indexMinor.c_str());
141  }
142 
143  // Make this tree a friend of the master.
144  master->AddFriend (d3pd->tree());
145  }
146  }
147 
148  {
149  TDirectory::TContext ctx (gDirectory, d3pd->tree()->GetDirectory());
150  d3pd->tree()->Write();
151  }
152  }
153 
154  // Get rid of the RootD3PD wrappers.
155  // (Doesn't delete the root trees themselves.)
156  m_d3pds.clear();
157 
158  return StatusCode::SUCCESS;
159 }

Member Data Documentation

◆ m_allowedNames

std::vector< std::string > D3PD::RootD3PDSvc::m_allowedNames
private

Property: Allowed names for the created D3PD.

Definition at line 104 of file RootD3PDSvc.h.

◆ m_autoFlush

long long D3PD::RootD3PDSvc::m_autoFlush
private

Property: Value to set for ROOT's AutoFlush parameter.

(Tells how often the tree baskets will be flushed.) 0 disables flushing. -1 (default) makes no changes to what THistSvc did. Any other negative number gives the number of bytes after which to flush. A positive number gives the number of entries after which to flush.

Definition at line 101 of file RootD3PDSvc.h.

◆ m_basketSize

int D3PD::RootD3PDSvc::m_basketSize
private

Property: Basket buffer size, or -1 to use the Root default.

Definition at line 90 of file RootD3PDSvc.h.

◆ m_d3pds

std::vector<std::unique_ptr<RootD3PD> > D3PD::RootD3PDSvc::m_d3pds
private

Remember all the tuples we've made.

Definition at line 113 of file RootD3PDSvc.h.

◆ m_doBranchRef

bool D3PD::RootD3PDSvc::m_doBranchRef
private

Property: If true, then add BranchRef info to the tuple.

Definition at line 77 of file RootD3PDSvc.h.

◆ m_entryOffsetLen

int D3PD::RootD3PDSvc::m_entryOffsetLen
private

Property: Basket entry offset buffer size, or -1 to use the Root default.

Definition at line 93 of file RootD3PDSvc.h.

◆ m_histSvc

ServiceHandle<ITHistSvc> D3PD::RootD3PDSvc::m_histSvc
private

Property: Gaudi THistSvc.

Definition at line 110 of file RootD3PDSvc.h.

◆ m_indexMajor

std::string D3PD::RootD3PDSvc::m_indexMajor
private

Property: Major variable name for index making, or null.

Definition at line 85 of file RootD3PDSvc.h.

◆ m_indexMinor

std::string D3PD::RootD3PDSvc::m_indexMinor
private

Property: Minor variable name for index making, or null.

Definition at line 87 of file RootD3PDSvc.h.

◆ m_masterTree

std::string D3PD::RootD3PDSvc::m_masterTree
private

Property: Name of the master tree.

If set, then this tree will be made a friend of the master. The master tree will also get an index built.

Definition at line 82 of file RootD3PDSvc.h.

◆ m_vetoedNames

std::vector< std::string > D3PD::RootD3PDSvc::m_vetoedNames
private

Property: Vetoed names for the created D3PD.

Definition at line 107 of file RootD3PDSvc.h.


The documentation for this class was generated from the following files:
D3PD::RootD3PDSvc::m_histSvc
ServiceHandle< ITHistSvc > m_histSvc
Property: Gaudi THistSvc.
Definition: RootD3PDSvc.h:110
initialize
void initialize()
Definition: run_EoverP.cxx:894
tree
TChain * tree
Definition: tile_monitor.h:30
skel.it
it
Definition: skel.GENtoEVGEN.py:396
D3PD::RootD3PDSvc::m_vetoedNames
std::vector< std::string > m_vetoedNames
Property: Vetoed names for the created D3PD.
Definition: RootD3PDSvc.h:107
D3PD::RootD3PDSvc::m_autoFlush
long long m_autoFlush
Property: Value to set for ROOT's AutoFlush parameter.
Definition: RootD3PDSvc.h:101
master
Definition: master.py:1
D3PD::RootD3PDSvc::m_allowedNames
std::vector< std::string > m_allowedNames
Property: Allowed names for the created D3PD.
Definition: RootD3PDSvc.h:104
D3PD::RootD3PDSvc::m_d3pds
std::vector< std::unique_ptr< RootD3PD > > m_d3pds
Remember all the tuples we've made.
Definition: RootD3PDSvc.h:113
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:85
D3PD::RootD3PDSvc::m_basketSize
int m_basketSize
Property: Basket buffer size, or -1 to use the Root default.
Definition: RootD3PDSvc.h:90
D3PD::RootD3PDSvc::m_indexMinor
std::string m_indexMinor
Property: Minor variable name for index making, or null.
Definition: RootD3PDSvc.h:87
D3PD::RootD3PDSvc::m_doBranchRef
bool m_doBranchRef
Property: If true, then add BranchRef info to the tuple.
Definition: RootD3PDSvc.h:77
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
hist_file_dump.f
f
Definition: hist_file_dump.py:135
beamspotman.dir
string dir
Definition: beamspotman.py:623
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
D3PD::RootD3PDSvc::m_entryOffsetLen
int m_entryOffsetLen
Property: Basket entry offset buffer size, or -1 to use the Root default.
Definition: RootD3PDSvc.h:93
D3PD::RootD3PDSvc::m_masterTree
std::string m_masterTree
Property: Name of the master tree.
Definition: RootD3PDSvc.h:82
D3PD::RootD3PDSvc::cleanup
static void cleanup()
Make sure all files are closed before exiting, to prevent crashes.
Definition: RootD3PDSvc.cxx:80
D3PD::RootD3PDSvc::m_indexMajor
std::string m_indexMajor
Property: Major variable name for index making, or null.
Definition: RootD3PDSvc.h:85