Commit ea954e41 authored by Werner Wiedenmann's avatar Werner Wiedenmann Committed by Graeme Stewart
Browse files

add example how to read back data scouting result (TrigExL2muCalibTest-20-00-03)

parent 3bf5d06b
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef L2MUCALIBTEST
#define L2MUCALIBTEST
#include "AthenaBaseComps/AthAlgorithm.h"
#include "GaudiKernel/IIncidentListener.h"
#include "TrigNavigation/Navigation.h"
#include <stdint.h>
/////////////////////////////////////////////////////////////////////////////
class IJobOptionsSvc;
class Incident;
class L2muCalibTest:public AthAlgorithm,
virtual public IIncidentListener {
public:
L2muCalibTest(const std::string& name, ISvcLocator* pSvcLocator);
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
// handler for "UpdateAfterFork" actions
void handle(const Incident& incident);
private:
IJobOptionsSvc* m_jobOptionsSvc;
BooleanProperty m_allowOksConfig;
BooleanProperty m_dumpCatalogue;
StringProperty m_muonCalBufferName;
IntegerProperty m_muonCalBufferSize;
BooleanProperty m_readBackDataScoutingCollection;
StringProperty m_keyDataScoutingROB;
StringProperty m_keyDataScoutingContainer;
// Navigation
ToolHandle<HLT::Navigation> m_navigationForEF;
HLT::Navigation* m_nav;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRIGPARTIALEBFILTER
#define TRIGPARTIALEBFILTER
#include "AthenaBaseComps/AthAlgorithm.h"
#include "EventInfo/TriggerInfo.h"
#include <string>
#include <stdint.h>
/////////////////////////////////////////////////////////////////////////////
class TrigPartialEBFilter : public AthAlgorithm {
public:
TrigPartialEBFilter(const std::string& name, ISvcLocator* pSvcLocator);
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
private:
bool randomAccept(double rate);
typedef std::vector< TriggerInfo::StreamTag > StreamTagVector_t;
/// Reference to StoreGateSvc;
std::string m_hltResultSGKey;
//Algorithms properties
DoubleProperty m_acceptRate; //fraction of physics evt to be accepted
// negative value: all physics rejected
// 0. - < 1.0 : randome selection
// >= 1.0 : all physics accepted
StringProperty m_hltInstance; // name of the HLT level: L2 or EF
StringProperty m_hltResultName; // tag name for the HLT result
StringProperty m_calStreamName; //calibration stream to be accepted;
// null string: all calibration streams
// accepted
};
#endif
package TrigExL2muCalibTest
author Werner Wiedenmann <Werner.Wiedenmann@cern.ch>
public
use AtlasPolicy AtlasPolicy-*
use AthenaBaseComps AthenaBaseComps-* Control
use EventInfo EventInfo-* Event
use GaudiInterface GaudiInterface-* External
use TrigNavigation TrigNavigation-* Trigger/TrigEvent
private
use StoreGate StoreGate-* Control
use TrigInterfaces TrigInterfaces-* Trigger/TrigSteer
use TrigSteeringEvent TrigSteeringEvent-* Trigger/TrigEvent
use TrigHLTResultByteStream TrigHLTResultByteStream-* Trigger/TrigSteer
use ByteStreamCnvSvcBase ByteStreamCnvSvcBase-* Event
use xAODTrigger xAODTrigger-* Event/xAOD
end_private
library TrigExL2muCalibTest *.cxx -s=components *.cxx
apply_pattern component_library
apply_pattern declare_joboptions files="*.py"
private
#=====================================================================
# This job options are for testing with Athena, e.g. run with
#
# athena TrigExL2muCalibTest/AthenaL2muCalibTestOptions.py
#
#=====================================================================
#
from AthenaCommon.Constants import VERBOSE, DEBUG, INFO, ERROR
# Add timestamp to python logger
from AthenaCommon.Logging import log
log.setFormat("%(asctime)s Py:%(name)-31s %(levelname)7s %(message)s")
from AthenaCommon.Logging import logging
log = logging.getLogger( 'TriggerUnixStandardSetup::setupCommonServices:' )
# Do the default Atlas job configuration first
import AthenaCommon.AtlasUnixStandardJob
# Now do HLT specific configuration
from AthenaCommon import CfgMgr
from AthenaCommon.AppMgr import theApp
from AthenaCommon.AppMgr import ServiceMgr as svcMgr
from AthenaCommon.AppMgr import ToolSvc
# make the message service available
svcMgr.MessageSvc = theApp.service( "MessageSvc" ) # already instantiated
MessageSvc = svcMgr.MessageSvc
MessageSvc.defaultLimit = 0
MessageSvc.enableSuppression = False
MessageSvc.OutputLevel = DEBUG
# StoreGateSvc
svcMgr.StoreGateSvc.ActivateHistory = False
# ProxyProviderSvc services configuration
svcMgr += CfgMgr.ProxyProviderSvc()
# --- ByteStreamAddressProviderSvc configuration
svcMgr += CfgMgr.ByteStreamAddressProviderSvc()
svcMgr.ProxyProviderSvc.ProviderNames += [ "ByteStreamAddressProviderSvc" ]
theApp.CreateSvc += [ svcMgr.ByteStreamAddressProviderSvc.getFullName() ]
svcMgr.ByteStreamAddressProviderSvc.OutputLevel = DEBUG
svcMgr.ByteStreamAddressProviderSvc.TypeNames += [
"HLT::HLTResult/DataScouting_03",
"HLT::HLTResult/DataScouting_05"
]
# Initialization of DetDescrCnvSvc
svcMgr += CfgMgr.DetDescrCnvSvc(
# specify primary Identifier dictionary to be used
IdDictName = "IdDictParser/ATLAS_IDS.xml"
)
theApp.CreateSvc += [ svcMgr.DetDescrCnvSvc.getFullName() ]
svcMgr.EventPersistencySvc.CnvServices += [ "DetDescrCnvSvc" ]
# --- ByteStreamCnvSvc configuration
svcMgr += CfgMgr.ByteStreamCnvSvc("ByteStreamCnvSvc")
svcMgr.EventPersistencySvc.CnvServices += [ "ByteStreamCnvSvc" ]
# Explicitly set a few OutputLevels (needed because some services are created in
# different order when running with the PSC)
svcMgr.StatusCodeSvc.OutputLevel = theApp.OutputLevel
svcMgr.IncidentSvc.OutputLevel = theApp.OutputLevel
svcMgr.ProxyProviderSvc.OutputLevel = theApp.OutputLevel
svcMgr.StoreGateSvc.OutputLevel = theApp.OutputLevel
# Input
include( "ByteStreamCnvSvc/BSEventStorageEventSelector_jobOptions.py" )
svcMgr.EventSelector.OutputLevel = DEBUG
svcMgr.ByteStreamInputSvc.OutputLevel = DEBUG
svcMgr.ByteStreamCnvSvc.OutputLevel = DEBUG
svcMgr.ByteStreamAddressProviderSvc.OutputLevel = DEBUG
#**************************************************************
#
# give input BS file here
#
#==============================================================
svcMgr.ByteStreamInputSvc.FullFileName = [ "bla-muon-calib._0001.data"]
#**************************************************************
#
# set number of events
#
#==============================================================
theApp.EvtMax = 5
#**************************************************************
#
# L2muCalibTest algorithm example
#
#==============================================================
#--------------------------------------------------------------
# Private Application Configuration options
#--------------------------------------------------------------
from TrigExL2muCalibTest.TrigExL2muCalibTestConf import L2muCalibTest
HelloWorld = L2muCalibTest("HelloWorld")
from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()
topSequence += HelloWorld
#
#--------------------------------------------------------------
# Algorithms Private Options
#--------------------------------------------------------------
#
#--- Allow overwrite of muon calibration buffer name from OKS/
#--- online configuration
#
HelloWorld.AllowOksConfig = False
#
#--- dump the property catalogue (when AllowOksConfig = TRUE)
#
HelloWorld.DumpPropertyCatalogue = False
#
#--- define the muon calibration buffer name and size
#
HelloWorld.MuonCalBufferName = "file://dummy-file-from-py-jobOptions"
HelloWorld.MuonCalBufferSize = 12345678
HelloWorld.ReadBackDataScoutingCollection = True
#
#==============================================================
#
# End of L2muCalibTest example
#
#**************************************************************
#**************************************************************
#
# L2muCalibTest example
#
#==============================================================
from AthenaCommon.AppMgr import ServiceMgr as svcMgr
from AthenaCommon.Constants import *
#--------------------------------------------------------------
# Private Application Configuration options
#--------------------------------------------------------------
from TrigExL2muCalibTest.TrigExL2muCalibTestConf import L2muCalibTest
HelloWorld = L2muCalibTest("HelloWorld")
from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()
topSequence += HelloWorld
#
#--------------------------------------------------------------
# Algorithms Private Options
#--------------------------------------------------------------
#
#--- Allow overwrite of muon calibration buffer name from OKS/
#--- online configuration
#
HelloWorld.AllowOksConfig = TRUE
#
#--- dump the property catalogue (when AllowOksConfig = TRUE)
#
HelloWorld.DumpPropertyCatalogue = TRUE
#
#--- define the muon calibration buffer name and size
#
HelloWorld.MuonCalBufferName = "file://dummy-file-from-py-jobOptions"
HelloWorld.MuonCalBufferSize = 12345678
#
#==============================================================
#
# End of L2muCalibTest example
#
#**************************************************************
#**************************************************************
#
# PebFilterOptions.py
#
#==============================================================
from AthenaCommon.Constants import *
from AthenaCommon import CfgMgr
PebFilter = CfgMgr.TrigPartialEBFilter("PebFilter")
#--------------------------------------------------------------
# Add the algorithm to the topSequence
#--------------------------------------------------------------
from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()
topSequence += PebFilter
#--------------------------------------------------------------
# Private Application Configuration options
#--------------------------------------------------------------
#
# --- Filter physics events (50% of the accepted rate)
#
#PebFilter.AcceptRate = .5
#
# --- Select a particular calibration stream for the building
#
#PebFilter.CalibrationStreamName = "StreamName"
#
# --- Set specific tag for the HLT result
#
#PebFilter.HLTInstance = "L2" or "EF"
#PebFilter.HLTResultName = "CalibrationStreamName"
#
#==============================================================
#
# End of PebFilterOptions.py
#
#**************************************************************
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TrigExL2muCalibTest/L2muCalibTest.h"
#include "GaudiKernel/IJobOptionsSvc.h"
#include "StoreGate/DataHandle.h"
#include "GaudiKernel/Incident.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "TrigInterfaces/Incidents.h"
#include "TrigSteeringEvent/HLTResult.h"
#include "TrigHLTResultByteStream/HLTResultByteStreamTool.h"
#include "ByteStreamCnvSvcBase/IROBDataProviderSvc.h"
#include "TrigSteeringEvent/Enums.h"
#include "xAODTrigger/TrigCompositeContainer.h"
#include "xAODTrigger/TrigCompositeAuxContainer.h"
// static const AlgFactory<L2muCalibTest> Factory;
// const IAlgFactory& L2muCalibTestFactory = Factory;
/////////////////////////////////////////////////////////////////////////////
L2muCalibTest::L2muCalibTest(const std::string& name, ISvcLocator* pSvcLocator) :
AthAlgorithm(name, pSvcLocator),
m_jobOptionsSvc(0),
m_allowOksConfig(true),
m_dumpCatalogue(false),
m_muonCalBufferName("NONE"),
m_muonCalBufferSize(0),
m_navigationForEF("HLT::Navigation/Navigation", this)
{
// Declare the properties
declareProperty("AllowOksConfig", m_allowOksConfig);
declareProperty("DumpPropertyCatalogue", m_dumpCatalogue);
declareProperty("MuonCalBufferName", m_muonCalBufferName);
declareProperty("MuonCalBufferSize", m_muonCalBufferSize);
declareProperty("ReadBackDataScoutingCollection", m_readBackDataScoutingCollection=0);
declareProperty("KeyDataScoutingROB", m_keyDataScoutingROB="DataScouting_03");
declareProperty("KeyDataScoutingContainer", m_keyDataScoutingContainer="HLT_xAOD__TrigCompositeContainer_MuonCalibrationStream");
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
StatusCode L2muCalibTest::initialize(){
// Part 1: Get the messaging service, print where you are
MsgStream log(msgSvc(), name());
ATH_MSG_INFO("initialize()");
StatusCode sc;
#ifdef ATLAS_GAUDI_V21
SmartIF<IService> tmp_msgSvc(msgSvc());
if(tmp_msgSvc.isValid()) {
ATH_MSG_INFO(" Algorithm = " << name() << " is connected to Message Service = "
<< tmp_msgSvc->name());
}
#else
Service* tmp_msgSvc = dynamic_cast<Service*> (msgSvc());
if(tmp_msgSvc != 0) {
ATH_MSG_INFO(" Algorithm = " << name() << " is connected to Message Service = "
<< tmp_msgSvc->name());
}
#endif
// Print out the property values after update from catalogue
ATH_MSG_INFO(" ---------------------------------------------------------- ");
ATH_MSG_INFO(" --- Properties before update from JobOptions Catalogue --- ");
ATH_MSG_INFO(" ---------------------------------------------------------- ");
ATH_MSG_INFO(" AllowOksConfig = " << m_allowOksConfig);
ATH_MSG_INFO(" DumpPropertyCatalogue = " << m_dumpCatalogue);
ATH_MSG_INFO(" MuonCalBufferName = " << m_muonCalBufferName);
ATH_MSG_INFO(" MuonCalBufferSize = " << m_muonCalBufferSize);
ATH_MSG_INFO(" ReadBackDataScoutingCollection = " << m_readBackDataScoutingCollection);
ATH_MSG_INFO(" KeyDataScoutingROB = " << m_keyDataScoutingROB);
ATH_MSG_INFO(" KeyDataScoutingContainer = " << m_keyDataScoutingContainer);
// Part 2: Get the JobOptionsSvc service, and update properties from catalogue
if ( m_allowOksConfig ) {
sc = service("JobOptionsSvc", m_jobOptionsSvc);
if (sc.isFailure()) {
ATH_MSG_ERROR("Could not find JobOptionsSvc");
return sc;
} else {
IService* svc = dynamic_cast<IService*>(m_jobOptionsSvc);
if(svc != 0 ) {
ATH_MSG_INFO(" Algorithm = " << name() << " is connected to JobOptionsSvc Service = "
<< svc->name());
}
if ( m_dumpCatalogue ) {
// Dump of the catalogue
ATH_MSG_INFO("=================================================");
ATH_MSG_INFO("Dump of the property catalogue.... ");
std::vector<std::string> clients = m_jobOptionsSvc->getClients();
std::vector<std::string>::iterator cit;
std::vector<const Property*>::const_iterator pit;
for( cit = clients.begin(); cit != clients.end(); cit++ ) {
ATH_MSG_INFO(" Properties of " << *cit << ": ";
const std::vector<const Property*>* properties = m_jobOptionsSvc->getProperties(*cit);
for( pit = properties->begin(); pit != properties->end(); pit++ ) {
log << (*pit)->name();
if( (pit+1) != properties->end()) log << ", ";
}
log);
}
ATH_MSG_INFO("=================================================");
}
// Overwrite the properties with values from the catalogue using the non existing algorithm
// 'MuonL2CalibrationConfig'
sc = m_jobOptionsSvc->setMyProperties("MuonHltCalibrationConfig",this);
if (sc.isFailure()) {
ATH_MSG_ERROR("Could not set properties from JobOptionsSvc catalogue.");
return sc;
}
// Find the Data Flow application name
bool df_found = false;
const std::vector<const Property*>* dataFlowProps = m_jobOptionsSvc->getProperties("DataFlowConfig");
if ( dataFlowProps ) {
ATH_MSG_INFO(" Properties available for 'DataFlowConfig': number = " << dataFlowProps->size());
ATH_MSG_INFO(" --------------------------------------------------- ");
for ( std::vector<const Property*>::const_iterator cur = dataFlowProps->begin();
cur != dataFlowProps->end(); cur++) {
ATH_MSG_INFO((*cur)->name() << " = " << (*cur)->toString());
// the application name is found
if ( (*cur)->name() == "DF_ApplicationName" ) {
df_found = true;
}
// the enabled ROB list is found
if ( (*cur)->name() == "DF_Enabled_ROB_IDs" ) {
SimpleProperty< std::vector<uint32_t> > enabledROBs;
enabledROBs.setName("enabledROBIds");
if (enabledROBs.assign(**cur)) {
ATH_MSG_INFO(" ---> got from OKS = " << enabledROBs.value().size() << " ROB ids.");
} else {
ATH_MSG_WARNING(" ---> set property failed.");
}
}
}
if ( !df_found ) {
ATH_MSG_INFO(" Property for DF_ApplicationName not found.");
}
} else {
ATH_MSG_INFO(" No Properties for 'DataFlowConfig' found.");
}
ATH_MSG_INFO("=================================================");
// release JobOptionsSvc
unsigned long mjcounter = m_jobOptionsSvc->release();
ATH_MSG_INFO(" --> Release JobOptionsSvc Service, Counter = " << mjcounter);
}
}
// Print out the property values after update from catalogue
ATH_MSG_INFO(" ---------------------------------------------------------- ");
ATH_MSG_INFO(" --- Properties after update from JobOptions Catalogue --- ");
ATH_MSG_INFO(" ---------------------------------------------------------- ");
ATH_MSG_INFO(" AllowOksConfig = " << m_allowOksConfig);
ATH_MSG_INFO(" DumpPropertyCatalogue = " << m_dumpCatalogue);
ATH_MSG_INFO(" MuonCalBufferName = " << m_muonCalBufferName);
ATH_MSG_INFO(" MuonCalBufferSize = " << m_muonCalBufferSize);
ATH_MSG_INFO("=================================================");
// Part 3: Locate the IncidentSvc and subscribe for UpdateAfterFork incident
ServiceHandle<IIncidentSvc> p_incidentSvc("IncidentSvc",name());
sc = p_incidentSvc.retrieve();
if (!sc.isSuccess()) {
ATH_MSG_ERROR("Could not find IncidentSvc");
return sc;
} else {
long int pri=100;
p_incidentSvc->addListener(this,"UpdateAfterFork",pri);
p_incidentSvc.release().ignore();
}
// retrieve navigation
if ( m_navigationForEF.retrieve().isFailure() ) {
ATH_MSG_FATAL("failed to get navigation, can not retrieve navigation tool: " << m_navigationForEF);
return StatusCode::FAILURE;
} else {
ATH_MSG_DEBUG("successfully retrieved navigation tool: " << m_navigationForEF);
}
return StatusCode::SUCCESS;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
StatusCode L2muCalibTest::execute() {
// Get the messaging service, print where you are
ATH_MSG_INFO("execute()");
if (!m_readBackDataScoutingCollection) return StatusCode::SUCCESS;
StatusCode sc;
ATH_MSG_DEBUG(" StoreGate structure: Begin execute " << name() << "\n" << evtStore()->dump());
// Get the Muon HLT DataScouting result
const DataHandle<HLT::HLTResult> datascouting_03_result;
sc = evtStore()->retrieve(datascouting_03_result,m_keyDataScoutingROB) ;
if ( sc.isFailure() ) {
ATH_MSG_ERROR("Could not find HLTResult with key = " << m_keyDataScoutingROB );
return sc;
}
ATH_MSG_DEBUG("HLTResult is level="<< datascouting_03_result->getHLTLevel());
const std::vector<uint32_t>& navData = datascouting_03_result->getNavigationResult();
if ( navData.size() != 0 ) {
ATH_MSG_DEBUG("navigation payload has size " << navData.size());
m_nav = &*m_navigationForEF;
m_nav->deserialize( navData );
} else {
ATH_MSG_WARNING("navigation payload has size 0" );
}
const DataHandle<xAOD::TrigCompositeContainer> muon_calib_obj;
sc = evtStore()->retrieve(muon_calib_obj, m_keyDataScoutingContainer) ;
if ( sc.isFailure() ) {
ATH_MSG_WARNING("Could not find muon calib obj with key = " << m_keyDataScoutingContainer);
} else {
const xAOD::TrigCompositeContainer* muon_comp_container = muon_calib_obj.cptr();
ATH_MSG_DEBUG("muon calib obj has size = " << muon_comp_container->size());
const std::string muon_buffer_name("MuonCalibrationStream");
for (const auto& ii : *muon_comp_container) {
ATH_MSG_DEBUG("Composite object has name = " << ii->name());
ATH_MSG_DEBUG("Composite object has detail " << muon_buffer_name << " = " << ii->hasDetail<std::vector<int> >(muon_buffer_name));
std::vector<int> detail_values;
bool got_data = ii->getDetail(muon_buffer_name,detail_values);
ATH_MSG_DEBUG("Composite object has detail " << muon_buffer_name << " = " << got_data << " with size = " << detail_values.size() );
}
}
ATH_MSG_DEBUG(" StoreGate structure: End execute " << name() << "\n" << evtStore()->dump());
return StatusCode::SUCCESS;
}