ATLAS Offline Software
CommonAugmentation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // CommonAugmentation.cxx, (c) ATLAS Detector software
8 // Author: James Catmore (James.Catmore@cern.ch)
9 // This code loops over common tools from the CP groups, which write
10 // into SG so that other derivations can make use of them without
11 // re-running the tools.
12 
14 
15 #include <sstream> // C++ utilities
16 #include <string>
17 #include <algorithm>
18 #include <fstream>
19 
20 #include "GaudiKernel/ISvcLocator.h"
22 #include "AthLinks/ElementLink.h"
23 #include "GaudiKernel/Chrono.h"
24 
25 #include "StoreGate/DataHandle.h"
27 #include "SGTools/StlVectorClids.h"
28 //#include "AthenaRootComps/TransferTree.h"
29 
31 
32 DerivationFramework::CommonAugmentation::CommonAugmentation(const std::string& name, ISvcLocator* pSvcLocator) :
33 AthAlgorithm(name, pSvcLocator),
34 m_chronoSvc("ChronoStatSvc", name)
35 {
36  // ------- Python changeable properties -------
37  declareProperty("AugmentationTools", m_augmentationTools);
38  //declareProperty("OutputMetaStore", m_ometaStore);
39  //---------------------------------------------
40 }
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
43 
45 
46  ATH_MSG_INFO("Initializing the common selections in " << name());
47 
48  // get the augmentation tools
49  if( m_augmentationTools.retrieve().isFailure() ) {
50  ATH_MSG_FATAL("Failed to retrieve augmentation tools");
51  return StatusCode::FAILURE;
52  } else {
53  ATH_MSG_INFO("The following augmentation tools will be applied....");
54  ATH_MSG_INFO(m_augmentationTools);
55  }
56 
57  // get the chrono auditor
58  if ( m_chronoSvc.retrieve().isFailure() ) {
59  ATH_MSG_FATAL("Failed to retrieve service " << m_chronoSvc);
60  return StatusCode::FAILURE;
61  }
62 
63  // Set accumulation variables to zero
64  //m_eventCount = 0;
65  //m_eventWeights = 0.0;
66 
67  return StatusCode::SUCCESS;
68 
69 }
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
72 
74 
75  // On your marks.... get set....
76  Chrono chrono( &(*m_chronoSvc), name() );
77  // GO!!
78 
79  //=============================================================================
80  // AUGMENTATION ===============================================================
81  //=============================================================================
82 
83  ToolHandleArray<IAugmentationTool>::iterator augmentationTool(m_augmentationTools.begin());
84  ToolHandleArray<IAugmentationTool>::iterator endOfAugmentationTools(m_augmentationTools.end());
85  while (augmentationTool != endOfAugmentationTools) {
86  if ( (**augmentationTool).addBranches().isFailure() ) {
87  ATH_MSG_ERROR("Augmentation failed!");
88  return StatusCode::FAILURE;
89  }
90  ++augmentationTool;
91  }
92 
93  //++m_eventCount;
94  //float* weight;
95  //if (evtStore()->contains<float>("mc_event_weight")) {
96  // CHECK(evtStore()->retrieve((const float*&)weight,"mc_event_weight"));
97  // m_eventWeights += *weight;
98  //}
99  return StatusCode::SUCCESS;
100 
101 }
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
104 //
105 //StatusCode DerivationFramework::CommonAugmentation::stop() {
106 //
107 // TTree* tree = new TTree("DerivationTree","Extra metadata from derivation framework");
108 // tree->Branch("totalEventsProcessed",&m_eventCount,"totalEventsProcessed/I");
109 // tree->Branch("summedEventWeights",&m_eventWeights,"summedEventWeights/F");
110 // tree->Fill();
111 // TransferTree* temp = new TransferTree(tree);
112 // if (m_ometaStore->record(temp,"ExtraMetadata").isFailure()) ATH_MSG_ERROR("Unable to record metadata tree " << tree->GetName());
113 // std::cout << "Just filled " << tree->GetName() << " with " << m_eventCount << " and " << m_eventWeights << std::endl;
114 // tree->Print();
115 // return StatusCode::SUCCESS;
116 //
117 //}
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
120 
122 
123  ATH_MSG_INFO( "============================================================================");
124  ATH_MSG_INFO( " The following CP tools were called by " << name() << " for the whole train:");
125  ToolHandleArray<IAugmentationTool>::iterator augmentationTool(m_augmentationTools.begin());
126  ToolHandleArray<IAugmentationTool>::iterator endOfAugmentationTools(m_augmentationTools.end());
127  while (augmentationTool != endOfAugmentationTools) {
128  ATH_MSG_INFO ( (**augmentationTool).name() );
129  ++augmentationTool;
130  }
131  ATH_MSG_INFO( "============================================================================");
132 
133  return StatusCode::SUCCESS;
134 
135 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::CommonAugmentation::finalize
StatusCode finalize()
Definition: CommonAugmentation.cxx:121
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CommonAugmentation.h
DerivationFramework::CommonAugmentation::CommonAugmentation
CommonAugmentation(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CommonAugmentation.cxx:32
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::CommonAugmentation::m_augmentationTools
ToolHandleArray< IAugmentationTool > m_augmentationTools
Definition: CommonAugmentation.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DataHandle.h
StlVectorClids.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
DerivationFramework::CommonAugmentation::execute
StatusCode execute()
Definition: CommonAugmentation.cxx:73
DefaultKey.h
DerivationFramework::CommonAugmentation::initialize
StatusCode initialize()
Definition: CommonAugmentation.cxx:44