Skip to content
Snippets Groups Projects
Commit 052caa3b authored by Tim Martin's avatar Tim Martin
Browse files

New xaod trigger decision maker for run 3

Former-commit-id: dc9939e5
parent df24d984
No related branches found
No related tags found
No related merge requests found
......@@ -10,19 +10,22 @@ atlas_depends_on_subdirs( PRIVATE
Control/AthenaBaseComps
Control/StoreGate
Event/EventInfo
Event/xAOD/xAODEventInfo
Event/xAOD/xAODTrigger
GaudiKernel
Trigger/TrigConfiguration/TrigConfInterfaces
Trigger/TrigConfiguration/TrigConfL1Data
Trigger/TrigEvent/TrigDecisionEvent
Trigger/TrigEvent/TrigSteeringEvent
Trigger/TrigSteer/TrigSteering
Trigger/TrigSteer/DecisionHandling
Trigger/TrigT1/TrigT1Result )
# Component(s) in the package:
atlas_add_component( TrigDecisionMaker
src/*.cxx
src/components/*.cxx
LINK_LIBRARIES AthenaBaseComps StoreGateLib SGtests EventInfo GaudiKernel TrigConfL1Data TrigDecisionEvent TrigSteeringEvent TrigSteeringLib TrigT1Result )
LINK_LIBRARIES AthenaBaseComps DecisionHandling StoreGateLib SGtests EventInfo xAODEventInfo GaudiKernel TrigConfL1Data TrigDecisionEvent TrigSteeringEvent TrigSteeringLib TrigT1Result xAODTrigger )
# Install files from the package:
atlas_install_python_modules( python/__init__.py python/TrigDecisionMakerConfig.py )
......
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
from TrigDecisionMaker.TrigDecisionMakerConf import TrigDec__TrigDecisionMaker
from TrigDecisionMaker.TrigDecisionMakerConf import TrigDec__TrigDecisionMakerMT
#from TrigDecisionMaker.TrigDecisionMakerConf import TrigDec__TrigDecisionTest
from AthenaCommon.AppMgr import ToolSvc
......@@ -19,8 +20,18 @@ class TrigDecisionMaker( TrigDec__TrigDecisionMaker ):
#handle.OutputLevel = DEBUG
#return
class TrigDecisionMakerMT( TrigDec__TrigDecisionMakerMT ):
__slots__ = []
def __init__(self, name = "TrigDecMakerMT"):
super( TrigDecisionMakerMT, self ).__init__( name )
from AthenaCommon.Logging import logging # loads logger
log = logging.getLogger( name )
def setDefaults(self, handle):
pass
# Following not yet ported to the AthenaMT / Run 3 alg
class TrigDecisionStream ( object) :
def __init__ ( self, streamName = "Stream1", fileName = "HLT.root",
......
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
/**************************************************************************
**
** File: TrigDecisionMakerMT.h
**
** Description: - Re-entrant Algorithm-derived class to run after the MT Trigger to create the
** xAOD::TrigDecision object. Based on TrigDecisionMaker.cxx
**
* @author Tim Martin <Tim.Martin@cern.ch> - University of Warwick
**
** Created: 16 July 2018
**
**************************************************************************/
#include "TrigDecisionMakerMT.h"
#include "TrigSteeringEvent/Lvl1Result.h"
#include "TrigSteering/Lvl1ResultAccessTool.h"
#include "xAODTrigger/TrigDecisionAuxInfo.h"
#include "TrigConfInterfaces/ITrigConfigSvc.h"
#include "TrigConfL1Data/BunchGroupSet.h"
#include "GaudiKernel/Incident.h"
using namespace TrigDec;
TrigDecisionMakerMT::TrigDecisionMakerMT(const std::string &name, ISvcLocator *pSvcLocator)
: ::AthReentrantAlgorithm(name, pSvcLocator),
m_trigConfigSvc("TrigConf::TrigConfigSvc/TrigConfigSvc", name),
m_lvl1Tool("HLT::Lvl1ResultAccessTool/Lvl1ResultAccessTool", this)
{}
TrigDecisionMakerMT::~TrigDecisionMakerMT() {}
StatusCode TrigDecisionMakerMT::initialize()
{
ATH_CHECK( m_HLTSummaryKeyIn.initialize() );
ATH_CHECK( m_ROIBResultKeyIn.initialize() );
ATH_CHECK( m_EventInfoKeyIn.initialize() );
ATH_CHECK( m_L1ResultKeyIn.initialize() );
renounce(m_L1ResultKeyIn); // This is an optional input. We can re-create it via m_ROIBResultKeyIn
ATH_CHECK( m_trigDecisionKeyOut.initialize() );
ATH_CHECK( m_lvl1Tool.retrieve() );
ATH_CHECK( m_trigConfigSvc.retrieve() );
return StatusCode::SUCCESS;
}
StatusCode TrigDecisionMakerMT::finalize()
{
// print out stats: used also to do regression tests
ATH_MSG_DEBUG ("=============================================");
ATH_MSG_DEBUG ("REGTEST Run summary:");
ATH_MSG_DEBUG ("REGTEST Events processed : " << m_nEvents);
ATH_MSG_DEBUG ("REGTEST Level 1 : passed = " << m_l1Passed);
ATH_MSG_DEBUG ("REGTEST HLT : passed = " << m_hltPassed);
ATH_MSG_DEBUG ("=============================================");
return StatusCode::SUCCESS;
}
StatusCode TrigDecisionMakerMT::execute_r(const EventContext& context) const
{
// increment event counter
m_nEvents++;
// Retrieve the results
const LVL1CTP::Lvl1Result* l1Result = nullptr;
if (m_doL1) {
ATH_CHECK(getL1Result(l1Result, context));
if (l1Result->isAccepted()) ++m_l1Passed;
}
const TrigCompositeUtils::DecisionContainer* hltResult = nullptr;
if (m_doHLT) ATH_CHECK(getHLTResult(hltResult, context));
std::unique_ptr<xAOD::TrigDecision> trigDec = std::make_unique<xAOD::TrigDecision>();
std::unique_ptr<xAOD::TrigDecisionAuxInfo> trigDecAux = std::make_unique<xAOD::TrigDecisionAuxInfo>();
trigDec->setStore(trigDecAux.get());
trigDec->setSMK( m_trigConfigSvc->masterKey() );
if (l1Result) {
trigDec->setTAV(l1Result->itemsAfterVeto());
trigDec->setTAP(l1Result->itemsAfterPrescale());
trigDec->setTBP(l1Result->itemsBeforePrescale());
}
if (hltResult) {
ATH_MSG_DEBUG("Got a DecisionContainer '" << m_HLTSummaryKeyIn.key() << "' of size " << hltResult->size());
TrigCompositeUtils::DecisionIDContainer allPassedSet;
// Expect only one object in this container, but allow many.
// Accumulate in a set to preserve ordering and remove any duplicates
for (const TrigCompositeUtils::Decision* decisionObject : *hltResult) {
// Collect all decisions (IDs of passed chains) from decisionObject into allPassedSet
TrigCompositeUtils::decisionIDs(decisionObject, allPassedSet);
}
if (allPassedSet.size()) ++m_hltPassed;
std::vector<TrigCompositeUtils::DecisionID> toRecordPassed;
std::copy(allPassedSet.begin(), allPassedSet.end(), std::back_inserter(toRecordPassed));
trigDec->setChainMTPassedRaw(toRecordPassed);
}
// TODO prescaled
// TODO resurrected
// get the bunch crossing id
auto eventInfoHandle = SG::makeHandle(m_EventInfoKeyIn, context);
if (!eventInfoHandle.isValid()) {
ATH_MSG_ERROR("Cannot read " << m_EventInfoKeyIn.key());
return StatusCode::FAILURE;
}
const xAOD::EventInfo* eventInfo = eventInfoHandle.get();
const char bgByte = getBGByte(eventInfo->bcid());
trigDec->setBGCode(bgByte);
ATH_MSG_DEBUG ( "Run '" << eventInfo->runNumber()
<< "'; Event '" << eventInfo->eventNumber()
<< "'; BCID '" << eventInfo->bcid()
<< "'; BG Code '" << (size_t)bgByte << "'" ) ;
ATH_MSG_DEBUG ("Decision object dump: " << *(trigDec.get()));
auto trigDecWriteHandle = SG::makeHandle( m_trigDecisionKeyOut, context );
ATH_CHECK( trigDecWriteHandle.record( std::move( trigDec ), std::move( trigDecAux ) ) );
ATH_MSG_DEBUG ("Recorded xAOD::TrigDecision to StoreGate with key = " << m_trigDecisionKeyOut.key());
return StatusCode::SUCCESS;
}
StatusCode TrigDecisionMakerMT::getL1Result(const LVL1CTP::Lvl1Result*& result, const EventContext& context) const
{
auto l1ResultHandle = SG::makeHandle(m_L1ResultKeyIn, context);
auto roibResultHandle = SG::makeHandle(m_ROIBResultKeyIn, context);
if (!roibResultHandle.isValid() && !l1ResultHandle.isValid()) {
ATH_MSG_ERROR("Cannot read " << m_ROIBResultKeyIn.key() << " or " << m_ROIBResultKeyIn.key());
return StatusCode::FAILURE;
}
// Prefer to remake from RoIB Result
if (roibResultHandle.isValid()) {
const ROIB::RoIBResult* roIBResult = roibResultHandle.get();
ATH_CHECK(m_lvl1Tool->updateItemsConfigOnly());
if (roIBResult && (roIBResult->cTPResult()).isComplete()) {
m_lvl1Tool->createL1Items(*roIBResult, true);
result = m_lvl1Tool->getLvl1Result();
ATH_MSG_DEBUG ( "Build LVL1CTP::Lvl1Result from valid CTPResult.");
} else {
ATH_MSG_DEBUG ( "No LVL1CTP::Lvl1Result built since no valid CTPResult is available.");
}
}
if (result == nullptr && roibResultHandle.isValid()) {
ATH_MSG_DEBUG("Cannot read " << m_ROIBResultKeyIn.key() << " Fall back to Lvl1Result");
result = l1ResultHandle.get();
}
return StatusCode::SUCCESS;
}
StatusCode TrigDecisionMakerMT::getHLTResult(const TrigCompositeUtils::DecisionContainer*& result, const EventContext& context) const
{
auto hltResultHandle = SG::makeHandle(m_HLTSummaryKeyIn, context);
if (!hltResultHandle.isValid()) {
ATH_MSG_ERROR("Cannot read " << m_HLTSummaryKeyIn.key());
return StatusCode::FAILURE;
}
result = hltResultHandle.get();
return StatusCode::SUCCESS;
}
char TrigDecisionMakerMT::getBGByte(int BCId) const {
const TrigConf::BunchGroupSet* bgs = m_trigConfigSvc->bunchGroupSet();
if(!bgs) {
ATH_MSG_WARNING ("Could not get BunchGroupSet to calculate BGByte");
return 0;
}
if((unsigned int)BCId >= bgs->bgPattern().size()) {
ATH_MSG_WARNING ("Could not return BGCode for BCid " << BCId << ", since size of BGpattern is " << bgs->bgPattern().size() ) ;
return 0;
}
return bgs->bgPattern()[BCId];
}
// -*- C++ -*-
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
/**************************************************************************
**
** File: TrigDecisionMakerMT.h
**
** Description: - Re-entrant algorithm-derived class to run after the Steering
** - Finds the list of defined chains at initialization
** - For each event:
** * Creates a xAODTriggerDecision object
** * Fills it with the outcome of each defined chain
** * Output to StoreGate via writehandle written to ESD/AOD
**
* @author Tim Martin <Tim.Martin@cern.ch> - University of Warwick
**
** Created: 16 July 2018
**
**************************************************************************/
#ifndef TrigDecisionMaker_TrigDecisionMakerMT_H
#define TrigDecisionMaker_TrigDecisionMakerMT_H
// Base class
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
#include "GaudiKernel/ServiceHandle.h"
#include "xAODEventInfo/EventInfo.h"
// trigger/configuration stuff
#include "xAODTrigger/TrigCompositeContainer.h"
#include "xAODTrigger/TrigDecision.h"
#include "DecisionHandling/TrigCompositeUtils.h"
#include "TrigT1Result/RoIBResult.h"
// containers
#include <vector>
#include <string>
#include <map>
namespace HLT {
class ILvl1ResultAccessTool;
}
namespace LVL1CTP {
class Lvl1Result;
}
namespace TrigConf {
class ITrigConfigSvc;
}
namespace TrigDec {
/**
* @class TrigDecisionMakerMT
* - Re-entrant algorithm-derived class to run after the MT Trigger
* - Finds the list of defined chains at initialization
* - For each event:
* * Creates a xAODTriggerDecision object
* * Fills it with the outcome of each defined chain & L1 data
* * Output to StoreGate via writehandle written to ESD/AOD
* * Based on TrigDecisionMaker.h
*
* @author Tim Martin <Tim.Martin@cern.ch> - University of Warwick
*/
class TrigDecisionMakerMT : public ::AthReentrantAlgorithm
{
public:
TrigDecisionMakerMT(const std::string &name, ISvcLocator *pSvcLocator); //!< std Gaudi Algorithm constructor
~TrigDecisionMakerMT(); //!< std deconstructor
// IAlgorithm virtual methods to implement
virtual StatusCode initialize() override; //!< std Gaudi initialize method -> read-in trigger configuration
virtual StatusCode execute_r( const EventContext& context ) const override; //!< Re-entrant execute to create the xAOD::TrigDecision
virtual StatusCode finalize() override; //!< std Gaudi finalize method -> print out statistics
StatusCode getL1Result (const LVL1CTP::Lvl1Result*& result, const EventContext& context) const; //!< retrieve LVL1 result (called in execute)
StatusCode getHLTResult(const TrigCompositeUtils::DecisionContainer*& result, const EventContext& context) const; //!< retrieve HLT results (called in execute)
char getBGByte(int BCId) const; //!< to get the BG byte encoded for a given BC
private:
Gaudi::Property<bool> m_doL1{this, "doL1", true, "Read L1 trigger information"};
Gaudi::Property<bool> m_doHLT{this, "doHLT", true, "Read HLT trigger information"};
// Tools & services
ServiceHandle<TrigConf::ITrigConfigSvc> m_trigConfigSvc; //!< handle to the full (L1 & HLT) trigger config service
ToolHandle<HLT::ILvl1ResultAccessTool> m_lvl1Tool; //!< tool to ease the access to the L1 results (RoIs, items, etc)
// Input keys configuration
SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> m_HLTSummaryKeyIn {this, "HLTSummary", "HLTSummary", "HLT summary container Key"};
SG::ReadHandleKey<LVL1CTP::Lvl1Result> m_L1ResultKeyIn {this, "Lvl1Result", "Lvl1Result", "Lvl1 Result Object Key"};
SG::ReadHandleKey<ROIB::RoIBResult> m_ROIBResultKeyIn {this, "RoIBResult", "RoIBResult", "RoIB Result Object Key"};
SG::ReadHandleKey<xAOD::EventInfo> m_EventInfoKeyIn {this, "EventInfo", "EventInfo", "Event Info Object Key"};
// Output configuration
SG::WriteHandleKey<xAOD::TrigDecision> m_trigDecisionKeyOut {this, "TrigDecisionKey", "xTrigDecision", "Output trigger decision object key"};
// For statistics
mutable std::atomic<uint32_t> m_nEvents{0}, m_l1Passed{0}, m_hltPassed{0};
};
}
#endif
#include "../TrigDecisionMaker.h"
#include "../TrigDecisionMakerMT.h"
//#include "TrigDecisionMaker/TrigDecisionTest.h"
DECLARE_COMPONENT( TrigDec::TrigDecisionMaker )
DECLARE_COMPONENT( TrigDec::TrigDecisionMakerMT )
//DECLARE_COMPONENT( TrigDec::TrigDecisionTest )
......@@ -17,4 +17,14 @@ checker.dumpTrigCompositeContainers = [ "FilteredEMRoIDecisions", "L2CaloLi
"JRoIDecisions", "MonitoringSummaryStep1", "RerunEMRoIDecisions", "RerunMURoIDecisions", "TAURoIDecisions", "EMRoIDecisions" ]
from AthenaCommon.AppMgr import topSequence
# At runtime it claims it currently does not need this but it's wrong
from xAODEventInfoCnv.xAODEventInfoCreator import xAODMaker__EventInfoCnvAlg
topSequence+=xAODMaker__EventInfoCnvAlg()
topSequence += checker
# Note that for now this needs to come after the checker.doDumpTrigCompsiteNavigation has force-retrieved all the TrigComposite collections from storegate
from TrigDecisionMaker.TrigDecisionMakerConfig import TrigDecisionMakerMT
topSequence+=TrigDecisionMakerMT()
topSequence.TrigDecMakerMT.OutputLevel = DEBUG
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment