ATLAS Offline Software
DigiDemoSetupAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "DigiDemoSetupAlg.h"
6 #include "AthViews/ViewHelper.h"
8 #include "StoreGate/ReadHandle.h"
9 
10 namespace AthViews {
11 
12 DigiDemoSetupAlg::DigiDemoSetupAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
13  AthAlgorithm( name, pSvcLocator )
14 {
15 }
16 
18 {
19 }
20 
22 {
23  ATH_MSG_DEBUG ("Initializing " << name() << "...");
24 
27  CHECK( m_scheduler.retrieve() );
28  CHECK( m_digiStore.retrieve() );
29 
30  return StatusCode::SUCCESS;
31 }
32 
34 {
35  ATH_MSG_DEBUG ("Finalizing " << name() << "...");
36 
37  return StatusCode::SUCCESS;
38 }
39 
41 {
42  ATH_MSG_DEBUG ("Executing " << name() << "...");
43 
44  const EventContext& ctx = getContext();
45 
46  //Get a pointer to the digitisation store
47  IProxyDict * digiStorePointer = dynamic_cast< IProxyDict* >( m_digiStore.get() );
48  if ( !digiStorePointer )
49  {
50  ATH_MSG_FATAL( "Unable to retrieve digitisation store" );
51  return StatusCode::FAILURE;
52  }
53 
54  //Hacky way to determine if you've already done the setup
55  SG::ReadHandle< int > firstHandle( "FirstTimeFlag" );
56  CHECK( firstHandle.setProxyDict( digiStorePointer ) );
57  if ( firstHandle.isValid() )
58  {
59  //Skip first time setup
60  ATH_MSG_INFO( "Digi store already set up" );
61  }
62  else
63  {
64  //Do first time setup
65  ATH_MSG_INFO( "Setting up digi store" );
66  SG::WriteHandle< int > firstHandleFiller( "FirstTimeFlag" );
67  CHECK( firstHandleFiller.setProxyDict( digiStorePointer ) );
68  CHECK( firstHandleFiller.record( std::make_unique< int >( 1 ) ) );
69 
70  //Make all the "pileup events"
71  for ( int eventIndex = 0; eventIndex < 100; ++eventIndex )
72  {
73  SG::View * digiView = new SG::View( m_viewBaseName, eventIndex, false, digiStorePointer->name() );
75  CHECK( digiHandle.setProxyDict( digiView ) );
76  CHECK( digiHandle.record( std::make_unique< std::vector< int > >( 1, eventIndex ) ) );
77  delete digiView;
78  }
79  }
80 
81  //Make a vector of views for "pileup events" to use in this event
82  auto viewVector = std::make_unique< ViewContainer >(); //( m_viewNumber, nullptr );
83  for ( int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex )
84  {
85  int sampleIndex = ( viewIndex + ctx.evt() + 37 ) % 100; // whatever
86  SG::View * digiView = new SG::View( m_viewBaseName, sampleIndex, false, digiStorePointer->name() );
87  viewVector->push_back( digiView );
88  }
89 
90  //Schedule the algorithms in views
91  CHECK( ViewHelper::scheduleViews( viewVector.get(), //View vector
92  m_viewNodeName, //Name of node to attach views to
93  ctx, //Context to attach the views to
94  m_scheduler.get() ) ); //ServiceHandle for the scheduler
95 
96  //Store the collection of views
97  SG::WriteHandle< ViewContainer > outputViewHandle( m_w_views, ctx );
98  CHECK( outputViewHandle.record( std::move( viewVector ) ) );
99 
100  return StatusCode::SUCCESS;
101 }
102 
103 
104 } //> end namespace AthViews
AthViews::DigiDemoSetupAlg::DigiDemoSetupAlg
DigiDemoSetupAlg()
Default constructor:
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
AthViews::DigiDemoSetupAlg::initialize
virtual StatusCode initialize()
Definition: DigiDemoSetupAlg.cxx:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthViews::DigiDemoSetupAlg::m_scheduler
ServiceHandle< IScheduler > m_scheduler
Containers.
Definition: DigiDemoSetupAlg.h:44
AthViews::DigiDemoSetupAlg::m_viewNodeName
Gaudi::Property< std::string > m_viewNodeName
Definition: DigiDemoSetupAlg.h:49
ViewHelper.h
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:51
WriteHandle.h
Handle class for recording to StoreGate.
AthViews::DigiDemoSetupAlg::m_digiStore
ServiceHandle< IProxyDict > m_digiStore
Definition: DigiDemoSetupAlg.h:45
AthViews::DigiDemoSetupAlg::m_viewBaseName
Gaudi::Property< std::string > m_viewBaseName
Definition: DigiDemoSetupAlg.h:48
AthViews::DigiDemoSetupAlg::m_w_ints
SG::WriteHandleKey< std::vector< int > > m_w_ints
Definition: DigiDemoSetupAlg.h:47
SG::VarHandleBase::setProxyDict
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
Definition: StoreGate/src/VarHandleBase.cxx:534
AthViews::DigiDemoSetupAlg::execute
virtual StatusCode execute()
Definition: DigiDemoSetupAlg.cxx:40
DigiDemoSetupAlg.h
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
ViewHelper::scheduleViews
StatusCode scheduleViews(ViewContainer *viewVector, std::string const &nodeName, EventContext const &sourceContext, SmartIF< IScheduler > scheduler, bool reverseOrder=false)
Definition: ViewHelper.h:84
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AthViews::DigiDemoSetupAlg::finalize
virtual StatusCode finalize()
Definition: DigiDemoSetupAlg.cxx:33
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthViews::DigiDemoSetupAlg::~DigiDemoSetupAlg
virtual ~DigiDemoSetupAlg()
Destructor:
Definition: DigiDemoSetupAlg.cxx:17
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AthViews
Definition: ViewDataVerifier.cxx:18
AthViews::DigiDemoSetupAlg::m_w_views
SG::WriteHandleKey< ViewContainer > m_w_views
Definition: DigiDemoSetupAlg.h:46
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
AthViews::DigiDemoSetupAlg::m_viewNumber
Gaudi::Property< int > m_viewNumber
Definition: DigiDemoSetupAlg.h:50
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ReadHandle.h
Handle class for reading from StoreGate.
SG::View
Definition: View.h:25
EventInfoCnvParams::eventIndex
thread_local event_number_t eventIndex
Definition: IEvtIdModifierSvc.h:34