ATLAS Offline Software
Loading...
Searching...
No Matches
HepMcParticleLink Class Reference

a link optimized in size for a GenParticle in a McEventCollection More...

#include <HepMcParticleLink.h>

Collaboration diagram for HepMcParticleLink:

Classes

class  ExtendedBarCode
 Persistent representation of a link. More...

Public Types

enum  PositionFlag { IS_EVENTNUM = 0 , IS_POSITION = 1 }
enum  UniqueIDFlag { IS_ID = 0 , IS_BARCODE = 1 }
typedef uint32_t barcode_type
typedef uint32_t index_type

Public Member Functions

 HepMcParticleLink (IProxyDict *sg=nullptr)
 Default constructor.
 HepMcParticleLink (const EventContext &ctx)
 Default constructor.
 HepMcParticleLink (barcode_type uid, uint32_t eventIndex, PositionFlag positionFlag, UniqueIDFlag uniqueIDFlag, IProxyDict *sg)
 Constructor.
 HepMcParticleLink (barcode_type uid, uint32_t eventIndex, PositionFlag positionFlag, UniqueIDFlag uniqueIDFlag, const EventContext &ctx=Gaudi::Hive::currentContext())
 Constructor.
 HepMcParticleLink (const HepMC::ConstGenParticlePtr &p, uint32_t eventIndex, PositionFlag positionFlag, IProxyDict *sg)
 Constructor.
 HepMcParticleLink (const HepMC::ConstGenParticlePtr &part, uint32_t eventIndex, PositionFlag positionFlag, const EventContext &ctx=Gaudi::Hive::currentContext())
 Constructor.
 HepMcParticleLink (const HepMcParticleLink &rhs)=default
 Copy constructor.
 HepMcParticleLink (HepMcParticleLink &&rhs) noexcept=default
 Move constructor.
HepMcParticleLink & operator= (const HepMcParticleLink &rhs)=default
 Assignment.
HepMcParticleLink & operator= (HepMcParticleLink &&rhs)=default
 Move Assignment.
pointer interface
const HepMC::GenParticle & operator* () const
 Dereference.
HepMC::ConstGenParticlePtr operator-> () const
 Dereference.
 operator HepMC::ConstGenParticlePtr () const
 Dereference.
HepMC::ConstGenParticlePtr cptr () const
 Dereference.
HepMC::ConstGenParticlePtr scptr () const
 Dereference/smart pointer.
bool linkIsNull () const
 return true if neither barcode nor id are valid
bool isValid () const
 Validity check.
bool operator! () const
 Validity check.
 operator bool () const
 Validity check.
Comparison operators.
bool operator== (const HepMcParticleLink &rhs) const
 Equality comparison.
bool operator!= (const HepMcParticleLink &rhs) const
 Inequality comparison.
bool operator< (const HepMcParticleLink &rhs) const
 Ordering comparison.

ParticleLink-specific methods.

IProxyDict * m_store
 Pointer to the store containing the event.
ATH_NO_UNIQUE_ADDRESS CxxUtils::CachedValue< HepMC::ConstGenParticlePtr > m_ptr
 Transient part. Pointer to the particle.
ExtendedBarCode m_extBarcode
 Persistent part: barcode and location of target GenEvent.
int barcode () const
 Return the barcode of the target particle.
int id () const
 Return the id of the target particle.
index_type eventIndex () const
 Return the event number of the referenced GenEvent.
index_type getEventPositionInCollection (IProxyDict *sg) const
 Return the position in the McEventCollection of the GenEvent pointed to by this HepMcParticleLink.
index_type getEventPositionInCollection (const EventContext &ctx) const
 Return the position in the McEventCollection of the GenEvent pointed to by this HepMcParticleLink.
EBC_SUPPRESSED_TRUTH getTruthSuppressionType () const
 Return whether the truth particle has been suppressed, as an enum.
void setTruthSuppressionType (EBC_SUPPRESSED_TRUTH truthSupp)
 Return whether the truth particle has been suppressed.
char getTruthSuppressionTypeAsChar () const
 Return whether the truth particle has been suppressed, as a char ('a'..'b').
barcode_type compress () const
 Hash the 32 bit barcode and 16 bit eventindex into a 32bit int.
void setExtendedBarCode (const ExtendedBarCode &extBarcode)
 Alter the persistent part of the link.
static int getEventNumberAtPosition (index_type position, IProxyDict *sg)
 Return the event number of the GenEvent at the specified position in the McEventCollection.
static int getEventNumberAtPosition (index_type position, const EventContext &ctx)
 Return the event number of the GenEvent at the specified position in the McEventCollection.
static std::vector< index_type > getEventPositionInCollection (index_type index, IProxyDict *sg)
 Return a vector of the positions in the McEventCollection of the GenEvent(s) with a given event number.
static HepMcParticleLink getRedirectedLink (const HepMcParticleLink &particleLink, uint32_t eventIndex, const EventContext &ctx)
 Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.
std::ostream & operator<< (std::ostream &os, const HepMcParticleLink &link)
 Output operator.
MsgStream & operator<< (MsgStream &os, const HepMcParticleLink &link)
 Output operator.
static const McEventCollection * retrieveMcEventCollection (IProxyDict *sg)
 Look up the event collection we're targeting.
static SG::DataProxy * find_proxy (IProxyDict *sg)
 Find the proxy for the target event collection.
static std::string getLastEventCollectionName ()
 Return the most recent SG key used for a particular collection type.

Detailed Description

a link optimized in size for a GenParticle in a McEventCollection

A link is defined by three items:

  • A target McEventCollection;
  • A particular GenEvent within this collection; and
  • A particular particle within the GenEvent.

There is a list of StoreGate keys for the McEventCollection (see the initialization of s_keys). When we want to dereference the link, we try to look up each possible key in turn until we find one that works. (The position of that key in the list is then remembered as a hint for where to start searching next time.)

The particular GenEvent within the collection can be represented as either an event number (as returned by GenEvent::event_number()) or by a position within the collection. Which case is desired is indicated by the value of the isIndexEventPosition argument to the constructors (defaulting to the event number case). In order to convert between these, we need to retrieve the McEventCollection from the store, but we don't have the store pointer once the link has been dereferenced. Therefore, when a position-based link is dereferenced, it is automatically changed to be event-number-based. This also happens when a link is constructed with an explicit ConstGenParticlePtr and a position-based GenEvent.

As a special case, a GenEvent number of 0 is interpreted as the first GenEvent in the collection.

The particle within the GenEvent is represented by a unique ID. A unique ID of 0 implies a null link.

In order to dereference a link, we need to reference a particular event store. By default, the current store (as defined by the current EventContext) is stored when the link is constructed; however, an explicit IProxyDict* or EventContext may also be specified.

See also
McEventCollection, GenEvent, ElementLink
Author
Paolo Calafiura

Definition at line 71 of file HepMcParticleLink.h.

Member Typedef Documentation

◆ barcode_type

Definition at line 74 of file HepMcParticleLink.h.

◆ index_type

Definition at line 75 of file HepMcParticleLink.h.

Member Enumeration Documentation

◆ PositionFlag

Enumerator
IS_EVENTNUM 
IS_POSITION 

Definition at line 78 of file HepMcParticleLink.h.

◆ UniqueIDFlag

Enumerator
IS_ID 
IS_BARCODE 

Definition at line 83 of file HepMcParticleLink.h.

Constructor & Destructor Documentation

◆ HepMcParticleLink() [1/8]

HepMcParticleLink::HepMcParticleLink ( IProxyDict * sg = nullptr)

Default constructor.

Makes a null link.

Parameters
sgOptional specification of a specific store to reference.

◆ HepMcParticleLink() [2/8]

HepMcParticleLink::HepMcParticleLink ( const EventContext & ctx)

Default constructor.

Makes a null link.

Parameters
ctxContext of the store to reference.

◆ HepMcParticleLink() [3/8]

HepMcParticleLink::HepMcParticleLink ( barcode_type uid,
uint32_t eventIndex,
PositionFlag positionFlag,
UniqueIDFlag uniqueIDFlag,
IProxyDict * sg )

Constructor.

