Commit d9ef2c1a authored by Tadej Novak's avatar Tadej Novak
Browse files

Merge branch 'hgtd_rdo_objects' into '21.9'

HGTD RDO objects

See merge request !45977
parents 7001d426 f4c0e9fd
################################################################################
#Package : HGTD_RawData
################################################################################
#Declare the package name:
atlas_subdir( HGTD_RawData )
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
atlas_depends_on_subdirs( PUBLIC
Event/EventContainers) ##why t.f. is this necessary???
atlas_add_library( HGTD_RawData
src/*.cxx
PUBLIC_HEADERS HGTD_RawData EventContainers
LINK_LIBRARIES Identifier AthContainers SGTools)
#atlas_add_dictionary( HGTD_PrepRawDataDict
# HGTD_RawData/HGTD_PrepRawDataDict.h
# HGTD_RawData/selection.xml
# LINK_LIBRARIES GaudiKernel HGTD_RawData)
set( _jobOPath "${CMAKE_CURRENT_SOURCE_DIR}/share" )
set( _jobOPath "${_jobOPath}:${CMAKE_JOBOPT_OUTPUT_DIRECTORY}" )
set( _jobOPath "${_jobOPath}:$ENV{JOBOPTSEARCHPATH}" )
atlas_add_test(test_HGTD_RDO
SOURCES test/test_HGTD_RDO.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} HGTD_RawData)
atlas_add_test(test_HGTD_RDOColl
SOURCES test/test_HGTD_RDOColl.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} HGTD_RawData)
atlas_add_test(test_HGTD_RDOCont
SOURCES test/test_HGTD_RDOCont.cxx
INCLUDE_DIRS ${Boost_INCLUDE_DIRS}
LINK_LIBRARIES ${Boost_LIBRARIES} HGTD_RawData TestTools SGTools
GaudiKernel StoreGateLib
ENVIRONMENT "JOBOPTSEARCHPATH=${_jobOPath}")
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/HGTD_RDO.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
*
* @brief This is a first implementation, but needs improvement in the future
* to be closer to real detector output. For now a format compatible with
* HGTD_Cluster was chosen for simplicity.
*
* Raw data word as sent from the ASIC.
* Contains: - TOA 7 bits [0, 127]
* - TOT 9 bits [0, 511]
* - BCID ?? (5 bits left in 32 bit word), but seems to be 8 bits
* - L1A 4 bits [0-15]
* - L1ID 8 bits [0-255]
* for pixel: 8 (TOT) + 8 (BCID) + 4 (L1A) + 8 (L1ID) = 28 < 32
* for HGTD: 7 (TOA) + 9 (TOT) + 8 (BCID) + 4 (L1A) + 8 (L1ID) = 36 > 32!!
* unsigned int -> 32 bits on 64 bit machines
* unsigned long long -> 64 bits on 64 bit machines
* unsigned int m_word; //This is used for Pixel, eqv to uint32_t
* uint64_t m_word; // FIXME might be that I have to use this here!!
* since is quite large, can I use std::bitset<N> here? =>> wastes space?!
* maybe better: bit field ??
* struct HGTD_RAWBitfield {
* unsigned int toa : 7;
* unsigned int tot : 9;
* unsigned int bcid : 8;
* unsigned int l1a : 4;
* unsigned int l1id : 8;
* };
* but: The layout of bit-fields is non-portable && might give issues with
* ROOT I/O
* maybe splitting the word into individual data members best?
* 16 bit for TAO & TOT (uint16_t)
* >=20 bit needed for bcid, l1a, l1id (uint16_t + uint8_t, grouped)
* totals to 40 bits
*/
#ifndef HGTD_RAWDATA_HGTD_RDO_H
#define HGTD_RAWDATA_HGTD_RDO_H
#include "Identifier/Identifiable.h"
#include "Identifier/Identifier.h"
#include <cstdint>
namespace HGTD {
class HGTD_RDO : public Identifiable {
public:
/**
* @brief Default constructor should NOT be used, needed for pool I/O.
*/
HGTD_RDO() = default;
HGTD_RDO(const HGTD_RDO&) = default;
HGTD_RDO(HGTD_RDO&&) = default;
HGTD_RDO& operator=(const HGTD_RDO&) = default;
HGTD_RDO& operator=(HGTD_RDO&&) = default;
// Destructor:
virtual ~HGTD_RDO() = default;
/**
* @brief Constructor with parameters
*
* @param [in] rdo_id Offline compact identifier of the readout channel.
* @param [in] toa Time of arrival, 7 bit word.
* @param [in] tot Time over threshold, 9 bit word.
* @param [in] bcid Bunch crossing ID.
* @param [in] l1_id ATLAS LVL1
* @param [in] l1_a Level 1 accept
* @param [in]
*/
HGTD_RDO(const Identifier rdo_id, const float toa, const int tot,
const unsigned short bcid, const unsigned short l1_id,
const unsigned short l1_a = 0);
virtual Identifier identify() const;
virtual float getTOA() const;
virtual unsigned int getTOT() const;
virtual unsigned short getBCID() const;
virtual unsigned short getL1ID() const;
virtual unsigned short getL1A() const;
private:
/** @brief Offline ID of the readout channel.
*/
Identifier m_rdo_id;
/** @brief Time of arrival, 7 bit word.
*/
float m_toa;
/** @brief Time over threshold, 9 bit word.
*/
int m_tot;
/** @brief Bunch crossing ID.
*/
unsigned short m_bcid;
/** @brief Level 1 accept.
*/
unsigned short m_l1_id;
/** @brief ATLAS LVL1.
*/
unsigned short m_l1_a;
};
inline Identifier HGTD_RDO::identify() const { return m_rdo_id; }
inline float HGTD_RDO::getTOA() const { return m_toa; }
inline unsigned int HGTD_RDO::getTOT() const { return m_tot; }
inline unsigned short HGTD_RDO::getBCID() const { return m_bcid; }
inline unsigned short HGTD_RDO::getL1ID() const { return m_l1_id; }
inline unsigned short HGTD_RDO::getL1A() const { return m_l1_a; }
} // namespace HGTD
#endif // HGTD_RAWDATA_HGTD_RDORAWDATA_H
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/HGTD_RDOCollections.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
*
* @brief
* FIXME: not sure yet what to do with assignment and copy? make all private
* as done in InDet? need to know why first...
*/
#ifndef HGTD_RAWDATA_HGTD_RDOCOLLECTION_H
#define HGTD_RAWDATA_HGTD_RDOCOLLECTION_H
#include "AthContainers/DataVector.h"
#include "HGTD_RawData/HGTD_RDO.h"
#include "Identifier/IdentifierHash.h"
namespace HGTD {
class HGTD_RDOCollection : public DataVector<HGTD::HGTD_RDO> {
// friend class HGTD_RDORawDataCollectionCnv_p1; //FIXME probably later
public:
/**
* @brief Default constructor should NOT be used, but is needed for pool I/O.
*/
HGTD_RDOCollection() = default;
HGTD_RDOCollection(IdentifierHash hash) : m_id_hash(hash) {}
void setIdentifier(Identifier id) { m_id = id; }
const IdentifierHash& identifierHash() const { return m_id_hash; }
const Identifier& identify() const { return m_id; }
private:
IdentifierHash m_id_hash;
Identifier m_id;
};
} // namespace HGTD
#endif // HGTD_RAWDATA_HGTD_RDOCOLLECTION_H
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/HGTD_RDOContainer.h
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
*
* @brief
*/
#ifndef HGTD_RAWDATA_HGTD_RDOCONTAINER_H
#define HGTD_RAWDATA_HGTD_RDOCONTAINER_H
#include "EventContainers/IdentifiableContainer.h"
#include "HGTD_RawData/HGTD_RDOCollection.h"
#include "SGTools/CLASS_DEF.h"
namespace HGTD {
class HGTD_RDOContainer
: public IdentifiableContainer<HGTD::HGTD_RDOCollection> {
// friend class HGTD_RDOCollectionCnv_p1; //FIXME probably later
public:
/**
* @brief Default constructor should NOT be used, but is needed for pool I/O.
*/
HGTD_RDOContainer() = default;
~HGTD_RDOContainer() = default;
HGTD_RDOContainer(unsigned int hashmax);
static const CLID& classID();
virtual const CLID& clID() const { return classID(); }
};
} // namespace HGTD
CLASS_DEF(HGTD::HGTD_RDOContainer, 1145604774, 1)
#endif // HGTD_RAWDATA_HGTD_RDOCONTAINER_H
ApplicationMgr.DLLs += { "StoreGate", "CLIDComps" };
ApplicationMgr.ExtSvc += { "StoreGateSvc", "StoreGateSvc/DetectorStore" };
#include "IOVSvc/IOVSvc.txt"
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/src/HGTD_RDO.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
*
* @brief Implementation of HGTD_RDO.h
*/
#include "HGTD_RawData/HGTD_RDO.h"
namespace HGTD {
HGTD_RDO::HGTD_RDO(const Identifier rdo_id, const float toa,
const int tot, const unsigned short bcid,
const unsigned short l1_id,
const unsigned short l1_a)
: Identifiable(),
m_rdo_id(rdo_id),
m_toa(toa),
m_tot(tot),
m_bcid(bcid),
m_l1_id(l1_id),
m_l1_a(l1_a) {}
} // namespace HGTD
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/src/HGTD_RDOContainer.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
*
* @brief Implementation of HGTD_RDOContainer.h
*/
#include "HGTD_RawData/HGTD_RDOContainer.h"
namespace HGTD {
HGTD::HGTD_RDOContainer::HGTD_RDOContainer(unsigned int hashmax)
: IdentifiableContainer<HGTD::HGTD_RDOCollection>(hashmax) {}
const CLID& HGTD::HGTD_RDOContainer::classID() {
return ClassID_traits<HGTD::HGTD_RDOContainer>::ID();
}
} // namespace HGTD
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/test/test_HGTD_RDO.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief Unit test of the HGTD_RDO class, testing initialisation
* and all constructors.
*/
#include "HGTD_RawData/HGTD_RDO.h"
#include "Identifier/Identifier.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
HGTD::HGTD_RDO createRDO() {
std::cout << "createRDO\n";
Identifier id(5678);
HGTD::HGTD_RDO rdo(id, 14.537, 212, 1, 2, 3);
std::cout << "createRDO done\n";
return rdo;
}
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 testCopyCtor(const HGTD::HGTD_RDO& rdo) {
std::cout << "testCopyCtor\n";
HGTD::HGTD_RDO copied_rdo(rdo);
compare(rdo, copied_rdo);
std::cout << "testCopyCtor done\n";
}
void testAssignment(const HGTD::HGTD_RDO& rdo) {
std::cout << "testAssignment\n";
HGTD::HGTD_RDO assigned_rdo = rdo;
compare(rdo, assigned_rdo);
std::cout << "testAssignment done\n";
}
void testMoveCtor(HGTD::HGTD_RDO rdo) {
std::cout << "testMoveCtor\n";
HGTD::HGTD_RDO copied_rdo(std::move(rdo));
compare(rdo, copied_rdo);
std::cout << "testMoveCtor done\n";
}
void testMoveAssignment(HGTD::HGTD_RDO rdo) {
std::cout << "testMoveAssignment\n";
HGTD::HGTD_RDO move_assign_rdo = std::move(rdo);
compare(rdo, move_assign_rdo);
std::cout << "testMoveAssignment done\n";
}
BOOST_AUTO_TEST_CASE(HGTD_RDO, *boost::unit_test::tolerance(1e-10)) {
std::cout << "running test_HGTD_RDO\n";
// don't bother with default ctor, should not be used!
Identifier id(1234);
float toa = 14.8348;
HGTD::HGTD_RDO rdo(id, toa, 266, 1, 2, 3);
BOOST_CHECK(rdo.identify() == id);
BOOST_CHECK(rdo.getTOA() == toa);
BOOST_CHECK(rdo.getTOT() == 266);
BOOST_CHECK(rdo.getBCID() == 1);
BOOST_CHECK(rdo.getL1ID() == 2);
BOOST_CHECK(rdo.getL1A() == 3);
HGTD::HGTD_RDO rdo2 = createRDO();
testCopyCtor(rdo2);
testAssignment(rdo2);
testMoveCtor(rdo2);
testMoveAssignment(rdo2);
std::cout << "running test_HGTD_RDO done\n";
}
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/test/test_HGTD_RDOColl.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief Unit test of the HGTD_RDOCollection class.
*/
#include "HGTD_RawData/HGTD_RDO.h"
#include "HGTD_RawData/HGTD_RDOCollection.h"
#include "Identifier/Identifier.h"
#include "Identifier/IdentifierHash.h"
#include <memory>
#include <vector>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
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);
}
BOOST_AUTO_TEST_CASE(HGTD_RDOColl) {
// create a collection
auto coll = std::make_unique<HGTD::HGTD_RDOCollection>(IdentifierHash(2));
// fill it with RDOs
for (int id = 1234; id < 1244; id++) {
std::unique_ptr<HGTD::HGTD_RDO> rdo = createRDO(id, 14.8348, 266, 1, 2, 3);
coll->push_back(std::move(rdo));
}
BOOST_CHECK(coll->identifierHash() == IdentifierHash(2));
BOOST_CHECK(coll->size() == 10);
}
/**
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*
* @file HGTD_RawData/test/test_HGTD_RDOCont.cxx
* @author Alexander Leopold <alexander.leopold@cern.ch>
* @date August, 2021
* @brief Unit test of the HGTD_RDOCollection class.
*/
#include "HGTD_RawData/HGTD_RDO.h"
#include "HGTD_RawData/HGTD_RDOCollection.h"
#include "HGTD_RawData/HGTD_RDOContainer.h"
#include "Identifier/Identifier.h"
#include "Identifier/IdentifierHash.h"
#include "SGTools/TestStore.h"
#include "StoreGate/StoreGateSvc.h"
#include "TestTools/initGaudi.h"
#include <memory>
#include <vector>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
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);
}
BOOST_AUTO_TEST_CASE(HGTD_RDOCont) {
// initialise Gaudi for testing
ISvcLocator* pSvcLoc;
BOOST_REQUIRE(Athena_test::initGaudi("test_HGTD_RDOCont.txt", pSvcLoc));
ISvcLocator* svc_locator = Gaudi::svcLocator();
// get StoreGate service
StoreGateSvc* storegate;
StatusCode sc = svc_locator->service("StoreGateSvc", storegate);
if (sc.isFailure()) {
BOOST_TEST(false);
}
auto container = std::make_unique<HGTD::HGTD_RDOContainer>(5);
for (int hash = 2; hash <= 3; hash++) {
// create a collection
auto collection =
std::make_unique<HGTD::HGTD_RDOCollection>(IdentifierHash(hash));
// fill it with RDOs
for (int id = 1234; id < 1244; id++) {
std::unique_ptr<HGTD::HGTD_RDO> rdo =
createRDO(id, 14.8348, 266, 1, 2, 3);
collection->push_back(std::move(rdo));
}
BOOST_CHECK(collection->identifierHash() == IdentifierHash(hash));
container->addCollection(collection.release(), hash, true);
}
// Get the sct helper from the detector store
sc = storegate->record(container.release(), "HGTD_RDOContainer");
if (sc.isFailure()) {
std::cout << "Could not record the HGTD_RDOContainer!\n";
BOOST_TEST(false);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment