ATLAS Offline Software
CommonAugmentation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 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 tool service
49  IToolSvc* toolSvc;
50  StatusCode sc = service("ToolSvc",toolSvc);
51  if (StatusCode::SUCCESS != sc) {
52  ATH_MSG_FATAL("Unable to retrieve ToolSvc");
53  return StatusCode::FAILURE;
54  }
55 
56  // get the augmentation tools
57  if( m_augmentationTools.retrieve().isFailure() ) {
58  ATH_MSG_FATAL("Failed to retrieve augmentation tools");
59  return StatusCode::FAILURE;
60  } else {
61  ATH_MSG_INFO("The following augmentation tools will be applied....");
62  ATH_MSG_INFO(m_augmentationTools);
63  }
64 
65  // get the chrono auditor
66  if ( m_chronoSvc.retrieve().isFailure() ) {
67  ATH_MSG_FATAL("Failed to retrieve service " << m_chronoSvc);
68  return StatusCode::FAILURE;
69  }
70 
71  // Set accumulation variables to zero
72  //m_eventCount = 0;
73  //m_eventWeights = 0.0;
74 
75  return StatusCode::SUCCESS;
76 
77 }
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
80 
82 
83  // On your marks.... get set....
84  Chrono chrono( &(*m_chronoSvc), name() );
85  // GO!!
86 
87  //=============================================================================
88  // AUGMENTATION ===============================================================
89  //=============================================================================
90 
91  ToolHandleArray<IAugmentationTool>::iterator augmentationTool(m_augmentationTools.begin());
92  ToolHandleArray<IAugmentationTool>::iterator endOfAugmentationTools(m_augmentationTools.end());
93  while (augmentationTool != endOfAugmentationTools) {
94  if ( (**augmentationTool).addBranches().isFailure() ) {
95  ATH_MSG_ERROR("Augmentation failed!");
96  return StatusCode::FAILURE;
97  }
98  ++augmentationTool;
99  }
100 
101  //++m_eventCount;
102  //float* weight;
103  //if (evtStore()->contains<float>("mc_event_weight")) {
104  // CHECK(evtStore()->retrieve((const float*&)weight,"mc_event_weight"));
105  // m_eventWeights += *weight;
106  //}
107  return StatusCode::SUCCESS;
108 
109 }
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
112 //
113 //StatusCode DerivationFramework::CommonAugmentation::stop() {
114 //
115 // TTree* tree = new TTree("DerivationTree","Extra metadata from derivation framework");
116 // tree->Branch("totalEventsProcessed",&m_eventCount,"totalEventsProcessed/I");
117 // tree->Branch("summedEventWeights",&m_eventWeights,"summedEventWeights/F");
118 // tree->Fill();
119 // TransferTree* temp = new TransferTree(tree);
120 // if (m_ometaStore->record(temp,"ExtraMetadata").isFailure()) ATH_MSG_ERROR("Unable to record metadata tree " << tree->GetName());
121 // std::cout << "Just filled " << tree->GetName() << " with " << m_eventCount << " and " << m_eventWeights << std::endl;
122 // tree->Print();
123 // return StatusCode::SUCCESS;
124 //
125 //}
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
128 
130 
131  ATH_MSG_INFO( "============================================================================");
132  ATH_MSG_INFO( " The following CP tools were called by " << name() << " for the whole train:");
133  ToolHandleArray<IAugmentationTool>::iterator augmentationTool(m_augmentationTools.begin());
134  ToolHandleArray<IAugmentationTool>::iterator endOfAugmentationTools(m_augmentationTools.end());
135  while (augmentationTool != endOfAugmentationTools) {
136  ATH_MSG_INFO ( (**augmentationTool).name() );
137  ++augmentationTool;
138  }
139  ATH_MSG_INFO( "============================================================================");
140 
141  return StatusCode::SUCCESS;
142 
143 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
DerivationFramework::CommonAugmentation::finalize
StatusCode finalize()
Definition: CommonAugmentation.cxx:129
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
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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:195
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
DerivationFramework::CommonAugmentation::execute
StatusCode execute()
Definition: CommonAugmentation.cxx:81
DefaultKey.h
DerivationFramework::CommonAugmentation::initialize
StatusCode initialize()
Definition: CommonAugmentation.cxx:44