ATLAS Offline Software
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),
11  m_ordered(Random),
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 
47  return &m_keyDescInstance;
48 }
49 
50 std::string JetCollection::getMomentMapName() const{
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
70  JetMomentMap* map = new JetMomentMap();
71  map->m_ownPolicy = m_ownPolicy;
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 
86  acquireJet(j);
88 }
89 
90 
92  acquireJet(j);
93  return DataVector<Jet>::insert(position,j);
94 }
95 
97 {
100 }
101 
103 {
106 }
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 
139 std::string JetCollection::author() const
140 {
142 }
143 void JetCollection::setAuthor(const std::string& author){
145 }
146 
148  //std::cout << "JetCollection Recorded "<< m_momentMapLink.cptr() << std::endl;
149  m_ownMap = false;
150  if( key == author() ){
151  key = getMomentMapName();
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 
163 void 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 }
JetMomentMap
Definition: JetMomentMap.h:21
Jet::s_defaultJetAuthor
static const size_t s_defaultJetAuthor
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:723
JetKeyDescriptorInstance::m_Stores
JetKeyDescriptor * m_Stores
Definition: JetKeyDescriptor.h:155
Jet::setJetId
void setJetId(size_t id)
Definition: Jet.cxx:1200
Jet::getMomentMap
const shape_map_t * getMomentMap(bool addIfMissing) const
Definition: Jet.cxx:1164
JetCollection::keyDesc
JetKeyDescriptorInstance * keyDesc() const
Definition: JetCollection.cxx:46
Jet
Basic data class defines behavior for all Jet objects The Jet class is the principal data class for...
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
skel.it
it
Definition: skel.GENtoEVGEN.py:407
JetCollection::acquireJet
void acquireJet(Jet *j)
Definition: JetCollection.cxx:108
JetCollection::JetCollection
JetCollection(SG::OwnershipPolicy own=SG::OWN_ELEMENTS)
Definition: JetCollection.cxx:9
TruthTest.itE
itE
Definition: TruthTest.py:25
JetKeyDescriptorInstance::instance
static JetKeyDescriptorInstance * instance()
Definition: JetKeyDescriptor.h:123
SG::OwnershipPolicy
OwnershipPolicy
describes the possible element ownership policies (see e.g. DataVector)
Definition: OwnershipPolicy.h:16
Jet::id
size_t id() const
returns this jet unique identifier in its collection
Definition: Jet.cxx:1194
JetMapBase::transferRecord
virtual void transferRecord(const JetMapBase< P > *fromMap, size_t oldIndex, size_t newIndex) const
transfer a record from an other map
JetCollection::getMomentMapName
std::string getMomentMapName() const
Definition: JetCollection.cxx:50
JetKeyDescriptorInstance::createKeyStore
void createKeyStore() const
Definition: JetKeyDescriptor.cxx:34
Jet::parentCollection
const JetCollection * parentCollection() const
a pointer to the collection this jet belongs to (can be NULL)
Definition: Jet.cxx:1196
JetCollection::resetJetId
void resetJetId(std::size_t)
Definition: JetCollection.cxx:163
Random
Definition: TrigAnalysis/TrigInDetAnalysisUser/Resplot/src/Random.h:26
JetMomentMap
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current JetMomentMap
Definition: JetEventTPCnv.cxx:103
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
JetCollection::m_keyDescInstance
JetKeyDescriptorInstance m_keyDescInstance
This JetKeyDescriptorInstance points by default to the global JetKeyDescriptorInstance's store....
Definition: JetCollection.h:126
JetCollection::m_nextId
size_t m_nextId
the next free identifier for jets inside this collection
Definition: JetCollection.h:120
JetCollection.h
JetCollection::m_jetAuthor
size_t m_jetAuthor
the author of this jetcollection.
Definition: JetCollection.h:114
JetCollection::clear
void clear()
Definition: JetCollection.cxx:96
DataVector::insert
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
Jet::jetAuthor
std::string jetAuthor() const
Author and calibration history are encoded in a simple way inside the jet object.
Definition: Jet.cxx:1108
JetKeyDescriptorInstance::getKey
const key_t & getKey(const category_t &cat, size_t index) const
Definition: JetKeyDescriptor.cxx:161
Jet::m_collection
const JetCollection * m_collection
Shape store link.
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:676
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DataVector::clear
void clear()
Erase all the elements in the collection.
JetCollection::m_momentMapLink
DataLink< JetMomentMap > m_momentMapLink
Definition: JetCollection.h:108
JetKeyConstants::InfoCat
static const key_t InfoCat
Index category for general jet info.
Definition: JetKeyDescriptor.h:94
JetCollection::setAuthor
void setAuthor(const std::string &author)
Definition: JetCollection.cxx:143
Jet::m_jetAuthor
size_t m_jetAuthor
Jet author store.
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:725
JetCollection::author
std::string author() const
Definition: JetCollection.cxx:139
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
JetCollection::m_ownMap
bool m_ownMap
false if the map is recorded in SG
Definition: JetCollection.h:130
DataVector< Jet >::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
JetCollection::getMomentMap
const JetMomentMap * getMomentMap() const
Definition: JetCollection.cxx:56
JetCollection::getNextId
size_t getNextId()
Definition: JetCollection.cxx:81
JetCollection::insert
iterator insert(iterator position, Jet *j)
Definition: JetCollection.cxx:91
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:25
Jet::s_defaultJetId
static const size_t s_defaultJetId
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:670
DataVector< Jet >::ownPolicy
SG::OwnershipPolicy ownPolicy() const
Return the ownership policy setting for this container.
JetKeyDescriptorInstance::getIndex
size_t getIndex(const category_t &cat, const key_t &key, bool createIfMissing=true)
Definition: JetKeyDescriptor.cxx:47
DataVector< Jet >::at
const Jet * at(size_type n) const
Access an element, as an rvalue.
JetMapBase::m_ownPolicy
SG::OwnershipPolicy m_ownPolicy
Definition: JetMapBase.h:166
JetCollection::iterator
DataVector< Jet >::iterator iterator
Definition: JetCollection.h:34
StoreGateSvc.h
JetCollection::push_back
void push_back(Jet *j)
Definition: JetCollection.cxx:85
JetKeyDescriptorInstance
Definition: JetKeyDescriptor.h:100
JetCollection::recordedInSG
void recordedInSG(std::string key)
Definition: JetCollection.cxx:147
DataVector< Jet >::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
JetKeyDescriptorInstance::m_ConstStores
const JetKeyDescriptor * m_ConstStores
Definition: JetKeyDescriptor.h:156
JetCollection::~JetCollection
virtual ~JetCollection()
Definition: JetCollection.cxx:27