ATLAS Offline Software
Loading...
Searching...
No Matches
L1BunchGroupSet.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9/*****************************************
10
11 L1BunchGroup
12
13*****************************************/
14
15TrigConf::L1BunchGroup::L1BunchGroup( const boost::property_tree::ptree & data )
17{
18 load();
19}
20
21void
23{
24 if(! isInitialized() || empty() ) {
25 return;
26 }
27 m_name = getAttribute("name", true, m_name);
29 const std::string firstStr{"first"};
30 const std::string lengthStr{"length"};
31 for( auto & train : getList("bcids") ) {
32 size_t first = train.getAttribute<size_t>(firstStr);
33 size_t length = train.getAttribute<size_t>(lengthStr);
34 m_bunchdef.emplace_back(first,length);
35 }
36}
37
38size_t
40 size_t nb = 0;
41 for ( const auto & train : m_bunchdef ) {
42 nb += train.second;
43 }
44 return nb;
45}
46
47bool
49 for ( const auto & train : m_bunchdef ) {
50 if( bcid >= train.first and bcid < train.first+train.second ) {
51 return true;
52 }
53 }
54 return false;
55}
56
57std::vector<uint16_t>
59{
60 std::vector<uint16_t> bunches;
61 bunches.reserve(size());
62 for (const auto &train : m_bunchdef)
63 {
64 // trains are pairs (first bunch crossing id, number of bunchcrossings)
65 for (uint16_t i = 0; i < train.second; ++i)
66 {
67 bunches.push_back(train.first + i);
68 }
69 }
70 return bunches;
71}
72
73
74/*****************************************
75
76 L1BunchGroupSet
77
78*****************************************/
79
80
84
85TrigConf::L1BunchGroupSet::L1BunchGroupSet( const boost::property_tree::ptree & data )
87{
88 load();
89}
90
93
94void
96{
97 if(! isInitialized() || empty() ) {
98 return;
99 }
100 m_name = getAttribute("name", true, m_name);
101 m_bunchGroups.resize(s_maxBunchGroups, std::shared_ptr<L1BunchGroup>(nullptr));
102 for( auto & bg : data().get_child("bunchGroups") ) {
103 auto bg_sptr = std::make_shared<L1BunchGroup>(bg.second);
104 m_bunchGroupsByName.emplace( std::piecewise_construct,
105 std::forward_as_tuple(bg.first),
106 std::forward_as_tuple(bg_sptr->id()) );
107 m_bunchGroups[bg_sptr->id()] = bg_sptr;
108 }
109}
110
111void
113{
114 m_bgsk = 0;
115 m_bunchGroupsByName.clear();
116 m_bunchGroups.clear();
117}
118
119const std::shared_ptr<TrigConf::L1BunchGroup> &
122}
123
124const std::shared_ptr<TrigConf::L1BunchGroup> &
126 return m_bunchGroups[id];
127}
128
129std::size_t
131 return std::count_if(m_bunchGroups.begin(), m_bunchGroups.end(), [](const auto &bg){return bg!=nullptr;});
132}
133
134std::size_t
136 return std::count_if(m_bunchGroups.begin(), m_bunchGroups.end(), [](const auto &bg){return bg->size()!=0;});
137}
138
141 // sanity check that we have enough bits in bgPattern_t for all bunchgroups
142 static_assert(sizeof(bgPattern_t)*8 >= s_maxBunchGroups);
143
144 bgPattern_t p{0};
145 for (size_t i = 0; i < s_maxBunchGroups; ++i) {
146 if (m_bunchGroups[i] && m_bunchGroups[i]->contains(bcid)) p += (1 << i);
147 }
148 return p;
149}
150
151void
153 std::cout << "Name '" << name() << "'" << std::endl;
154 std::cout << "Number of non-empty bunchgroups: " << sizeNonEmpty() << std::endl;
155 if(detailed) {
156 for( const auto & bg : m_bunchGroups ) {
157 if (bg) {
158 std::cout << " " << bg->name() << " (id " << bg->id() << ") has " << bg->size() << " bunches" << std::endl;
159 }
160 }
161 } else {
162 const auto & paired = getBunchGroup(1);
163 if (paired) {
164 std::cout << "Bunchgroup " << paired->name() << " has " << paired->size() << " bunches" << std::endl;
165 }
166 }
167}
double length(const pvec &v)
size_t size() const
Number of registered mappings.
static const Attributes_t empty
virtual const std::string & name() const final
std::vector< DataStructure > getList(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to array structure.
const ptree & data() const
Access to the underlying data, if needed.
DataStructure()
Default constructor, leading to an uninitialized configuration object.
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
std::vector< std::shared_ptr< L1BunchGroup > > m_bunchGroups
vector of size 16 (L1BunchGroup::s_maxBunchGroups
static const size_t s_maxBunchGroups
Hardware limit for number of bunch group.
std::map< std::string, size_t > m_bunchGroupsByName
maps bgrp name (BGRP0, BGRP1,...) to bunchgroup
bgPattern_t bgPattern(size_t bcid) const
Return word with bit-pattern of fired bunchgroups for given bcid.
std::size_t size() const
Accessor to the number of defined bunchgroups.
const std::shared_ptr< L1BunchGroup > & getBunchGroup(const std::string &name) const
Accessor to the bunchgroup by name.
unsigned int m_bgsk
the bunch group key
virtual void clear() override
Clearing the configuration data.
uint16_t bgPattern_t
type for bunchgroup pattern bitset
virtual ~L1BunchGroupSet()
Destructor.
std::size_t sizeNonEmpty() const
Accessor to the number of non-empty bunchgroups.
void printSummary(bool detailed=false) const
print a more or less detailed summary
bool contains(size_t bcid) const
check if bunchgroup contains a certain bunch
std::vector< std::pair< size_t, size_t > > m_bunchdef
std::size_t size() const
Accessor to the number of bunches.
L1BunchGroup()
Constructor.
std::vector< uint16_t > bunches() const
list of all bunches
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116