ATLAS Offline Software
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 
22 namespace {
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 
42 namespace 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 
92  StatusCode TrigConfBunchCrossingTool::beginEvent() {
93 
94  // Simply call the function doing the heavy lifting:
95  ATH_CHECK( loadConfig() );
96 
97  // Return gracefully:
98  return StatusCode::SUCCESS;
99  }
100 
106  TrigConfBunchCrossingTool::configID() const {
107 
108  return static_cast< configid_type >( m_bgId );
109  }
110 
120  std::vector< float >
121  TrigConfBunchCrossingTool::configuredIntensitiesBeam1() const {
122 
123  return std::vector< float >();
124  }
125 
135  std::vector< float >
136  TrigConfBunchCrossingTool::configuredIntensitiesBeam2() const {
137 
138  return std::vector< float >();
139  }
140 
150  std::vector< float >
151  TrigConfBunchCrossingTool::configuredUnpairedIntensitiesBeam1() const {
152 
153  return std::vector< float >();
154  }
155 
165  std::vector< float >
166  TrigConfBunchCrossingTool::configuredUnpairedIntensitiesBeam2() const {
167 
168  return std::vector< float >();
169  }
170 
184  StatusCode TrigConfBunchCrossingTool::loadConfig() {
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",
265  BUNCH_CONFIG_INCIDENT_NAME ) );
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
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
StandaloneBunchgroupHandler.bg
bg
Definition: StandaloneBunchgroupHandler.py:243
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trig
The common trigger namespace for trigger analysis tools.
Definition: CaloTowerVecMon.h:44
initialize
void initialize()
Definition: run_EoverP.cxx:894
TrigConf::IILVL1ConfigSvc
Interface for all services/tools that provide LVL1 menu configuration information.
Definition: IILVL1ConfigSvc.h:36
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
TrigConf::IILVL1ConfigSvc::bunchGroupSet
virtual const BunchGroupSet * bunchGroupSet() const =0
Provides the LVL1 bunch group set.
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trig::IBunchCrossingConfProvider::configid_type
unsigned int configid_type
Declare the interface that this class provides.
Definition: IBunchCrossingConfProvider.h:60
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
BunchGroup.h
TrigConf::BunchGroupSet::bunchGroups
const std::vector< BunchGroup > & bunchGroups() const
Definition: BunchGroupSet.h:27
BunchGroupSet.h
TrigConf::TrigConfData::id
unsigned int id() const
Definition: TrigConfData.h:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TrigConfBunchCrossingTool.h
operator<<
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Definition: TestGaudiProperty.cxx:69
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
ServiceHandle< IIncidentSvc >