ATLAS Offline Software
Loading...
Searching...
No Matches
Object.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
5#ifndef GLOBALSIM_OBJECT_H
6#define GLOBALSIM_OBJECT_H
7
10
11#include "BitSpec.h" // for NoBase
12
13namespace GlobalSim {
14
15 // Object template class exists so that can have "whole object" methods like bits(), which need to know about
16 // the "Spec" as a whole. If tried to put these into the ObjectAcc subclass, that subclass doesn't know about
17 // the Spec it lives in, so in the DECLARE_FIELDS macro we would also have to pass the SpecName
18 // in order to define (in the macro) the bits() method that uses SpecName::packFields etc
19
20 template<typename Spec> class Object; // forward declare primary template
21
22 // Terminal case: nothing more to compose. Also conveniently can create and own an AuxElement in one place
23 template<>
24 class Object<NoBase> {
25 public:
26 explicit Object(const SG::AuxElement& obj) : m_ref(obj) {}
27
28 Object() : m_owned(std::make_shared<SG::AuxElement>()), m_ref(*m_owned) {
29 m_owned->makePrivateStore();
30 }
31 protected:
32 const SG::AuxElement &auxRef() const { return m_ref; }
33 private:
34 std::shared_ptr<SG::AuxElement> m_owned; // null when wrapping external object;
36 };
37
38 template<typename Spec>
39 class Object : public Object<typename Spec::BaseSpec>, public Spec::ObjectAcc {
40 public:
42
43 static constexpr Spec spec{}; // allows access to the BitSpec with obj.spec. syntax
44
45
46 explicit Object(const SG::AuxElement &obj) : BaseObject(obj), Spec::ObjectAcc(obj) {
47
48 }
49
50 // convenience constructor that will create and use a private AuxElement
51 explicit Object() : BaseObject(), Spec::ObjectAcc(BaseObject::auxRef()) { }
52
53 // ------------------------------------------------------------------------
54 // Complete packed representation.
55 // ------------------------------------------------------------------------
56
57 Spec::bitset_type bits() const {
58 return Spec::packFields(Spec::allFields(), Spec::ObjectAcc::m_obj);
59 }
60
61 void operator=(const Spec::bitset_type &bits) {
62 std::apply([&](const auto *... field) {
63 (field->decodeAndAssignFrom(bits, const_cast<SG::AuxElement &>(Spec::ObjectAcc::m_obj)), ...);
64 },
65 Spec::allFields());
66 }
67
68 public:
69 const SG::AuxElement *objectPtr() const {
70 return &this->Spec::ObjectAcc::m_obj;
71 }
72
73 void dump() const {
75 }
76
77
78 };
79
80}
81
82#endif
Base class for elements of a container that can have aux data.
const SG::AuxElement & auxRef() const
Definition Object.h:32
const SG::AuxElement & m_ref
Definition Object.h:35
Object(const SG::AuxElement &obj)
Definition Object.h:26
std::shared_ptr< SG::AuxElement > m_owned
Definition Object.h:34
const SG::AuxElement * objectPtr() const
Definition Object.h:69
void dump() const
Definition Object.h:73
Object< typename Spec::BaseSpec > BaseObject
Definition Object.h:41
Object(const SG::AuxElement &obj)
Definition Object.h:46
void operator=(const Spec::bitset_type &bits)
Definition Object.h:61
Spec::bitset_type bits() const
Definition Object.h:57
AlgTool to read in LArStripNeighborhoods, and run the BDT Algorithm.
Definition BitSpec.h:24
Forward declaration.
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
STL namespace.
void dump(const SG::AuxElement &obj)
Helper function for dumping xAOD objects on the screen in PyROOT.