18#include "GaudiKernel/MsgStream.h"
30constexpr int NKEYS = 5;
32std::string s_keys[NKEYS] = {
"TruthEvent",
"G4Truth",
"GEN_AOD",
"GEN_EVENT",
"Bkg_TruthEvent"};
42std::atomic<unsigned> s_hint = std::size (s_keys);
45const unsigned short CPTRMAXMSGCOUNT = 100;
62 static const char codes[
EBC_NSUPP] = {
'a',
'b'};
64 return codes[suppEnum];
80 log << MSG::ERROR <<
" Wrong truth Suppression Char (" << std::string(&suppChar,1) <<
") set in HepMcParticleLink ExtendedBarCode object !!!" <<
endmsg;
91 os <<
"Event index " ;
95 os << position <<
" (position in collection) ";
98 os << event_number <<
" (event number) ";
100 os <<
", Unique ID " ;
102 uniqueID (particle_id, particle_barcode);
103 if (particle_barcode == 0 && particle_id == 0) {
104 os <<
" 0 (id/barcode) ";
107 os << particle_barcode <<
" (barcode) ";
110 os << particle_id <<
" (id) ";
112 os <<
", McEventCollection "
122 std::ostringstream
ss;
154 if (part !=
nullptr && positionFlag ==
IS_POSITION) {
161 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
181 const bool is_valid =
m_ptr.isValid();
192 <<
"cptr: no truth particle associated with this hit (barcode==0)."
193 <<
" Probably this is a noise hit" <<
endmsg;
205 if (event_number == 0) {
206 pEvt = pEvtColl->at(0);
209 if (position < pEvtColl->
size()) {
210 pEvt = pEvtColl->at (position);
215 log << MSG::WARNING <<
"cptr: position = " << position <<
", McEventCollection size = "<< pEvtColl->size() <<
endmsg;
221 pEvt = pEvtColl->find (event_number);
224 if (
nullptr != pEvt) {
228 m_extBarcode.makeIndex (pEvt->event_number(), position);
230 if (event_number == 0) {
231 m_extBarcode.makeIndex (pEvt->event_number(), position);
241 if (genParticleID > -1) {
251 const auto &particles = pEvt->particles();
252 if (particle_id-1 < particles.size()) {
265 <<
"cptr: Mc Truth not stored for event at " << position
269 <<
"cptr: Mc Truth not stored for event with event number " << event_number
275 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
318 return int(particle_barcode);
351 if (event_position < coll->
size()) {
352 pEvt = coll->at (event_position);
355 const int genEventNumber = pEvt->event_number();
360 if (genEventNumber > -1) {
361 event_number =
static_cast<index_type>(genEventNumber);
400 if (event_number == 0) {
425std::vector<HepMcParticleLink::index_type>
428 std::vector<index_type> positions; positions.reserve(1);
429 const int int_event_number =
static_cast<int>(event_number);
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);
438 if (positions.empty() ) {
452 if (position < coll->
size()) {
453 return coll->at (position)->event_number();
458 log << MSG::WARNING <<
"getEventNumberAtPosition: position = " << position <<
", McEventCollection size = "<< coll->size() <<
endmsg;
492 return redirectedLink;
521 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
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;
540 using sgkey_array_t = std::array<
SG::sgkey_t, std::size (s_keys)>;
541 static const sgkey_array_t s_sgkeys =
544 for (
size_t i = 0; i < std::size (s_keys); ++i)
555 proxy = holder.
proxy();
558 if (hint != s_hint.load(std::memory_order_relaxed)) {
559 s_hint.store(hint, std::memory_order_relaxed);
561 static std::once_flag log_flag;
562 std::call_once(log_flag, [hint]() {
564 log << MSG::INFO <<
"find_proxy: Using " << s_keys[hint]
565 <<
" as McEventCollection key for this job " <<
endmsg;
570 if (hint >= std::size (s_keys)) hint = 0;
571 }
while (hint != hint_orig);
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 "
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;
585 if (
count > CPTRMAXMSGCOUNT) {
586 log << MSG::VERBOSE <<
"find_proxy: No Valid MC event Collection found "
598 static const std::string unset =
"CollectionNotSet";
599 unsigned idx = s_hint;
600 if (idx < std::size (s_keys)) {
615 link.m_extBarcode.print(os);
628 link.m_extBarcode.print(os);
uint32_t CLID
The Class ID type.
std::ostream & operator<<(std::ostream &os, const HepMcParticleLink &link)
Output operator.
size_t size() const
Number of registered mappings.
void print(char *figname, TCanvas *c1)
#define ATLAS_THREAD_SAFE
Persistent representation of a link.
void print(std::ostream &os) const
Dump in textual format to a stream.
static char truthSuppressionTypeAsChar(EBC_SUPPRESSED_TRUTH suppEnum)
Translate truth suppression enum to a char ('a'..'b').
static EBC_SUPPRESSED_TRUTH truthSuppressionTypeFromChar(char suppChar)
Translate truth suppression char ('a'..'b') to an enum.
static constexpr index_type UNDEFINED
All 1's. Used to represent an undefined index/position.
void uniqueID(barcode_type &id, barcode_type &barcode) const
Return the GenParticle id/barcode.
static constexpr barcode_type UNDEFINEDBC
EBC_SUPPRESSED_TRUTH getTruthSuppressionType() const
Return whether the truth particle has been suppressed, as an enum.
void setExtendedBarCode(const ExtendedBarCode &extBarcode)
Alter the persistent part of the link.
int id() const
Return the id of the target particle.
bool linkIsNull() const
return true if neither barcode nor id are valid
static SG::DataProxy * find_proxy(IProxyDict *sg)
Find the proxy for the target event collection.
static int getEventNumberAtPosition(index_type position, IProxyDict *sg)
Return the event number of the GenEvent at the specified position in the McEventCollection.
static const McEventCollection * retrieveMcEventCollection(IProxyDict *sg)
Look up the event collection we're targeting.
HepMC::ConstGenParticlePtr cptr() const
Dereference.
HepMcParticleLink(IProxyDict *sg=nullptr)
Default constructor.
ExtendedBarCode m_extBarcode
Persistent part: barcode and location of target GenEvent.
static std::string getLastEventCollectionName()
Return the most recent SG key used for a particular collection type.
index_type eventIndex() const
Return the event number of the referenced GenEvent.
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.
int barcode() const
Return the barcode of the target particle.
IProxyDict * m_store
Pointer to the store containing the event.
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 numbe...
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.
ATH_NO_UNIQUE_ADDRESS CxxUtils::CachedValue< HepMC::ConstGenParticlePtr > m_ptr
Transient part. Pointer to the particle.
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.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Manage DataProxy reference in ElementLink/DataLink.
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.
singleton-like access to IMessageSvc via open function and helper
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
IMessageSvc * getMessageSvc(bool quiet=false)
IProxyDict * proxyDictFromEventContext()
Return the IProxyDict for this thread's current context.
ConstGenParticlePtr barcode_to_particle(const GenEvent *e, int id)
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
HepMC3::GenEvent GenEvent
DATA * DataProxy_cast(DataProxy *proxy)
cast the proxy into the concrete data object it proxies
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Some out-of-line helpers for ExtendedEventContext.
static constexpr CLID ID()