ATLAS Offline Software
JetCollection.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 }
25 
26  //std::cout << " JetCollection deleting " << m_jetAuthor <<std::endl;
28  // remove myself from my jets. Otherwise, they might invoke me
29  // in their destructors.
30  iterator it = begin();
31  iterator itE = end();
32  for(;it != itE; ++it){
33  (*it)->m_collection = nullptr;
34  }
35  }
36 
37  if( (m_ownMap) && m_momentMapLink.isValid() ) {
38  delete m_momentMapLink.cptr();
39  }
40 
41 }
42 
44  return &m_keyDescInstance;
45 }
46 
47 std::string JetCollection::getMomentMapName() const{
48  std::string mapname = author();
49  mapname +="MomentMap";
50  return mapname;
51 }
52 
54 
55  //std::cout << "asking map in "<< author() << std::endl;
56  if ( !m_momentMapLink.isValid() ) {
57  // we first try to retrieve it :
58  std::string mapname = getMomentMapName();
59  m_momentMapLink.toIdentifiedObject ( mapname); // by name, because we don't use DataLink_p2 class yet
60 
61  //m_momentMapLink->access(); // this hsould work whe we use DataLink_p2 P class.
62 
63  //std::cout << "Datalink invalid set "<< mapname << std::endl;
64  if ( !m_momentMapLink.isValid() ) {
65  //std::cout << "Datalink invalid create map "<< mapname << std::endl;
66  // Nothing available from SG/disk. We create the map
67  JetMomentMap* map = new JetMomentMap();
68  map->m_ownPolicy = m_ownPolicy;
70  // This means we own it !
71  m_ownMap = true;
72  }
73  }
74 
75  return m_momentMapLink.cptr();
76 }
77 
79  return m_nextId++; // this returns m_nextId *then* increments it
80 }
81 
83  acquireJet(j);
85 }
86 
87 
89  acquireJet(j);
90  return DataVector<Jet>::insert(position,j);
91 }
92 
94 {
97 }
98 
100 {
103 }
104 
106  // If the jet is orphan, adopt it
107  // this means : acquire its moments if they exist and give it an Id
108  // otherwise, we do nothing.
109 
110  if ( j->parentCollection() && (m_ownPolicy == SG::OWN_ELEMENTS )) return ; // this case is very bad anyway, there will be problems, we can't do anything.
111 
112  // In the case this collection has no author, simply acquire those from the jet.
114  std::string viewS = "";
115  if( m_ownPolicy == SG::VIEW_ELEMENTS ) viewS ="View"; // We want to distinguish the name from the jet's original collection.
116  m_jetAuthor = keyDesc()->getIndex(JetKeyConstants::InfoCat,j->jetAuthor()+viewS,true); // use the real jetAuthor() (m_jetAuthor index
117  }
118  // std::cout << " acquireJet jid="<<j->id() <<" "<<author()<<std::endl;
119 
120  size_t oldId = j->id();
122  if( oldId != Jet::s_defaultJetId ){
123  // jet might have moments to be tranfered
124  const JetMomentMap *jmap = j->getMomentMap();
125  // The moment map associated to this collection has the same m_ownPolicy,
126  // so the call knows how to deal the moments (i.e. copy or move)
127  if( jmap ){ getMomentMap()->transferRecord( jmap, oldId, j->id() ); }
128 
129  }
130  // set myself as this jet parent now (not before !) if needed
131  if( m_ownPolicy == SG::OWN_ELEMENTS ) j->m_collection = this;
132 
133 }
134 
135 
136 std::string JetCollection::author() const
137 {
139 }
140 void JetCollection::setAuthor(const std::string& author){
142 }
143 
145  //std::cout << "JetCollection Recorded "<< m_momentMapLink.cptr() << std::endl;
146  m_ownMap = false;
147  if( key == author() ){
148  key = getMomentMapName();
150  }else {
151  // this should never happen, so I let the raw std::cout
152  std::cout << " JetCollection ERROR attempt to record in SG with key ="<< key << " while author ="<< author() << " both should be the same."<< std::endl;
153  }
154 
155 
156  //
157 
158 }
159 
160 void JetCollection::resetJetId(std::size_t id_) {
161 
162  //make sure the jet belongs to us
163  if (m_ownPolicy == SG::OWN_ELEMENTS) {
164  if ( this->at(id_)->m_collection != this) return;
165  }
166 
167  //this allows changing the jet id of a view collection...not ideal
168 
169  this->at(id_)->setJetId(id_+1);
170 
171 }
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:1199
Jet::getMomentMap
const shape_map_t * getMomentMap(bool addIfMissing) const
Definition: Jet.cxx:1163
DataVector< Jet >::m_ownPolicy
ROOT_SELECTION_NS::MemberAttributes< kTransient > m_ownPolicy
We do not want to save this.
Definition: DataVector.h:3440
JetCollection::keyDesc
JetKeyDescriptorInstance * keyDesc() const
Definition: JetCollection.cxx:43
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:396
JetCollection::acquireJet
void acquireJet(Jet *j)
Definition: JetCollection.cxx:105
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:1193
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:47
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:1195
JetCollection::resetJetId
void resetJetId(std::size_t)
Definition: JetCollection.cxx:160
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:93
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:1107
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:581
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:140
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:136
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:53
JetCollection::getNextId
size_t getNextId()
Definition: JetCollection.cxx:78
JetCollection::insert
iterator insert(iterator position, Jet *j)
Definition: JetCollection.cxx:88
CaloCondBlobAlgs_fillNoiseFromASCII.author
string author
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:26
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:168
JetCollection::iterator
DataVector< Jet >::iterator iterator
Definition: JetCollection.h:34
StoreGateSvc.h
JetCollection::push_back
void push_back(Jet *j)
Definition: JetCollection.cxx:82
JetKeyDescriptorInstance
Definition: JetKeyDescriptor.h:100
JetCollection::recordedInSG
void recordedInSG(std::string key)
Definition: JetCollection.cxx:144
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:24