Parameters
uidUnique ID of the target particle. 0 means a null link.
eventIndexIdentifies the target GenEvent in a McEventCollection, as either the event number if isIndexEventPosition is IS_EVENTNUM, or the position in the container if isIndexEventPosition is IS_POSITION. 0 always means the first event in the collection.
positionFlagSee eventIndex.
sgOptional specification of a specific store to reference.

◆ HepMcParticleLink() [4/8]

HepMcParticleLink::HepMcParticleLink ( barcode_type uid,
uint32_t eventIndex,
PositionFlag positionFlag,
UniqueIDFlag uniqueIDFlag,
const EventContext & ctx = Gaudi::Hive::currentContext() )

Constructor.

Parameters
uidUnique ID of the target particle. 0 means a null link.
eventIndexIdentifies the target GenEvent in a McEventCollection, as either the event number if isIndexEventPosition is IS_EVENTNUM, or the position in the container if isIndexEventPosition is IS_POSITION. 0 always means the first event in the collection.
positionFlagSee eventIndex.
ctxContext of the store to reference.

◆ HepMcParticleLink() [5/8]

HepMcParticleLink::HepMcParticleLink ( const HepMC::ConstGenParticlePtr & part,
uint32_t eventIndex,
PositionFlag positionFlag,
IProxyDict * sg )

Constructor.

Parameters
pParticle to reference.
eventIndexIdentifies the target GenEvent in a McEventCollection, as either the event number if isIndexEventPosition is IS_EVENTNUM, or the position in the container if isIndexEventPosition is IS_POSITION. 0 always means the first event in the collection.
positionFlagSee eventIndex.
sgOptional specification of a specific store to reference.

Definition at line 144 of file HepMcParticleLink.cxx.

148 : m_store (sg),
149 m_ptr (part),
150 m_extBarcode((nullptr != part) ? HepMC::uniqueID(part) : 0, eventIndex, positionFlag, IS_ID)
151{
152 assert(part);
153
154 if (part != nullptr && positionFlag == IS_POSITION) {
155 if (const McEventCollection* pEvtColl = retrieveMcEventCollection(sg)) {
156 const HepMC::GenEvent *pEvt = pEvtColl->at (eventIndex);
157 m_extBarcode.makeIndex (pEvt->event_number(), eventIndex);
158 }
159 else {
160 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
161 log << MSG::WARNING << "cptr: McEventCollection not found" << endmsg;
162 }
163 }
164}
#define endmsg
IMessageSvc * getMessageSvc(bool quiet=false)
int uniqueID(const T &p)
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39

◆ HepMcParticleLink() [6/8]

HepMcParticleLink::HepMcParticleLink ( const HepMC::ConstGenParticlePtr & part,
uint32_t eventIndex,
PositionFlag positionFlag,
const EventContext & ctx = Gaudi::Hive::currentContext() )

Constructor.

Parameters
pParticle to reference.
eventIndexIdentifies the target GenEvent in a McEventCollection, as either the event number if isIndexEventPosition is IS_EVENTNUM, or the position in the container if isIndexEventPosition is IS_POSITION. 0 always means the first event in the collection.
positionFlagSee eventIndex.
ctxContext of the store to reference.

◆ HepMcParticleLink() [7/8]

HepMcParticleLink::HepMcParticleLink ( const HepMcParticleLink & rhs)
default

Copy constructor.

◆ HepMcParticleLink() [8/8]

HepMcParticleLink::HepMcParticleLink ( HepMcParticleLink && rhs)
defaultnoexcept

Move constructor.

Member Function Documentation

◆ barcode()

int HepMcParticleLink::barcode ( ) const

Return the barcode of the target particle.

0 for a null link. FIXME: return type.

Definition at line 311 of file HepMcParticleLink.cxx.

312{
313 // if m_BC is zero (delta rays), then just return that same for barcode and id
314 if (m_extBarcode.uid()) {
315 barcode_type particle_id, particle_barcode;
316 m_extBarcode.uniqueID (particle_id, particle_barcode);
317 if (particle_barcode != ExtendedBarCode::UNDEFINEDBC) {
318 return int(particle_barcode);
319 }
320 // dummy link
321 if (!m_ptr.isValid() && !m_store) {
322 return 0; // TODO Decide if this is a good default - constant from MagicNumbers.h instead?
323 }
324 // we will need to look up the barcode from the GenParticle
325 (void) eventIndex(); // FIXME be careful to avoid an infinite loop of calls here
326 if (cptr()) {
327 return HepMC::barcode(cptr());
328 }
329 }
330 return 0;
331}
int barcode(const T *p)
Definition Barcode.h:15

◆ compress()

barcode_type HepMcParticleLink::compress ( ) const

Hash the 32 bit barcode and 16 bit eventindex into a 32bit int.

◆ cptr()

HepMC::ConstGenParticlePtr HepMcParticleLink::cptr ( ) const

Dereference.

Definition at line 178 of file HepMcParticleLink.cxx.

179{
180 // dummy link
181 const bool is_valid = m_ptr.isValid();
182 if (!is_valid && !m_store) {
183 return nullptr;
184 }
185 if (is_valid) {
186 return *m_ptr.ptr();
187 }
188 if (m_extBarcode.linkIsNull()) {
189 #if 0
190 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
191 log << MSG::DEBUG
192 << "cptr: no truth particle associated with this hit (barcode==0)."
193 << " Probably this is a noise hit" << endmsg;
194 #endif
195 return nullptr;
196 }
197 IProxyDict* sg = m_store;
198 if (!sg) {
200 }
201 if (const McEventCollection* pEvtColl = retrieveMcEventCollection(sg)) {
202 const HepMC::GenEvent *pEvt = nullptr;
203 index_type event_number, position;
204 m_extBarcode.eventIndex (event_number, position);
205 if (event_number == 0) {
206 pEvt = pEvtColl->at(0);
207 }
208 else if (position != ExtendedBarCode::UNDEFINED) {
209 if (position < pEvtColl->size()) {
210 pEvt = pEvtColl->at (position);
211 }
212 else {
213 #if 0
214 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
215 log << MSG::WARNING << "cptr: position = " << position << ", McEventCollection size = "<< pEvtColl->size() << endmsg;
216 #endif
217 return nullptr;
218 }
219 }
220 else {
221 pEvt = pEvtColl->find (event_number);
222 }
223
224 if (nullptr != pEvt) {
225 // Be sure to update m_extBarcode before m_ptrs;
226 // otherwise, the logic in eventIndex() won't work correctly.
227 if (position != ExtendedBarCode::UNDEFINED) {
228 m_extBarcode.makeIndex (pEvt->event_number(), position);
229 }
230 if (event_number == 0) {
231 m_extBarcode.makeIndex (pEvt->event_number(), position);
232 }
233 if ( !m_extBarcode.linkIsNull() ) { // Check that either the ID or Barcode is non-zero or undefined
234 barcode_type particle_id, particle_barcode;
235 m_extBarcode.uniqueID (particle_id, particle_barcode);
236 if (particle_id == ExtendedBarCode::UNDEFINEDBC) {
237 // barcode to GenParticle
238 const HepMC::ConstGenParticlePtr p = HepMC::barcode_to_particle(pEvt,int(particle_barcode));
239 if (p) {
240 int genParticleID = HepMC::uniqueID(p);
241 if (genParticleID > -1) {
242 particle_id = static_cast<barcode_type>(genParticleID);
243 m_extBarcode.makeID (particle_id, particle_barcode);
244 }
245 m_ptr.set (p);
246 return p;
247 }
248 }
249 else {
250 // id to GenParticle
251 const auto &particles = pEvt->particles();
252 if (particle_id-1 < particles.size()) {
253 const HepMC::ConstGenParticlePtr p = particles[particle_id-1];
254 if (p) {
255 m_ptr.set (p);
256 return p;
257 }
258 }
259 }
260 }
261 } else {
262 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
263 if (position != ExtendedBarCode::UNDEFINED) {
264 log << MSG::WARNING
265 << "cptr: Mc Truth not stored for event at " << position
266 << endmsg;
267 } else {
268 log << MSG::WARNING
269 << "cptr: Mc Truth not stored for event with event number " << event_number
270 << endmsg;
271 }
272 }
273 } else {
274 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
275 log << MSG::WARNING << "cptr: McEventCollection not found" << endmsg;
276 }
277 return nullptr;
278}
size_t size() const
Number of registered mappings.
IProxyDict * proxyDictFromEventContext()
Return the IProxyDict for this thread's current context.
ConstGenParticlePtr barcode_to_particle(const GenEvent *e, int id)
Definition GenEvent.h:446
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.

◆ eventIndex()

HepMcParticleLink::index_type HepMcParticleLink::eventIndex ( ) const

Return the event number of the referenced GenEvent.

0 means the first GenEvent in the collection.

Definition at line 338 of file HepMcParticleLink.cxx.

339{
340 // dummy link
341 if (!m_ptr.isValid() && !m_store) {
343 }
344
345 index_type event_number, event_position;
346 m_extBarcode.eventIndex (event_number, event_position);
347 if (event_number == ExtendedBarCode::UNDEFINED) {
348 const HepMC::GenEvent* pEvt{};
349 IProxyDict* sg_nc ATLAS_THREAD_SAFE = m_store;
350 if (const McEventCollection* coll = retrieveMcEventCollection (sg_nc)) {
351 if (event_position < coll->size()) {
352 pEvt = coll->at (event_position);
353 }
354 if (pEvt) {
355 const int genEventNumber = pEvt->event_number();
356 // Be sure to update m_extBarcode before m_ptr.
357 // Otherwise, if two threads run this method simultaneously,
358 // one thread could see event_number == UNDEFINED, but where m_ptr
359 // is already updated so we get nullptr back for sg.
360 if (genEventNumber > -1) {
361 event_number = static_cast<index_type>(genEventNumber);
362 m_extBarcode.makeIndex (event_number, event_position);
363 return event_number;
364 }
365 if (barcode() != 0) {
367 if (pp) {
368 m_ptr.set (pp);
369 }
370 }
371 }
372 }
373 }
374 // Don't trip the assertion for a null link.
375 if ( m_extBarcode.linkIsNull() )
376 {
377 return (event_number != ExtendedBarCode::UNDEFINED) ? event_number : 0;
378 }
379 // Attempt to find the GenParticle
380 cptr();
381 // Check if event_number is valid once more
382 m_extBarcode.eventIndex (event_number, event_position);
383 assert (event_number != ExtendedBarCode::UNDEFINED);
384 return event_number;
385}
#define ATLAS_THREAD_SAFE

◆ find_proxy()

SG::DataProxy * HepMcParticleLink::find_proxy ( IProxyDict * sg)
staticprivate

Find the proxy for the target event collection.

Parameters
sgTarget event store. May return nullptr if the collection is not found.

Definition at line 532 of file HepMcParticleLink.cxx.

533{
535 unsigned int hint_orig = s_hint.load(std::memory_order_relaxed);
536 if (hint_orig >= std::size (s_keys)) hint_orig = 0;
537 unsigned int hint = hint_orig;
538
539 // Cache key -> sgkey translation.
540 using sgkey_array_t = std::array<SG::sgkey_t, std::size (s_keys)>;
541 static const sgkey_array_t s_sgkeys =
542 [&]() {
543 sgkey_array_t a;
544 for (size_t i = 0; i < std::size (s_keys); ++i)
545 a[i] = sg->stringToKey (s_keys[i], clid);
546 return a;
547 }();
548
549 do {
550 SG::DataProxy* proxy = sg->proxy (clid, s_keys[hint]);
551 if (!proxy) {
552 // try with input renamng.
553 SG::DataProxyHolder holder;
554 holder.toTransient (s_sgkeys[hint], sg, true);
555 proxy = holder.proxy();
556 }
557 if (proxy) {
558 if (hint != s_hint.load(std::memory_order_relaxed)) {
559 s_hint.store(hint, std::memory_order_relaxed);
560 }
561 static std::once_flag log_flag;
562 std::call_once(log_flag, [hint]() {
563 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
564 log << MSG::INFO << "find_proxy: Using " << s_keys[hint]
565 << " as McEventCollection key for this job " << endmsg;
566 });
567 return proxy;
568 }
569 ++hint;
570 if (hint >= std::size (s_keys)) hint = 0;
571 } while (hint != hint_orig);
572
573 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
574 static std::atomic<unsigned long> msgCount {0};
575 unsigned int count = ++msgCount;
576 if (count <= CPTRMAXMSGCOUNT) {
577 log << MSG::WARNING << "find_proxy: No Valid MC event Collection found "
578 << endmsg;
579 }
580 if (count == CPTRMAXMSGCOUNT) {
581 log << MSG::WARNING <<"find_proxy: suppressing further messages about valid MC event Collection. Use \n"
582 << " msgSvc.setVerbose += [HepMcParticleLink]\n"
583 << "to see all messages" << endmsg;
584 }
585 if (count > CPTRMAXMSGCOUNT) {
586 log << MSG::VERBOSE << "find_proxy: No Valid MC event Collection found "
587 << endmsg;
588 }
589 return nullptr;
590}
uint32_t CLID
The Class ID type.
static Double_t a
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const =0
Get proxy with given id and key.
virtual sgkey_t stringToKey(const std::string &str, CLID clid)=0
Find the key for a string/CLID pair.
void toTransient(sgkey_t sgkey, IProxyDict *sg=nullptr, bool noDummy=false)
Finish initialization after link has been read.
SG::DataProxy * proxy(bool nothrow=false) const
Return the DataProxy for this link.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32

◆ getEventNumberAtPosition() [1/2]

int HepMcParticleLink::getEventNumberAtPosition ( index_type position,
const EventContext & ctx )
static

Return the event number of the GenEvent at the specified position in the McEventCollection.

Parameters
positionin the McEventCollection
sgTarget event store. Returns -999 when position is larger than the McEventCollection size

Definition at line 468 of file HepMcParticleLink.cxx.

469{
471}

◆ getEventNumberAtPosition() [2/2]

int HepMcParticleLink::getEventNumberAtPosition ( index_type position,
IProxyDict * sg )
static

Return the event number of the GenEvent at the specified position in the McEventCollection.

Parameters
positionin the McEventCollection
sgTarget event store. Returns -999 when position is larger than the McEventCollection size

Definition at line 449 of file HepMcParticleLink.cxx.

450{
451 if (const McEventCollection* coll = retrieveMcEventCollection (sg)) {
452 if (position < coll->size()) {
453 return coll->at (position)->event_number();
454 }
455 }
456#if 0
457 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
458 log << MSG::WARNING << "getEventNumberAtPosition: position = " << position << ", McEventCollection size = "<< coll->size() << endmsg;
459#endif
460 return -999;
461}

◆ getEventPositionInCollection() [1/3]

HepMcParticleLink::index_type HepMcParticleLink::getEventPositionInCollection ( const EventContext & ctx) const

Return the position in the McEventCollection of the GenEvent pointed to by this HepMcParticleLink.

Return the position in the McEventCollection of the (first) GenEvent with a given event number.

Parameters
sgTarget event context. FIXME - need to be able to flag when no event with the appropriate event_number was found.

Definition at line 414 of file HepMcParticleLink.cxx.

415{
416 IProxyDict* sg = Atlas::proxyDictFromEventContext (ctx);
418}

◆ getEventPositionInCollection() [2/3]

std::vector< HepMcParticleLink::index_type > HepMcParticleLink::getEventPositionInCollection ( index_type index,
IProxyDict * sg )
static

Return a vector of the positions in the McEventCollection of the GenEvent(s) with a given event number.

Return the position in the McEventCollection of the (first) GenEvent with a given event number.

Parameters
indexthe event number of the required GenEvent
sgTarget event store. Returns a vector containing only ExtendedBarCode::UNDEFINED FIXME when no event with the appropriate event_number was found. (Multiple entries in the vector is technically a bug, but can't be fixed until the HepMC3 migration.)

Definition at line 426 of file HepMcParticleLink.cxx.

427{
428 std::vector<index_type> positions; positions.reserve(1);
429 const int int_event_number = static_cast<int>(event_number);
430 if (const McEventCollection* coll = retrieveMcEventCollection (sg)) {
431 size_t sz = coll->size();
432 for (size_t i = 0; i < sz; i++) {
433 if ((*coll)[i]->event_number() == int_event_number) {
434 positions.push_back(i);
435 }
436 }
437 }
438 if (positions.empty() ) {
439 positions.push_back(ExtendedBarCode::UNDEFINED);
440 }
441 return positions;
442}
static Double_t sz

◆ getEventPositionInCollection() [3/3]

HepMcParticleLink::index_type HepMcParticleLink::getEventPositionInCollection ( IProxyDict * sg) const

Return the position in the McEventCollection of the GenEvent pointed to by this HepMcParticleLink.

Return the position in the McEventCollection of the (first) GenEvent with a given event number.

Parameters
sgTarget event store. FIXME - need to be able to flag when no event with the appropriate event_number was found.

Definition at line 393 of file HepMcParticleLink.cxx.

394{
395 index_type event_number, position;
396 m_extBarcode.eventIndex (event_number, position);
397 if (position != ExtendedBarCode::UNDEFINED) {
398 return position;
399 }
400 if (event_number == 0) {
401 return 0;
402 }
403
404 std::vector<index_type> positions = getEventPositionInCollection(event_number, sg);
405 return positions[0];
406}

◆ getLastEventCollectionName()

std::string HepMcParticleLink::getLastEventCollectionName ( )
staticprivate

Return the most recent SG key used for a particular collection type.

Definition at line 596 of file HepMcParticleLink.cxx.

597{
598 static const std::string unset = "CollectionNotSet";
599 unsigned idx = s_hint;
600 if (idx < std::size (s_keys)) {
601 return s_keys[idx];
602 }
603 return unset;
604}

◆ getRedirectedLink()

HepMcParticleLink HepMcParticleLink::getRedirectedLink ( const HepMcParticleLink & particleLink,
uint32_t eventIndex,
const EventContext & ctx )
static

Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.

Parameters
particleLinkthe current HepMcParticleLink
eventIndexthe event number (unless zero) of the GenEvent which the redirected HepMcParticleLink should point at

Definition at line 481 of file HepMcParticleLink.cxx.

482{
483 const HepMcParticleLink::PositionFlag idxFlag =
485 // Support reading in legacy barcode-based persistent EDM for now
486 const int uniqueID =
487 (particleLink.barcode() != 0) ? particleLink.barcode() : particleLink.id();
488 const HepMcParticleLink::UniqueIDFlag uidFlag =
490 HepMcParticleLink redirectedLink(uniqueID, eventIndex, idxFlag, uidFlag, ctx);
491 redirectedLink.setTruthSuppressionType(particleLink.getTruthSuppressionType());
492 return redirectedLink;
493}

◆ getTruthSuppressionType()

EBC_SUPPRESSED_TRUTH HepMcParticleLink::getTruthSuppressionType ( ) const

Return whether the truth particle has been suppressed, as an enum.

◆ getTruthSuppressionTypeAsChar()

char HepMcParticleLink::getTruthSuppressionTypeAsChar ( ) const

Return whether the truth particle has been suppressed, as a char ('a'..'b').

◆ id()

int HepMcParticleLink::id ( ) const

Return the id of the target particle.

Return the id of the referenced GenParticle.

0 for a null link.

Definition at line 284 of file HepMcParticleLink.cxx.

285{
286 // if m_BC is zero (delta rays), then just return that same for barcode and id
287 if (m_extBarcode.uid()) {
288 // dummy link
289 if (!m_ptr.isValid() && !m_store) {
290 return 0; // TODO Decide if this is a good default - constant from MagicNumbers.h instead?
291 }
292
293 barcode_type particle_id, particle_barcode;
294 m_extBarcode.uniqueID (particle_id, particle_barcode);
295 if (particle_id == ExtendedBarCode::UNDEFINEDBC) {
296 (void) cptr(); // FIXME be careful to avoid an infinite loop of calls here
297 m_extBarcode.uniqueID (particle_id, particle_barcode);
298 }
299 if (particle_id != ExtendedBarCode::UNDEFINEDBC) {
300 return particle_id;
301 }
302 }
303 return 0;
304}

◆ isValid()

bool HepMcParticleLink::isValid ( ) const

Validity check.

Dereference and check for null.

◆ linkIsNull()

bool HepMcParticleLink::linkIsNull ( ) const

return true if neither barcode nor id are valid

Definition at line 170 of file HepMcParticleLink.cxx.

170 {
171 return m_extBarcode.linkIsNull();
172}

◆ operator bool()

HepMcParticleLink::operator bool ( ) const

Validity check.

Dereference and check for null.

◆ operator HepMC::ConstGenParticlePtr()

HepMcParticleLink::operator HepMC::ConstGenParticlePtr ( ) const

Dereference.

◆ operator!()

bool HepMcParticleLink::operator! ( ) const

Validity check.

Dereference and check for null.

◆ operator!=()

Inequality comparison.

◆ operator*()

const HepMC::GenParticle & HepMcParticleLink::operator* ( ) const

Dereference.

◆ operator->()

HepMC::ConstGenParticlePtr HepMcParticleLink::operator-> ( ) const

Dereference.

◆ operator<()

bool HepMcParticleLink::operator< ( const HepMcParticleLink & rhs) const

Ordering comparison.

◆ operator=() [1/2]

HepMcParticleLink & HepMcParticleLink::operator= ( const HepMcParticleLink & rhs)
default

Assignment.

◆ operator=() [2/2]

HepMcParticleLink & HepMcParticleLink::operator= ( HepMcParticleLink && rhs)
default

Move Assignment.

◆ operator==()

bool HepMcParticleLink::operator== ( const HepMcParticleLink & rhs) const

Equality comparison.

◆ retrieveMcEventCollection()

const McEventCollection * HepMcParticleLink::retrieveMcEventCollection ( IProxyDict * sg)
staticprivate

Look up the event collection we're targeting.

Parameters
sgTarget event store. May return nullptr if the collection is not found.

Definition at line 513 of file HepMcParticleLink.cxx.

514{
515 const McEventCollection* pEvtColl = nullptr;
516 SG::DataProxy* proxy = find_proxy (sg);
517 if (proxy) {
518 pEvtColl = SG::DataProxy_cast<McEventCollection> (proxy);
519 if (!pEvtColl) {
520 MsgStream log (Athena::getMessageSvc(), "HepMcParticleLink");
521 log << MSG::WARNING << "cptr: McEventCollection not found" << endmsg;
522 }
523 }
524 return pEvtColl;
525}
DATA * DataProxy_cast(DataProxy *proxy)
cast the proxy into the concrete data object it proxies

◆ scptr()

HepMC::ConstGenParticlePtr HepMcParticleLink::scptr ( ) const
inline

Dereference/smart pointer.

Definition at line 491 of file HepMcParticleLink.h.

491{ return cptr(); }

◆ setExtendedBarCode()

void HepMcParticleLink::setExtendedBarCode ( const ExtendedBarCode & extBarcode)

Alter the persistent part of the link.

Definition at line 499 of file HepMcParticleLink.cxx.

500{
501 m_extBarcode = extBarcode;
503 m_ptr.reset();
504}

◆ setTruthSuppressionType()

void HepMcParticleLink::setTruthSuppressionType ( EBC_SUPPRESSED_TRUTH truthSupp)

Return whether the truth particle has been suppressed.

◆ operator<< [1/2]

MsgStream & operator<< ( MsgStream & os,
const HepMcParticleLink & link )
friend

Output operator.

Parameters
osMsgStream to which to output.
linkLink to dump.

Definition at line 625 of file HepMcParticleLink.cxx.

627{
628 link.m_extBarcode.print(os);
629 return os;
630}
pointer & link(pointer p) const
Return a reference to the link for an element.

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream & os,
const HepMcParticleLink & link )
friend

Output operator.

Parameters
osStream to which to output.
linkLink to dump.

Definition at line 612 of file HepMcParticleLink.cxx.

614{
615 link.m_extBarcode.print(os);
616 return os;
617}

Member Data Documentation

◆ m_extBarcode

ExtendedBarCode HepMcParticleLink::m_extBarcode
private

Persistent part: barcode and location of target GenEvent.

Definition at line 699 of file HepMcParticleLink.h.

◆ m_ptr

Transient part. Pointer to the particle.

Definition at line 695 of file HepMcParticleLink.h.

◆ m_store

IProxyDict* HepMcParticleLink::m_store
private

Pointer to the store containing the event.

Definition at line 687 of file HepMcParticleLink.h.


The documentation for this class was generated from the following files: