ATLAS Offline Software
Loading...
Searching...
No Matches
TrigConfBunchCrossingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// STL include(s):
7#include <algorithm>
8#include <vector>
9
10// Gaudi include(s):
11#ifndef XAOD_STANDALONE
12# include "GaudiKernel/IIncidentSvc.h"
13#endif // not XAOD_STANDALONE
14
15// Trigger config include(s):
18
19// Local include(s):
21
22namespace {
23
24 template< typename T >
25 MsgStream& operator<< ( MsgStream& out, const std::vector< T >& vec ) {
26
27 out << "[";
28 for( size_t i = 0; i < vec.size(); ++i ) {
29 out << vec[ i ];
30 if( i < vec.size() - 1 ) {
31 out << ", ";
32 }
33 }
34 out << "]";
35
36 // Return the stream:
37 return out;
38 }
39
40} // private namespace
41
42namespace Trig {
43
44 TrigConfBunchCrossingTool::
45 TrigConfBunchCrossingTool( const std::string& name )
46 : BunchCrossingToolBase( name ), m_bgId( -1 ),
47#ifndef XAOD_STANDALONE
48 m_configSvc( "TrigConf::xAODConfigSvc/xAODConfigSvc", name ),
49#endif // not XAOD_STANDALONE
50 m_configTool( "TrigConf::xAODConfigTool" ) {
51
52 // Declare the properties of the tool:
53#ifndef XAOD_STANDALONE
54 declareProperty( "ConfigSvc", m_configSvc );
55#endif // not XAOD_STANDALONE
56 declareProperty( "ConfigTool", m_configTool=nullptr );
57 }
58
60
61 // Reset he bunch group ID, so at the next update we definitely
62 // load a new configuration:
63 m_bgId = -1;
64
65 // Report about the initialization:
66 ATH_MSG_INFO( "Initializing TrigConfBunchCrossingTool" );
67 ATH_MSG_INFO( " Maximal bunch spacing: " << m_maxBunchSpacing << " ns" );
68 ATH_MSG_INFO( " Length of train front: " << m_frontLength << " ns" );
69 ATH_MSG_INFO( " Length of train tail : " << m_tailLength << " ns" );
70#ifndef XAOD_STANDALONE
71 ATH_MSG_DEBUG( " LVL1 config service : " << m_configSvc );
72#endif // XAOD_STANDALONE
73 ATH_MSG_DEBUG( " Trig config tool : " << m_configTool );
74
75 // Retrieve the trigger configuration service/tool:
76#ifndef XAOD_STANDALONE
77 if (!m_configTool.empty()) {
78 ATH_MSG_DEBUG( " xAODConfigTool is set - will read from xAOD metadata" );
79 ATH_CHECK( m_configTool.retrieve() );
80 } else {
81 ATH_MSG_DEBUG( " xAODConfigTool is not set - will read from xAODConfigSvc" );
82 ATH_CHECK( m_configSvc.retrieve() );
83 }
84#else
85 ATH_CHECK( m_configTool.retrieve() );
86#endif // not XAOD_STANDALONE
87
88 // Return gracefully:
89 return StatusCode::SUCCESS;
90 }
91
93
94 // Simply call the function doing the heavy lifting:
96
97 // Return gracefully:
98 return StatusCode::SUCCESS;
99 }
100
107
108 return static_cast< configid_type >( m_bgId );
109 }
110
120 std::vector< float >
122
123 return std::vector< float >();
124 }
125
135 std::vector< float >
137
138 return std::vector< float >();
139 }
140
150 std::vector< float >
152
153 return std::vector< float >();
154 }
155
165 std::vector< float >
167
168 return std::vector< float >();
169 }
170
185
186 // Decide where to take the configuration from:
187 TrigConf::IILVL1ConfigSvc* configSvc = 0;
188#ifndef XAOD_STANDALONE
189 if (m_configTool.isSet()) {
190 configSvc = m_configTool.operator->();
191 } else {
192 configSvc = m_configSvc.operator->();
193 }
194#else
195 configSvc = m_configTool.operator->();
196#endif // not XAOD_STANDALONE
197
198 // Check if the needed info is even there:
199 if( ! configSvc->bunchGroupSet() ) {
200 ATH_MSG_FATAL( "Trigger configuration service doesn't provide "
201 "BunchGroupSet information" );
202 return StatusCode::FAILURE;
203 }
204
205 // Check if we already have the correct configuration:
206 if( configSvc->bunchGroupSet()->id() == m_bgId ) {
207 return StatusCode::SUCCESS;
208 }
209
210 // Report to the user what we're doing:
211 ATH_MSG_INFO( "Updating tool configuration to BGKey #"
212 << configSvc->bunchGroupSet()->id() );
213
214 // Print the configuration for debugging purposes, and remember which one
215 // we're processing:
216 m_bgId = configSvc->bunchGroupSet()->id();
217 printBunchGroups( configSvc );
218
219 //
220 // Select the collision bunch group:
221 //
222 const std::vector< TrigConf::BunchGroup >& bgs =
223 configSvc->bunchGroupSet()->bunchGroups();
224 std::vector< TrigConf::BunchGroup >::const_iterator filled_bg =
225 bgs.begin();
226 ++filled_bg;
227 ATH_MSG_INFO( "Taking the second bunch group as the colliding bunch "
228 "group" );
229
230 //
231 // Now interpret the information:
232 //
233 ATH_CHECK( loadSingleBunches( filled_bg->bunches() ) );
234 ATH_CHECK( loadBunchTrains( filled_bg->bunches() ) );
235
236 //
237 // Select the unpaired bunches. The overlaps are taken care of by the
238 // base tool.
239 //
240 std::vector< int > unpaired;
241 // These are the "unpaired isolated" bunches:
242 if( bgs.size() > 4 ) {
243 unpaired.insert( unpaired.end(), bgs[ 4 ].bunches().begin(),
244 bgs[ 4 ].bunches().end() );
245 }
246 // These are the "unpaired non-isolated" bunches:
247 if( bgs.size() > 5 ) {
248 unpaired.insert( unpaired.end(), bgs[ 5 ].bunches().begin(),
249 bgs[ 5 ].bunches().end() );
250 }
251
252 //
253 // Now interpret the information:
254 //
255 ATH_CHECK( loadUnpairedBunches( unpaired, unpaired ) );
256
257 // Print the configuration to give some feedback to the user:
258 printConfig();
259
260#ifndef XAOD_STANDALONE
261 // Let everybody know that the configuration of the tool has changed:
262 ServiceHandle< IIncidentSvc > incidentSvc( "IncidentSvc", name() );
263 ATH_CHECK( incidentSvc.retrieve() );
264 incidentSvc->fireIncident( Incident( "BunchConfiguration update",
266#endif // not XAOD_STANDALONE
267
268 // Return gracefully:
269 return StatusCode::SUCCESS;
270 }
271
276 void TrigConfBunchCrossingTool::
277 printBunchGroups( const TrigConf::IILVL1ConfigSvc* svc ) const {
278
279 // Skip the rest if nothing will be printed anyway:
280 if( ! msgLvl( MSG::VERBOSE ) ) return;
281
282 // Print the information:
283 ATH_MSG_VERBOSE( "Printing BunchGroup configuration:" );
284 for( const auto& bg : svc->bunchGroupSet()->bunchGroups() ) {
285 ATH_MSG_VERBOSE( " BG \"" << bg.name() << "\": " << bg.bunches() );
286 }
287
288 // Return gracefully:
289 return;
290 }
291
292} // namespace Trig
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
bool msgLvl(const MSG::Level lvl) const
const std::vector< BunchGroup > & bunchGroups() const
Interface for all services/tools that provide LVL1 menu configuration information.
virtual const BunchGroupSet * bunchGroupSet() const =0
Provides the LVL1 bunch group set.
unsigned int id() const
static const std::string BUNCH_CONFIG_INCIDENT_NAME
Type name for the incident that such tools should emit.
Base class for all BunchCrossingTool implementations.
StatusCode loadBunchTrains(const std::vector< int > &bunches, const std::vector< float > &bunch_int1=std::vector< float >(), const std::vector< float > &bunch_int2=std::vector< float >())
Interpret the configuration for bunch trains.
StatusCode loadSingleBunches(const std::vector< int > &bunches, const std::vector< float > &bunch_int1=std::vector< float >(), const std::vector< float > &bunch_int2=std::vector< float >())
Interpret the configuration for single bunches.
void printConfig() const
Function printing the configuration of the tool.
int m_maxBunchSpacing
The maximum bunch spacing that the tool should consider.
int m_frontLength
Length of the "front" of a bunch train.
StatusCode loadUnpairedBunches(const std::vector< int > &beam1, const std::vector< int > &beam2, const std::vector< float > &bunch_int1=std::vector< float >(), const std::vector< float > &bunch_int2=std::vector< float >())
Interpret the configuration for unpaired bunches.
int m_tailLength
Length of the "tail" of a bunch train.
unsigned int configid_type
Declare the interface that this class provides.
virtual std::vector< float > configuredUnpairedIntensitiesBeam1() const
Override the default implementation because this tool doesn't provide this info.
void printBunchGroups(const TrigConf::IILVL1ConfigSvc *svc) const
Print the "raw" configuration for debugging.
unsigned int m_bgId
DB ID of the BunchGroups settings which was loaded last.
StatusCode loadConfig()
Make sure that the latest/correct configuration is loaded.
virtual std::vector< float > configuredIntensitiesBeam1() const
Override the default implementation because this tool doesn't provide this info.
virtual configid_type configID() const
Unique identifier for the current configuration.
virtual std::vector< float > configuredIntensitiesBeam2() const
Override the default implementation because this tool doesn't provide this info.
ServiceHandle< TrigConf::ILVL1ConfigSvc > m_configSvc
The config service handle.
virtual StatusCode beginEvent()
Function called when a new event is loaded.
virtual std::vector< float > configuredUnpairedIntensitiesBeam2() const
Override the default implementation because this tool doesn't provide this info.
ToolHandle< TrigConf::ITrigConfigTool > m_configTool
The config tool handle.
virtual ASG_TOOL_CLASS2(TrigConfBunchCrossingTool, Trig::IBunchCrossingTool, Trig::IBunchCrossingConfProvider) public StatusCode initialize()
Create a proper constructor for Athena.
The common trigger namespace for trigger analysis tools.