Skip to content
Snippets Groups Projects
Commit 107914a2 authored by Jon Burr's avatar Jon Burr
Browse files

Change TreeMakerAlg to make the tree in initialize

parent 0b4e418f
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,7 @@
#define ASGANALYSISALGORITHMS_TREEMAKERALG_H
#include <AnaAlgorithm/AnaAlgorithm.h>
class TTree;
#include "AsgTools/PropertyWrapper.h"
namespace CP {
......@@ -29,35 +28,27 @@ namespace CP {
public:
/// Algorithm constructor
TreeMakerAlg( const std::string& name, ISvcLocator* svcLoc );
using EL::AnaAlgorithm::AnaAlgorithm;
/// @name Functions inherited from @c EL::AnaAlgorithm
/// @{
virtual StatusCode initialize() override;
/// Function executed once per event
StatusCode execute() override;
StatusCode execute() override { return StatusCode::SUCCESS; }
/// @}
private:
/// Function setting up the internal data structures on the first event
StatusCode setupTree();
/// @name Algorithm properties
/// @{
/// The name of the output tree to write
std::string m_treeName;
/// Flust setting for the output tree
int m_treeAutoFlush;
/// @}
/// @name Helper variables
/// @{
/// Configured tree status
bool m_treeConfigured{false};
Gaudi::Property<std::string> m_treeName{
this, "TreeName", "physics", "Name of the tree to write"};
/// Flush setting for the output tree
Gaudi::Property<int> m_treeAutoFlush{
this, "TreeAutoFlush", 200, "AutoFlush value for the output tree"};
/// @}
......
......@@ -8,37 +8,16 @@
namespace CP {
TreeMakerAlg::TreeMakerAlg( const std::string& name,
ISvcLocator* svcLoc )
: EL::AnaAlgorithm( name, svcLoc ) {
// Declare the algorithm's properties.
declareProperty( "TreeName", m_treeName = "physics",
"Name of the tree to write" );
declareProperty( "TreeAutoFlush", m_treeAutoFlush = 200,
"AutoFlush value for the output tree" );
}
StatusCode TreeMakerAlg::execute() {
if( m_treeConfigured ) {
return StatusCode::SUCCESS;
}
// Create the output tree.
ATH_CHECK( book( TTree( m_treeName.c_str(), "xAOD->NTuple tree" ) ) );
TTree *mytree { tree( m_treeName ) };
if( ! mytree ) {
ATH_MSG_ERROR( "Could not create output tree \"" << m_treeName
<< "\"" );
return StatusCode::FAILURE;
}
mytree->SetAutoFlush( m_treeAutoFlush );
ATH_MSG_INFO( "Created xAOD->NTuple tree: " << m_treeName );
m_treeConfigured = true;
// Return gracefully.
return StatusCode::SUCCESS;
StatusCode TreeMakerAlg::initialize() {
ANA_CHECK(book(TTree(m_treeName.value().c_str(), "xAOD->NTuple tree")));
TTree *treePtr = tree(m_treeName);
if (!treePtr)
{
ANA_MSG_ERROR("Failed to create output tree \"" << m_treeName.value() << "\"");
return StatusCode::FAILURE;
}
treePtr->SetAutoFlush(m_treeAutoFlush);
return StatusCode::SUCCESS;
}
} // namespace CP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment