ATLAS Offline Software
Loading...
Searching...
No Matches
MMARTPacket.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4#include <vector>
5#include <exception>
6#include <sstream>
7#include <string>
8#include <algorithm>
9#include <tuple>
10
13
14
15Muon::nsw::MMARTPacket::MMARTPacket (std::vector<uint32_t>& payload) {
16
17 std::size_t readPointer{0};
18 std::span<const std::uint32_t> data{payload.data(), 3};
19
20 if (payload.size()!=3) {
21 throw std::runtime_error( Muon::nsw::format( "ART Packet size not as expected: expected exactly 3 uint32_t, got {}", payload.size() ));
22 }
23
24 //decoding
29 //remember ART 7 is first in the bit stream, ART 0 is last!
30 for (uint8_t i = 0; i < 8; i++){
32 }
33 std::reverse(m_art_ARTs.begin(), m_art_ARTs.end()); //so that ART0 is element0 and no confusion is made
34
35 //populating layer,channel pair
36 std::vector<std::tuple<uint8_t,uint8_t,uint8_t>> artHitInfo = VMMmapToHits();
37
38 for (uint8_t i = 0; i < artHitInfo.size(); i++){
39 m_channels.push_back( std::pair<uint8_t,uint16_t>(getLayer(), getVMMChannelPosition( getBoardPosition(std::get<0>(artHitInfo[i])) , std::get<1>(artHitInfo[i]) , std::get<2>(artHitInfo[i]))) );
40 }
41
42}
43
44
45std::vector<std::tuple<uint8_t,uint8_t,uint8_t>> Muon::nsw::MMARTPacket::VMMmapToHits (){
46 std::vector<std::tuple<uint8_t,uint8_t>> hitmapBoardVMM;
47 std::vector<std::tuple<uint8_t,uint8_t,uint8_t>> artHitInfo;
48
49 for (uint8_t i = 0; i<32; i++){
50 if ((m_art_VMMmap >> i) & 0b1) {
51 hitmapBoardVMM.push_back( std::make_tuple( (int)(i/8), i%8 ) ); //board, vmm
52 }
53 }
54
55 if (hitmapBoardVMM.size()>8) {
56 throw std::runtime_error("ART Packet cannot contain more than 8 ART hits!");
57 }
58
59 for (uint8_t i = 0; i<hitmapBoardVMM.size(); i++){
60 artHitInfo.push_back( std::make_tuple( std::get<0>(hitmapBoardVMM[i]), std::get<1>(hitmapBoardVMM[i]), m_art_ARTs[i] ) );
61 }
62
63 return artHitInfo;
64}
65
66
68 int rightLeft = (int)(m_art_fiberID/2.) % 2;
69 int layer = getLayer();
70
71 int flipBoardOrder = 0;
72 int flipFiberOrder = 0;
73
74 if (rightLeft==0){
75 if ( layer==1 || layer==2 || layer==5 || layer==6 ) {flipFiberOrder = 1;}
76 else {flipBoardOrder = 1;}
77 } else {
78 if ( layer==1 || layer==2 || layer==5 || layer==6 ) {flipBoardOrder = 1;}
79 else {flipFiberOrder = 1;}
80 }
81 if (flipBoardOrder) board = 3-board;
82
83 int pcb = 0;
84 if (!flipFiberOrder){
85 if (m_art_fiberID % 2 == 0) {pcb = board;}
86 else {pcb = board+4;}
87 } else {
88 if (m_art_fiberID % 2 == 1) {pcb = board;}
89 else {pcb = board+4;}
90 }
91 pcb+=1;
92
93 int boardPosition = -1;
94 if (layer%2==1){
95 if (rightLeft==1) {boardPosition = (pcb-1) * 2;}
96 else {boardPosition = (pcb-1) * 2 + 1;}
97 } else {
98 if (rightLeft==0) {boardPosition = (pcb-1) * 2;}
99 else {boardPosition = (pcb-1) * 2 + 1;}
100 }
101
102 return boardPosition;
103
104}
105
106int Muon::nsw::MMARTPacket::getVMMChannelPosition (int boardPosition, int vmm, int ch){
107 int vmmPosition;
108 if (boardPosition%2==0){vmmPosition = 7-vmm;}
109 else {vmmPosition = vmm;}
110
111 vmmPosition += boardPosition*8;
112 int chPosition = 64*vmmPosition;
113
114 if (boardPosition%2==0){chPosition += (63 - ch);}
115 else {chPosition += ch;}
116
117 return chPosition;
118
119}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::vector< std::pair< uint8_t, uint16_t > > m_channels
Definition MMARTPacket.h:37
std::vector< std::tuple< uint8_t, uint8_t, uint8_t > > VMMmapToHits()
uint8_t getLayer() const
Definition MMARTPacket.h:39
std::vector< uint32_t > m_art_ARTs
Definition MMARTPacket.h:35
MMARTPacket(std::vector< uint32_t > &payload)
int getBoardPosition(int board)
int getVMMChannelPosition(int boardPosition, int vmm, int ch)
constexpr int size_art_fiberID
constexpr int size_art_pipeID
constexpr int size_art_VMMmap
constexpr int size_art_ARTs
constexpr int size_art_BCID
std::string format(const std::string &str, const T &arg)
constexpr Target decode_and_advance(const std::span< const Source > words, std::size_t &start, const std::size_t size)
Decode bits from data of words and advance the read pointer.
void reverse(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of reverse for DataVector/List.