ATLAS Offline Software
ParticleSortingAlg.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // ParticleSortingAlg.cxx
8 // Implementation file for class ParticleSortingAlg
9 // Author: Karsten Koeneke <karsten.koeneke@cern.ch>
11 
12 // EventUtils includes
13 #include "ParticleSortingAlg.h"
14 
15 // FrameWork includes
16 #include "Gaudi/Property.h"
18 
20 // Public methods:
22 
23 // Constructors
26  ISvcLocator* pSvcLocator ) :
27  ::AthAlgorithm( name, pSvcLocator ),
28  m_jos("JobOptionsSvc", name),
29  m_tool("ParticleSortingTool/ParticleSortingTool", this),
30  m_inCollKey(""),
31  m_setInCollKey(false),
32  m_outCollKey(""),
33  m_setOutCollKey(false),
34  m_sortVar("pt"),
35  m_setSortVar(false),
36  m_sortDescending(true),
37  m_setSortDescending(false),
38  m_nEventsProcessed(0)
39 {
40  declareProperty("JobOptionsSvc", m_jos, "The JobOptionService instance.");
41 
42  declareProperty("SortingTool", m_tool, "The private ParticleSortingTool" );
43 
44  declareProperty("InputContainer", m_inCollKey="", "Input container name" );
45  m_inCollKey.declareUpdateHandler( &ParticleSortingAlg::setupInputContainer, this );
46 
47  declareProperty("OutputContainer", m_outCollKey="",
48  "The name of the output container (with SG::VIEW_ELEMENTS) with the sorted copy of input objects" );
49  m_outCollKey.declareUpdateHandler( &ParticleSortingAlg::setupOutputContainer, this );
50 
51  declareProperty("SortVariable", m_sortVar="pt",
52  "Define by what parameter to sort (default: 'pt'; allowed: 'pt', 'eta', 'phi', 'm', 'e', 'rapidity')" );
53  m_sortVar.declareUpdateHandler( &ParticleSortingAlg::setupSortVar, this );
54 
55  declareProperty("SortDescending", m_sortDescending=true,
56  "Define if the container should be sorted in a descending order (default=true)" );
57  m_sortDescending.declareUpdateHandler( &ParticleSortingAlg::setupSortDescending, this );
58 }
59 
60 
61 
62 // Destructor
65 {}
66 
67 
68 
69 // Athena Algorithm's Hooks
72 {
73  ATH_MSG_DEBUG ("Initializing " << name() << "...");
74 
75  // Print out the used configuration
76  ATH_MSG_DEBUG ( " using = " << m_jos );
77  ATH_MSG_DEBUG ( " using = " << m_tool );
78  ATH_MSG_DEBUG ( " using = " << m_inCollKey );
79  ATH_MSG_DEBUG ( " using = " << m_outCollKey );
80  ATH_MSG_DEBUG ( " using = " << m_sortVar );
81  ATH_MSG_DEBUG ( " using = " << m_sortDescending );
82 
83 
84  // Initialize the counters to zero
85  m_nEventsProcessed = 0 ;
86 
87 
88  // Get the JobOptionService
89  // We will use this to set the properties of our private skimming tool
90  // from the properties of this algorithm.
91  ATH_MSG_VERBOSE( "Getting the JobOptionService");
92  ATH_CHECK( m_jos.retrieve() );
93 
94  // Get the full name of the private skimTool
95  ATH_MSG_VERBOSE( "Getting the full name of the tool");
96  const std::string& fullToolName = this->name() + "." + m_tool.name();
97  ATH_MSG_DEBUG( "Got the full name of the tool: " << fullToolName );
98 
99  // Now, set all properties of the private skimTool that were acutally configured
100  if (m_setInCollKey) {
101  ATH_MSG_DEBUG( "Setting property" << m_inCollKey
102  << " of private tool with name: '" << fullToolName << "'" );
103  m_jos->set (fullToolName + "." + m_inCollKey.name(), m_inCollKey.toString());
104  }
105  if (m_setOutCollKey) {
106  ATH_MSG_DEBUG( "Setting property" << m_outCollKey
107  << " of private tool with name: '" << fullToolName << "'" );
108  m_jos->set (fullToolName + "." + m_outCollKey.name(), m_outCollKey.toString());
109  }
110  if (m_setSortVar) {
111  ATH_MSG_DEBUG( "Setting property" << m_sortVar
112  << " of private tool with name: '" << fullToolName << "'" );
113  m_jos->set (fullToolName + "." + m_sortVar.name(), m_sortVar.toString());
114  }
115  if (m_setSortDescending) {
116  ATH_MSG_DEBUG( "Setting property" << m_sortDescending
117  << " of private tool with name: '" << fullToolName << "'" );
118  m_jos->set (fullToolName + "." + m_sortDescending.name(), m_sortDescending.toString());
119  }
120  ATH_MSG_DEBUG( "Done setting properties of the tool");
121 
122  // Get the skimming tool
123  ATH_CHECK( m_tool.retrieve() );
124 
125  ATH_MSG_DEBUG ( "==> done with initialize " << name() << "..." );
126 
127  return StatusCode::SUCCESS;
128 }
129 
130 
131 
133 {
134  ATH_MSG_DEBUG ("Finalizing " << name() << "...");
135 
136  // Release all tools and services
137  ATH_CHECK( m_jos.release() );
138  ATH_CHECK( m_tool.release() );
139 
140  return StatusCode::SUCCESS;
141 }
142 
143 
144 
146 {
147  // Increase the event counter
149 
150  // Simple status message at the beginning of each event execute,
151  ATH_MSG_DEBUG ( "==> execute " << name() << " on " << m_nEventsProcessed << ". event..." );
152 
153  // Call the tool
154  ATH_CHECK( m_tool->addBranches() );
155 
156  return StatusCode::SUCCESS;
157 }
ParticleSortingAlg::setupSortVar
void setupSortVar(Gaudi::Details::PropertyBase &)
This internal method will realize if a user sets the 'SortVariable' property.
Definition: ParticleSortingAlg.h:135
ParticleSortingAlg::m_inCollKey
StringProperty m_inCollKey
Input container name.
Definition: ParticleSortingAlg.h:84
ParticleSortingAlg::ParticleSortingAlg
ParticleSortingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: ParticleSortingAlg.cxx:25
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
IAugmentationTool.h
ParticleSortingAlg::initialize
virtual StatusCode initialize() override
Athena algorithm's initalize hook.
Definition: ParticleSortingAlg.cxx:71
ParticleSortingAlg::m_outCollKey
StringProperty m_outCollKey
The name of the output container (with SG::VIEW_ELEMENTS) with the sorted copy of input objects.
Definition: ParticleSortingAlg.h:91
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ParticleSortingAlg::execute
virtual StatusCode execute() override
Athena algorithm's execute hook.
Definition: ParticleSortingAlg.cxx:145
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ParticleSortingAlg::m_setSortVar
bool m_setSortVar
This boolean is true if the user sets the 'SortVariable' property.
Definition: ParticleSortingAlg.h:101
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ParticleSortingAlg::m_jos
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jos
The job options service (will be used to forward this algs properties to the private tool)
Definition: ParticleSortingAlg.h:78
ParticleSortingAlg::m_sortDescending
BooleanProperty m_sortDescending
Define if the container should be sorted in a descending order (default=true)
Definition: ParticleSortingAlg.h:105
ParticleSortingAlg::m_setOutCollKey
bool m_setOutCollKey
This boolean is true if the user sets the 'OutputContainer' property.
Definition: ParticleSortingAlg.h:94
ParticleSortingAlg::m_nEventsProcessed
unsigned long m_nEventsProcessed
Internal event counter.
Definition: ParticleSortingAlg.h:112
ParticleSortingAlg::m_sortVar
StringProperty m_sortVar
Define by what parameter to sort (default: 'pt')
Definition: ParticleSortingAlg.h:98
AthAlgorithm
Definition: AthAlgorithm.h:47
ParticleSortingAlg::setupSortDescending
void setupSortDescending(Gaudi::Details::PropertyBase &)
This internal method will realize if a user sets the 'SortDeceding' property.
Definition: ParticleSortingAlg.h:142
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ParticleSortingAlg::m_setInCollKey
bool m_setInCollKey
This boolean is true if the user sets the 'InputContainer' property.
Definition: ParticleSortingAlg.h:87
ParticleSortingAlg.h
ParticleSortingAlg::setupInputContainer
void setupInputContainer(Gaudi::Details::PropertyBase &)
This internal method will realize if a user sets the 'InputContainer' property.
Definition: ParticleSortingAlg.h:123
ParticleSortingAlg::m_tool
ToolHandle< DerivationFramework::IAugmentationTool > m_tool
The ToolHandle to the private ParticleSortingTool.
Definition: ParticleSortingAlg.h:81
ParticleSortingAlg::m_setSortDescending
bool m_setSortDescending
This boolean is true if the user sets the 'SortDescending' property.
Definition: ParticleSortingAlg.h:108
ParticleSortingAlg::setupOutputContainer
void setupOutputContainer(Gaudi::Details::PropertyBase &)
This internal method will realize if a user sets the 'OutputContainer' property.
Definition: ParticleSortingAlg.h:129
ParticleSortingAlg::finalize
virtual StatusCode finalize() override
Athena algorithm's finalize hook.
Definition: ParticleSortingAlg.cxx:132
ParticleSortingAlg::~ParticleSortingAlg
virtual ~ParticleSortingAlg()
Destructor:
Definition: ParticleSortingAlg.cxx:64