Commit ea3bd03b authored by Paul Keener's avatar Paul Keener Committed by Graeme Stewart
Browse files

Support table versions upto 255 in RodDecoder (TRT_RawDataByteStreamCnv-00-03-09)

parent 988692cf
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ITRT_RAWDATABYTESTREAMCNV_TRTRAWCONTRAWEVENTTOOL_H
#define ITRT_RAWDATABYTESTREAMCNV_TRTRAWCONTRAWEVENTTOOL_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "ByteStreamData/RawEvent.h"
#include "InDetRawData/TRT_RDO_Container.h"
class ITRTRawContByteStreamTool: virtual public IAlgTool
{
public:
static const InterfaceID& interfaceID( ) ;
//! New convert method which makes use of the encoder class (as done for other detectors)
virtual StatusCode convert(TRT_RDO_Container* cont, RawEventWrite* re ) = 0;
};
inline const InterfaceID& ITRTRawContByteStreamTool::interfaceID( )
{
static const InterfaceID IID ("ITRTRawContByteStreamTool", 1, 0);
return IID;
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ITRT_RAWDATABYTESTREAMCNV_TRTRAWDATAPROVIDERTOOL_H
#define ITRT_RAWDATABYTESTREAMCNV_TRTRAWDATAPROVIDERTOOL_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "InDetRawData/TRT_RDO_Container.h"
#include "ByteStreamData/RawEvent.h"
#include <vector>
using OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment;
// the tool to decode a ROB frament
class ITRTRawDataProviderTool : virtual public IAlgTool
{
public:
//! AlgTool InterfaceID
static const InterfaceID& interfaceID( ) ;
//! this is the main decoding method
virtual StatusCode convert( std::vector<const ROBFragment*>& vecRobs,
TRT_RDO_Container* rdoIdc ) = 0;
};
inline const InterfaceID& ITRTRawDataProviderTool::interfaceID( )
{
static const InterfaceID IID ("ITRTRawDataProviderTool", 1, 0);
return IID;
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ITRT_RAWDATABYTESTREAM_TRT_RODDECODER_H
#define ITRT_RAWDATABYTESTREAM_TRT_RODDECODER_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "Identifier/IdentifierHash.h"
#include "ByteStreamData/RawEvent.h"
#include "InDetRawData/TRT_RDO_Container.h"
#include <vector>
using OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment;
// the tool to decode a ROB frament
class ITRT_RodDecoder : virtual public IAlgTool
{
public:
//! interfaceID
static const InterfaceID& interfaceID( ) ;
//! the method to fill the IDC
virtual StatusCode fillCollection ( const ROBFragment* robFrag,
TRT_RDO_Container* rdoIdc,
std::vector<IdentifierHash>* vecHash = 0 ) = 0;
};
inline const InterfaceID& ITRT_RodDecoder::interfaceID( )
{
static const InterfaceID IID ("ITRT_RodDecoder", 1, 0);
return IID;
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ITRT_DETRAWDATABYTESTREAMCNV_TRT_RODENCODER_H
#define ITRT_RAWDATABYTESTREAMCNV_TRT_RODENCODER_H
// #include <inttypes.h>
//#include "ByteStreamData/RawEvent.h"
//#include "InDetIdentifier/TRT_ID.h"
//#include "InDetRawData/TRT_RDORawData.h"
//#include "TRT_Cabling/TRT_IdMapping.h"
#include <vector>
class TRT_ID;
class TRT_IdMapping;
class TRT_RDORawData;
/** This class provides conversion from TRT RDO to ROD format.
*/
class ITRT_RodEncoder
{
public:
typedef TRT_RDORawData RDO ;
typedef std::vector<const RDO*> VRDO;
//! add RDO to internal vector
virtual void addRdo(const RDO * rdo) = 0;
//! setId Helper
virtual void set_trt_IdHelper ( const TRT_ID * trt_id) = 0;
//! setIdMapping
virtual void set_trt_IdMapping ( TRT_IdMapping* trt_IdMapping) = 0;
//! setRodMinorVersion
virtual void setRodMinorVersion (unsigned short RodBlockVersion) = 0;
//! conversion of ROD into ROD fragment
virtual StatusCode fillROD(std::vector<uint32_t>& v, MsgStream& log ) = 0;
virtual StatusCode fillROD3(std::vector<uint32_t>& v, MsgStream& log ) = 0;
};
#endif
package TRT_RawDataByteStreamCnv
author Paul Keener <Paul.Keener@cern.ch>
use AtlasPolicy AtlasPolicy-*
use AthenaBaseComps AthenaBaseComps-* Control
use InDetRawData InDetRawData-* InnerDetector/InDetRawEvent
use Identifier Identifier-* DetectorDescription
use ByteStreamData ByteStreamData-* Event
private
use StoreGate StoreGate-* Control
use GaudiInterface GaudiInterface-* External
use ByteStreamCnvSvcBase ByteStreamCnvSvcBase-* Event
use InDetIdentifier InDetIdentifier-* InnerDetector/InDetDetDescr
use TRT_Cabling TRT_Cabling-* InnerDetector/InDetDetDescr
use EventInfo EventInfo-* Event
use InDetReadoutGeometry InDetReadoutGeometry-* InnerDetector/InDetDetDescr
use TRT_ConditionsServices TRT_ConditionsServices-* InnerDetector/InDetConditions
use PathResolver PathResolver-* Tools
use AtlasCOOL AtlasCOOL-* External
use AtlasCORAL AtlasCORAL-* External
use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL
end_private
# Declare the tdaq-common components that are required (only relevent for cmake - invisible to CMT)
apply_pattern cmake_add_command command="find_package(tdaq-common COMPONENTS eformat_write DataWriter)"
# create the regular dual_use_lib for the Container converters + helper classes
#apply_pattern dual_use_library files="*.cxx"
apply_pattern component_library
library TRT_RawDataByteStreamCnv *.cxx components/*.cxx
apply_pattern declare_runtime files="*.dat"
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
@mainpage TRT_RawDataByteStreamCnv Package
@author Paul.Keener@cern.ch, Markus.Elsing@cern.ch
@section TRT_RawDataByteStreamCnvInfro Introduction
This package contains the classes to read TRT real data or MC byte stream information and to write MC byte stream. It is using the new IDC. The decoding classes are used by the TriOnlineSpacePointProvider and the InDetTrigRawDataByteStreamCnv for the LVL2 and Event Filter BS decoding.
@section TRT_RawDataByteStreamCnvRea Reading Byte Stream
- TRTRawDataProvider: The main algorithm to decode the BS event for the TRT. It uses the TRTRawDataProviderTool to decode the fragments.
- TRTRawDataProviderTool: the main tool to decode the BS fragments. It will update the IDC using the TRT_RodDecoder tool. The IDC is cleared at the beginning of a new event. For the Event Filter it there is bookkeeping not to decode a ROB block twice. No special code is needed to handle the old TRT readout with the split collections.
- TRT_RodDecoder: the tool to decode a ROB fragment and to fill the collections into the IDC. It decodes the full fragement, creates the RDOs and pushes them into the collections in IDC. If a collection is not yet in the IDC, it is created on the fly. Note that the calling class has to make sure that the IDC is not filled already with the data. There is an optional argument in a vector<IdHash>*, which if given does restrict the decoding to the collections which have a hash listed in this vector.
@section TRT_RawDataByteStreamCnvWri Writing Byte Stream
The writing of the Byte Stream makes use of the old Byte Stream converter infrastructure using StoreGate converters. It is using 3 classes:
- TRTRawContByteStreamCnv: this is the ATHENA/Storegate/BSConverter class to write the TRT RDO container into a RawEvent file. The method to write RDO into BS is createRep(...). The reverse createObj(...) is not used an returns failure.
- TRTRawContByteStreamTool: the driving tool to really do the conversions of the whole TRT RDO container. The method used is convert(...). For each ROD block a encoder tool is created, the RDOs are pushed into it and the encoder is asked to return the fragment.
- TRT_RodEncoder: the tool that encodes the RDOs of one ROD block.
@section TRT_RawDataByteStreamCnvReq Requirements file
@include requirements
*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TRTRawContByteStreamCnv.h"
#include "ByteStreamCnvSvcBase/IByteStreamEventAccess.h"
#include "ByteStreamCnvSvcBase/ByteStreamAddress.h"
#include "ByteStreamData/RawEvent.h"
#include "GaudiKernel/DataObject.h"
#include "GaudiKernel/MsgStream.h"
// ------------------------------------------------------
// constructor
TRTRawContByteStreamCnv::TRTRawContByteStreamCnv(ISvcLocator* svcloc) :
Converter(ByteStream_StorageType, classID(),svcloc),
m_tool ("TRTRawContByteStreamTool"), // init tool handles
m_byteStreamEventAccess("ByteStreamCnvSvc","TRTRawContByteStreamCnv") // init service handle
{}
// ------------------------------------------------------
// destructor
TRTRawContByteStreamCnv::~TRTRawContByteStreamCnv( )
{}
// ------------------------------------------------------
// initialize
StatusCode
TRTRawContByteStreamCnv::initialize()
{
StatusCode sc = Converter::initialize();
if(StatusCode::SUCCESS!=sc) return sc;
MsgStream log(messageService(), "TRTRawContByteStreamCnv");
log << MSG::DEBUG<< " initialize " <<endreq;
// Retrieve ByteStreamCnvSvc
if (m_byteStreamEventAccess.retrieve().isFailure()) {
log << MSG::FATAL << "Failed to retrieve service " << m_byteStreamEventAccess << endreq;
return StatusCode::FAILURE;
} else
log << MSG::INFO << "Retrieved service " << m_byteStreamEventAccess << endreq;
// Retrieve byte stream tool
if (m_tool.retrieve().isFailure()) {
log << MSG::FATAL << "Failed to retrieve tool " << m_tool << endreq;
return StatusCode::FAILURE;
} else
log << MSG::INFO << "Retrieved tool " << m_tool << endreq;
log << MSG::INFO << "Leaving TRTRawContByteStreamCnv::initialize()" << endreq;
return StatusCode::SUCCESS;
}
// ------------------------------------------------------
// convert TRT Raw Data in the container into ByteStream
StatusCode
TRTRawContByteStreamCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
{
// message stream
MsgStream log(messageService(), "TRTRawContByteStreamCnv");
// get RawEvent pointer
RawEventWrite* re = m_byteStreamEventAccess->getRawEvent();
// get IDC for TRT Raw Data
TRT_RDO_Container* cont=0;
StoreGateSvc::fromStorable(pObj, cont);
if(!cont){
log << MSG::ERROR << " Can not cast to TRTRawContainer " << endreq ;
return StatusCode::FAILURE;
}
// set up the IOpaqueAddress for Storegate
std::string nm = pObj->registry()->name();
pAddr = new ByteStreamAddress(classID(),nm,"");
// now use the tool to do the conversion
StatusCode sc = m_tool->convert(cont, re );
if(sc.isFailure()){
log << MSG::ERROR
<< " Could not convert rdo with TRTRawContByteStreamTool " << endreq;
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS ;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef TRT_RAWDATABYTESTREAMCNV_TRTRAWCONTRAWEVENTCNV_H
#define TRT_RAWDATABYTESTREAMCNV_TRTRAWCONTRAWEVENTCNV_H
#include "GaudiKernel/Converter.h"
#include "GaudiKernel/ToolHandle.h"
#include "GaudiKernel/ServiceHandle.h"
#include "InDetRawData/InDetRawDataCLASS_DEF.h"
#include "TRT_RawDataByteStreamCnv/ITRTRawContByteStreamTool.h"
class DataObject;
class TRTRawContByteStreamTool ;
class IByteStreamEventAccess ;
#include <string>
// Abstract factory to create the converter
template <class TYPE> class CnvFactory;
// Externals
extern long ByteStream_StorageType;
// the converter for writing BS from TRT Raw Data
class TRTRawContByteStreamCnv: public Converter {
friend class CnvFactory<TRTRawContByteStreamCnv>;
~TRTRawContByteStreamCnv( );
protected:
TRTRawContByteStreamCnv(ISvcLocator* svcloc);
public:
typedef TRT_RDO_Container TRTRawContainer;
//! Storage type and class ID
virtual long repSvcType() const { return ByteStream_StorageType;}
static long storageType() { return ByteStream_StorageType; }
static const CLID& classID() { return ClassID_traits<TRTRawContainer>::ID(); }
//! initialize
virtual StatusCode initialize();
//! create Obj is not used !
virtual StatusCode createObj(IOpaqueAddress* /* pAddr */, DataObject*& /* pObj */)
{ return StatusCode::FAILURE;}
//! this creates the RawEvent fragments for the TRT
virtual StatusCode createRep(DataObject* pObj, IOpaqueAddress*& pAddr);
private:
// for BS infrastructure
ToolHandle<ITRTRawContByteStreamTool> m_tool; // ME: use tool handles
ServiceHandle<IByteStreamEventAccess> m_byteStreamEventAccess; // ME: use service handle
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "TRTRawContByteStreamTool.h"
#include "ByteStreamCnvSvcBase/FullEventAssembler.h"
#include "ByteStreamCnvSvcBase/SrcIdMap.h"
#include "GaudiKernel/ToolFactory.h"
#include "GaudiKernel/MsgStream.h"
#include "InDetReadoutGeometry/TRT_DetectorManager.h"
#include "TRT_RodEncoder.h"
// ------------------------------------------------------------------------
// default contructor
TRTRawContByteStreamTool::TRTRawContByteStreamTool
( const std::string& type, const std::string& name,const IInterface* parent )
: AthAlgTool(type,name,parent),
m_trt_CablingSvc ("TRT_CablingSvc", name )
{
declareInterface< ITRTRawContByteStreamTool >( this );
declareProperty("RodBlockVersion",m_RodBlockVersion=3);
return;
}
// ------------------------------------------------------------------------
// destructor
TRTRawContByteStreamTool::~TRTRawContByteStreamTool()
{
return;
}
// ------------------------------------------------------------------------
// initialize the tool
StatusCode
TRTRawContByteStreamTool::initialize()
{
StatusCode sc = AlgTool::initialize();
if (sc.isFailure())
{
ATH_MSG_FATAL( "Failed to init baseclass" );
return StatusCode::FAILURE;
}
// Retrieve id mapping
if (m_trt_CablingSvc.retrieve().isFailure())
{
ATH_MSG_FATAL( "Failed to retrieve tool " << m_trt_CablingSvc );
return StatusCode::FAILURE;
} else
ATH_MSG_INFO( "Retrieved tool " << m_trt_CablingSvc );
// Get the TRT Helper
if (detStore()->retrieve(m_trt_idHelper, "TRT_ID").isFailure())
{
ATH_MSG_FATAL( "Could not get TRT ID helper" );
return StatusCode::FAILURE;
}
return sc;
}
// ------------------------------------------------------------------------
// finalize the tool
StatusCode
TRTRawContByteStreamTool::finalize()
{
StatusCode sc = AlgTool::finalize();
return sc;
}
// ------------------------------------------------------------------------
// New convert method which makes use of the encoder class (as done for
// other detectors)
StatusCode
TRTRawContByteStreamTool::convert(TRT_RDO_Container* cont, RawEventWrite* re )
{
StatusCode sc(StatusCode::SUCCESS);
m_fea.clear();
FullEventAssembler<SrcIdMap>::RODDATA* theROD ;
// set ROD Minor version
m_fea.setRodMinorVersion(m_RodBlockVersion);
ATH_MSG_DEBUG( " Setting Minor Version Number to "<<m_RodBlockVersion );
// a map for ROD ID onto Encoder
std::map<uint32_t, TRT_RodEncoder> mapEncoder;
ATH_MSG_DEBUG( " number of collections "<< cont->size() );
//loop over the collections in the TRT RDO container
TRT_RDO_Container::const_iterator it_coll = cont->begin();
TRT_RDO_Container::const_iterator it_coll_end = cont->end();
for( ; it_coll!=it_coll_end;++it_coll)
{
const TRTRawCollection* coll = (*it_coll) ;
if ( 0 != coll )
{
// Collection Id
Identifier id = coll->identify() ;
// Layer Id associated to the collection Id (Mapping)
Identifier IdLayer = m_trt_idHelper->layer_id(id);
std::vector<uint32_t> robids = m_trt_CablingSvc->getRobID(IdLayer);
eformat::helper::SourceIdentifier sid_rob(robids[0]);
// Building the rod ID
eformat::helper::SourceIdentifier sid_rod( sid_rob.subdetector_id(),
sid_rob.module_id() );
uint32_t rodId = sid_rod.code();
// loop over RDOs in the collection;
TRTRawCollection::const_iterator it_b = coll->begin();
TRTRawCollection::const_iterator it_e = coll->end();
for(; it_b!=it_e; ++it_b) // loop over RDOs in the collection;
{
const RDO* theRdo = *it_b; // fill rdo vector VRDO in
mapEncoder[rodId].addRdo(theRdo); // RodEncoder with the collection
}
}
} // End loop over collections
// loop over Encoder map and fill all ROD Data Blocks
std::map<uint32_t,TRT_RodEncoder>::iterator it_map = mapEncoder.begin();
std::map<uint32_t,TRT_RodEncoder>::iterator it_map_end = mapEncoder.end();
for (; (it_map != it_map_end) && (sc == StatusCode::SUCCESS); ++it_map)
{
TRT_RodEncoder theEncoder = (*it_map).second;
// set the idhelper, mapping and minor version
theEncoder.set_trt_IdHelper (m_trt_idHelper);
theEncoder.set_trt_cabling (m_trt_CablingSvc);
theEncoder.setRodMinorVersion(m_RodBlockVersion);
// use encoder to get ROD fragment data
theROD = m_fea.getRodData((*it_map).first); // get ROD data address