Commit 86a1fe4f authored by Tadej Novak's avatar Tadej Novak
Browse files

Merge branch 'hgtd_rdo_tp_converters_21p9' into '21.9'

adding TP converters for HGTD RDO objects

See merge request !46045
parents e61e4e77 2ea4f528
......@@ -18,7 +18,7 @@ atlas_add_tpcnv_library( HGTD_EventTPCnv
PUBLIC_HEADERS HGTD_EventTPCnv
LINK_LIBRARIES DataModel DataModelAthenaPoolLib StoreGateLib
AthenaPoolCnvSvcLib AthenaPoolUtilities Identifier GaudiKernel
HGTD_Identifier TrkEventTPCnv HGTD_PrepRawData
HGTD_Identifier TrkEventTPCnv HGTD_PrepRawData HGTD_RawData
PRIVATE_LINK_LIBRARIES AthenaBaseComps AthenaKernel TrkMeasurementBase
EventPrimitives HGTD_ReadoutGeometry TrkEventPrimitives CxxUtils
InDetEventTPCnv)
......@@ -42,3 +42,15 @@ atlas_add_test( HGTD_ClusterContainerCnv_p1_test
LINK_LIBRARIES ${Boost_LIBRARIES} HGTD_EventTPCnv TestTools IdDictParser SGTools
GaudiKernel
ENVIRONMENT "JOBOPTSEARCHPATH=${_jobOPath}")
atlas_add_test( HGTD_RDOCnv_p1_test
SOURCES test/HGTD_RDOCnv_p1_test.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} HGTD_EventTPCnv IdDictParser)
atlas_add_test( HGTD_RDOContainerCnv_p1_test
SOURCES test/HGTD_RDOContainerCnv_p1_test.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} HGTD_EventTPCnv IdDictParser TestTools
SGTools GaudiKernel
ENVIRONMENT "JOBOPTSEARCHPATH=${_jobOPath}")
......@@ -14,6 +14,9 @@
#include "HGTD_EventTPCnv/HGTD_ClusterContainer_p1.h"
#include "HGTD_EventTPCnv/HGTD_Cluster_p1.h"
#include "HGTD_EventTPCnv/HGTD_PRD_Collection_p1.h"
#include "HGTD_EventTPCnv/HGTD_RDO_p1.h"
#include "HGTD_EventTPCnv/HGTD_RDOCollection_p1.h"
#include "HGTD_EventTPCnv/HGTD_RDOContainer_p1.h"
namespace HGTD_EventTPCnvDict {
struct tmp {
......
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/HGTD_RDOCnv_p1.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief Transient/Persistent converter for the HGTD_RDO class.
*
*/
#ifndef HGTD_EVENTTPCNV_HGTD_RDOCNV_P1_H
#define HGTD_EVENTTPCNV_HGTD_RDOCNV_P1_H
#include "AthenaPoolCnvSvc/T_AthenaPoolTPConverter.h"
#include "HGTD_EventTPCnv/HGTD_RDO_p1.h"
#include "HGTD_RawData/HGTD_RDO.h"
class MsgStream;
namespace HGTD {
class HGTD_RDOCnv_p1
: public T_AthenaPoolTPCnvBase<HGTD::HGTD_RDO, HGTD::HGTD_RDO_p1> {
public:
HGTD_RDOCnv_p1() = default;
void persToTrans(const HGTD::HGTD_RDO_p1* pers_obj, HGTD::HGTD_RDO* trans_obj,
MsgStream& log);
void transToPers(const HGTD::HGTD_RDO* trans_obj, HGTD::HGTD_RDO_p1* pers_obj,
MsgStream& log);
};
} // namespace HGTD
#endif // HGTD_EVENTTPCNV_HGTD_RDOCNV_P1_H
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/HGTD_RDOCollection_p1.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief
*/
#ifndef HGTD_EVENTTPCNV_HGTD_RDOCOLLECTION_P1_H
#define HGTD_EVENTTPCNV_HGTD_RDOCOLLECTION_P1_H
#include "Identifier/IdentifierHash.h"
namespace HGTD {
class HGTD_RDOCollection_p1 {
public:
typedef IdentifierHash::value_type IdType_t;
HGTD_RDOCollection_p1() : m_hash_id(0), m_size(0){};
// container cnvs do conversions
friend class HGTD_RDOContainerCnv_p1;
private:
// Hash Identifier of this collection
IdType_t m_hash_id;
// Number of RDOs in a given collection
unsigned short m_size;
};
} // namespace HGTD
#endif // HGTD_EVENTTPCNV_HGTD_RDOCOLLECTION_P1_H
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/HGTD_RDOContainerCnv_p1.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief
*
*/
#ifndef HGTD_EVENTTPCNV_HGTD_RDOCONTAINERCNV_P1_H
#define HGTD_EVENTTPCNV_HGTD_RDOCONTAINERCNV_P1_H
#include "AthenaPoolCnvSvc/T_AthenaPoolTPConverter.h"
#include "HGTD_EventTPCnv/HGTD_RDOContainer_p1.h"
#include "HGTD_RawData/HGTD_RDOContainer.h"
class HGTD_ID;
class StoreGateSvc;
namespace HGTD {
class HGTD_RDOContainerCnv_p1
: public T_AthenaPoolTPCnvBase<HGTD::HGTD_RDOContainer,
HGTD::HGTD_RDOContainer_p1> {
public:
typedef HGTD::HGTD_RDOContainer_p1 Pers_t;
typedef HGTD::HGTD_RDOContainer Trans_t;
HGTD_RDOContainerCnv_p1() : m_is_initialized(false) {}
virtual void persToTrans(const Pers_t* persistent_container,
Trans_t* transient_container, MsgStream& log);
virtual void transToPers(const Trans_t* transient_container,
Pers_t* persistent_container, MsgStream& log);
virtual Trans_t* createTransient(const Pers_t* persistent_container,
MsgStream& log);
private:
StatusCode initialize(MsgStream& log);
const HGTD_ID* m_hgtd_idhelper;
bool m_is_initialized;
};
} // namespace HGTD
#endif // HGTD_EVENTTPCNV_HGTD_RDOCONTAINERCNV_P1_H
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/HGTD_RDOContainer_p1.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief
*/
#ifndef HGTD_RDOCONTAINER_P1_H
#define HGTD_RDOCONTAINER_P1_H
#include "HGTD_EventTPCnv/HGTD_RDOCollection_p1.h"
#include "HGTD_EventTPCnv/HGTD_RDO_p1.h"
#include <string>
#include <vector>
namespace HGTD {
class HGTD_RDOContainer_p1 {
public:
/// Default constructor
HGTD_RDOContainer_p1() = default;
// holds information to restore the individual collections from the flattened
// list of persistified clusters
std::vector<HGTD::HGTD_RDOCollection_p1> m_collection_separator;
std::vector<HGTD::HGTD_RDO_p1> m_rdo_list;
};
} // namespace HGTD
#endif
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/HGTD_RDO_p1.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief Represents the persitified version of HGTD_RDO.
*/
#ifndef HGTD_EVENTTPCNV_HGTD_RDO_P1_H
#define HGTD_EVENTTPCNV_HGTD_RDO_P1_H
#include "HGTD_RawData/HGTD_RDO.h"
#include "Identifier/Identifier.h"
namespace HGTD {
class HGTD_RDO_p1 {
public:
typedef Identifier::value_type IdType_t;
HGTD_RDO_p1() = default;
friend class HGTD_RDOCnv_p1;
private:
IdType_t m_rdo_id;
float m_toa;
int m_tot;
unsigned short m_bcid;
unsigned short m_l1_id;
unsigned short m_l1_a;
};
} // namespace HGTD
#endif // HGTD_RDO_P1_H
......@@ -4,4 +4,9 @@
<class name="std::vector<HGTD::HGTD_Cluster_p1>" />
<class name="HGTD::HGTD_PRD_Collection_p1" />
<class name="HGTD::HGTD_ClusterContainer_p1" id="7B3D57D6-F590-4266-974D-A0807122DA5F" />
<class name="HGTD::HGTD_RDO_p1" />
<class name="std::vector<HGTD::HGTD_RDO_p1>" />
<class name="HGTD::HGTD_RDOCollection_p1" />
<class name="HGTD::HGTD_RDOContainer_p1" id="C25315CC-F0A2-43D6-8F42-012BE34B0107" />
</lcgdict>
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @fileHGTD_EventTPCnv/src/HGTD_RDOCnv_p1.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief
*/
#include "HGTD_EventTPCnv/HGTD_RDOCnv_p1.h"
void HGTD::HGTD_RDOCnv_p1::transToPers(const HGTD::HGTD_RDO* trans_obj,
HGTD::HGTD_RDO_p1* pers_obj,
MsgStream& log) {
log << MSG::VERBOSE << "calling HGTD_RDOCnv_p1::transToPers" << endreq;
pers_obj->m_rdo_id = trans_obj->identify().get_compact();
pers_obj->m_toa = trans_obj->getTOA();
pers_obj->m_tot = trans_obj->getTOT();
pers_obj->m_bcid = trans_obj->getBCID();
pers_obj->m_l1_id = trans_obj->getL1ID();
pers_obj->m_l1_a = trans_obj->getL1A();
}
void HGTD::HGTD_RDOCnv_p1::persToTrans(const HGTD::HGTD_RDO_p1* pers_obj,
HGTD::HGTD_RDO* trans_obj,
MsgStream& log) {
log << MSG::VERBOSE << "calling HGTD_RDOCnv_p1::persToTrans" << endreq;
*trans_obj = HGTD::HGTD_RDO(Identifier(pers_obj->m_rdo_id), pers_obj->m_toa,
pers_obj->m_tot, pers_obj->m_bcid,
pers_obj->m_l1_id, pers_obj->m_l1_a);
}
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/src/HGTD_RDOContainerCnv_p1.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief Implementation file of HGTD_RDOContainerCnv_p1.h
*/
#include "HGTD_EventTPCnv/HGTD_RDOContainerCnv_p1.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/StatusCode.h"
#include "HGTD_EventTPCnv/HGTD_RDOCnv_p1.h"
#include "HGTD_EventTPCnv/HGTD_RDOCollection_p1.h"
#include "HGTD_EventTPCnv/HGTD_RDO_p1.h"
#include "HGTD_Identifier/HGTD_ID.h"
#include "Identifier/Identifier.h"
#include "StoreGate/StoreGateSvc.h"
#include <memory>
StatusCode HGTD::HGTD_RDOContainerCnv_p1::initialize(MsgStream& log) {
// Do not initialize again:
m_is_initialized = true;
// Get Storegate, ID helpers, and so on
ISvcLocator* svcLocator = Gaudi::svcLocator();
StoreGateSvc* detStore;
StatusCode sc = svcLocator->service("StoreGateSvc", detStore);
if (sc.isFailure()) {
log << MSG::FATAL << "StoreGate service not found !" << endreq;
return StatusCode::FAILURE;
}
// get DetectorStore service
sc = svcLocator->service("DetectorStore", detStore);
if (sc.isFailure()) {
log << MSG::FATAL << "DetectorStore service not found !" << endreq;
return StatusCode::FAILURE;
}
// Get the ID helper from the detector store
sc = detStore->retrieve(m_hgtd_idhelper, "HGTD_ID");
if (sc.isFailure()) {
log << MSG::FATAL << "Could not get HGTD_ID helper !" << endreq;
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
void HGTD::HGTD_RDOContainerCnv_p1::transToPers(
const Trans_t* transient_container, Pers_t* persistent_container,
MsgStream& log) {
if (!m_is_initialized) {
if (this->initialize(log) != StatusCode::SUCCESS) {
log << MSG::FATAL << "Could not initialize HGTD_RDOContainerCnv_p1 "
<< endreq;
}
}
HGTD_RDOCnv_p1 rdo_converter;
size_t n_collections = transient_container->numberOfCollections();
Trans_t::const_iterator container_itr = transient_container->begin();
persistent_container->m_collection_separator.resize(n_collections);
size_t collection_separator_index_begin = 0;
size_t total_n_clusters = 0;
for (size_t coll_i = 0; coll_i < n_collections; coll_i++, container_itr++) {
const HGTD::HGTD_RDOCollection& collection = (**container_itr);
size_t collection_size = collection.size();
persistent_container->m_collection_separator.at(coll_i).m_hash_id =
collection.identifierHash().value();
persistent_container->m_collection_separator.at(coll_i).m_size =
collection_size;
// continously resize the toal size of vector holding the individual
// clusters
total_n_clusters += collection_size;
persistent_container->m_rdo_list.resize(total_n_clusters);
if (log.level() <= MSG::VERBOSE) {
log << MSG::VERBOSE << "Reading RDO collections size of "
<< collection_size << endreq;
}
for (size_t rdo_i = 0; rdo_i < collection_size; rdo_i++) {
// get pointer to next position in the vector that will be persistified
HGTD::HGTD_RDO_p1* pers_rdo =
&((persistent_container->m_rdo_list)
.at(rdo_i + collection_separator_index_begin));
const HGTD::HGTD_RDO* trans_rdo =
dynamic_cast<const HGTD::HGTD_RDO*>(collection.at(rdo_i));
rdo_converter.transToPers(trans_rdo, pers_rdo, log);
}
// start next collection at end of previous
collection_separator_index_begin += collection.size();
}
if (log.level() <= MSG::DEBUG) {
log << MSG::DEBUG
<< "Writing HGTD_ClusterContainer to HGTD_ClusterContainer_p1 done"
<< endreq;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void HGTD::HGTD_RDOContainerCnv_p1::persToTrans(
const Pers_t* persistent_container, Trans_t* transient_container,
MsgStream& log) {
if (!m_is_initialized) {
if (this->initialize(log) != StatusCode::SUCCESS) {
log << MSG::FATAL << "Could not initialize HGTD_RDOContainerCnv_p1 "
<< endreq;
}
}
std::unique_ptr<HGTD::HGTD_RDOCollection> collection = nullptr;
HGTD_RDOCnv_p1 rdo_converter;
size_t collection_separator_index_begin = 0;
for (size_t coll_i = 0;
coll_i < persistent_container->m_collection_separator.size(); ++coll_i) {
const HGTD::HGTD_RDOCollection_p1& rdo_coll =
persistent_container->m_collection_separator.at(coll_i);
// get the identifier for the collection
IdentifierHash coll_idhash = IdentifierHash(rdo_coll.m_hash_id);
Identifier coll_id = m_hgtd_idhelper->wafer_id(coll_idhash);
collection = std::make_unique<HGTD::HGTD_RDOCollection>(coll_idhash);
collection->setIdentifier(coll_id);
unsigned short n_clusters = rdo_coll.m_size;
collection->resize(n_clusters);
for (unsigned short rdo_i = 0; rdo_i < n_clusters; ++rdo_i) {
const HGTD::HGTD_RDO_p1* pers_rdo =
&((persistent_container->m_rdo_list)
.at(rdo_i + collection_separator_index_begin));
// NOTE I think I have to new it before calling the converter
HGTD::HGTD_RDO* trans_rdo = new HGTD::HGTD_RDO();
rdo_converter.persToTrans(pers_rdo, trans_rdo, log);
(*collection).at(rdo_i) = trans_rdo;
}
collection_separator_index_begin += n_clusters;
StatusCode sc =
transient_container->addCollection(collection.release(), coll_idhash);
if (sc.isFailure()) {
throw std::runtime_error("Failed to add collection to ID Container");
}
}
}
HGTD::HGTD_RDOContainerCnv_p1::Trans_t*
HGTD::HGTD_RDOContainerCnv_p1::createTransient(
const Pers_t* persistent_container, MsgStream& log) {
if (!m_is_initialized) {
if (this->initialize(log) != StatusCode::SUCCESS) {
log << MSG::FATAL << "Could not initialize HGTD_RDOContainerCnv_p1 "
<< endreq;
}
}
std::unique_ptr<Trans_t> transient_container =
std::make_unique<Trans_t>(m_hgtd_idhelper->wafer_hash_max());
persToTrans(persistent_container, transient_container.get(), log);
return (transient_container.release());
}
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/test/HGTD_RDOCnv_p1_test.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief Tests the conversion between transient and persistent version of the
* HGTD_RDO class.
*/
#include "GaudiKernel/MsgStream.h"
#include "HGTD_EventTPCnv/HGTD_RDOCnv_p1.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
HGTD::HGTD_RDO createRDO(int id, float time, int tot, int bcid, int lv1a,
int lv1id) {
std::cout << "createRDO\n";
Identifier identifier(id);
return HGTD::HGTD_RDO(identifier, time, tot, bcid, lv1a, lv1id);
}
void compare(const HGTD::HGTD_RDO& p1, const HGTD::HGTD_RDO& p2) {
std::cout << "compare HGTD_RDO\n";
BOOST_CHECK(p1.identify() == p2.identify());
BOOST_CHECK(p1.getTOA() == p2.getTOA());
BOOST_CHECK(p1.getTOT() == p2.getTOT());
BOOST_CHECK(p1.getBCID() == p2.getBCID());
BOOST_CHECK(p1.getL1ID() == p2.getL1ID());
BOOST_CHECK(p1.getL1A() == p2.getL1A());
std::cout << "compare HGTD_RDO done\n";
}
void convertAndBack(const HGTD::HGTD_RDO& trans1) {
std::cout << "convertAndBack\n";
MsgStream log(0, "test");
HGTD::HGTD_RDOCnv_p1 cnv;
HGTD::HGTD_RDO_p1 pers;
cnv.transToPers(&trans1, &pers, log);
HGTD::HGTD_RDO trans2;
cnv.persToTrans(&pers, &trans2, log);
compare(trans1, trans2);
std::cout << "convertAndBack done\n";
}
BOOST_AUTO_TEST_CASE(HGTD_RDOCnv_p1) {
std::cout << "start test\n";
HGTD::HGTD_RDO rdo = createRDO(1234, 14.8348, 266, 1, 2, 3);
convertAndBack(rdo);
}
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_EventTPCnv/test/HGTD_RDOContainerCnv_p1_test.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date Apr, 2021
* @brief
*/
#include "GaudiKernel/MsgStream.h"
#include "HGTD_EventTPCnv/HGTD_RDOContainerCnv_p1.h"
#include "HGTD_Identifier/HGTD_ID.h"
#include "HGTD_RawData/HGTD_RDOContainer.h"
#include "IdDictParser/IdDictParser.h"
#include "Identifier/Identifier.h"
#include "SGTools/TestStore.h"
#include "StoreGate/StoreGateSvc.h"
#include "TestTools/initGaudi.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
const HGTD_ID* g_hgtd_idhelper;
std::unique_ptr<HGTD::HGTD_RDO> createRDO(int id, float time, int tot, int bcid,
int lv1a, int lv1id) {
std::cout << "createRDO\n";
Identifier identifier(id);
return std::make_unique<HGTD::HGTD_RDO>(identifier, time, tot, bcid, lv1a,
lv1id);
}
void compare(const HGTD::HGTD_RDO& p1, const HGTD::HGTD_RDO& p2) {
std::cout << "compare HGTD_RDO\n";
BOOST_CHECK(p1.identify() == p2.identify());
BOOST_CHECK(p1.getTOA() == p2.getTOA());
BOOST_CHECK(p1.getTOT() == p2.getTOT());
BOOST_CHECK(p1.getBCID() == p2.getBCID());
BOOST_CHECK(p1.getL1ID() == p2.getL1ID());