ATLAS Offline Software
Loading...
Searching...
No Matches
SensitiveDetectorBase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef G4ATLASTOOLS_SENSITIVEDETECTORBASE_H
6#define G4ATLASTOOLS_SENSITIVEDETECTORBASE_H
7
8#pragma GCC diagnostic push
9// SDtools that have not yet been migrated to the new SD interface will trigger
10// this warning because SetupEvent(AtlasG4EventUserInfo&) and
11// Gather(AtlasG4EventUserInfo&) are hidden. this is fine, as these methods are
12// not used in the old-style SDs, but should be migrated. Remove this when all
13// SDs are migrated.
14#pragma GCC diagnostic ignored "-Woverloaded-virtual"
15
16// Base classes
19
20// Members
21#include "G4VSensitiveDetector.hh"
22#include "G4Types.hh"
23#ifdef G4MULTITHREADED
24# include "tbb/concurrent_unordered_map.h"
25#endif
26
27// STL library
28#include <string>
29#include <vector>
30#include <thread>
31
32// Forward declarations
33class G4LogicalVolume;
34class G4VSensitiveDetector;
35
36
49class SensitiveDetectorBase : public extends<AthAlgTool, ISensitiveDetector>
50{
51
52 public:
53
55 SensitiveDetectorBase(const std::string& type, const std::string& name,
56 const IInterface *parent);
59
65 StatusCode initializeSD() override;
66
68
70 virtual StatusCode SetupEvent() override { return StatusCode::SUCCESS; }
71 virtual StatusCode SetupEvent(HitCollectionMap&) override {
72 return SetupEvent();
73 }
74
76
78 virtual StatusCode Gather() override { return StatusCode::SUCCESS; }
79 virtual StatusCode Gather(HitCollectionMap&) override {
80 return Gather();
81 };
82
83 protected:
84
86
87 StatusCode assignSD(std::unique_ptr<G4VSensitiveDetector> sd,
88 const std::vector<std::string>& volumes) const;
89
91
93 G4VSensitiveDetector* getSD();
94
96 Gaudi::Property<std::vector<std::string> > m_volumeNames{this, "LogicalVolumeNames", {}};
98 Gaudi::Property<std::vector<std::string> > m_outputCollectionNames{this, "OutputCollectionNames", {}};
99
101 Gaudi::Property<bool> m_noVolumes{this, "NoVolumes", false};
102
104 void SetSensitiveDetector(G4LogicalVolume*, G4VSensitiveDetector*) const;
105
106 private:
107
109
110 void setSD(G4VSensitiveDetector*);
111
113
115 static bool matchStrings(const char *first, const char * second);
116
117#ifdef G4MULTITHREADED
119 using SDThreadMap_t = tbb::concurrent_unordered_map
120 < std::thread::id, G4VSensitiveDetector*, std::hash<std::thread::id> >;
122 SDThreadMap_t m_sdThreadMap;
123#else
125 G4VSensitiveDetector* m_SD{};
126#endif
127
128}; // class SensitiveDetectorBase
129
130#pragma GCC diagnostic pop
131
132#endif
Small wrapper around hit collection map to facilitate accessing the hit collection.
StatusCode assignSD(std::unique_ptr< G4VSensitiveDetector > sd, const std::vector< std::string > &volumes) const
Assign SD to a list of volumes.
virtual StatusCode SetupEvent(HitCollectionMap &) override
G4VSensitiveDetector * m_SD
The sensitive detector to which this thing corresponds.
virtual StatusCode Gather() override
End of an athena event.
Gaudi::Property< std::vector< std::string > > m_volumeNames
All the volumes to which this SD is assigned.
virtual StatusCode SetupEvent() override
Beginning of an athena event.
StatusCode initializeSD() override
Setup an SD in the current thread.
Gaudi::Property< bool > m_noVolumes
This SensitiveDetector has no volumes associated with it.
Gaudi::Property< std::vector< std::string > > m_outputCollectionNames
Names of all output collections written out by this SD.
SensitiveDetectorBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
static bool matchStrings(const char *first, const char *second)
Match two strings with wildcard support.
G4VSensitiveDetector * getSD()
Retrieve the current SD.
void setSD(G4VSensitiveDetector *)
Set the current SD.
void SetSensitiveDetector(G4LogicalVolume *, G4VSensitiveDetector *) const
Method stolen from G4VUserDetectorConstruction in G4 10.2.
virtual ~SensitiveDetectorBase()
Empty virtual destructor.
virtual StatusCode Gather(HitCollectionMap &) override