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#include "HepMC3/GenParticle.h"
10#include "HepMC3/GenVertex.h"
11#include "HepMC3/GenEvent.h"
13namespace HepMC {
14template <class T>
15inline int barcode(const T* p){ return p->barcode(); }
16inline int barcode(int p){ return p; }
17template <class T, std::enable_if_t< !std::is_pointer<T>::value &&
18 !std::is_same<T, HepMC3::GenParticlePtr>::value &&
19 !std::is_same<T, HepMC3::ConstGenParticlePtr>::value &&
20 !std::is_same<T, HepMC3::GenVertexPtr>::value &&
21 !std::is_same<T, HepMC3::ConstGenVertexPtr>::value &&
22 !std::is_same<T, HepMC3::GenVertex>::value &&
23 !std::is_same<T, HepMC3::GenParticle>::value &&
24 !std::is_same<T, int>::value
25 , bool > = true>
26inline int barcode(const T& p){ return p.barcode();}
27
28template <class T, std::enable_if_t<
29 std::is_same<T, HepMC3::GenParticlePtr>::value ||
30 std::is_same<T, HepMC3::ConstGenParticlePtr>::value ||
31 std::is_same<T, HepMC3::GenVertexPtr>::value ||
32 std::is_same<T, HepMC3::ConstGenVertexPtr>::value
33 , bool > = true >
34inline int barcode(const T& p) {
35 if (!p) return 0;
36 const HepMC3::GenEvent* e = p->parent_event();
37 if (!e) return 0;
38 std::shared_ptr<HepMC3::IntAttribute> barcode = e->attribute<HepMC3::IntAttribute>(HepMCStr::barcode, p->id());
39 return barcode ? (barcode->value()) : p->id();
40}
41
42template <class T, std::enable_if_t<
43 std::is_same<T, HepMC3::GenParticle>::value ||
44 std::is_same<T, HepMC3::GenVertex>::value
45 , bool > = true >
46inline int barcode(const T& p) {
47 const HepMC3::GenEvent* e = p.parent_event();
48 if (!e) return 0;
49 std::shared_ptr<HepMC3::IntAttribute> barcode = e->attribute<HepMC3::IntAttribute>(HepMCStr::barcode, p.id());
50 return barcode ? (barcode->value()) : p.id();
51}
52
53}
54#endif
const std::string barcode
int barcode(const T *p)
Definition Barcode.h:15