ATLAS Offline Software
Loading...
Searching...
No Matches
JetCollection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8
10 DataVector<Jet>(own),
12 m_jetAuthor(Jet::s_defaultJetAuthor),
13 m_nextId(Jet::s_defaultJetId+1),
14 m_keyDescInstance(false),
15 m_ownMap(false),
16 m_fastjetClustSeq(nullptr)
17{
18 // by default the keyDescInstance points to the global s_instance's stores .
19 // The JetCollection cnv replaces that by the store read from file.
20 if( ! JetKeyDescriptorInstance::instance()->m_ConstStores ) JetKeyDescriptorInstance::instance()->createKeyStore(); // this may happen inside Trigger navigation system
23}
24// Coverity warns about SG::ExcConstStorable being thrown from the isValid(),
25// but that can't actually happen.
26//coverity[uncaught_except]
28
29 //std::cout << " JetCollection deleting " << m_jetAuthor <<std::endl;
30 if(m_ownPolicy == SG::OWN_ELEMENTS){
31 // remove myself from my jets. Otherwise, they might invoke me
32 // in their destructors.
33 iterator it = begin();
34 iterator itE = end();
35 for(;it != itE; ++it){
36 (*it)->m_collection = nullptr;
37 }
38 }
39
40 if( (m_ownMap) && m_momentMapLink.isValid() ) {
41 delete m_momentMapLink.cptr();
42 }
43
44}
45
49
51 std::string mapname = author();
52 mapname +="MomentMap";
53 return mapname;
54}
55
57
58 //std::cout << "asking map in "<< author() << std::endl;
59 if ( !m_momentMapLink.isValid() ) {
60 // we first try to retrieve it :
61 std::string mapname = getMomentMapName();
62 m_momentMapLink.toIdentifiedObject ( mapname); // by name, because we don't use DataLink_p2 class yet
63
64 //m_momentMapLink->access(); // this hsould work whe we use DataLink_p2 P class.
65
66 //std::cout << "Datalink invalid set "<< mapname << std::endl;
67 if ( !m_momentMapLink.isValid() ) {
68 //std::cout << "Datalink invalid create map "<< mapname << std::endl;
69 // Nothing available from SG/disk. We create the map
71 map->m_ownPolicy = m_ownPolicy;
72 m_momentMapLink.toStorableObject( *map );
73 // This means we own it !
74 m_ownMap = true;
75 }
76 }
77
78 return m_momentMapLink.cptr();
79}
80
82 return m_nextId++; // this returns m_nextId *then* increments it
83}
84
89
90
95
101
107
109 // If the jet is orphan, adopt it
110 // this means : acquire its moments if they exist and give it an Id
111 // otherwise, we do nothing.
112
113 if ( j->parentCollection() && (m_ownPolicy == SG::OWN_ELEMENTS )) return ; // this case is very bad anyway, there will be problems, we can't do anything.
114
115 // In the case this collection has no author, simply acquire those from the jet.
117 std::string viewS = "";
118 if( m_ownPolicy == SG::VIEW_ELEMENTS ) viewS ="View"; // We want to distinguish the name from the jet's original collection.
119 m_jetAuthor = keyDesc()->getIndex(JetKeyConstants::InfoCat,j->jetAuthor()+viewS,true); // use the real jetAuthor() (m_jetAuthor index
120 }
121 // std::cout << " acquireJet jid="<<j->id() <<" "<<author()<<std::endl;
122
123 size_t oldId = j->id();
124 if( m_ownPolicy == SG::OWN_ELEMENTS ) j->setJetId( getNextId() );
125 if( oldId != Jet::s_defaultJetId ){
126 // jet might have moments to be tranfered
127 const JetMomentMap *jmap = j->getMomentMap();
128 // The moment map associated to this collection has the same m_ownPolicy,
129 // so the call knows how to deal the moments (i.e. copy or move)
130 if( jmap ){ getMomentMap()->transferRecord( jmap, oldId, j->id() ); }
131
132 }
133 // set myself as this jet parent now (not before !) if needed
134 if( m_ownPolicy == SG::OWN_ELEMENTS ) j->m_collection = this;
135
136}
137
138
139std::string JetCollection::author() const
140{
142}
146
147void JetCollection::recordedInSG(std::string key){
148 //std::cout << "JetCollection Recorded "<< m_momentMapLink.cptr() << std::endl;
149 m_ownMap = false;
150 if( key == author() ){
151 key = getMomentMapName();
152 m_momentMapLink.toIdentifiedObject ( key);
153 }else {
154 // this should never happen, so I let the raw std::cout
155 std::cout << " JetCollection ERROR attempt to record in SG with key ="<< key << " while author ="<< author() << " both should be the same."<< std::endl;
156 }
157
158
159 //
160
161}
162
163void JetCollection::resetJetId(std::size_t id_) {
164
165 //make sure the jet belongs to us
166 if (m_ownPolicy == SG::OWN_ELEMENTS) {
167 if ( this->at(id_)->m_collection != this) return;
168 }
169
170 //this allows changing the jet id of a view collection...not ideal
171
172 this->at(id_)->setJetId(id_+1);
173
174}
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current JetMomentMap
const Jet * at(size_type n) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
DataVector(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
const_iterator end() const noexcept
const_iterator begin() const noexcept
SG::OwnershipPolicy ownPolicy() const
void clear()
Erase all the elements in the collection.
size_t m_nextId
the next free identifier for jets inside this collection
std::string getMomentMapName() const
void acquireJet(Jet *j)
OrderedVar m_ordered
const fastjet::ClusterSequence * m_fastjetClustSeq
Pointer to the fastjet object this jet is build from.
bool m_ownMap
false if the map is recorded in SG
iterator insert(iterator position, Jet *j)
void setAuthor(const std::string &author)
std::string author() const
JetKeyDescriptorInstance m_keyDescInstance
This JetKeyDescriptorInstance points by default to the global JetKeyDescriptorInstance's store....
void resetJetId(std::size_t)
DataLink< JetMomentMap > m_momentMapLink
void recordedInSG(std::string key)
JetCollection(SG::OwnershipPolicy own=SG::OWN_ELEMENTS)
virtual ~JetCollection()
const JetMomentMap * getMomentMap() const
size_t m_jetAuthor
the author of this jetcollection.
DataVector< Jet >::iterator iterator
void push_back(Jet *j)
JetKeyDescriptorInstance * keyDesc() const
Theses classes implement a mapping between string and index used by jets.
const JetKeyDescriptor * m_ConstStores
JetKeyDescriptor * m_Stores
static JetKeyDescriptorInstance * instance()
size_t getIndex(const category_t &cat, const key_t &key, bool createIfMissing=true)
const key_t & getKey(const category_t &cat, size_t index) const
virtual void transferRecord(const JetMapBase< P > *fromMap, size_t oldIndex, size_t newIndex) const
transfer a record from an other map
size_t id() const
Index category for jet shapes.
Definition Jet.cxx:1194
const shape_map_t * getMomentMap(bool addIfMissing) const
Definition Jet.cxx:1164
std::string jetAuthor() const
Author and calibration history are encoded in a simple way inside the jet object.
Definition Jet.cxx:1108
size_t m_jetAuthor
Jet author store.
const JetCollection * parentCollection() const
a pointer to the collection this jet belongs to (can be NULL)
Definition Jet.cxx:1196
static const size_t s_defaultJetId
static const size_t s_defaultJetAuthor
void setJetId(size_t id)
Definition Jet.cxx:1200
const JetCollection * m_collection
Shape store link.
STL class.
OwnershipPolicy
@ OWN_ELEMENTS
this data object owns its elements
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
static const key_t InfoCat
Index category for general jet info.