20#include "TCollection.h"
34 : base_class (name, svcloc),
35 m_histSvc (
"THistSvc", name)
38 std::atexit (cleanup);
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 "
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 "
60 declareProperty (
"VetoedNames", m_vetoedNames,
61 "Variable names that are not allowed to end up in the "
62 "created D3PDs. Regular expressions are allowed.");
80void RootD3PDSvc::cleanup ()
84 TIter it (gROOT->GetListOfFiles());
85 while (TObject* o = it.Next()) {
86 if (TFile* f =
dynamic_cast<TFile*
> (o))
97 CHECK( AthService::initialize() );
98 CHECK( m_histSvc.retrieve() );
99 return StatusCode::SUCCESS;
108 return StatusCode::SUCCESS;
118 for (
size_t i = 0; i < m_d3pds.size(); i++) {
122 if (!m_indexMajor.empty())
123 d3pd->
tree()->BuildIndex (m_indexMajor.c_str(), m_indexMinor.c_str());
126 if (!d3pd->
master().empty()) {
128 TDirectory* dir = d3pd->
tree()->GetDirectory();
130 dynamic_cast<TTree*
> (dir->Get (d3pd->
master().c_str()));
131 if (!
master && d3pd->
tree()->GetEntries() > 0)
135 if (!
master->GetTreeIndex()) {
138 master->ResetBranchAddresses();
140 master->BuildIndex (m_indexMajor.c_str(), m_indexMinor.c_str());
149 TDirectory::TContext ctx (gDirectory, d3pd->
tree()->GetDirectory());
150 d3pd->
tree()->Write();
158 return StatusCode::SUCCESS;
175StatusCode RootD3PDSvc::make (
const std::string& name,
ID3PD* & d3pd)
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);
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")
189 poolfile = sname.substr (jpos+1, std::string::npos);
190 if (!poolfile.empty() && poolfile[poolfile.size()-1] ==
'/')
191 poolfile.erase (poolfile.size()-1);
194 if (jpos != std::string::npos){
195 sname.erase(jpos,sname.size()-jpos-1);
197 master = sname + master;
201 TTree*
tree =
new TTree (tname.c_str(), tname.c_str());
205 if (m_autoFlush != -1)
206 tree->SetAutoFlush (m_autoFlush);
207 auto rd3pd = std::make_unique<RootD3PD>
209 m_allowedNames, m_vetoedNames,
210 m_basketSize, m_entryOffsetLen);
212 if (!poolfile.empty())
213 rd3pd->setPoolFile (poolfile);
215 CHECK( m_histSvc->regTree (name,
tree) );
218 m_d3pds.push_back (std::move (rd3pd));
219 return StatusCode::SUCCESS;
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Service to create a Root-based D3PD tree.
Define an abstract interface for building a D3PD tree.
virtual StatusCode stop() override
Standard Gaudi stop method.
virtual StatusCode initialize() override
Standard Gaudi initialize method.
virtual StatusCode finalize() override
Standard Gaudi finalize method.
RootD3PDSvc(const std::string &name, ISvcLocator *svcloc)
Constructor.
const TTree * tree() const
Return the underlying root tree.
const std::string & master() const
Return the name of the master tree.
Block filler tool for noisy FEB information.