ATLAS Offline Software
Loading...
Searching...
No Matches
Barcode.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4/* Author: Andrii Verbytskyi andrii.verbytskyi@mpp.mpg.de */
5
6#ifndef ATLASHEPMC_BARCODE_H
7#define ATLASHEPMC_BARCODE_H
8#include <type_traits>
9#ifdef HEPMC3
10#include "HepMC3/GenParticle.h"
11#include "HepMC3/GenVertex.h"
12#include "HepMC3/GenEvent.h"
13#endif
14namespace HepMC {
15template <class T>
16inline int barcode(const T* p){ return p->barcode(); }
17inline int barcode(int p){ return p; }
18#ifdef HEPMC3
19template <class T, std::enable_if_t< !std::is_pointer<T>::value &&
20 !std::is_same<T, HepMC3::GenParticlePtr>::value &&
21 !std::is_same<T, HepMC3::ConstGenParticlePtr>::value &&
22 !std::is_same<T, HepMC3::GenVertexPtr>::value &&
23 !std::is_same<T, HepMC3::ConstGenVertexPtr>::value &&
24 !std::is_same<T, HepMC3::GenVertex>::value &&
25 !std::is_same<T, HepMC3::GenParticle>::value &&
26 !std::is_same<T, int>::value
27 , bool > = true>
28inline int barcode(const T& p){ return p.barcode();}
29
30template <class T, std::enable_if_t<
31 std::is_same<T, HepMC3::GenParticlePtr>::value ||
32 std::is_same<T, HepMC3::ConstGenParticlePtr>::value ||
33 std::is_same<T, HepMC3::GenVertexPtr>::value ||
34 std::is_same<T, HepMC3::ConstGenVertexPtr>::value
35 , bool > = true >
36inline int barcode(const T& p) {
37 if (!p) return 0;
38 const HepMC3::GenEvent* e = p->parent_event();
39 if (!e) return 0;
40 std::shared_ptr<HepMC3::IntAttribute> barcode = e->attribute<HepMC3::IntAttribute>("barcode", p->id());
41 return barcode ? (barcode->value()) : p->id();
42}
43
44template <class T, std::enable_if_t<
45 std::is_same<T, HepMC3::GenParticle>::value ||
46 std::is_same<T, HepMC3::GenVertex>::value
47 , bool > = true >
48inline int barcode(const T& p) {
49 const HepMC3::GenEvent* e = p.parent_event();
50 if (!e) return 0;
51 std::shared_ptr<HepMC3::IntAttribute> barcode = e->attribute<HepMC3::IntAttribute>("barcode", p.id());
52 return barcode?(barcode->value()):p.id();
53}
54#else
55template <class T, std::enable_if_t<!std::is_pointer<T>::value &&
56 !std::is_same<T,int>::value
57 , bool> = true> inline int barcode(const T& p){ return p.barcode();}
58#endif
59
60}
61#endif
int barcode(const T *p)
Definition Barcode.h:16
unsigned long long T