Skip to content

Commit 2d4e568

Browse files
wiechuladavidrohr
authored andcommitted
Add RDH mapping for feeId
1 parent 3c3aafd commit 2d4e568

File tree

3 files changed

+217
-1
lines changed

3 files changed

+217
-1
lines changed

Detectors/TPC/base/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ o2_add_library(TPCBase
3434
src/Sector.cxx
3535
src/Utils.cxx
3636
PUBLIC_LINK_LIBRARIES Vc::Vc Boost::boost O2::DataFormatsTPC
37-
O2::CCDB FairRoot::Base)
37+
O2::DetectorsRaw O2::CCDB FairRoot::Base)
3838

3939
o2_target_root_dictionary(TPCBase
4040
HEADERS include/TPCBase/CalArray.h
@@ -88,6 +88,12 @@ o2_add_test(Parameters
8888
SOURCES test/testTPCParameters.cxx
8989
LABELS tpc)
9090

91+
o2_add_test(RDHUtils
92+
COMPONENT_NAME tpc
93+
PUBLIC_LINK_LIBRARIES O2::TPCBase
94+
SOURCES test/testRDHUtils.cxx
95+
LABELS tpc)
96+
9197
#o2_add_test(CCDBInterface
9298
# COMPONENT_NAME tpc
9399
# PUBLIC_LINK_LIBRARIES O2::TPCBase
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef AliceO2_TPC_RDHUtils_H
12+
#define AliceO2_TPC_RDHUtils_H
13+
14+
#include "DetectorsRaw/RDHUtils.h"
15+
//#include "Headers/RAWDataHeader.h"
16+
17+
namespace o2
18+
{
19+
namespace tpc
20+
{
21+
namespace rdh_utils
22+
{
23+
24+
using o2::raw::RDHUtils;
25+
using FEEIDType = uint16_t;
26+
static constexpr FEEIDType UserLogicLinkID = 15;
27+
28+
/// compose feeid from cru, endpoint and link
29+
static constexpr FEEIDType getFEEID(const FEEIDType cru, const FEEIDType endpoint, const FEEIDType link) { return FEEIDType((cru << 7) | ((endpoint & 1) << 6) | (link & 0x3F)); }
30+
template <typename T>
31+
static constexpr FEEIDType getFEEID(const T cru, const T endpoint, const T link)
32+
{
33+
return getFEEID(FEEIDType(cru), FEEIDType(endpoint), FEEIDType(link));
34+
}
35+
36+
/// extract cru number from feeid
37+
static constexpr FEEIDType getCRU(const FEEIDType feeID) { return (feeID >> 7); }
38+
39+
/// extract endpoint from feeid
40+
static constexpr FEEIDType getEndPoint(const FEEIDType feeID) { return (feeID >> 6) & 0x1; }
41+
42+
/// extract endpoint from feeid
43+
static constexpr FEEIDType getLink(const FEEIDType feeID) { return feeID & 0x3F; }
44+
45+
/// extract cru, endpoint and link from feeid
46+
static constexpr void getMapping(const FEEIDType feeID, FEEIDType& cru, FEEIDType& endpoint, FEEIDType& link)
47+
{
48+
cru = getCRU(feeID);
49+
endpoint = getEndPoint(feeID);
50+
link = getLink(feeID);
51+
}
52+
53+
/// if link in feeID is from user logic
54+
static constexpr bool isFromUserLogic(const FEEIDType feeID) { return (getLink(feeID) == UserLogicLinkID); }
55+
56+
/// extract cru number from RDH
57+
template <typename RDH>
58+
static constexpr FEEIDType getCRU(const RDH& rdh)
59+
{
60+
return getCRU(RDHUtils::getFEEID(rdh));
61+
}
62+
63+
/// extract endpoint from RDH
64+
template <typename RDH>
65+
static constexpr FEEIDType getEndPoint(const RDH& rdh)
66+
{
67+
return getEndPoint(RDHUtils::getFEEID(rdh));
68+
}
69+
70+
/// extract link from RDH
71+
template <typename RDH>
72+
static constexpr FEEIDType getLink(const RDH& rdh)
73+
{
74+
return getLink(RDHUtils::getFEEID(rdh));
75+
}
76+
77+
/// if link in feeID is from user logic
78+
template <typename RDH>
79+
static constexpr bool isFromUserLogic(const RDH& rdh)
80+
{
81+
return isFromUserLogic(RDHUtils::getFEEID(rdh));
82+
}
83+
84+
template <typename RDH, typename T>
85+
static constexpr void setFEEID(RDH& rdh, const T cru, const T endpoint, const T link)
86+
{
87+
RDHUtils::setFEEID(rdh, getFEEID(cru, endpoint, link));
88+
}
89+
90+
/// extract cru, endpoint and link from RDH
91+
template <typename RDH>
92+
static constexpr void getMapping(const RDH& rdh, FEEIDType& cru, FEEIDType& endpoint, FEEIDType& link)
93+
{
94+
cru = getCRU(rdh);
95+
endpoint = getEndPoint(rdh);
96+
link = getLink(rdh);
97+
}
98+
99+
} // namespace rdh_utils
100+
} // namespace tpc
101+
} // namespace o2
102+
103+
#endif
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#define BOOST_TEST_MODULE Test TPC CalDet class
12+
#define BOOST_TEST_MAIN
13+
#define BOOST_TEST_DYN_LINK
14+
#include <boost/test/unit_test.hpp>
15+
16+
#include <vector>
17+
18+
#include "Headers/RAWDataHeader.h"
19+
#include "TPCBase/RDHUtils.h"
20+
21+
namespace o2
22+
{
23+
namespace tpc
24+
{
25+
using namespace rdh_utils;
26+
27+
struct FEEDetails {
28+
FEEDetails(FEEIDType c, FEEIDType e, FEEIDType l) : cru(c), endpoint(e), link(l), feeID((cru << 7) | (endpoint << 6) | link), userLogic(l == UserLogicLinkID) {}
29+
FEEIDType cru{};
30+
FEEIDType endpoint{};
31+
FEEIDType link{};
32+
FEEIDType feeID{};
33+
bool userLogic{};
34+
};
35+
36+
BOOST_AUTO_TEST_CASE(testRDHUtils)
37+
{
38+
// coose some random values
39+
std::vector<FEEDetails> testDetails;
40+
testDetails.emplace_back(359, 1, 15);
41+
testDetails.emplace_back(1, 0, 10);
42+
testDetails.emplace_back(100, 1, 8);
43+
testDetails.emplace_back(142, 0, 1);
44+
testDetails.emplace_back(225, 1, 9);
45+
46+
o2::header::RAWDataHeaderV4 rdh4;
47+
o2::header::RAWDataHeaderV5 rdh5;
48+
o2::header::RAWDataHeaderV6 rdh6;
49+
50+
for (const auto& fee : testDetails) {
51+
const auto feeID = getFEEID(fee.cru, fee.endpoint, fee.link);
52+
53+
// default checks
54+
auto cru = getCRU(feeID);
55+
auto link = getLink(feeID);
56+
auto endpoint = getEndPoint(feeID);
57+
bool userLogic = isFromUserLogic(feeID);
58+
59+
BOOST_CHECK_EQUAL(feeID, fee.feeID);
60+
BOOST_CHECK_EQUAL(cru, fee.cru);
61+
BOOST_CHECK_EQUAL(endpoint, fee.endpoint);
62+
BOOST_CHECK_EQUAL(link, fee.link);
63+
BOOST_CHECK_EQUAL(userLogic, fee.userLogic);
64+
65+
// RDH v4 checks
66+
rdh4.feeId = feeID;
67+
cru = getCRU(rdh4);
68+
link = getLink(rdh4);
69+
endpoint = getEndPoint(rdh4);
70+
userLogic = isFromUserLogic(rdh4);
71+
72+
BOOST_CHECK_EQUAL(feeID, fee.feeID);
73+
BOOST_CHECK_EQUAL(cru, fee.cru);
74+
BOOST_CHECK_EQUAL(endpoint, fee.endpoint);
75+
BOOST_CHECK_EQUAL(link, fee.link);
76+
BOOST_CHECK_EQUAL(userLogic, fee.userLogic);
77+
78+
// RDH v5 checks
79+
rdh5.feeId = feeID;
80+
cru = getCRU(rdh5);
81+
link = getLink(rdh5);
82+
endpoint = getEndPoint(rdh5);
83+
userLogic = isFromUserLogic(rdh5);
84+
85+
BOOST_CHECK_EQUAL(feeID, fee.feeID);
86+
BOOST_CHECK_EQUAL(cru, fee.cru);
87+
BOOST_CHECK_EQUAL(endpoint, fee.endpoint);
88+
BOOST_CHECK_EQUAL(link, fee.link);
89+
BOOST_CHECK_EQUAL(userLogic, fee.userLogic);
90+
91+
// RDH v6 checks
92+
rdh6.feeId = feeID;
93+
cru = getCRU(rdh6);
94+
link = getLink(rdh6);
95+
endpoint = getEndPoint(rdh6);
96+
userLogic = isFromUserLogic(rdh6);
97+
98+
BOOST_CHECK_EQUAL(feeID, fee.feeID);
99+
BOOST_CHECK_EQUAL(cru, fee.cru);
100+
BOOST_CHECK_EQUAL(endpoint, fee.endpoint);
101+
BOOST_CHECK_EQUAL(link, fee.link);
102+
BOOST_CHECK_EQUAL(userLogic, fee.userLogic);
103+
}
104+
}
105+
106+
} // namespace tpc
107+
} // namespace o2

0 commit comments

Comments
 (0)