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

added Event/EventPacker from LHCb (LHCb/v41r0)

parent bbb15a34
......@@ -31,3 +31,6 @@
[lb-checkout "LHCb.Hlt/HltDAQ"]
base = 4fb78a28e1dc4c4f5e858d0f6b0371aa9bc8f212
imported = 26b40caca408e53f5959c238cd35d37f88411761
[lb-checkout "LHCb.Event/EventPacker"]
base = bc8b6f3624f30836b6286160a8ae09798f5ad829
imported = 26b40caca408e53f5959c238cd35d37f88411761
################################################################################
# Package: EventPacker
################################################################################
gaudi_subdir(EventPacker v5r11)
gaudi_depends_on_subdirs(DAQ/MDF
Event/DAQEvent
Event/HltEvent
Event/MCEvent
Event/MicroDst
Event/RecEvent
Event/TrackEvent
GaudiAlg
GaudiKernel
Kernel/LHCbKernel
Kernel/Relations)
find_package(Boost COMPONENTS regex)
gaudi_add_library(EventPackerLib
src/lib/*.cpp
PUBLIC_HEADERS Event
LINK_LIBRARIES MCEvent PhysEvent RecEvent GaudiAlgLib GaudiKernel LHCbKernel)
gaudi_add_module(EventPacker
src/component/*.cpp
INCLUDE_DIRS Boost
LINK_LIBRARIES Boost MDFLib DAQEventLib HltEvent MCEvent MicroDstLib RecEvent TrackEvent GaudiAlgLib GaudiKernel LHCbKernel RelationsLib EventPackerLib)
gaudi_add_dictionary(EventPacker
dict/PackedEventDict.h
dict/PackedEventDict.xml
LINK_LIBRARIES MCEvent PhysEvent RecEvent GaudiAlgLib GaudiKernel LHCbKernel EventPackerLib)
#ifndef __EVENTPACKER_EVENT_GENERICBUFFER_H__
#define __EVENTPACKER_EVENT_GENERICBUFFER_H__
#include "GaudiKernel/DataObject.h"
namespace LHCb
{
/** @class GenericBuffer
*
* Generic char buffer for storing data.
*
* @author Wouter Hulsbergen
* @date 2015-10-01
*/
static const CLID CLID_GenericBuffer = 1556 ;
class GenericBuffer : public DataObject
{
public:
/// type of data holder
typedef std::vector<char> DataType ;
/// non-const accessor
DataType& data() { return m_data; }
/// const accessor
const DataType& data() const { return m_data; }
/// Class ID
static const CLID& classID() { return CLID_GenericBuffer ; }
/// Class ID
virtual const CLID& clID() const { return GenericBuffer::classID(); }
private:
std::vector<char> m_data ;
} ;
}
#endif
#ifndef EVENT_PackedCaloCluster_H
#define EVENT_PackedCaloCluster_H 1
// STL
#include <string>
// Kernel
#include "Event/StandardPacker.h"
// Event
#include "Event/CaloCluster.h"
// Gaudi
#include "GaudiKernel/DataObject.h"
#include "GaudiKernel/StatusCode.h"
#include "GaudiKernel/GaudiException.h"
namespace LHCb
{
// -----------------------------------------------------------------------
/** @struct CaloClusterEntry Event/PackedCaloCluster.h
*
* Packed LHCb::CaloClusterEntry
*
* @author Christopher Rob Jones
* @date 2012-03-30
*/
struct PackedCaloClusterEntry
{
long long digit{-1};
unsigned int status{0};
short int fraction{0};
template<typename T>
inline void save(T& buf) const {
buf.io(digit, status, fraction);
}
template<typename T>
inline void load(T& buf, unsigned int /*version*/) {
save(buf); // identical operation until version is incremented
}
};
/** @struct PackedCaloCluster Event/PackedCaloCluster.h
*
* Packed LHCb::CaloCluster
*
* @author Christopher Rob Jones
* @date 2012-03-30
*/
struct PackedCaloCluster
{
int key{0};
int type{0};
unsigned int seed{0};
int pos_x{0}, pos_y{0}, pos_z{0}, pos_e{0};
int pos_c0{0}, pos_c1{0};
int pos_cov00{0},pos_cov11{0},pos_cov22{0};
short int pos_cov10{0},pos_cov20{0},pos_cov21{0};
int pos_spread00{0},pos_spread11{0};
short int pos_spread10{0};
unsigned short int firstEntry{0}, lastEntry{0};
template<typename T>
inline void save(T& buf) const {
buf.io(
key, type, seed,
pos_x, pos_y, pos_z, pos_e,
pos_c0, pos_c1,
pos_cov00, pos_cov11, pos_cov22,
pos_cov10, pos_cov20, pos_cov21,
pos_spread00, pos_spread11,
pos_spread10,
firstEntry, lastEntry
);
}
template<typename T>
inline void load(T& buf, unsigned int /*version*/) {
save(buf); // identical operation until version is incremented
}
};
// -----------------------------------------------------------------------
static const CLID CLID_PackedCaloClusters = 1541;
/// Namespace for locations in TDS
namespace PackedCaloClusterLocation
{
static const std::string& Default = "pRec/Calo/Clusters";
}
/** @class PackedCaloClusters Event/PackedCaloCluster.h
*
* Packed Calo Clusters
*
* @author Christopher Rob Jones
* @date 2009-10-13
*/
class PackedCaloClusters : public DataObject
{
public:
/// Vector of PackedCaloCluster objects
typedef std::vector<LHCb::PackedCaloCluster> ClusterVector;
/// Vector of PackedCaloClusterEntry objects
typedef std::vector<LHCb::PackedCaloClusterEntry> ClusterEntryVector;
public:
/// Default Packing Version
static char defaultPackingVersion() { return 0; }
public:
/// Class ID
static const CLID& classID() { return CLID_PackedCaloClusters; }
/// Class ID
virtual const CLID& clID() const { return PackedCaloClusters::classID(); }
public:
/// Write access to the data vector
ClusterVector & data() { return m_clusters; }
/// Read access to the data vector
const ClusterVector & data() const { return m_clusters; }
/// Write access to the data vector
ClusterEntryVector & entries() { return m_entries; }
/// Read access to the data vector
const ClusterEntryVector & entries() const { return m_entries; }
/// Set the packing version
void setPackingVersion( const char ver ) { m_packingVersion = ver; }
/// Access the packing version
char packingVersion() const { return m_packingVersion; }
/// Describe serialization of object
template<typename T>
inline void save(T& buf) const {
buf.template save<uint8_t>(m_packingVersion);
buf.template save<uint8_t>(version());
buf.save(m_clusters);
buf.save(m_entries);
}
/// Describe de-serialization of object
template<typename T>
inline void load(T& buf) {
setPackingVersion(buf.template load<uint8_t>());
setVersion(buf.template load<uint8_t>());
if (m_packingVersion > defaultPackingVersion()) {
throw std::runtime_error("PackedCaloClusters packing version is not supported: "
+ std::to_string(m_packingVersion));
}
buf.load(m_clusters, m_packingVersion);
buf.load(m_entries, m_packingVersion);
}
private:
/// Data packing version
char m_packingVersion{ defaultPackingVersion() };
/// The packed data objects
ClusterVector m_clusters;
/// Packed Calo Entries
ClusterEntryVector m_entries;
};
// -----------------------------------------------------------------------
/** @class CaloClusterPacker Event/PackedCaloCluster.h
*
* Utility class to handle the packing and unpacking of the Calo Clusters
*
* @author Christopher Rob Jones
* @date 2012-03-30
*/
class CaloClusterPacker
{
public:
// These are required by the templated algorithms
typedef LHCb::CaloCluster Data;
typedef LHCb::PackedCaloCluster PackedData;
typedef LHCb::CaloClusters DataVector;
typedef LHCb::PackedCaloClusters PackedDataVector;
static const std::string& packedLocation()
{
return LHCb::PackedCaloClusterLocation::Default;
}
static const std::string& unpackedLocation()
{
return LHCb::CaloClusterLocation::Default;
}
private:
/// Default Constructor hidden
CaloClusterPacker() {}
public:
/// Default Constructor
CaloClusterPacker( const GaudiAlgorithm * p ) : m_pack(p) { }
public:
/// Pack Calo Clusters
void pack( const DataVector & clus,
PackedDataVector & pclus ) const;
/// Unpack Calo Clusters
void unpack( const PackedDataVector & pclus,
DataVector & cluss ) const;
/// Compare two Calo Clusters containers to check the packing -> unpacking performance
StatusCode check( const DataVector & dataA,
const DataVector & dataB ) const;
/// Compare two Calo Clusters to check the packing -> unpacking performance
StatusCode check( const Data & dataA,
const Data & dataB ) const;
public:
/// Access the parent algorithm
const GaudiAlgorithm& parent() const { return *(m_pack.parent()); }
/// Safe sqrt ...
inline double safe_sqrt( const double x ) const
{ return ( x > 0 ? std::sqrt(x) : 0.0 ); }
/// Check if the given packing version is supported
bool isSupportedVer( const char& ver ) const
{
const bool OK = ( 0 == ver );
if ( UNLIKELY(!OK) )
{
std::ostringstream mess;
mess << "Unknown packed data version " << (int)ver;
throw GaudiException( mess.str(), "RichPIDPacker", StatusCode::FAILURE );
}
return OK;
}
private:
/// Standard packing of quantities into integers ...
StandardPacker m_pack;
};
// -----------------------------------------------------------------------
}
#endif // EVENT_PackedCaloCluster_H
#ifndef EVENT_PACKEDCALOHYPO_H
#define EVENT_PACKEDCALOHYPO_H 1
#include "GaudiKernel/DataObject.h"
#include "GaudiKernel/StatusCode.h"
#include "GaudiKernel/GaudiException.h"
// Kernel
#include "Event/StandardPacker.h"
// Event
#include "Event/CaloHypo.h"
#include <string>
#include <vector>
namespace LHCb
{
/** @struct PackedCaloHypo Event/PackedCaloHypo.h
* Packed description of a CaloHypo
*
* @author Olivier Callot
* @date 2008-11-10
*/
struct PackedCaloHypo
{
int key{0};
int hypothesis{0};
int lh{0};
// from CaloPosition
int z{0};
// position (3) + 3x3 symmetric covariance matrix
int posX{0}, posY{0}, posE{0};
int cov00{0}, cov11{0}, cov22{0};
short int cov10{0}, cov20{0}, cov21{0};
short int cerr10{0}; // non diagonal terms of the x,y spread matrix.
// center in x,y + 2x2 symetric covariance matrix
int centX{0};
int centY{0};
int cerr00{0};
int cerr11{0};
unsigned short int firstDigit{0};
unsigned short int lastDigit{0};
unsigned short int firstCluster{0};
unsigned short int lastCluster{0};
unsigned short int firstHypo{0};
unsigned short int lastHypo{0};
template<typename T>
inline void save(T& buf) const {
buf.io(
key, hypothesis, lh, z, posX, posY, posE,
cov00, cov11, cov22,
cov10, cov20, cov21,
cerr10,
centX, centY, cerr00, cerr11,
firstDigit, lastDigit,
firstCluster, lastCluster,
firstHypo, lastHypo
);
}
template<typename T>
inline void load(T& buf, unsigned int /*version*/) {
save(buf); // identical operation until version is incremented
}
};
static const CLID CLID_PackedCaloHypos = 1551;
// Namespace for locations in TDS
namespace PackedCaloHypoLocation
{
static const std::string& Photons = "pRec/Calo/Photons";
static const std::string& Electrons = "pRec/Calo/Electrons";
static const std::string& MergedPi0s = "pRec/Calo/MergedPi0s";
static const std::string& SplitPhotons = "pRec/Calo/SplitPhotons";
}
/** @class PackedCaloHypos Event/PackedCaloHypo.h
*
* Vector of packed CaloHypos
*
* @author Olivier Callot
* @date 2008-11-10
*/
class PackedCaloHypos : public DataObject
{
public:
/// Default Packing Version
static char defaultPackingVersion() { return 1; }
public:
/// Standard constructor
PackedCaloHypos( )
{
m_vect.reserve(100);
m_refs.reserve(1000);
}
public:
virtual const CLID& clID() const { return PackedCaloHypos::classID(); }
static const CLID& classID() { return CLID_PackedCaloHypos; }
public:
std::vector<PackedCaloHypo>& hypos() { return m_vect; }
const std::vector<PackedCaloHypo>& hypos() const { return m_vect; }
std::vector<long long>& refs() { return m_refs; }
const std::vector<long long>& refs() const { return m_refs; }
public:
/// Set the packing version
void setPackingVersion( const char ver ) { m_packingVersion = ver; }
/// Access the packing version
char packingVersion() const { return m_packingVersion; }
/// Describe serialization of object
template<typename T>
inline void save(T& buf) const {
buf.template save<uint8_t>(m_packingVersion);
buf.template save<uint8_t>(version());
buf.save(m_vect);
buf.save(m_refs);
}
/// Describe de-serialization of object
template<typename T>
inline void load(T& buf) {
setPackingVersion(buf.template load<uint8_t>());
setVersion(buf.template load<uint8_t>());
if (m_packingVersion < 1 || m_packingVersion > defaultPackingVersion()) {
throw std::runtime_error("PackedCaloHypos packing version is not supported: "
+ std::to_string(m_packingVersion));
}
buf.load(m_vect, m_packingVersion);
buf.load(m_refs);
}
private:
std::vector<PackedCaloHypo> m_vect;
std::vector<long long> m_refs;
/// Data packing version
char m_packingVersion{0};
};
/** @class CaloHypoPacker Event/PackedCaloHypo.h
*
* Utility class to handle the packing and unpacking of CaloHypos
*
* @author Christopher Rob Jones
* @date 05/04/2012
*/
class CaloHypoPacker
{
public:
typedef LHCb::CaloHypo Data;
typedef LHCb::PackedCaloHypo PackedData;
typedef LHCb::CaloHypos DataVector;
typedef LHCb::PackedCaloHypos PackedDataVector;
private:
/// Default Constructor hidden
CaloHypoPacker() {}
public:
/// Default Constructor
CaloHypoPacker( const GaudiAlgorithm * p ) : m_pack(p) {}
public:
/// Pack CaloHypos
void pack( const DataVector & hypos,
PackedDataVector & phypos ) const;
/// Unpack CaloHypos
void unpack( const PackedDataVector & phypos,
DataVector & hypos ) const;
/// Compare two CaloHypos to check the packing -> unpacking performance
StatusCode check( const DataVector & dataA,
const DataVector & dataB ) const;
private:
/// Access the parent algorithm
const GaudiAlgorithm& parent() const { return *(m_pack.parent()); }
/// Safe sqrt ...
inline double safe_sqrt( const double x ) const
{ return ( x > 0 ? std::sqrt(x) : 0.0 ); }
/// Check if the given packing version is supported
bool isSupportedVer( const char& ver ) const
{
const bool OK = ( 1 == ver || 0 == ver );
if ( !OK )
{
std::ostringstream mess;
mess << "Unknown packed data version " << (int)ver;
throw GaudiException( mess.str(), "CaloHypoPacker", StatusCode::FAILURE );
}
return OK;
}
private:
/// Standard packing of quantities into integers ...
StandardPacker m_pack;
};
}
#endif // EVENT_PACKEDCALOHYPO_H
// $Id: $
#ifndef EVENT_PACKEDCLUSTER_H
#define EVENT_PACKEDCLUSTER_H 1
#include "GaudiKernel/DataObject.h"
#include "Event/VeloCluster.h"
#include "Event/STCluster.h"
#include <string>
#include <vector>
namespace LHCb
{
/** @class PackedCluster PackedCluster.h Event/PackedCluster.h
*