Skip to content
Snippets Groups Projects
Commit 62624784 authored by Oleg Kuprash's avatar Oleg Kuprash
Browse files

Merge branch '22.0-adding-utilities-for-decision-handling' into 'master'

L1 result decoding in a new HLT MT approach

See merge request !1525
parents 2810a90d 709781a6
No related merge requests found
Showing
with 1017 additions and 15 deletions
################################################################################
# Package: DecisionHandling
################################################################################
# Declare the package name:
atlas_subdir( DecisionHandling )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Event/xAOD/xAODTrigger
# GaudiKernel
Control/AthContainers
Control/AthLinks
PRIVATE
#Control/AthViews
# Control/StoreGate
#Control/AthenaBaseComps
# Control/CxxUtils
Trigger/TrigConfiguration/TrigConfHLTData
#Trigger/TrigEvent/TrigSteeringEvent
#Trigger/TrigSteer/L1Decoder
AtlasTest/TestTools
Control/StoreGate
)
atlas_add_library( DecisionHandlingLib
src/*.cxx
PUBLIC_HEADERS DecisionHandling
LINK_LIBRARIES xAODTrigger GaudiKernel
PRIVATE_LINK_LIBRARIES AthenaBaseComps CxxUtils TrigConfHLTData )
# Component(s) in the package:
atlas_add_component( DecisionHandling
src/components/*.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES}
${ROOT_LIBRARIES} GaudiKernel AthViews AthenaBaseComps CxxUtils xAODTrigger DecisionHandlingLib
)
atlas_add_test( TrigCompositeUtils_test
SOURCES test/TrigCompositeUtils_test.cxx
LINK_LIBRARIES TestTools xAODTrigger DecisionHandlingLib
AthContainers )
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef DecisionHandling_HLTIdentifier_h
#define DecisionHandling_HLTIdentifier_h
#include <string>
#include <vector>
#include <set>
#include <map>
#include "GaudiKernel/MsgStream.h"
/*
@brief An trigger identifier class, used to provide mapping fromt the human readable IDs to efficienct unsigned ints
*/
namespace HLT {
class Identifier {
public:
/*
@brief disables reporting human readable names == no debugging, fast execution
*/
static void reportStringIDs(bool report) { s_reportStringIDs = report; }
static bool reportStringIDs() { return s_reportStringIDs; }
/*
@brief constructs identifier from human redable name
*/
Identifier(const std::string& stringID);
/*
@brief Construct wiht numeric ID
*/
Identifier(unsigned id) : m_id(id) {}
/*
@brief reports human redable name if it is enabled or, empty string
*/
std::string name() const;
/*
@brief numeric ID
*/
unsigned numeric() const { return m_id; }
/*
@brief comparisons, for containers
*/
bool operator == ( const Identifier& rhs ) const { return numeric() == rhs.numeric(); }
bool operator < ( const Identifier& rhs ) const { return numeric() < rhs.numeric(); }
private:
unsigned m_id;
static bool s_reportStringIDs;
};
typedef std::vector<HLT::Identifier> IDVec;
typedef std::set<HLT::Identifier> IDSet;
typedef std::map<HLT::Identifier, IDVec> IDtoIDVecMap;
}
MsgStream& operator<< ( MsgStream& m, const HLT::Identifier& id );
#endif // HLTIdentifier
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef DecisionHandling_TrigCompositeUtils_h
#define DecisionHandling_TrigCompositeUtils_h
#include <set>
#include <memory>
#include "GaudiKernel/EventContext.h"
#include "StoreGate/WriteHandleKey.h"
#include "StoreGate/ReadHandleKey.h"
#include "StoreGate/WriteHandle.h"
#include "StoreGate/ReadHandle.h"
#include "xAODTrigger/TrigCompositeContainer.h"
#include "xAODTrigger/TrigCompositeAuxContainer.h"
namespace TrigCompositeUtils {
// alias types, for readability and to simplify future evolution
typedef xAOD::TrigComposite Decision;
typedef xAOD::TrigCompositeContainer DecisionContainer;
typedef xAOD::TrigCompositeAuxContainer DecisionAuxContainer;
typedef SG::WriteHandle<DecisionContainer> DecisionWriteHandle;
/*
creates and right away stores the DecisionContainer under the key
*/
DecisionWriteHandle createAndStore(const SG::WriteHandleKey<DecisionContainer>& key, const EventContext& ctx);
/*
@brief helper method to that created the Decision objects, places it in the container and returns
This is to make this:
auto d = newDecisionIn(output);
instead of:
auto d = new Decision;
output->push_back(d);
*/
Decision* newDecisionIn (DecisionContainer* dc);
// aliases for the decision IDs, in fact this are just ints
typedef unsigned int DecisionID;
typedef std::set<DecisionID> DecisionIDContainer;
/*
@brief Appends the decision (given as ID) to the decision object
*/
void addDecisionID( DecisionID id, Decision* d);
/*
@brief Extracts DecisionIDs stored in the Decsion object
*/
void decisionIDs(const Decision* d, DecisionIDContainer& id );
/*
@brief Checks if any of the DecisionIDs passed in arg required is availble in Decision object
*/
bool passingIDs( const Decision* d, const DecisionIDContainer& required);
}
#endif // DecisionHandling_TrigCompositeUtils_h
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// DecisionHandling includes
#include "DecisionHandling/HLTIdentifier.h"
// FrameWork includes
#include "GaudiKernel/Property.h"
#include "DumpDecisions.h"
///////////////////////////////////////////////////////////////////
// Public methods:
///////////////////////////////////////////////////////////////////
// Constructors
////////////////
DumpDecisions::DumpDecisions( const std::string& name,
ISvcLocator* pSvcLocator )
: AthReentrantAlgorithm( name, pSvcLocator )
{
declareProperty( "Decisions", m_decisionKey, "Input Decisions" );
declareProperty( "VerbosityLevel", m_verbosityLevel, "3 - tries to print as much possible, 2 - only list of objects and their decisions, 1 - only list of active objets");
}
// Destructor
///////////////
DumpDecisions::~DumpDecisions()
{}
// Athena Algorithm's Hooks
////////////////////////////
StatusCode DumpDecisions::initialize()
{
ATH_MSG_INFO ("Initializing " << name() << "...");
CHECK( m_decisionKey.initialize() );
return StatusCode::SUCCESS;
}
StatusCode DumpDecisions::finalize() {
ATH_MSG_INFO ("Finalizing " << name() << "...");
return StatusCode::SUCCESS;
}
StatusCode DumpDecisions:: execute_r( const EventContext& ctx ) const {
using namespace TrigCompositeUtils;
// DecisionInput decisionInput;
auto decisionInput = SG::makeHandle(m_decisionKey, ctx);
// CHECK( decisionInput.retrieve() );
// CHECK ( decisionInput.retrieve( m_decisionKey, ctx) );
ATH_MSG_DEBUG( "Retrieved decision with the key " << m_decisionKey.key() );
ATH_MSG_DEBUG( "Pointer value " << decisionInput.cptr() );
for ( auto d: *decisionInput ) {
DecisionIDContainer ids;
TrigCompositeUtils::decisionIDs( d, ids );
ATH_MSG_DEBUG( "Decision object with " << ids.size() << " decisions" );
if ( m_verbosityLevel >= 2 ) {
for ( auto id: ids ) {
ATH_MSG_DEBUG( "Passing decision " << HLT::Identifier(id) );
}
}
}
return StatusCode::SUCCESS;
}
///////////////////////////////////////////////////////////////////
// Const methods:
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Non-const methods:
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Protected methods:
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Const methods:
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// Non-const methods:
///////////////////////////////////////////////////////////////////
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef DECISIONHANDLING_DUMPDECISIONS_H
#define DECISIONHANDLING_DUMPDECISIONS_H 1
// STL includes
#include <string>
#include "DecisionHandling/TrigCompositeUtils.h"
// FrameWork includes
#include "AthenaBaseComps/AthReentrantAlgorithm.h"
class DumpDecisions
: public ::AthReentrantAlgorithm
{
///////////////////////////////////////////////////////////////////
// Public methods:
///////////////////////////////////////////////////////////////////
public:
// Copy constructor:
/// Constructor with parameters:
DumpDecisions( const std::string& name, ISvcLocator* pSvcLocator );
/// Destructor:
virtual ~DumpDecisions();
// Athena algorithm's Hooks
StatusCode initialize() override;
StatusCode execute_r( const EventContext& ctx ) const override;
StatusCode finalize() override;
private:
SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> m_decisionKey;
size_t m_verbosityLevel = 3; // see docu. of property
/// Default constructor:
DumpDecisions();
};
#endif //> !DECISIONHANDLING_DUMPDECISIONS_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrigConfHLTData/HLTUtils.h"
#include "DecisionHandling/HLTIdentifier.h"
using namespace HLT;
bool Identifier::s_reportStringIDs = true; // default for now
Identifier::Identifier(const std::string& stringID)
: m_id( TrigConf::HLTUtils::string2hash(stringID, "Identifier") ) {}
std::string Identifier::name() const {
if ( Identifier::reportStringIDs() ) {
return TrigConf::HLTUtils::hash2string(numeric(), "Identifier");
}
return "";
}
MsgStream& operator<< ( MsgStream& m, const HLT::Identifier& id ) {
if ( Identifier::reportStringIDs() ) {
m << id.name() << " ID#" << id.numeric();
} else {
m << "ID#" << id.numeric();
}
return m;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "StoreGate/WriteHandle.h"
#include "StoreGate/ReadHandle.h"
#include "AthContainers/AuxElement.h"
#include "DecisionHandling/TrigCompositeUtils.h"
static SG::AuxElement::Accessor< std::vector< int > > readWriteAccessor( "decisions" );
static SG::AuxElement::ConstAccessor< std::vector<int> > readOnlyAccessor( "decisions" );
namespace TrigCompositeUtils {
DecisionWriteHandle createAndStore(const SG::WriteHandleKey<DecisionContainer>& key, const EventContext& ctx) {
SG::WriteHandle<DecisionContainer> handle(key, ctx);
auto data = std::make_unique<DecisionContainer>() ;
auto aux = std::make_unique<DecisionAuxContainer>() ;
data->setStore(aux.get());
handle.record( std::move( data ), std::move( aux ) ).ignore();
return handle;
}
Decision* newDecisionIn (DecisionContainer* dc) {
Decision * x = new Decision;
dc->push_back( x );
readWriteAccessor( *x ).size(); // fake operation just to make the decsions decoration
return x;
}
void addDecisionID( DecisionID id, Decision* d) {
readWriteAccessor( *d ).push_back( id );
}
void decisionIDs( const Decision* d, DecisionIDContainer& destination ) {
const std::vector<int>& decisions = readOnlyAccessor( *d );
destination.insert( decisions.begin(), decisions.end() );
}
bool passingIDs( const Decision* d, const DecisionIDContainer& required ) {
for ( auto id : readOnlyAccessor( *d ) ) {
if ( required.count( id ) > 0 )
return true;
}
return false;
}
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "../DumpDecisions.h"
DECLARE_ALGORITHM_FACTORY( DumpDecisions )
DECLARE_FACTORY_ENTRIES( DumpDecisions )
{
DECLARE_ALGORITHM( DumpDecisions )
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "GaudiKernel/LoadFactoryEntries.h"
LOAD_FACTORY_ENTRIES( DecisionHandling )
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include <iostream>
//#include "TestTools/expect.h"
#include "DecisionHandling/TrigCompositeUtils.h"
#include "xAODTrigger/TrigCompositeAuxContainer.h"
int main() {
using namespace TrigCompositeUtils;
auto dc = std::make_unique<DecisionContainer>();
auto decisionAux = std::make_unique<DecisionAuxContainer>();
dc->setStore(decisionAux.get());
// try insertions
auto d1 = newDecisionIn(dc.get());
addDecisionID( 1, d1 );
addDecisionID( 2, d1 );
auto d2 = newDecisionIn(dc.get());
addDecisionID( 1, d2 );
addDecisionID( 3, d2 );
DecisionIDContainer ids;
decisionIDs(d1, ids);
for (auto id: ids)
std::cout << id << " from d1\n";
decisionIDs(d2, ids);
for (auto id: ids)
std::cout << id << " from d1 and d2\n";
ids.clear();
ids.insert(3);
ids.insert(7);
const DecisionIDContainer& cids = ids;
{
bool yn = passingIDs(d1, cids);
std::cout << " 3 or 7 contained in d1 " << (yn ? "YES" : "NO") << std::endl;
}
{
bool yn = passingIDs(d2, cids);
std::cout << " 3 or 7 contained in d2 " << (yn ? "YES" : "NO") << std::endl;
}
return 0;
}
......@@ -22,7 +22,8 @@ atlas_depends_on_subdirs( PUBLIC
Trigger/TrigEvent/TrigSteeringEvent
Trigger/TrigT1/TrigT1Interfaces
Trigger/TrigT1/TrigT1Result
Trigger/TrigMonitoring/TrigMonitorBase )
Trigger/TrigMonitoring/TrigMonitorBase
Trigger/TrigSteer/DecisionHandling )
# External dependencies:
find_package( Boost COMPONENTS filesystem thread system )
......@@ -33,13 +34,22 @@ atlas_add_library( L1DecoderLib
src/*.cxx
PUBLIC_HEADERS L1Decoder
INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} GaudiKernel AthViews AthenaBaseComps CxxUtils xAODTrigger TrigConfHLTData TrigConfL1Data TrigSteeringEvent TrigT1Interfaces TrigT1Result TrigMonitorBaseLib
LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES}
GaudiKernel AthViews AthenaBaseComps CxxUtils
xAODTrigger TrigConfHLTData TrigConfL1Data
TrigSteeringEvent TrigT1Interfaces TrigT1Result
TrigMonitorBaseLib DecisionHandlingLib
)
atlas_add_component( L1Decoder
src/components/*.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} GaudiKernel AthViews AthenaBaseComps CxxUtils xAODTrigger TrigConfHLTData TrigConfL1Data TrigSteeringEvent TrigT1Interfaces TrigT1Result L1DecoderLib
LINK_LIBRARIES ${Boost_LIBRARIES}
${ROOT_LIBRARIES} GaudiKernel AthViews
AthenaBaseComps CxxUtils xAODTrigger
TrigConfHLTData TrigConfL1Data TrigSteeringEvent
TrigT1Interfaces TrigT1Result
L1DecoderLib
)
# Install files from the package:
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef L1Decoder_TrigIdentifiers_h
#define L1Decoder_TrigIdentifiers_h
......
......@@ -5,7 +5,10 @@
#
# get_files LVL1config_Physics_pp_v5.xml
# ln -s /afs/cern.ch/atlas/project/trigger/pesa-sw/validation/atn-test/data15_13TeV.00266904.physics_EnhancedBias.merge.RAW._lb0452._SFO-1._0001.1 input.data
#
# exact config for this data is: https://atlas-trigconf.cern.ch/run2/smkey/2142/l1key/1077/hltkey/765/
import os.path
assert os.path.isfile('input.data'), 'No input file: see the JO to see how to get it'
## @file L1Topo_ReadBS_test.py
## @brief Example job options file to read BS file to test a converter
......@@ -80,18 +83,45 @@ if nThreads >= 1:
topSequence += SGInputLoader( OutputLevel=INFO, ShowEventDump=False )
topSequence.SGInputLoader.Load = [ ('ROIB::RoIBResult','RoIBResult') ]
from L1Decoder.L1DecoderConf import CTPUnpackingTool, EMRoIsUnpackingTool, L1Decoder, MURoIsUnpackingTool
l1Decoder = L1Decoder( OutputLevel=DEBUG )
l1Decoder.ctpUnpacker = CTPUnpackingTool( OutputLevel = DEBUG, ForceEnableAllChains=True )
l1Decoder.ctpUnpacker.CTPToChainMapping = ["0:HLT_e3", "0:HLT_g5", "1:HLT_e7", "15:HLT_mu6", "33:HLT_2mu6", "15:HLT_mu6idperf", "42:HLT_e15mu4"] # this are real IDs of L1_* items in pp_v5 menu
emUnpacker = EMRoIsUnpackingTool( OutputLevel=DEBUG )
emUnpacker.ThresholdToChainMapping = ["EM3 : HLT_e3", "EM3 : HLT_g5", "EM7 : HLT_e7", "EM15 : HLT_e15mu4" ]
muUnpacker = MURoIsUnpackingTool( OutputLevel=DEBUG )
muUnpacker.ThresholdToChainMapping = ["MU6 : HLT_mu6", "MU6 : HLT_mu6idperf", "MU4 : HLT_e15mu4"]
# do not know yet how to configure the services for it
l1Decoder.roiUnpackers = [emUnpacker]
l1Decoder.Chains="HLTChainsResult"
topSequence += l1Decoder
#Run calo decoder
from L1Decoder.L1DecoderConf import L1CaloDecoder
caloDecoder = L1CaloDecoder() # by default it is steered towards the RoIBResult of the name above
caloDecoder.OutputLevel=VERBOSE
topSequence += caloDecoder
#Dumper
from ViewAlgs.ViewAlgsConf import DumpDecisions
dumper = DumpDecisions("L1CaloDecisions")
dumper.OutputLevel=VERBOSE
topSequence += dumper
from DecisionHandling.DecisionHandlingConf import DumpDecisions
emDecisionsDumper = DumpDecisions("DumpEML1RoIs", OutputLevel=DEBUG)
emDecisionsDumper.Decisions = "EMRoIDecisions"
topSequence += emDecisionsDumper
chainSeedingDumper = DumpDecisions("ChainSeedingDumper", OutputLevel=DEBUG)
chainSeedingDumper.Decisions = "HLTChainsResult"
topSequence += chainSeedingDumper
# caloDecoder = L1CaloDecoder() # by default it is steered towards the RoIBResult of the name above
# caloDecoder.OutputLevel=VERBOSE
# topSequence += caloDecoder
# #Dumper
# from ViewAlgs.ViewAlgsConf import DumpDecisions
# dumper = DumpDecisions("L1CaloDecisions")
# dumper.OutputLevel=VERBOSE
# topSequence += dumper
#--------------------------------------------------------------
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "DecisionHandling/HLTIdentifier.h"
#include "TrigT1Result/RoIBResult.h"
#include "CTPUnpackingTool.h"
using namespace HLT;
CTPUnpackingTool::CTPUnpackingTool( const std::string& type,
const std::string& name,
const IInterface* parent )
: AthAlgTool(type, name, parent) {
declareProperty("CTPToChainMapping", m_ctpToChainProperty, "Mapping of the form: '34:HLT_x', '35:HLT_y', ..., both CTP ID and chain may appear many times");
declareProperty("ForceEnableAllChains", m_forceEnable=false, "Enables all chains in each event, testing mode");
}
CTPUnpackingTool::~CTPUnpackingTool()
{}
StatusCode CTPUnpackingTool::decodeCTPToChainMapping() {
std::istringstream input;
for ( auto entry: m_ctpToChainProperty ) {
input.clear();
input.str(entry);
size_t ctpId;
input >> ctpId;
char delim;
input >> delim;
if ( delim != ':' ) {
ATH_MSG_ERROR( "Error in conf. entry: " << entry << " missing ':'" );
return StatusCode::FAILURE;
}
std::string chainName;
input >> chainName;
ATH_MSG_DEBUG( "Chain " << chainName << " seeded from CTP item of ID " << ctpId );
m_ctpToChain[ctpId].push_back( HLT::Identifier(chainName) );
}
return StatusCode::SUCCESS;
}
StatusCode CTPUnpackingTool::decode( const ROIB::RoIBResult& roib, HLT::IDVec& enabledChains ) const {
size_t numberPfActivatedBits= 0;
auto tav = roib.cTPResult().TAV();
const size_t tavSize = tav.size();
for ( size_t wordCounter = 0; wordCounter < tavSize; ++wordCounter ) {
for ( size_t bitCounter = 0; bitCounter < 32; ++bitCounter ) {
const size_t ctpIndex = 32*wordCounter + bitCounter;
const bool decision = ( tav[wordCounter].roIWord() & (1 << bitCounter) ) > 0;
if ( decision == true or m_forceEnable ) {
if ( decision )
ATH_MSG_DEBUG( "L1 item " << ctpIndex << " active, enabling chains");
numberPfActivatedBits++;
auto itr = m_ctpToChain.find(ctpIndex);
if ( itr != m_ctpToChain.end() )
enabledChains.insert( enabledChains.end(), itr->second.begin(), itr->second.end() );
}
}
}
for ( auto chain: enabledChains ) {
ATH_MSG_DEBUG( "Enabling chain: " << chain );
}
if ( numberPfActivatedBits == 0 ) {
ATH_MSG_ERROR( "All CTP bits were disabled, this event shoudl not have shown here" );
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
// -*- c++ -*-
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef L1DECODER_CTPUNPACKINGTOOL_H
#define L1DECODER_CTPUNPACKINGTOOL_H 1
#include "GaudiKernel/IAlgTool.h"
#include "AthenaBaseComps/AthAlgTool.h"
#include "DecisionHandling/HLTIdentifier.h"
namespace ROIB {
class RoIBResult;
}
const InterfaceID IID_CTPUnpackingTool("CTPUnpackingTool", 1, 0);
class CTPUnpackingTool
: virtual public ::IAlgTool, virtual public AthAlgTool
{
public:
static const InterfaceID& interfaceID();
CTPUnpackingTool( const std::string& type,
const std::string& name,
const IInterface* parent );
virtual ~CTPUnpackingTool();
/*
@brief The method decodes CTP bits content of the RoIBResult and fills the list of chains which are activated by those bits
The mapping ctpToChain is expected to contain the CTP bit number mapping to the chain identifiers
@warning if the mapping is empty it means an empty menu. This condition is NOT checked and not reported.
@warning if none of CTP bits is set this is also an error condition, this is the event should not have been passed to HLT
*/
StatusCode decode(const ROIB::RoIBResult& roib, HLT::IDVec& enabledChains) const;
StatusCode initialize(){ return decodeCTPToChainMapping(); }
protected:
StatusCode decodeCTPToChainMapping();
private:
typedef std::map<size_t, HLT::IDVec> IndexToIdentifiers;
IndexToIdentifiers m_ctpToChain;
std::vector<std::string> m_ctpToChainProperty;
bool m_forceEnable;
};
inline const InterfaceID& CTPUnpackingTool::interfaceID()
{
return IID_CTPUnpackingTool;
}
#endif // L1DECODER_CTPUNPACKINGTOOL_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// L1Decoder includes
#include "EMRoIsUnpackingTool.h"
#include "TrigT1Result/RoIBResult.h"
#include "TrigT1Interfaces/TrigT1CaloDefs.h"
///////////////////////////////////////////////////////////////////
// Public methods:
///////////////////////////////////////////////////////////////////
// Constructors
////////////////
EMRoIsUnpackingTool::EMRoIsUnpackingTool( const std::string& type,
const std::string& name,
const IInterface* parent )
: AthAlgTool ( type, name, parent ),
m_configSvc( "TrigConf::LVL1ConfigSvc/LVL1ConfigSvc", name ) {
declareProperty( "Decisions", m_decisionsKey="EMRoIDecisions", "Decisions for each RoI" );
declareProperty( "ThresholdToChainMapping", m_thresholdToChainProperty, "Mapping from the threshold name to chain in the form: 'EM3 : HLT_e5', 'EM3 : HLT_e5tight', ..., (note spaces)" );
declareProperty( "OutputTrigRoIs", m_trigRoIsKey="EMRoIs", "Name of the RoIs object produced by the unpacker" );
declareProperty( "OutputRecRoIs", m_recRoIsKey="RecEMRoIs", "Name of the RoIs object produced by the unpacker" );
declareProperty( "RoIWidth", m_roIWidth = 0.1, "Size of RoI in eta/ phi" );
}
EMRoIsUnpackingTool::~EMRoIsUnpackingTool(){
}
StatusCode EMRoIsUnpackingTool::initialize() {
CHECK( m_configSvc.retrieve() );
CHECK( m_decisionsKey.initialize() );
CHECK( m_trigRoIsKey.initialize() );
CHECK( m_recRoIsKey.initialize() );
if (decodeMapping().isFailure() ) {
ATH_MSG_ERROR( "Failed to decode threshold to chains mapping, is the format th : chain?" );
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
StatusCode EMRoIsUnpackingTool::updateConfiguration() {
using namespace TrigConf;
const ThresholdConfig* thresholdConfig = m_configSvc->thresholdConfig();
auto filteredThresholds= thresholdConfig->getThresholdVector( L1DataDef::EM );
ATH_MSG_DEBUG( "Number of filtered thresholds " << filteredThresholds.size() );
for (auto th : filteredThresholds ) {
if ( th != nullptr ) {
ATH_MSG_DEBUG( "Found threshold in the configuration: " << th->name() << " of ID: " << HLT::Identifier(th->name()).numeric() );
m_emThresholds.push_back(th);
} else {
ATH_MSG_DEBUG( "Nullptr to the threshold" );
}
}
return StatusCode::SUCCESS;
}
StatusCode EMRoIsUnpackingTool::finalize()
{
return StatusCode::SUCCESS;
}
StatusCode EMRoIsUnpackingTool::unpack( const EventContext& ctx,
const ROIB::RoIBResult& roib,
const HLT::IDSet& activeChains ) const {
using namespace TrigCompositeUtils;
auto decisionOutput = std::make_unique<DecisionContainer>();
auto decisionAux = std::make_unique<DecisionAuxContainer>();
decisionOutput->setStore(decisionAux.get());
auto trigRoIs = std::make_unique< TrigRoiDescriptorCollection >();
auto recRoIs = std::make_unique< DataVector<LVL1::RecEmTauRoI> >();
// RoIBResult contains vector of EM fragments
for ( auto& emTauFragment : roib.eMTauResult() ) {
for ( auto& roi : emTauFragment.roIVec() ) {
uint32_t roIWord = roi.roIWord();
if ( not ( LVL1::TrigT1CaloDefs::EMRoIWordType == roi.roIType() ) ) {
ATH_MSG_DEBUG( "Skipping RoI as it is not EM threshold " << roIWord );
continue;
}
auto recRoI = new LVL1::RecEmTauRoI( roIWord, &m_emThresholds );
recRoIs->push_back( recRoI );
auto trigRoI = new TrigRoiDescriptor( roIWord, 0u ,0u,
recRoI->eta(), recRoI->eta()-m_roIWidth, recRoI->eta()+m_roIWidth,
recRoI->phi(), recRoI->phi()-m_roIWidth, recRoI->phi()+m_roIWidth );
trigRoIs->push_back( trigRoI );
ATH_MSG_DEBUG( "RoI word: 0x" << MSG::hex << std::setw(8) << roIWord << MSG::dec );
auto decision = TrigCompositeUtils::newDecisionIn( decisionOutput.get() );
for ( auto th: m_emThresholds ) {
ATH_MSG_VERBOSE( "Checking if the threshold " << th->name() << " passed" );
if ( recRoI->passedThreshold( th->thresholdNumber() ) ) {
ATH_MSG_DEBUG("Passed Threshold name " << th->name());
addChainsToDecision( HLT::Identifier( th->name() ), decision, activeChains );
}
}
// TODO would be nice to have this. Requires modifying the TC class: decision->setDetail("Thresholds", passedThresholds); // record passing threshold names (for easy debugging)
decision->setObjectLink( "initialRoI", ElementLink<TrigRoiDescriptorCollection>(m_trigRoIsKey.key(), trigRoIs->size()-1 ) );
decision->setObjectLink( "initialRecRoI", ElementLink<DataVector<LVL1::RecEmTauRoI>>(m_recRoIsKey.key(), recRoIs->size()-1) );
}
}
for ( auto roi: *trigRoIs ) {
ATH_MSG_DEBUG("RoI Eta: " << roi->eta() << " Phi: " << roi->phi() << " RoIWord: " << roi->roiWord());
}
// recording
{
SG::WriteHandle<TrigRoiDescriptorCollection> handle(m_trigRoIsKey, ctx);
CHECK( handle.record (std::move(trigRoIs)) );
}
{
SG::WriteHandle<DataVector<LVL1::RecEmTauRoI>> handle(m_recRoIsKey, ctx);
CHECK( handle.record( std::move(recRoIs)) );
}
{
auto handle = SG::makeHandle(m_decisionsKey, ctx);
CHECK ( handle.record( std::move( decisionOutput ), std::move( decisionAux ) ) );
}
return StatusCode::SUCCESS; // what else
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef L1DECODER_EMROISUNPACKINGTOOL_H
#define L1DECODER_EMROISUNPACKINGTOOL_H 1
// STL includes
#include <string>
#include "TrigConfInterfaces/ILVL1ConfigSvc.h"
#include "TrigConfL1Data/ThresholdConfig.h"
#include "TrigConfL1Data/TriggerThreshold.h"
#include "TrigT1Interfaces/RecEmTauRoI.h"
#include "TrigSteeringEvent/TrigRoiDescriptorCollection.h"
// FrameWork includes
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ServiceHandle.h"
// L1Decoder includes
#include "./IRoIsUnpackingTool.h"
class EMRoIsUnpackingTool : virtual public AthAlgTool, virtual public IRoIsUnpackingTool {
public:
EMRoIsUnpackingTool( const std::string& type,
const std::string& name,
const IInterface* parent );
virtual ~EMRoIsUnpackingTool();
StatusCode unpack(const EventContext& ctx,
const ROIB::RoIBResult& roib,
const HLT::IDSet& activeChains) const override;
// Athena algtool's Hooks
StatusCode initialize() override;
StatusCode updateConfiguration() override;
StatusCode finalize() override;
private:
EMRoIsUnpackingTool();
std::vector<TrigConf::TriggerThreshold*> m_emThresholds;
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_trigRoIsKey;
SG::WriteHandleKey< DataVector<LVL1::RecEmTauRoI> > m_recRoIsKey;
ServiceHandle<TrigConf::ILVL1ConfigSvc> m_configSvc;
float m_roIWidth;
};
#endif //> !L1DECODER_EMROISUNPACKINGTOOL_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include <iostream>
// L1Decoder includes
#include "IRoIsUnpackingTool.h"
IRoIsUnpackingTool::~IRoIsUnpackingTool()
{}
StatusCode IRoIsUnpackingTool::decodeMapping() {
std::istringstream input;
for ( auto entry: m_thresholdToChainProperty ) {
input.clear();
input.str(entry);
std::string thresholdName;
char delim;
std::string chainName;
input >> thresholdName >> delim >> chainName;
if ( delim != ':' ) {
return StatusCode::FAILURE;
}
m_thresholdToChainMapping[HLT::Identifier(thresholdName)].push_back(HLT::Identifier(chainName));
}
return StatusCode::SUCCESS;
}
void IRoIsUnpackingTool::addChainsToDecision( HLT::Identifier thresholdId,
TrigCompositeUtils::Decision* d,
const HLT::IDSet& activeChains ) const {
auto chains = m_thresholdToChainMapping.find( thresholdId );
if ( chains == m_thresholdToChainMapping.end() )
return;
for ( auto chainId: chains->second ) {
if ( activeChains.find(chainId) != activeChains.end() )
TrigCompositeUtils::addDecisionID( chainId.numeric(), d );
}
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef L1DECODER_IROISUNPACKINGTOOL_H
#define L1DECODER_IROISUNPACKINGTOOL_H 1
#include "GaudiKernel/IAlgTool.h"
#include "AthenaBaseComps/AthAlgTool.h"
#include "DecisionHandling/TrigCompositeUtils.h"
#include "DecisionHandling/HLTIdentifier.h"
namespace ROIB {
class RoIBResult;
}
static const InterfaceID IID_IRoIsUnpackingTool("IRoIsUnpackingTool", 1, 0);
class IRoIsUnpackingTool
: virtual public ::IAlgTool
{
public:
/** Destructor:
*/
virtual ~IRoIsUnpackingTool();
typedef HLT::IDtoIDVecMap ThresholdToIdentifiers;
static const InterfaceID& interfaceID();
/*
@brief Invoked when there is a potential change of the configuration. Typically beginRun.
*/
virtual StatusCode updateConfiguration() = 0;
/*
@brief The methods reads the RoIB result object and unpacks fragment of it, depending of the implementation (i.e. EM, J..)
In addition to the impl. specific collection a collection of decision objects is created with each decision tagged by the chain ID it relates to.
The mapping of threshold IDs and the chains is provided externally at each call (may be refactored later as this is pure config information).
*/
virtual StatusCode unpack(const EventContext& ctx,
const ROIB::RoIBResult& roib,
const HLT::IDSet& activeChains) const = 0;
protected:
SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer> m_decisionsKey;
std::vector<std::string> m_thresholdToChainProperty;
std::map<HLT::Identifier, HLT::IDVec> m_thresholdToChainMapping;
StatusCode decodeMapping();
void addChainsToDecision( HLT::Identifier thresholdId,
TrigCompositeUtils::Decision* d,
const HLT::IDSet& activeChains ) const;
};
inline const InterfaceID& IRoIsUnpackingTool::interfaceID() {
return IID_IRoIsUnpackingTool;
}
#endif //> !L1DECODER_IROISUNPACKINGTOOL_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
// L1Decoder includes
#include "JRoIsUnpackingTool.h"
// STL includes
// FrameWork includes
#include "GaudiKernel/IToolSvc.h"
// StoreGate
#include "StoreGate/StoreGateSvc.h"
///////////////////////////////////////////////////////////////////
// Public methods:
///////////////////////////////////////////////////////////////////
// Constructors
////////////////
JRoIsUnpackingTool::JRoIsUnpackingTool( const std::string& type,
const std::string& name,
const IInterface* parent ) :
::AthAlgTool ( type, name, parent )
{
//
// Property declaration
//
//declareProperty( "Property", m_nProperty );
}
// Destructor
///////////////
JRoIsUnpackingTool::~JRoIsUnpackingTool()
{}
// Athena algtool's Hooks
////////////////////////////
StatusCode JRoIsUnpackingTool::initialize()
{
ATH_MSG_INFO ("Initializing " << name() << "...");
return StatusCode::SUCCESS;
}
StatusCode JRoIsUnpackingTool::finalize()
{
ATH_MSG_INFO ("Finalizing " << name() << "...");
return StatusCode::SUCCESS;
}
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