Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • rrabadan/LHCb
  • talin/LHCb
  • imjelde/LHCb
  • mstahl/LHCb
  • padeken/LHCb
  • mimazure/LHCb
  • roiser/LHCb
  • conrad/LHCb
  • kklimasz/LHCb
  • rcurrie/LHCb
  • wkrzemie/LHCb
  • fkeizer/LHCb
  • valassi/LHCb
  • hschrein/LHCb
  • anstahll/LHCb
  • jonrob/LHCb
  • graven/LHCb
  • clemenci/LHCb
  • chaen/LHCb
  • sstahl/LHCb
  • lhcb/LHCb
21 results
Show changes
Commits on Source (8)
Showing with 88 additions and 42 deletions
......@@ -83,6 +83,7 @@ gaudi_add_library(DetDescLib
ROOT::GenVector
ROOT::MathCore
VDT::vdt
yaml-cpp
)
if(USE_DD4HEP)
target_link_libraries(DetDescLib PUBLIC LbDD4hepLib)
......
......@@ -24,6 +24,7 @@
#include <string>
#include <type_traits>
#include <utility>
#include <yaml-cpp/node/node.h>
namespace LHCb::DetDesc {
template <typename Base>
......@@ -104,6 +105,9 @@ namespace LHCb::DetDesc {
}
if constexpr ( detail::is_condition_type_v<T> ) {
return *m_ptr;
} else if constexpr ( std::is_same_v<T, YAML::Node> ) {
if ( !m_ptr->payload.has_value() ) m_ptr->payload = m_ptr->toYAML();
return std::any_cast<YAML::Node&>( m_ptr->payload );
} else { // unbox...
using BoxedType = std::conditional_t<std::is_copy_constructible_v<T>, T, detail::CopyWrapper<T>>;
const auto* p = std::any_cast<BoxedType>( &m_ptr->payload );
......
......@@ -159,6 +159,11 @@ namespace LHCb::DetDesc {
using Exp = std::decay_t<Input>;
if constexpr ( std::is_base_of_v<ValidDataObject, Exp> ) {
return castAndCheck<std::add_pointer_t<std::add_const_t<Exp>>>( i->second, key );
} else if constexpr ( std::is_same_v<YAML::Node, Exp> ) {
const auto& p = castAndCheck<ParamValidDataObject const*>( i->second, key );
// the const_cast here is safe because condition derivations are sequential by contruction
if ( !p.payload.has_value() ) const_cast<ParamValidDataObject&>( p ).payload = p.toYAML();
return std::any_cast<YAML::Node const&>( p.payload );
} else {
const auto& p = castAndCheck<ParamValidDataObject const*>( i->second, key );
return castAndCheck<Exp>( p.payload, key );
......
......@@ -17,6 +17,7 @@
#include "GaudiKernel/SmartRef.h"
#include <iostream>
#include <optional>
#include <string>
struct IAlignment;
......
......@@ -18,6 +18,7 @@
#include "DetDesc/ParamList.h"
#include <any>
#include <yaml-cpp/yaml.h>
/** @class ParamValidDataObject ParamValidDataObject.h DetDesc/ParamValidDataObject.h
*
......@@ -151,6 +152,8 @@ public:
/// Convert a parameter to a string (for xml representation).
virtual std::string paramToString( const std::string& name, int precision ) const;
YAML::Node toYAML() const;
public:
template <class T>
void addParam( const std::string& name, T value, std::string comment = {} ) {
......
......@@ -203,3 +203,35 @@ std::string ParamValidDataObject::paramToString( const std::string& name, int pr
if ( !i ) throw ParamException( name );
return i->toXMLStr( name, comment( name ), precision );
}
YAML::Node ParamValidDataObject::toYAML() const {
YAML::Node node;
for ( auto& name : paramNames() ) {
if ( is<int>( name ) ) {
node[name] = param<int>( name );
} else if ( is<double>( name ) ) {
node[name] = param<double>( name );
} else if ( is<std::string>( name ) ) {
node[name] = param<std::string>( name );
} else if ( is<std::vector<int>>( name ) ) {
node[name] = param<std::vector<int>>( name );
} else if ( is<std::vector<double>>( name ) ) {
node[name] = param<std::vector<double>>( name );
} else if ( is<std::vector<std::string>>( name ) ) {
node[name] = param<std::vector<std::string>>( name );
} else if ( is<std::map<std::string, int>>( name ) ) {
node[name] = param<std::map<std::string, int>>( name );
} else if ( is<std::map<std::string, double>>( name ) ) {
node[name] = param<std::map<std::string, double>>( name );
} else if ( is<std::map<std::string, std::string>>( name ) ) {
node[name] = param<std::map<std::string, std::string>>( name );
} else if ( is<std::map<int, int>>( name ) ) {
node[name] = param<std::map<int, int>>( name );
} else if ( is<std::map<int, double>>( name ) ) {
node[name] = param<std::map<int, double>>( name );
} else if ( is<std::map<int, std::string>>( name ) ) {
node[name] = param<std::map<int, std::string>>( name );
}
}
return node;
}
......@@ -25,7 +25,6 @@ gaudi_add_library(DetDescCnvLib
LHCb::DetDescLib
LHCb::XmlToolsLib
XercesC::XercesC
yaml-cpp
)
gaudi_add_module(DetDescCnv
......
......@@ -29,8 +29,6 @@ class ISvcLocator;
#include "TH2D.h"
#include "TH3D.h"
#include <yaml-cpp/yaml.h>
// -----------------------------------------------------------------------
namespace {
/// helper function for converton of 1d or 2d histograms
......@@ -157,11 +155,6 @@ StatusCode XmlBaseConditionCnv::i_fillObj( xercesc::DOMElement* childElement, Da
// gets the object
Condition* dataObj = static_cast<Condition*>( refpObject );
// This function gets called for every XML child element, so we have to
// keep updating the YAML version of the condition.
if ( dataObj->payload.type() != typeid( YAML::Node ) ) dataObj->payload = YAML::Node{};
YAML::Node& node = std::any_cast<YAML::Node&>( dataObj->payload );
// gets the element's name
const XMLCh* tagName = childElement->getNodeName();
// dispatches, based on the name
......@@ -218,11 +211,9 @@ StatusCode XmlBaseConditionCnv::i_fillObj( xercesc::DOMElement* childElement, Da
if ( type == "int" ) {
int data = static_cast<int>( xmlSvc()->eval( value, false ) );
dataObj->addParam<int>( name, data, comment );
node[name] = data;
} else if ( type == "double" ) {
double data = xmlSvc()->eval( value, false );
dataObj->addParam<double>( name, data, comment );
node[name] = data;
} else if ( type == "Histo1D" ) {
StatusCode sc = _addHisto<DetDesc::Params::Histo1D>( dataObj, name, value, comment );
if ( sc.isFailure() )
......@@ -237,7 +228,6 @@ StatusCode XmlBaseConditionCnv::i_fillObj( xercesc::DOMElement* childElement, Da
error() << "failed to parse Histo3D name ='" << name << "' value = '" << value << "'" << endmsg;
} else {
dataObj->addParam<std::string>( name, value, comment );
node[name] = value;
}
} else if ( 0 == xercesc::XMLString::compareString( paramVectorString, tagName ) ) {
// parses the value
......@@ -268,13 +258,10 @@ StatusCode XmlBaseConditionCnv::i_fillObj( xercesc::DOMElement* childElement, Da
}
if ( "int" == type ) {
node[name] = i_vect;
dataObj->addParam( name, std::move( i_vect ), comment );
} else if ( "double" == type ) {
node[name] = d_vect;
dataObj->addParam( name, std::move( d_vect ), comment );
} else {
node[name] = vect;
dataObj->addParam( name, std::move( vect ), comment );
}
}
......@@ -287,30 +274,24 @@ StatusCode XmlBaseConditionCnv::i_fillObj( xercesc::DOMElement* childElement, Da
xercesc::DOMNodeList* entries = childElement->getChildNodes();
if ( keytype == "string" ) {
if ( valuetype == "int" ) {
auto data = i_makeMap<std::string, int>( entries );
node[name] = data;
auto data = i_makeMap<std::string, int>( entries );
dataObj->addParam( name, std::move( data ), comment );
} else if ( valuetype == "double" ) {
auto data = i_makeMap<std::string, double>( entries );
node[name] = data;
auto data = i_makeMap<std::string, double>( entries );
dataObj->addParam( name, std::move( data ), comment );
} else {
auto data = i_makeMap<std::string, std::string>( entries );
node[name] = data;
auto data = i_makeMap<std::string, std::string>( entries );
dataObj->addParam( name, std::move( data ), comment );
}
} else if ( keytype == "int" ) {
if ( valuetype == "int" ) {
auto data = i_makeMap<int, int>( entries );
node[name] = data;
auto data = i_makeMap<int, int>( entries );
dataObj->addParam( name, std::move( data ), comment );
} else if ( valuetype == "double" ) {
auto data = i_makeMap<int, double>( entries );
node[name] = data;
auto data = i_makeMap<int, double>( entries );
dataObj->addParam( name, std::move( data ), comment );
} else {
auto data = i_makeMap<int, std::string>( entries );
node[name] = data;
auto data = i_makeMap<int, std::string>( entries );
dataObj->addParam( name, std::move( data ), comment );
}
} else {
......
......@@ -28,6 +28,7 @@ using MuonDAQHelper = LHCb::Detector::Muon::DAQHelper;
# include "GaudiKernel/SmartDataPtr.h"
# include <memory>
# include <optional>
# include <string>
# include <vector>
......
......@@ -19,6 +19,8 @@ using DeVPSensor = LHCb::Detector::DeVPSensor;
# include <array>
# include <atomic>
# include <bitset>
# include <set>
// Gaudi
# include "GaudiKernel/MsgStream.h"
......
......@@ -570,11 +570,12 @@ namespace LHCb::Calo::Functor {
float Etot;
float x;
float y;
float Epos;
};
template <typename Range, class DE>
std::optional<EXY> calculateClusterEXY( Range&& r, DE de ) {
// reset initial parameters
EXY exy{0, 0, 0};
EXY exy{0, 0, 0, 0};
// no detector
if ( !de ) return std::nullopt;
// empty sequence
......@@ -598,12 +599,11 @@ namespace LHCb::Calo::Functor {
const Gaudi::XYZPoint& refPos = de->cellCenter( leading_id );
// energy for position
float epos = 0.0f;
for ( const auto& entry : r ) {
auto e = energy_f( entry );
if ( entry.status().test( DigitStatus::Mask::UseForEnergy ) ) exy.Etot += e; // accumulate digit energy
if ( entry.status().test( DigitStatus::Mask::UseForPosition ) ) {
epos += e; // accumulate digit energy for position
exy.Epos += e; // accumulate digit energy for position
if ( entry.cellID() != leading_id ) {
const Gaudi::XYZPoint& pos = de->cellCenter( entry.cellID() );
exy.x += e * ( pos.x() - refPos.x() );
......@@ -612,10 +612,10 @@ namespace LHCb::Calo::Functor {
}
}
// accumulated energy is NULL!
if ( 0 == epos ) return std::nullopt;
if ( 0 == exy.Epos ) return std::nullopt;
// rescale x and y
exy.x = refPos.x() + exy.x / epos;
exy.y = refPos.y() + exy.y / epos;
exy.x = refPos.x() + exy.x / exy.Epos;
exy.y = refPos.y() + exy.y / exy.Epos;
return exy;
}
......
......@@ -21,13 +21,6 @@
#pragma once
// from STL
#include <cstdint>
#include <map>
#include <sstream>
#include <type_traits>
#include <vector>
// GaudiKernel
#include "GaudiKernel/HashMap.h"
#include "GaudiKernel/Kernel.h"
......@@ -36,6 +29,14 @@
#include "Kernel/RichSmartID.h"
#include "Kernel/RichSmartIDHashFuncs.h"
// STL
#include <cassert>
#include <cstdint>
#include <map>
#include <sstream>
#include <type_traits>
#include <vector>
namespace Rich::DAQ {
//---------------------------------------------------------------------------------
......@@ -383,9 +384,11 @@ namespace Rich::DAQ {
static constexpr const I MaskSide = ( I )( ( I( 1 ) << BitsSide ) - I( 1 ) ) << ShiftSide;
static constexpr const I MaskPartition = ( I )( ( I( 1 ) << BitsPartition ) - I( 1 ) ) << ShiftPartition;
public:
/// Use base constructors
using NumericType<std::int16_t>::NumericType;
private:
/// Set the given data into the given field
constexpr void set( const I value, const I shift, const I mask ) noexcept {
setData( ( ( value << shift ) & mask ) | ( data() & ~mask ) );
}
public:
/// Get the partition
......@@ -410,6 +413,20 @@ namespace Rich::DAQ {
return ( this->NumericType<std::int16_t>::isValid() && rich() != Rich::InvalidDetector );
}
public:
/// Use base constructors
using NumericType<std::int16_t>::NumericType;
/// Constructor from individual data fields
SourceID( const Rich::DetectorType r, const Rich::Side s, const std::uint16_t p ) {
set( ( Rich::Rich1 == r ? RICH1 : RICH2 ), ShiftPartition, MaskPartition );
set( s, ShiftSide, MaskSide );
set( p, ShiftPayload, MaskPayload );
assert( r == rich() );
assert( s == side() );
assert( p == payload() );
}
public:
/// Overload output to ostream
friend inline std::ostream& operator<<( std::ostream& os, const SourceID& id ) {
......