Commit 6724cab0 authored by Joerg Stelzer's avatar Joerg Stelzer
Browse files

implement comments

parent bf22c3aa
......@@ -20,8 +20,8 @@ namespace TrigConf {
public:
struct HLTPrescale {
bool enabled { false };
double prescale { 1 };
bool enabled { false }; // chain enabled
double prescale { 1 }; // prescale value
};
/** Constructor */
......
......@@ -5,7 +5,8 @@ from AthenaCommon.Logging import logging
from collections import OrderedDict as odict
import json
_hltPrescaleKeyFolderName = "/TRIGGER/HLT/PrescaleKey <tag>HEAD</tag>"
def getHLTPrescaleFolderName():
return "/TRIGGER/HLT/PrescaleKey <tag>HEAD</tag>"
# L1 Json file name
......@@ -170,12 +171,9 @@ def getHLTConfigSvc( flags = None ):
# configuration of HLTConfigSvc
@memoize
def setupHLTPrescaleCondAlg( flags = None ):
global _hltPrescaleKeyFolderName
log = logging.getLogger('TrigConfigSvcCfg')
from TrigConfigSvc.TrigConfigSvcConf import TrigConf__HLTPrescaleCondAlg
from AthenaCommon.Constants import DEBUG
hltPrescaleCondAlg = TrigConf__HLTPrescaleCondAlg( "HLTPrescaleCondAlg" )
hltPrescaleCondAlg.OutputLevel = DEBUG
tc = getTrigConfigFromFlag( flags )
hltPrescaleCondAlg.Source = tc["source"]
......@@ -198,9 +196,8 @@ def setupHLTPrescaleCondAlg( flags = None ):
condSequence = AthSequencer("AthCondSeq")
condSequence += hltPrescaleCondAlg
from IOVDbSvc.CondDB import conddb
conddb.addFolder( "TRIGGER", _hltPrescaleKeyFolderName, className="AthenaAttributeList",
extensible = True)
log.info("Adding folder %s to conddb", _hltPrescaleKeyFolderName )
conddb.addFolder( "TRIGGER", getHLTPrescaleFolderName(), className="AthenaAttributeList" )
log.info("Adding folder %s to conddb", getHLTPrescaleFolderName() )
return hltPrescaleCondAlg
......@@ -228,14 +225,13 @@ def TrigConfigSvcCfg( flags ):
def HLTPrescaleCondAlgCfg( flags ):
global _hltPrescaleKeyFolderName
log = logging.getLogger('TrigConfigSvcCfg')
from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
from IOVDbSvc.IOVDbSvcConfig import addFolders
acc = ComponentAccumulator()
acc.addCondAlgo( setupHLTPrescaleCondAlg( flags ) )
acc.merge(addFolders(flags, _hltPrescaleKeyFolderName, "TRIGGER_ONL", className="AthenaAttributeList"))
log.info("Adding folder %s to CompAcc", _hltPrescaleKeyFolderName )
acc.merge(addFolders(flags, getHLTPrescaleFolderName(), "TRIGGER_ONL", className="AthenaAttributeList"))
log.info("Adding folder %s to CompAcc", getHLTPrescaleFolderName() )
return acc
......
......@@ -16,9 +16,9 @@ TrigConf::HLTPrescaleCondAlg::HLTPrescaleCondAlg(const std::string& name, ISvcLo
{}
TrigConf::HLTPrescalesSet *
TrigConf::HLTPrescalesSetPtr
TrigConf::HLTPrescaleCondAlg::createFromFile( const std::string & filename ) const {
auto pss = new HLTPrescalesSet;
auto pss = std::make_shared<HLTPrescalesSet>();
// load the file into the HLT prescales set
ATH_MSG_DEBUG( "Setting up JsonFileLoader with file " << filename );
TrigConf::JsonFileLoader psLoader;
......@@ -28,20 +28,19 @@ TrigConf::HLTPrescaleCondAlg::createFromFile( const std::string & filename ) con
ATH_MSG_INFO( "HLT prescales set successfully loaded from file " << filename );
} else {
ATH_MSG_WARNING( "Failed loading HLT prescales set from file " << filename ); // will be made an error later
delete pss;
pss = nullptr;
}
return pss;
}
TrigConf::HLTPrescalesSet *
TrigConf::HLTPrescalesSetPtr
TrigConf::HLTPrescaleCondAlg::createFromDB( unsigned int psk, bool isRun3 ) const {
if( ! isRun3 ) {
ATH_MSG_WARNING( "Currently it is not possible to load run 2 prescale sets from the database. Will not load HLT psk " << psk );
return nullptr;
}
auto pss = new HLTPrescalesSet;
auto pss = std::make_shared<HLTPrescalesSet>();
// load the HLT psk into the HLT prescales set
ATH_MSG_DEBUG( "Setting up TrigDBHLTPrescalesSetLoader with DB connection " << m_dbConnection.value() );
TrigConf::TrigDBHLTPrescalesSetLoader psLoader(m_dbConnection);
......@@ -53,7 +52,6 @@ TrigConf::HLTPrescaleCondAlg::createFromDB( unsigned int psk, bool isRun3 ) cons
catch(std::exception & e) {
ATH_MSG_WARNING( "Failed loading HLT prescales set from db with key " << psk ); // will be made an error later
ATH_MSG_WARNING( e.what() );
delete pss;
pss = nullptr;
}
return pss;
......@@ -128,16 +126,7 @@ TrigConf::HLTPrescaleCondAlg::execute(const EventContext& ctx) const {
ATH_MSG_FATAL("Failed to retrieve validity range for " << readH.key());
return StatusCode::FAILURE;
} else {
ATH_MSG_DEBUG("V2 Read handle has range " << range);
EventIDBase::number_type run = ctx.eventID().run_number();
EventIDBase::number_type lb = ctx.eventID().lumi_block();
EventIDBase start, stop;
start.set_run_number(run);
start.set_lumi_block(lb);
stop.set_run_number(run);
stop.set_lumi_block(lb+1);
range = EventIDRange(start,stop);
ATH_MSG_DEBUG("New range " << range);
ATH_MSG_DEBUG("Read handle has range " << range);
}
// get the prescale key from the cool folder
hltPsk = (*pskAL)["HltPrescaleKey"].data<cool::UInt32>();
......@@ -156,10 +145,7 @@ TrigConf::HLTPrescaleCondAlg::execute(const EventContext& ctx) const {
}
ATH_MSG_DEBUG("New range again " << range);
HLTPrescalesSet * pss (nullptr);
std::shared_ptr<HLTPrescalesSet> pss;
if( m_configSource == "FILE" ) {
pss = m_pssMap.at(0);
......@@ -173,9 +159,9 @@ TrigConf::HLTPrescaleCondAlg::execute(const EventContext& ctx) const {
bool isRun3 = range.start().run_number()>350000;
m_pssMap[hltPsk] = createFromDB( hltPsk, isRun3 );
pss = m_pssMap.at( hltPsk );
}
pss = m_pssMap.at( hltPsk );
} else {
......
......@@ -15,8 +15,12 @@
#include <tbb/concurrent_unordered_map.h>
#include <memory>
namespace TrigConf {
using HLTPrescalesSetPtr = std::shared_ptr<HLTPrescalesSet>;
/**
* @brief Condition algorithm to provide the L1 trigger menu
*
......@@ -38,13 +42,13 @@ namespace TrigConf {
private:
// helper function to load a HLT prescales set from a file
HLTPrescalesSet * createFromFile( const std::string & filename ) const;
HLTPrescalesSetPtr createFromFile( const std::string & filename ) const;
// helper function to load a HLT prescales set from a prescale key
HLTPrescalesSet * createFromDB( unsigned int psk, bool isRun3 ) const;
HLTPrescalesSetPtr createFromDB( unsigned int psk, bool isRun3 ) const;
// map the prescale key to a HLTPrescalesSet
mutable tbb::concurrent_unordered_map<unsigned int, HLTPrescalesSet *> m_pssMap;
mutable tbb::concurrent_unordered_map<unsigned int, HLTPrescalesSetPtr> m_pssMap;
// input key to the HLT Prescale Key folder
SG::ReadCondHandleKey<AthenaAttributeList> m_pskFolderInputKey{ this, "PSKFolder", "/TRIGGER/HLT/PrescaleKey", "SG Key of AthenaAttributeList containing hlt psk"};
......@@ -54,9 +58,9 @@ namespace TrigConf {
// properties
Gaudi::Property< std::string > m_configSource { this, "Source", "FILE", "Configuration source, can be 'FILE', 'DB', or 'COOL'" };
Gaudi::Property< std::string > m_dbConnection { this, "TriggerDB", "", "DB connection alias" };
Gaudi::Property< unsigned int > m_psk { this, "HLTPsk", 0, "HLT prescale key" };
Gaudi::Property< std::string > m_filename { this, "Filename", "", "HLT prescale json file" };
Gaudi::Property< std::string > m_dbConnection { this, "TriggerDB", "", "DB connection alias or 'JOSVC', used when property Source set to 'DB' or set to 'COOL'." };
Gaudi::Property< unsigned int > m_psk { this, "HLTPsk", 0, "HLT prescale key, used when property 'Source' set to 'DB'" };
Gaudi::Property< std::string > m_filename { this, "Filename", "", "HLT prescale json file, used when property 'Source' set to 'FILE'" };
};
......
......@@ -24,10 +24,7 @@ PrescalingTool::~PrescalingTool()
StatusCode
PrescalingTool::initialize()
{
CHECK( m_eventInfo.initialize( ! m_eventInfo.key().empty() ) );
CHECK(m_hltPrescaleSetInputKey.initialize( ! m_hltPrescaleSetInputKey.key().empty() ));
return StatusCode::SUCCESS;
}
......@@ -62,18 +59,13 @@ StatusCode PrescalingTool::prescaleChains( const EventContext& ctx,
// prepare the result
remainActive.reserve( initiallyActive.size() );
// create the seed from the CTP time
size_t seed = initiallyActive[0].numeric();
if ( ! m_eventInfo.key().empty() ) {
auto handle = SG::makeHandle( m_eventInfo, ctx );
const xAOD::EventInfo* event = handle.cptr();
seed = event->timeStamp() ^ event->timeStampNSOffset();
}
// create the seed from the event time
size_t seed = ctx.eventID().time_stamp() ^ ctx.eventID().time_stamp_ns_offset();
CLHEP::HepRandomEngine* engine = m_RNGEngines.getEngine( ctx );
engine->setSeed( seed, 0 );
// go through all active chains
for ( auto ch: initiallyActive ) {
for ( const auto & ch: initiallyActive ) {
bool decisionToKeep { false };
try {
const auto & prescale = hltPrescaleSet->prescale( ch.numeric() );
......
......@@ -57,7 +57,6 @@ class PrescalingTool : public extends<AthAlgTool, IPrescalingTool> {
private:
// input data
SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{ this, "EventInfo", "EventInfo", "EventInfo object, source of CTP time used to reseed the RNG" };
SG::ReadCondHandleKey<TrigConf::HLTPrescalesSet> m_hltPrescaleSetInputKey{ this, "HLTPrescales", "HLTPrescales", "HLT prescales set"};
// properties
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment