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

added Event/DAQEvent from LHCb (LHCb/v41r0)

parent 62d0daf5
......@@ -22,3 +22,6 @@
[lb-checkout "LHCb.Event/MCEvent"]
base = d01b97284391813b093754763a71126fe929e0d2
imported = 26b40caca408e53f5959c238cd35d37f88411761
[lb-checkout "LHCb.Event/DAQEvent"]
base = 62d0daf5f20c4e9f1beb97ec47d906fc223f27d1
imported = 26b40caca408e53f5959c238cd35d37f88411761
################################################################################
# Package: DAQEvent
################################################################################
gaudi_subdir(DAQEvent v9r22)
gaudi_depends_on_subdirs(GaudiKernel
GaudiObjDesc)
include(GaudiObjDesc)
god_build_headers(xml/*.xml)
gaudi_add_library(DAQEventLib
src/*.cpp
PUBLIC_HEADERS Event
LINK_LIBRARIES GaudiKernel)
gaudi_add_dictionary(DAQEvent
xml/lcgdict/lcg_headers.h
xml/lcgdict/lcg_selection.xml
LINK_LIBRARIES GaudiKernel DAQEventLib
OPTIONS --comments)
#ifndef DAQEVENT_RAWBANK_H
#define DAQEVENT_RAWBANK_H 1
#include <string>
#include <vector>
/** @class LHCb::RawBank RawBank.h
*
* Raw data bank sent by the TELL1 boards of the LHCb DAQ.
*
* For a detailed description of the raw bank format,
* see <a href="https://edms.cern.ch/document/565851/5">EDMS-565851/5</a>
*
* Note concerning the changes done 06/03/2006:
* - The bank size is in BYTES
* - The full size of a bank in memory is long word (32 bit) aligned
* ie. a bank of 17 Bytes length actually uses 20 Bytes in memory.
* - The bank length accessors size() and setSize() do not contain
* the bank header, ie. size() = (total size) - (header size).
* - The length passed to the RawEvent::createBank should NOT
* contain the size of the header !
* - If the full padded bank size is required use the utility
* function RawBank::totalSize = size + header size + padding size.
*
* @author Helder Lopes
* @author Markus Frank
* created Tue Oct 04 14:45:20 2005
*
*/
namespace LHCb
{
class RawBankSubClass;
class RawBank {
/// Need to declare some friend to avoid compiler warnings
friend class RawBankSubClass;
private:
/// Default Constructor
RawBank() {}
/// Default Destructor
~RawBank() {}
public:
// typedef for std::vector of RawBank
typedef std::vector<RawBank*> Vector;
typedef std::vector<const RawBank*> ConstVector;
/// Define bank types for RawBank
enum BankType{ L0Calo=0, // 0
L0DU, // 1
PrsE, // 2
EcalE, // 3
HcalE, // 4
PrsTrig, // 5
EcalTrig, // 6
HcalTrig, // 7
Velo, // 8
Rich, // 9
TT, // 10
IT, // 11
OT, // 12
Muon, // 13
L0PU, // 14
DAQ, // 15
ODIN, // 16
HltDecReports, // 17
VeloFull, // 18
TTFull, // 19
ITFull, // 20
EcalPacked, // 21
HcalPacked, // 22
PrsPacked, // 23
L0Muon, // 24
ITError, // 25
TTError, // 26
ITPedestal, // 27
TTPedestal, // 28
VeloError, // 29
VeloPedestal, // 30
VeloProcFull, // 31
OTRaw, // 32
OTError, // 33
EcalPackedError, // 34
HcalPackedError, // 35
PrsPackedError, // 36
L0CaloFull, // 37
L0CaloError, // 38
L0MuonCtrlAll, // 39
L0MuonProcCand, // 40
L0MuonProcData, // 41
L0MuonRaw, // 42
L0MuonError, // 43
GaudiSerialize, // 44
GaudiHeader, // 45
TTProcFull, // 46
ITProcFull, // 47
TAEHeader, // 48
MuonFull, // 49
MuonError, // 50
TestDet, // 51
L0DUError, // 52
HltRoutingBits, // 53
HltSelReports, // 54
HltVertexReports,// 55
HltLumiSummary, // 56
L0PUFull, // 57
L0PUError, // 58
DstBank, // 59
DstData, // 60
DstAddress, // 61
FileID, // 62
VP, // 63
FTCluster, // 64
VL, // 65
UT, // 66
UTFull, // 67
UTError, // 68
UTPedestal, // 69
HC, // 70
HltTrackReports, // 71
HCError, // 72
// Add new types here. Don't forget to update also RawBank.cpp
LastType // LOOP Marker; add new bank types ONLY before!
};
/// Get any bank type as a string
static std::string typeName(LHCb::RawBank::BankType e);
/// Get this bank type as a string
inline std::string typeName(){return LHCb::RawBank::typeName( type() ); }
/// Magic pattern for Raw bank headers
enum RawPattern{ MagicPattern=0xCBCB };
/// Access to magic word for integrity check
int magic() const { return m_magic; }
/// Set magic word
void setMagic() { m_magic = MagicPattern; }
/// Header size
int hdrSize() const { return sizeof(RawBank)-sizeof(m_data);}
/// Return size of the data body part of the bank
int size() const { return m_length-hdrSize(); }
/// Set data size of the bank in bytes
void setSize(size_t val) { m_length = (val&0xFFFF)+hdrSize(); }
/// Access the full (padded) size of the bank
int totalSize() const {
typedef unsigned int T;
return m_length%sizeof(T)==0 ? m_length : (m_length/sizeof(T)+1)*sizeof(T);
}
/// Return bankType of this bank
BankType type() const { return BankType(int(m_type)); }
/// Set the bank type
void setType(BankType val) { m_type = (unsigned char)(char(val)&0xFF); }
/// Return version of this bank
int version() const { return m_version; }
/// Set the version information of this bank
void setVersion(int val) { m_version = (unsigned char)(val&0xFF); }
/// Return SourceID of this bank (TELL1 board ID)
int sourceID() const { return m_sourceID; }
/// Set the source ID of this bank (TELL1 board ID)
void setSourceID(int val) { m_sourceID = (unsigned short)(val&0xFFFF); }
/// Return pointer to begining of data body of the bank
unsigned int* data() { return &m_data[0]; }
/// Return pointer to begining of data body of the bank (const data access)
const unsigned int* data() const { return &m_data[0]; }
/// Begin iterator
template <typename T> T* begin(){ return (T*)m_data; }
/// End iterator
template <typename T> T* end() { return ((T*)m_data) + size()/sizeof(T); }
/// Begin iterator over const iteration
template <typename T> const T* begin() const {return (T*)m_data;}
/// End iterator of const iteration
template <typename T> const T* end() const {return ((T*)m_data) + size()/sizeof(T); }
private:
/// Magic word (by definition 0xCBCB)
unsigned short m_magic;
/// Bank length in bytes (must be >= 0)
unsigned short m_length;
/// Bank type (must be >= 0)
unsigned char m_type;
/// Version identifier (must be >= 0)
unsigned char m_version;
/// Source ID (valid source IDs are > 0; invalid ones 0)
short m_sourceID;
/// Opaque data block
unsigned int m_data[1];
}; // class RawBank
} // namespace LHCb
#endif ///DAQEvent_RawBank_H
#ifndef DAQEVENT_RAWEVENT_H
#define DAQEVENT_RAWEVENT_H 1
// Include files
#include "GaudiKernel/DataObject.h"
#include "Event/RawBank.h"
#include <string>
#include <vector>
#include <map>
namespace LHCb
{
// Class ID definition
static const CLID CLID_RawEvent = 1002;
// Namespace for locations in TDS
#ifdef __INTEL_COMPILER // Disable ICC remark
#pragma warning(disable:177) // variable was declared but never referenced
#endif
namespace RawEventLocation {
static const std::string& Default = "DAQ/RawEvent"; ///< Original FULL Raw Event
static const std::string& Emulated = "Emu/RawEvent";
static const std::string& Copied = "pRec/RawEvent";
static const std::string& Calo = "Calo/RawEvent"; ///< Copy of Calo banks
static const std::string& Muon = "Muon/RawEvent"; ///< Copy of Muon banks, for MDST
static const std::string& Rich = "Rich/RawEvent"; ///< Copy of Rich banks
static const std::string& Trigger = "Trigger/RawEvent"; ///< Copy of Trigger banks for Stripping and MDST
static const std::string& Other = "Other/RawEvent"; ///< Copy of all banks except Calo, Muon, Rich and Trigger (now Obsolete)
static const std::string& Velo = "Velo/RawEvent"; ///< Copy of Velo banks
static const std::string& Tracker = "Tracker/RawEvent"; ///< Copy of IT, OT and TT banks
static const std::string& HC = "HC/RawEvent"; ///< Copy of Herschel banks
static const std::string& Unstripped = "Unstripped/RawEvent"; ///< Miscellaneous banks not required by stripping lines.
}
/** @class LHCb::RawEvent RawEvent.h
*
* Raw event
*
* @author Helder Lopes
* @author Markus Frank
* created Tue Oct 04 14:45:29 2005
*
*/
class RawEvent : public DataObject {
public:
/** @class LHCb::RawEvent::Bank RawEvent.h Event/RawEvent.h
*
* Shadow class used to deal with persistency.
* This class is entirely internal. Do not change.
* In particular the field comments are hints to ROOT
* to support the storage of variable size C-arrays in order
* to avoid a copy of the data.
*
* Banks can be removed using the removeBank(RawBank*) member
* function. The bank to be removed must be identified by its
* pointer to ensure unambiguous bank identification also in the
* event where multiple banks if the same bank type are present.
* If no other bank of the category of the bank (Banktype)to
* be removed is anymore present in the raw event, also the
* category is removed.
*
* Note:
* - The length passed to the RawEvent::createBank should NOT
* contain the size of the header !
*
* @author M.Frank
* @version 1.0
*/
struct Bank {
int m_len; // Bank length
char m_owns; //! transient data member: ownership flag
unsigned int* m_buff; //[m_len]
/// Default constructor
Bank() : m_len(0), m_owns(1), m_buff(0) {}
/// Initializing constructor
Bank(int len, char owns, unsigned int* b) : m_len(len), m_owns(owns), m_buff(b) {}
/// Copy constructor
Bank(const Bank& c) : m_len(c.m_len), m_owns(c.m_owns), m_buff(c.m_buff) {
}
/// Assignment operator
Bank& operator=(const Bank& c) {
m_len = c.m_len;
m_owns = c.m_owns;
m_buff = c.m_buff;
return *this;
}
/// Access to memory buffer
unsigned int* buffer() { return m_buff; }
/// Access to ownership flag.
bool ownsMemory() const { return m_owns == 1; }
};
/// Default Constructor
RawEvent();
/// Default Destructor
virtual ~RawEvent();
/// Retrieve class identifier (static)
static const CLID& classID() { return CLID_RawEvent; }
/// Retrieve class identifier (virtual overload)
virtual const CLID& clID() const { return RawEvent::classID(); }
/// accessor method to the vector of Raw banks for a given bank type
const std::vector<RawBank*> & banks(RawBank::BankType bankType) {
// The optimizer should be able to deal with this...
return m_mapped ? m_eventMap[bankType] : mapBanks(bankType);
}
/// For offline use only: copy data into a set of banks, adding bank header internally.
void addBank(int sourceID,
RawBank::BankType bankType,
int version,
const std::vector<unsigned int>& data);
/// For offline use only: copy data into a bank, adding bank header internally.
void addBank(RawBank* data); // Pointer to data block (payload) of bank
/// Take ownership of a bank, including the header
void adoptBank(RawBank* bank, // Pointer to beginning of bank (i.e. bank header)
bool adopt_memory); // Flag to adopt memory
/// Remove bank identified by its pointer
/** Remove raw data bank from bankset and update bank map.
* The bank removal can fail if the specified bank was not found.
*
* @param bank [IN] Pointer to raw bank structure to be removed.
*
* @return Boolean value indicating success (=true) or failure(=false)
*/
bool removeBank(RawBank* bank);
/// Rawbank creator
/** Create raw bank and fill values
* @param srcID [IN] Source identifier
* @param typ [IN] Bank type (from RawBank::BankType enum)
* @param vsn [IN] Bank version
* @param len [IN] Length of data segment in bytes
* @param data [IN] Data buffer (if NULL, no data are copied)
*
* @return Initialized Pointer to RawBank structure
*/
static RawBank* createBank( int srcID,
RawBank::BankType typ,
int vsn,
size_t len,
const void* data=0);
/// Access the full length 32 bit aligned length of a bank in bytes
/** Access full bank length
* @param len [IN] Raw unaligned bank length
*
* @return padded bank size in bytes
*/
static size_t paddedBankLength(size_t len);
private:
/// Map banks on first request
/** @param bankType [IN] type of banks to be returned (from RawBank::BankType enum)
*
* @return vector of mapped banks corresponding to bankType
*/
const std::vector<RawBank*> & mapBanks(RawBank::BankType bankType);
std::map<RawBank::BankType,std::vector<RawBank*> > m_eventMap; //! transient Map with RawBanks (values) for each bank type
std::vector<Bank> m_banks; // Vector with persistent bank structure
bool m_mapped; //! transient
}; // class RawEvent
} // namespace LHCb
#endif /// DAQEVENT_RAWEVENT_H
package DAQEvent
version v9r22
use GaudiKernel v*
branches cmt doc Event src xml
private
use GaudiObjDesc v* -no_auto_imports
end_private
# Produce Header-Files from XML description
# ====================================================================
apply_pattern god_headers files=../xml/*.xml
apply_pattern install_more_includes more=Event
# ==================== Produce LCG dictionary ===============================
macro DAQEventGen_dependencies DAQEventObj2Doth
apply_pattern reflex_dictionary \
dictionary=DAQEvent \
headerfiles=$(DAQEVENTROOT)/xml/lcgdict/lcg_headers.h \
selectionfile=$(DAQEVENTROOT)/xml/lcgdict/lcg_selection.xml \
options=--comments
# ==================== linker library =======================================
macro DAQEventLib_dependencies DAQEventObj2Doth
library DAQEventLib *.cpp
apply_pattern linker_library library=DAQEventLib
This diff is collapsed.
// $Id: RawBank.cpp,v 1.9 2010-01-15 13:20:13 marcin Exp $
// local
#include "Event/RawBank.h"
//-----------------------------------------------------------------------------
// Implementation file for class : RawBank
//
// 2008-02-13 : Marco Cattaneo
//-----------------------------------------------------------------------------
//=============================================================================
std::string LHCb::RawBank::typeName(LHCb::RawBank::BankType e){
switch ( e ) {
//
// Important note:
// Keep the order exactly as in the RawEvent header file!
//
case LHCb::RawBank::L0Calo : return "L0Calo";
case LHCb::RawBank::L0DU : return "L0DU";
case LHCb::RawBank::PrsE : return "PrsE";
case LHCb::RawBank::EcalE : return "EcalE";
case LHCb::RawBank::HcalE : return "HcalE";
case LHCb::RawBank::PrsTrig : return "PrsTrig";
case LHCb::RawBank::EcalTrig : return "EcalTrig";
case LHCb::RawBank::HcalTrig : return "HcalTrig";
case LHCb::RawBank::Velo : return "Velo";
case LHCb::RawBank::Rich : return "Rich";
case LHCb::RawBank::TT : return "TT";
case LHCb::RawBank::IT : return "IT";
case LHCb::RawBank::OT : return "OT";
case LHCb::RawBank::Muon : return "Muon";
case LHCb::RawBank::L0PU : return "L0PU";
case LHCb::RawBank::DAQ : return "DAQ";
case LHCb::RawBank::ODIN : return "ODIN";
case LHCb::RawBank::HltDecReports : return "HltDecReports";
case LHCb::RawBank::VeloFull : return "VeloFull";
case LHCb::RawBank::TTFull : return "TTFull";
case LHCb::RawBank::ITFull : return "ITFull";
case LHCb::RawBank::EcalPacked : return "EcalPacked";
case LHCb::RawBank::HcalPacked : return "HcalPacked";
case LHCb::RawBank::PrsPacked : return "PrsPacked";
case LHCb::RawBank::L0Muon : return "L0Muon";
case LHCb::RawBank::ITError : return "ITError";
case LHCb::RawBank::TTError : return "TTError";
case LHCb::RawBank::ITPedestal : return "ITPedestal";
case LHCb::RawBank::TTPedestal : return "TTPedestal";
case LHCb::RawBank::VeloError : return "VeloError";
case LHCb::RawBank::VeloPedestal : return "VeloPedestal";
case LHCb::RawBank::VeloProcFull : return "VeloProcFull";
case LHCb::RawBank::OTRaw : return "OTRaw";
case LHCb::RawBank::OTError : return "OTError";
case LHCb::RawBank::EcalPackedError : return "EcalPackedError";
case LHCb::RawBank::HcalPackedError : return "HcalPackedError";
case LHCb::RawBank::PrsPackedError : return "PrsPackedError";
case LHCb::RawBank::L0CaloFull : return "L0CaloFull";
case LHCb::RawBank::L0CaloError : return "L0CaloError";
case LHCb::RawBank::L0MuonCtrlAll : return "L0MuonCtrlAll";
case LHCb::RawBank::L0MuonProcCand : return "L0MuonProcCand";
case LHCb::RawBank::L0MuonProcData : return "L0MuonProcData";
case LHCb::RawBank::L0MuonRaw : return "L0MuonRaw";
case LHCb::RawBank::L0MuonError : return "L0MuonError";
case LHCb::RawBank::GaudiSerialize : return "GaudiSerialize";
case LHCb::RawBank::GaudiHeader : return "GaudiHeader";
case LHCb::RawBank::TTProcFull : return "TTProcFull";
case LHCb::RawBank::ITProcFull : return "ITProcFull";
case LHCb::RawBank::TAEHeader : return "TAEHeader";
case LHCb::RawBank::MuonFull : return "MuonFull";
case LHCb::RawBank::MuonError : return "MuonError";
case LHCb::RawBank::TestDet : return "TestDet";
case LHCb::RawBank::L0DUError : return "L0DUError";
case LHCb::RawBank::HltRoutingBits : return "HltRoutingBits";
case LHCb::RawBank::HltSelReports : return "HltSelReports";
case LHCb::RawBank::HltVertexReports: return "HltVertexReports";
case LHCb::RawBank::HltLumiSummary : return "HltLumiSummary";
case LHCb::RawBank::L0PUFull : return "L0PUFull";
case LHCb::RawBank::L0PUError : return "L0PUError";
case LHCb::RawBank::DstBank : return "DstBank";
case LHCb::RawBank::DstData : return "DstData";
case LHCb::RawBank::DstAddress : return "DstAddress";
case LHCb::RawBank::FileID : return "FileID";
case LHCb::RawBank::VP : return "VP";
case LHCb::RawBank::FTCluster : return "FTCluster";
case LHCb::RawBank::VL : return "VL";
case LHCb::RawBank::UT : return "UT";
case LHCb::RawBank::UTFull : return "UTFull";
case LHCb::RawBank::UTError : return "UTError";
case LHCb::RawBank::UTPedestal : return "UTPedestal";
case LHCb::RawBank::HC : return "HC";
case LHCb::RawBank::HltTrackReports : return "HltTrackReports";
case LHCb::RawBank::HCError : return "HCError";
default : return "Undefined_name";
};
}
//=============================================================================
// $Id: RawEvent.cpp,v 1.15 2010-01-07 10:25:17 frankb Exp $
#include "Event/RawEvent.h"
#include <cstring> // for memcpy with gcc 4.3
namespace {
inline LHCb::RawBank* allocateBank(size_t len) {
size_t mem_len = LHCb::RawEvent::paddedBankLength(len);
size_t new_len = mem_len/sizeof(unsigned int);
unsigned int* mem = new unsigned int[new_len];
if ( mem_len != len ) {
mem[new_len-1] = 0;
}
return (LHCb::RawBank*)mem;
}
}
// Default Constructor
LHCb::RawEvent::RawEvent()
: m_mapped(false)
{
}
// Default Destructor
LHCb::RawEvent::~RawEvent() {
for(std::vector<Bank>::iterator i=m_banks.begin(); i != m_banks.end(); ++i) {
Bank& b = *i;
if ( b.ownsMemory() && b.buffer() ) {
delete [] b.buffer();
}
}
m_banks.clear();
}
size_t LHCb::RawEvent::paddedBankLength(size_t len) {
size_t mem_len = len+sizeof(LHCb::RawBank)-sizeof(unsigned int);
if ( mem_len%sizeof(unsigned int) ) { // Need padding
mem_len = (mem_len/sizeof(unsigned int) + 1)*sizeof(unsigned int);
}
return mem_len;
}
const std::vector<LHCb::RawBank*>& LHCb::RawEvent::mapBanks(RawBank::BankType bankType) {
for(std::vector<Bank>::iterator i=m_banks.begin(); i != m_banks.end(); ++i) {
LHCb::RawBank* bank = (LHCb::RawBank*)(*i).buffer();
m_eventMap[bank->type()].push_back(bank);
}
m_mapped = true;
return m_eventMap[bankType];
}
// For offline use only: copy data into a set of banks, adding bank header internally.
void LHCb::RawEvent::addBank( int srcID,
LHCb::RawBank::BankType typ,
int vsn,
const std::vector<unsigned int>& data) {
adoptBank( createBank(srcID, typ, vsn, data.size()*sizeof(unsigned int), &(*data.begin())), true );