ATLAS Offline Software
Loading...
Searching...
No Matches
L1BunchGroupSet.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 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 for( auto & train : getList("bcids") ) {
30 size_t first = train.getAttribute<size_t>("first");
31 size_t length = train.getAttribute<size_t>("length");
32 m_bunchdef.emplace_back(first,length);
33 }
34}
35
36size_t
38 size_t nb = 0;
39 for ( const auto & train : m_bunchdef ) {
40 nb += train.second;
41 }
42 return nb;
43}
44
45bool
47 for ( const auto & train : m_bunchdef ) {
48 if( bcid >= train.first and bcid < train.first+train.second ) {
49 return true;
50 }
51 }
52 return false;
53}
54
55std::vector<uint16_t>
57{
58 std::vector<uint16_t> bunches;
59 bunches.reserve(size());
60 for (const auto &train : m_bunchdef)
61 {
62 // trains are pairs (first bunch crossing id, number of bunchcrossings)
63 for (uint16_t i = 0; i < train.second; ++i)
64 {
65 bunches.push_back(train.first + i);
66 }
67 }
68 return bunches;
69}
70
71
72/*****************************************
73
74 L1BunchGroupSet
75
76*****************************************/
77
78
82
83TrigConf::L1BunchGroupSet::L1BunchGroupSet( const boost::property_tree::ptree & data )
85{
86 load();
87}
88
91
92void
94{
95 if(! isInitialized() || empty() ) {
96 return;
97 }
98 m_name = getAttribute("name", true, m_name);
99 m_bunchGroups.resize(s_maxBunchGroups, std::shared_ptr<L1BunchGroup>(nullptr));
100 for( auto & bg : data().get_child("bunchGroups") ) {
101 auto bg_sptr = std::make_shared<L1BunchGroup>(bg.second);
102 m_bunchGroupsByName.emplace( std::piecewise_construct,
103 std::forward_as_tuple(bg.first),
104 std::forward_as_tuple(bg_sptr->id()) );
105 m_bunchGroups[bg_sptr->id()] = bg_sptr;
106 }
107}
108
109void
111{
112 m_bgsk = 0;
113 m_bunchGroupsByName.clear();
114 m_bunchGroups.clear();
115}
116
117const std::shared_ptr<TrigConf::L1BunchGroup> &
120}
121
122const std::shared_ptr<TrigConf::L1BunchGroup> &
124 return m_bunchGroups[id];
125}
126
127std::size_t
129 return std::count_if(m_bunchGroups.begin(), m_bunchGroups.end(), [](const auto &bg){return bg!=nullptr;});
130}
131
132std::size_t
134 return std::count_if(m_bunchGroups.begin(), m_bunchGroups.end(), [](const auto &bg){return bg->size()!=0;});
135}
136
139 // sanity check that we have enough bits in bgPattern_t for all bunchgroups
140 static_assert(sizeof(bgPattern_t)*8 >= s_maxBunchGroups);
141
142 bgPattern_t p{0};
143 for (size_t i = 0; i < s_maxBunchGroups; ++i) {
144 if (m_bunchGroups[i] && m_bunchGroups[i]->contains(bcid)) p += (1 << i);
145 }
146 return p;
147}
148
149void
151 std::cout << "Name '" << name() << "'" << std::endl;
152 std::cout << "Number of non-empty bunchgroups: " << sizeNonEmpty() << std::endl;
153 if(detailed) {
154 for( const auto & bg : m_bunchGroups ) {
155 if (bg) {
156 std::cout << " " << bg->name() << " (id " << bg->id() << ") has " << bg->size() << " bunches" << std::endl;
157 }
158 }
159 } else {
160 const auto & paired = getBunchGroup(1);
161 if (paired) {
162 std::cout << "Bunchgroup " << paired->name() << " has " << paired->size() << " bunches" << std::endl;
163 }
164 }
165}
double length(const pvec &v)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
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:114