Commit bbb15a34 authored by Alex Pearce's avatar Alex Pearce
Browse files

added Hlt/HltDAQ from LHCb (LHCb/v41r0)

parent 4fb78a28
......@@ -28,3 +28,6 @@
[lb-checkout "LHCb.DAQ/DAQKernel"]
base = 72997283dd8ce1c05c699ab0b0a349546b407c5a
imported = 26b40caca408e53f5959c238cd35d37f88411761
[lb-checkout "LHCb.Hlt/HltDAQ"]
base = 4fb78a28e1dc4c4f5e858d0f6b0371aa9bc8f212
imported = 26b40caca408e53f5959c238cd35d37f88411761
################################################################################
# Package: HltDAQ
################################################################################
gaudi_subdir(HltDAQ v4r28)
gaudi_depends_on_subdirs(Det/DetCond
Det/DetDesc
Event/DAQEvent
Event/HltEvent
Event/LumiEvent
Event/EventPacker
GaudiAlg
GaudiKernel
GaudiObjDesc
Hlt/HltServices
Kernel/HltInterfaces
Phys/LoKiHlt
DAQ/DAQKernel)
find_package(AIDA)
find_package(Boost COMPONENTS iostreams filesystem)
include(GaudiObjDesc)
god_build_headers(xml/*.xml
DESTINATION HltDAQ)
gaudi_add_library(HltDAQLib
src/lib/*.cpp
PUBLIC_HEADERS HltDAQ
INCLUDE_DIRS Boost AIDA
LINK_LIBRARIES Boost DetCondLib DetDescLib DAQEventLib DAQKernelLib HltEvent GaudiAlgLib GaudiKernel HltInterfaces LoKiHltLib)
gaudi_add_module(HltDAQ
src/component/*.cpp
INCLUDE_DIRS Boost AIDA HltDAQ
LINK_LIBRARIES HltDAQLib Boost DetCondLib DetDescLib DAQEventLib DAQKernelLib HltEvent GaudiAlgLib GaudiKernel HltInterfaces LoKiHltLib)
gaudi_add_unit_test(utestTrackingCoder
src/utest/utestTrackingCoder.cpp
LINK_LIBRARIES GaudiKernel HltEvent HltDAQLib
TYPE Boost)
gaudi_add_test(QMTest QMTEST)
#ifndef HLTCOMMON_HLTEVALUATOR_H
#define HLTCOMMON_HLTEVALUATOR_H 1
// Include files
#include <array>
#include <functional>
// boost
#include <boost/variant.hpp>
// from Gaudi
#include "GaudiAlg/GaudiHistoAlg.h"
#include "GaudiKernel/IUpdateManagerSvc.h"
#include "GaudiKernel/IIncidentListener.h"
#include "GaudiKernel/GaudiException.h"
#include "DetDesc/Condition.h"
#include "Kernel/IHltMonitorSvc.h"
#include "LoKi/OdinTypes.h"
#include "LoKi/L0Types.h"
#include "LoKi/HLTTypes.h"
#include "LoKi/IHltFactory.h"
/** @class HltEvaluator HltEvaluator.h
*
*
* @author Gerhard Raven
* @date 2008-07-29
*/
class HltEvaluator : public extends1<GaudiHistoAlg, IIncidentListener> {
public:
/// Standard constructor
HltEvaluator( const std::string& name, ISvcLocator* pSvcLocator );
~HltEvaluator( ) = default; ///< Destructor
StatusCode initialize() override; ///< Algorithm initialization
protected:
/// Decode
virtual StatusCode decode() = 0;
StatusCode times(double& t, double& w, double& et) const;
template <class T>
const T getData(const std::string location) {
auto it = m_data.find(location);
const DataObject* d{nullptr};
if (it == end(m_data)) {
d = getIfExists<T>(location);
m_data.emplace(std::move(location), d);
} else {
d = it->second;
}
return static_cast<const T>(d);
}
enum { nBits = 3 * sizeof(unsigned int) * 8 };
template<class PRED>
struct Eval {
Eval(std::string loc) : location{std::move(loc)} {}
using Predicate = PRED;
using Arg = typename PRED::argument_type;
PRED* predicate = nullptr;
StatEntity *counter = nullptr;
AIDA::IHistogram1D* hist = nullptr;
RateCounter* rate = nullptr;
std::string location;
};
using ODINEval = Eval<LoKi::Types::ODIN_Cut>;
using L0Eval = Eval<LoKi::Types::L0_Cut>;
using HltEval = Eval<LoKi::Types::HLT_Cut>;
using EvalVariant = boost::variant<ODINEval, L0Eval, HltEval>;
class Builder : public boost::static_visitor<StatusCode> {
public:
Builder(HltEvaluator* parent, std::string expr,
std::string title, std::string htitle)
: m_parent{parent}, m_expr{std::move(expr)}, m_title{std::move(title)},
m_htitle{std::move(htitle)} {}
template <typename EVAL>
StatusCode operator()( EVAL& eval ) {
using BooleanConstant = typename LoKi::BasicFunctors<typename EVAL::Arg>::BooleanConstant;
typename EVAL::Predicate cut(BooleanConstant(false));
StatusCode sc = m_parent->factory().get(m_expr, cut, m_parent->preambulo());
if (sc.isFailure()) return std::move(sc);
eval.predicate = cut.clone();
eval.counter = &(m_parent->counter(m_title));
if (m_parent->m_hltMonSvc.isValid())
eval.rate = &(m_parent->m_hltMonSvc->rateCounter(m_parent->name() + "/" + m_htitle));
m_parent->declareInfo(boost::str( boost::format("COUNTER_TO_RATE[%s]") % m_htitle ),
*(eval.counter), m_htitle);
int nBins = int(m_parent->m_timeSpan / m_parent->m_binWidth + 0.5);
//TODO: set AxisLabels
eval.hist = m_parent->book1D(m_htitle, 0, nBins * m_parent->m_binWidth, nBins);
return StatusCode::SUCCESS;
}
private:
HltEvaluator* m_parent;
LoKi::Hybrid::IHltFactory* m_factory;
const std::string m_expr;
const std::string m_title;
const std::string m_htitle;
};
class Evaluator : public boost::static_visitor<bool> {
public:
Evaluator(HltEvaluator* parent, double t, double weight, double evtTime)
: m_parent{parent}, m_t{t}, m_weight{weight}, m_evtTime{evtTime} {}
template <typename EVAL>
bool operator()( EVAL& eval ) {
using Arg = typename EVAL::Arg;
Arg data = m_parent->getData<Arg>(eval.location);
if (!data) return false;
if (!eval.predicate) return false;
bool result = (*eval.predicate)(data);
*(eval.counter) += result;
if (result) eval.hist->fill(m_t, m_weight);
if (result && eval.rate) eval.rate->count(m_evtTime);
return result;
}
private:
HltEvaluator* m_parent;
double m_t;
double m_weight;
double m_evtTime;
};
struct Deleter : public boost::static_visitor<> {
template <typename EVAL>
void operator()( EVAL& eval ) const {
delete eval.predicate;
eval.counter = nullptr;
eval.hist = nullptr;
eval.rate = nullptr;
}
};
unsigned long long startOfRun() const {
// just in case we did not have the conditions DB start-of-run time...
if (m_startOfRun == 0) {
auto odin = get<LHCb::ODIN>(m_odin_location);
m_startOfRun = odin->gpsTime();
}
return m_startOfRun;
}
LoKi::Hybrid::IHltFactory& factory() const {
if (!m_factory) {
std::string factoryType = (0 == name().find ( "Hlt1" ) ?
"LoKi::Hybrid::HltFactory/Hlt1HltFactory:PUBLIC" :
(0 == name().find ( "Hlt2" ) ?
"LoKi::Hybrid::HltFactory/Hlt2HltFactory:PUBLIC" :
"LoKi::Hybrid::HltFactory/HltFactory:PUBLIC"));
m_factory = tool<LoKi::Hybrid::IHltFactory>(factoryType);
}
return *m_factory;
}
const std::string& preambulo() const {
return m_preambulo;
}
double binWidth() const { return m_binWidth; }
double timeSpan() const { return m_timeSpan; }
SmartIF<IHltMonitorSvc> m_hltMonSvc;
mutable LoKi::Hybrid::IHltFactory* m_factory;
std::string m_odin_location;
std::string m_l0_location;
std::string m_hlt_location[2];
std::string m_raw_location;
std::map<unsigned int,std::string> m_bits;
bool m_evals_updated;
bool m_preambulo_updated;
std::string m_preambulo;
private:
bool m_useCondDB;
std::string m_monSvc;
std::vector<std::string> m_preambulo_ ; // the preambulo property
std::unordered_map<std::string, const DataObject*> m_data;
Condition *m_runpars;
SmartIF<IUpdateManagerSvc> m_updMgrSvc;
mutable unsigned long long m_startOfRun = 0;
double m_binWidth; // in _minutes_!
double m_timeSpan; // in _minutes_!
StatusCode i_updateConditions();
void handle(const Incident&) override;
void updatePreambulo ( Property& );
};
#endif // HLTEVALUATOR_H
// $Id: HltTrackingCoder.h $
#ifndef HLTTRACKINGCODER_H
#define HLTTRACKINGCODER_H 1
// Include files
#include "Event/Track.h"
#include <vector>
/** @function HltTrackingCoder HltTrackingCoder.h
*
*
* @author Sebastian Neubert
* @date 2014-01-10
*
* Helper to code / decode Tracks into / from RawBank
*
* Unit tests for these functions are in utestTrackingCoder.cxx
*
* Encoding of track information into RawBank
* For each track:
* (nLhHCbIDs, ID0, ID1, ... IDn)
*
* tracks are just concatenated
*
*/
void
encodeTracks(const LHCb::Tracks& tracks, // Input track container
std::vector<unsigned int>& rawBank,
bool writeStates); // Output RawBank body
unsigned int
// returns number of decoded tracks
decodeTracks(const unsigned int* rawBank, // Input pointer to rawBank body
unsigned int nentries, // Input number of entries in rawBank
LHCb::Tracks& tracks); // Output track container
#endif // HLTTRACKINGCODER_H
#ifndef IREPORTCONVERT_H
#define IREPORTCONVERT_H 1
#include <string>
#include "Event/HltObjectSummary.h"
#include "Event/HltSelReports.h"
#include "HltDAQ/HltSelRepRBStdInfo.h"
#include "GaudiKernel/IAlgTool.h"
// For LHCb objects
#include "Event/Particle.h"
#include "Event/ProtoParticle.h"
#include "Event/Track.h"
#include "Event/RecSummary.h"
#include "Event/RichPID.h"
#include "Event/MuonPID.h"
#include "Event/CaloCluster.h"
#include "Event/RecVertex.h"
#include "Event/Vertex.h"
#include "GaudiKernel/VectorMap.h"
using LHCb::HltObjectSummary;
using LHCb::HltSelRepRBStdInfo;
static const InterfaceID IID_IReportConvert("IReportConvert", 1 , 0);
class IReportConvert : virtual public IAlgTool {
public:
virtual void setReportVersion(int) = 0;
virtual void setReportVersionLatest() = 0;
virtual int getReportVersion() = 0;
virtual int getLatestVersion() = 0;
virtual int getSizeSelRepParticleLatest() = 0;
/// Retrieve interface ID
static const InterfaceID& interfaceID() { return IID_IReportConvert; } // Actual operator function
// Decode the sub-bank properly
virtual void SummaryFromRaw( HltObjectSummary::Info*, HltSelRepRBStdInfo::StdInfo*, int ) = 0;
//
// Put the information in to the HltObjectSummary
virtual void ParticleObject2Summary( HltObjectSummary::Info*, const LHCb::Particle*, bool) = 0;
virtual void ProtoParticleObject2Summary( HltObjectSummary::Info*, const LHCb::ProtoParticle*, bool) = 0;
virtual void TrackObject2Summary( HltObjectSummary::Info*, const LHCb::Track*, bool) = 0;
virtual void RichPIDObject2Summary( HltObjectSummary::Info*, const LHCb::RichPID*, bool) = 0;
virtual void MuonPIDObject2Summary( HltObjectSummary::Info*, const LHCb::MuonPID*, bool) = 0;
virtual void CaloClusterObject2Summary( HltObjectSummary::Info*, const LHCb::CaloCluster*, bool) = 0;
virtual void CaloHypoObject2Summary( HltObjectSummary::Info*, const LHCb::CaloHypo*, bool) = 0;
virtual void RecVertexObject2Summary( HltObjectSummary::Info*, const LHCb::RecVertex*, bool) = 0;
virtual void VertexObject2Summary( HltObjectSummary::Info*, const LHCb::Vertex*, bool) = 0;
virtual void RecSummaryObject2Summary( HltObjectSummary::Info*, const LHCb::RecSummary*) = 0;
virtual void GenericMapObject2Summary( HltObjectSummary::Info*, const GaudiUtils::VectorMap<short,float>*) = 0;
//
// Put the information in the summary back in the object
virtual void ParticleObjectFromSummary( const HltObjectSummary::Info*, LHCb::Particle*, bool) = 0;
virtual void ProtoParticleObjectFromSummary( const HltObjectSummary::Info*, LHCb::ProtoParticle*, bool) = 0;
virtual void TrackObjectFromSummary( const HltObjectSummary::Info*, LHCb::Track*, bool) = 0;
virtual void RichPIDObjectFromSummary( const HltObjectSummary::Info*, LHCb::RichPID*, bool) = 0;
virtual void MuonPIDObjectFromSummary( const HltObjectSummary::Info*, LHCb::MuonPID*, bool) = 0;
virtual void CaloClusterObjectFromSummary( const HltObjectSummary::Info*, LHCb::CaloCluster*, bool) = 0;
virtual void CaloHypoObjectFromSummary( const HltObjectSummary::Info*, LHCb::CaloHypo*, bool) = 0;
virtual void RecVertexObjectFromSummary( const HltObjectSummary::Info*, LHCb::RecVertex*, bool) = 0;
virtual void VertexObjectFromSummary( const HltObjectSummary::Info*, LHCb::Vertex*, bool) = 0;
virtual void RecSummaryObjectFromSummary( const HltObjectSummary::Info*, LHCb::RecSummary*) = 0;
virtual void GenericMapObjectFromSummary( const HltObjectSummary::Info*, GaudiUtils::VectorMap<short,float>*) = 0;
};
#endif
This diff is collapsed.
#=====================================================================
# Created : 2009-06-23
# Maintainer : Tomasz Skwarnicki
#=====================================================================
package HltDAQ
version v4r28
#=====================================================================
# Structure, i.e. directories to process.
#=====================================================================
branches cmt doc src tests xml HltDAQ
#=====================================================================
# Used packages
#=====================================================================
use GaudiKernel v*
private
use GaudiObjDesc v* -no_auto_imports
end_private
use Boost v* LCG_Interfaces
use AIDA v* LCG_Interfaces -no_auto_imports
use GaudiAlg v*
use HltInterfaces v* Kernel
use HltEvent v* Event
use DAQEvent v* Event
use EventPacker v* Event
use DAQKernel v* DAQ
use LoKiHlt v* Phys
use HltServices v* Hlt
use LumiEvent v* Event
#### for CORAL access
use DetCond v* Det
#### for getting the StartOfRun condition
use DetDesc v* Det
### for access to the config.tar file with configurations
use HltTCK v* TCK -no_auto_imports
# include_path none
#=====================================================================
# Produce Header-Files from XML description
#=====================================================================
apply_pattern god_headers files=../xml/*.xml
macro HltDAQObj2Doth_GODflags " -s ../HltDAQ/ " \
WIN32 " -s ..\HltDAQ\ "
#=====================================================================
# define component library link options
#=====================================================================
apply_pattern component_library library=HltDAQ
#=====================================================================
# Component library building rule
#=====================================================================
library HltDAQ ../src/*.cpp
#=====================================================================
# define component library link options for use in HltDAQ and outside
#=====================================================================
apply_pattern install_more_includes more=HltDAQ
#=====================================================================
# unit test application building rule
#=====================================================================
application utestTrackingCoder -import=Boost utest/utestTrackingCoder.cpp utest/HltTrackingCoder_utest.cpp
macro_append Boost_linkopts " $(Boost_linkopts_iostreams) $(Boost_linkopts_filesystem)"
macro_append Boost_linkopts " -lboost_unit_test_framework-${Boost_compiler_version}-mt-${Boost_debug}${Boost_file_version}"
private
# Work around to be able to compile with Gaudi v22r5
macro_append pp_cppflags " -DBOOST_FILESYSTEM_VERSION=3 "
# This work around comes from GaudiGLS, but it seems to be needed here
# only since Gaudi v27r0.
# Note: libgslcblas is needed by libgsl, but the link is missing.
macro_prepend GSL_linkopts " -Wl,--no-as-needed " \
target-darwin "" \
target-winxp ""
macro_append GSL_linkopts " -Wl,--as-needed " \
target-darwin "" \
target-winxp "" \
target-icc ""
# Note: we pass only "--no-as-needed" to icc because the icc linker seems not
# to understand positional arguments, so the last of "--as-needed" or
# "--no-as-needed" wins.
end_private
#private
#macro_remove cppoptimized_s "-O2"
#macro_append cppoptimized_s "-g"
#end_private
#=====================================================================
#at least GaudiConf for IOHelper and LHCbApp
private
macro PRConfig_use "" QMTest "PRConfig v* -no_auto_imports"
use $(PRConfig_use)
macro Utils_use "" QMTest "DAQUtils v* DAQ -no_auto_imports"
use $(Utils_use)
macro LHCbK_use "" QMTest "LHCbAlgs v* Kernel -no_auto_imports"
use $(LHCbK_use)
macro GaudiC_use "" QMTest "GaudiConf v* -no_auto_imports"
use $(GaudiC_use)
end_private
apply_pattern QMTest
This diff is collapsed.
// $Id$
// Include files
// from Gaudi
#include "Event/HltDecReport.h"
#include "Event/HltDecReports.h"
// local
#include "HltDecReportsDecoder.h"
#include "HltDecReportsWriter.h"
//-----------------------------------------------------------------------------
// Implementation file for class : HltDecReportsDecoder
//
// 2008-08-02 : Tomasz Skwarnicki
//-----------------------------------------------------------------------------
// Declaration of the Algorithm Factory
DECLARE_ALGORITHM_FACTORY( HltDecReportsDecoder )
using namespace LHCb;
namespace {
// version 1 layout:
// decision: 0x 1 x
// error: 0x e xxx0
// #cand: 0x f0 xxxx 0000
// stage: 0x ff00 xxxx xxxx 0000 0000
// id: 0xffff 0000
// version 0 layout:
// decision: 0x 1 x
// error: 0x 70 0xxx 0000
// #cand: 0x ff80 xxxx xxxx x000 0000
// stage: 0x e xxx0
// id: 0xffff 0000
struct v0_v1 {
HltDecReport convert( unsigned int x ) {
// ID & decision stay the same
unsigned int temp = ( x & 0xffff0001 );
// stage needs to be moved
temp |= (x&0xe)<<7;
// number of candidates -- move & truncate
unsigned int nc = (x>>7)&0x1ff;
temp |= ( nc>0xf ? 0xf : nc )<<4;
// error just moves
temp |= (x&0x70)>>3;
return HltDecReport(temp);
}
};
struct vx_vx {
HltDecReport convert( unsigned int x ) { return HltDecReport(x); }
};
}
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
HltDecReportsDecoder::HltDecReportsDecoder( const std::string& name,
ISvcLocator* pSvcLocator)
: HltRawBankDecoderBase( name, pSvcLocator )
{
declareProperty("OutputHltDecReportsLocation",
m_outputHltDecReportsLocation= LHCb::HltDecReportsLocation::Default);
}
//=============================================================================
// Main execution
//=============================================================================
StatusCode HltDecReportsDecoder::execute() {
if ( msgLevel(MSG::DEBUG) ) debug() << "==> Execute" << endmsg;
// create output container and put it on TES
auto outputSummary = new HltDecReports();
put( outputSummary, m_outputHltDecReportsLocation );
std::vector<const RawBank*> hltdecreportsRawBanks = selectRawBanks( RawBank::HltDecReports );
if ( hltdecreportsRawBanks.empty() ) {
return Warning(" Could not find HltDecReports raw bank. Returning empty HltDecReports.", StatusCode::SUCCESS,20);
}
if( hltdecreportsRawBanks.size() != 1 ){
Warning(" More then one HltDecReports RawBanks for requested SourceID in RawEvent. Will only process the first one. " ,StatusCode::SUCCESS, 20 ).ignore();
}
const RawBank *hltdecreportsRawBank = hltdecreportsRawBanks.front();
if( hltdecreportsRawBank->magic() != RawBank::MagicPattern ){
return Error(" HltDecReports RawBank has wrong magic number. Return without decoding.",StatusCode::FAILURE );
}
if( hltdecreportsRawBank->version() > kVersionNumber ){
return Error(
" HltDecReports RawBank version # is larger then the known ones.... cannot decode, use newer version." ,StatusCode::FAILURE );
}
// ----------------------------------------------------------
const unsigned int *content = hltdecreportsRawBank->begin<unsigned int>();
// version 0 has only decreps, version 1 has TCK, taskID, then decreps...