Skip to content

Commit 8106f42

Browse files
mfasDashahor02
authored andcommitted
[EMCAL-629] Add support for in-memory raw decoding
Add RawReaderMemory (templated) for the support of raw encoding of an in-memory block of raw data (directly provided by the readout application). The interface is the same as in RawReaderFile. The raw buffer is adapted in order to construct itself from a char array. Template specification is added for the EMCAL raw data header.
1 parent 361f353 commit 8106f42

9 files changed

Lines changed: 323 additions & 70 deletions

File tree

Detectors/EMCAL/reconstruction/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
o2_add_library(EMCALReconstruction
1313
SOURCES src/RawReaderFile.cxx
14+
src/RawReaderMemory.cxx
1415
src/RawBuffer.cxx
1516
src/RawHeaderStream.cxx
1617
src/RAWDataHeader.cxx
@@ -24,6 +25,7 @@ o2_add_library(EMCALReconstruction
2425
o2_target_root_dictionary(
2526
EMCALReconstruction
2627
HEADERS include/EMCALReconstruction/RawReaderFile.h
28+
include/EMCALReconstruction/RawReaderMemory.h
2729
include/EMCALReconstruction/AltroDecoder.h
2830
include/EMCALReconstruction/RAWDataHeader.h
2931
include/EMCALReconstruction/Mapper.h)

Detectors/EMCAL/reconstruction/include/EMCALReconstruction/RawBuffer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <array>
1414
#include <cstdint>
1515
#include <iosfwd>
16+
#include <gsl/span>
1617

1718
namespace o2
1819
{
@@ -35,12 +36,20 @@ class RawBuffer
3536
/// Does not overwrite the word buffer but just resets the counter and iterator
3637
void flush();
3738

38-
/// \brief Read superpage from stream
39+
/// \brief Read page from stream
40+
/// \param in Input file stream
41+
/// \param payloadsize Number of char words in payload
3942
/// Read a whole superpage from the raw stream
4043
/// and convert the bitwise representation directly
4144
/// into 32 bit words
4245
void readFromStream(std::istream& in, uint32_t payloadsize);
4346

47+
/// \brief Read page from raw memory buffer
48+
/// \param rawmemory Raw memory buffer (as char words) with size of the payload from the raw data header
49+
/// Converts the char word raw memory buffer of a pages into
50+
/// into the 32 bit word buffer
51+
void readFromMemoryBuffer(const gsl::span<char> rawmemory);
52+
4453
/// \brief Get the number of data words read for the superpage
4554
/// \return Number of data words in the superpage
4655
int getNDataWords() const { return mNDataWords; }
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
#ifndef ALICEO2_EMCAL_RAWDECODINGERROR_H
11+
#define ALICEO2_EMCAL_RAWDECODINGERROR_H
12+
13+
#include <exception>
14+
15+
namespace o2
16+
{
17+
18+
namespace emcal
19+
{
20+
21+
/// \class RawDecodingError
22+
/// \brief Error handling of the raw reader
23+
///
24+
/// The following error types are defined:
25+
/// - Page not found
26+
/// - Raw header decoding error
27+
/// - Payload decoding error
28+
class RawDecodingError : public std::exception
29+
{
30+
public:
31+
/// \enum ErrorType_t
32+
/// \brief Codes for different error types
33+
enum class ErrorType_t {
34+
PAGE_NOTFOUND, ///< Page was not found (page index outside range)
35+
HEADER_DECODING, ///< Header cannot be decoded (format incorrect)
36+
PAYLOAD_DECODING, ///< Payload cannot be decoded (format incorrect)
37+
HEADER_INVALID, ///< Header in memory not belonging to requested superpage
38+
PAYLOAD_INVALID, ///< Payload in memory not belonging to requested superpage
39+
};
40+
41+
/// \brief Constructor
42+
/// \param errtype Identifier code of the error type
43+
///
44+
/// Constructing the error with error code. To be called when the
45+
/// exception is thrown.
46+
RawDecodingError(ErrorType_t errtype) : mErrorType(errtype)
47+
{
48+
}
49+
50+
/// \brief destructor
51+
~RawDecodingError() noexcept override = default;
52+
53+
/// \brief Providing error message of the exception
54+
/// \return Error message of the exception
55+
const char* what() const noexcept override
56+
{
57+
switch (mErrorType) {
58+
case ErrorType_t::PAGE_NOTFOUND:
59+
return "Page with requested index not found";
60+
case ErrorType_t::HEADER_DECODING:
61+
return "RDH of page cannot be decoded";
62+
case ErrorType_t::PAYLOAD_DECODING:
63+
return "Payload of page cannot be decoded";
64+
case ErrorType_t::HEADER_INVALID:
65+
return "Access to header not belonging to requested superpage";
66+
case ErrorType_t::PAYLOAD_INVALID:
67+
return "Access to payload not belonging to requested superpage";
68+
};
69+
return "Undefined error";
70+
}
71+
72+
/// \brief Get the type identifier of the error handled with this exception
73+
/// \return Error code of the exception
74+
ErrorType_t getErrorType() const { return mErrorType; }
75+
76+
private:
77+
ErrorType_t mErrorType; ///< Type of the error
78+
};
79+
80+
} // namespace emcal
81+
82+
} // namespace o2
83+
84+
#endif

Detectors/EMCAL/reconstruction/include/EMCALReconstruction/RawReaderFile.h

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <array>
1414
#include <bitset>
1515
#include <cstdint>
16-
#include <exception>
1716
#include <fstream>
1817
#include <string>
1918

@@ -38,65 +37,6 @@ template <class RawHeader>
3837
class RawReaderFile
3938
{
4039
public:
41-
/// \class Error
42-
/// \brief Error handling of the raw reader
43-
///
44-
/// The following error types are defined:
45-
/// - Page not found
46-
/// - Raw header decoding error
47-
/// - Payload decoding error
48-
class Error : public std::exception
49-
{
50-
public:
51-
/// \enum ErrorType_t
52-
/// \brief Codes for different error types
53-
enum class ErrorType_t {
54-
PAGE_NOTFOUND, ///< Page was not found (page index outside range)
55-
HEADER_DECODING, ///< Header cannot be decoded (format incorrect)
56-
PAYLOAD_DECODING, ///< Payload cannot be decoded (format incorrect)
57-
HEADER_INVALID, ///< Header in memory not belonging to requested superpage
58-
PAYLOAD_INVALID, ///< Payload in memory not belonging to requested superpage
59-
};
60-
61-
/// \brief Constructor
62-
/// \param errtype Identifier code of the error type
63-
///
64-
/// Constructing the error with error code. To be called when the
65-
/// exception is thrown.
66-
Error(ErrorType_t errtype) : mErrorType(errtype)
67-
{
68-
}
69-
70-
/// \brief destructor
71-
~Error() noexcept override = default;
72-
73-
/// \brief Providing error message of the exception
74-
/// \return Error message of the exception
75-
const char* what() const noexcept override
76-
{
77-
switch (mErrorType) {
78-
case ErrorType_t::PAGE_NOTFOUND:
79-
return "Page with requested index not found";
80-
case ErrorType_t::HEADER_DECODING:
81-
return "RDH of page cannot be decoded";
82-
case ErrorType_t::PAYLOAD_DECODING:
83-
return "Payload of page cannot be decoded";
84-
case ErrorType_t::HEADER_INVALID:
85-
return "Access to header not belonging to requested superpage";
86-
case ErrorType_t::PAYLOAD_INVALID:
87-
return "Access to payload not belonging to requested superpage";
88-
};
89-
return "Undefined error";
90-
}
91-
92-
/// \brief Get the type identifier of the error handled with this exception
93-
/// \return Error code of the exception
94-
ErrorType_t getErrorType() const { return mErrorType; }
95-
96-
private:
97-
ErrorType_t mErrorType; ///< Type of the error
98-
};
99-
10040
/// \brief Constructor
10141
///
10242
/// Opening the raw file and determining its size and the number
@@ -114,7 +54,7 @@ class RawReaderFile
11454

11555
/// \brief Read page with a given index
11656
/// \param page Index of the page to be decoded
117-
/// \throw Error if the page cannot be read or header or payload cannot be deocded
57+
/// \throw RawDecodingError if the page cannot be read or header or payload cannot be deocded
11858
///
11959
/// The reader will try to read the page with a certain index. In
12060
/// case the page cannot be decoded (page index outside range,
@@ -150,14 +90,14 @@ class RawReaderFile
15090
void init();
15191

15292
/// \brief Decode the Raw Data Header
153-
/// \throw Error with HEADER_DECODING in case the header decoding failed
93+
/// \throw RawDecodingError with HEADER_DECODING in case the header decoding failed
15494
///
15595
/// Decoding the raw header. Function assumes that the pointer
15696
/// is at the beginning of the raw header
15797
void readHeader();
15898

15999
/// \brief Decode the payload
160-
/// \throw Error with PAYLOAD_DECODING in case the payload decoding failed
100+
/// \throw RawDecodingError with PAYLOAD_DECODING in case the payload decoding failed
161101
///
162102
/// Decoding the payload. The function assumes that the pointer is at
163103
/// the beginning of the payload of the page. Needs the raw header of the
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
#ifndef ALICEO2_EMCAL_RAWREADERMEMORY_H
11+
#define ALICEO2_EMCAL_RAWREADERMEMORY_H
12+
13+
#include <gsl/span>
14+
#include <Rtypes.h>
15+
16+
#include "EMCALReconstruction/RawBuffer.h"
17+
18+
namespace o2
19+
{
20+
21+
namespace emcal
22+
{
23+
24+
template <class RawHeader>
25+
class RawReaderMemory
26+
{
27+
public:
28+
RawReaderMemory(const gsl::span<char> rawmemory);
29+
30+
/// \brief Destructor
31+
~RawReaderMemory() = default;
32+
33+
/// \brief set new raw memory chunk
34+
/// \param rawmemory New raw memory chunk
35+
void setRawMemory(const gsl::span<char> rawmemory);
36+
37+
/// \brief Read the next page from the stream
38+
/// \throw Error if the page cannot be read or header or payload cannot be deocded
39+
void nextPage();
40+
41+
/// \brief Read page with a given index
42+
/// \param page Index of the page to be decoded
43+
/// \throw RawDecodingError if the page cannot be read or header or payload cannot be deocded
44+
///
45+
/// The reader will try to read the page with a certain index. In
46+
/// case the page cannot be decoded (page index outside range,
47+
/// decoding of header or payload failed), and excpetion is raised.
48+
void readPage(int page);
49+
50+
/// \brief access to the raw header of the current page
51+
/// \return Raw header of the current page
52+
/// \throw RawDecodingError with HEADER_INVALID if the header was not decoded
53+
const RawHeader& getRawHeader() const;
54+
55+
/// \brief access to the
56+
const RawBuffer& getRawBuffer() const;
57+
58+
/// \brief get the size of the file in bytes
59+
/// \return size of the file in byte
60+
int getFileSize() const noexcept { return mRawMemoryBuffer.size(); }
61+
62+
/// \brief get the number of pages in the file
63+
/// \return number of pages in the file
64+
int getNumberOfPages() const noexcept { return mNumData; }
65+
66+
/// \brief check if more pages are available in the raw file
67+
/// \return true if there is a next page
68+
bool hasNext() const { return mCurrentPosition < mNumData; }
69+
70+
protected:
71+
void init();
72+
73+
private:
74+
gsl::span<char> mRawMemoryBuffer;
75+
RawBuffer mRawBuffer;
76+
RawHeader mRawHeader;
77+
int mCurrentPosition = 0; ///< Current page in file
78+
int mNumData = 0; ///< Number of pages
79+
bool mRawHeaderInitialized = false; ///< RDH for current page initialized
80+
bool mPayloadInitialized = false; ///< Payload for current page initialized
81+
82+
ClassDefNV(RawReaderMemory, 1);
83+
};
84+
85+
} // namespace emcal
86+
87+
} // namespace o2
88+
89+
#endif

Detectors/EMCAL/reconstruction/src/EMCALReconstructionLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#pragma link C++ class o2::emcal::RawReaderFile < o2::emcal::RAWDataHeader> + ;
1818
#pragma link C++ class o2::emcal::RawReaderFile < o2::header::RAWDataHeaderV4> + ;
19+
#pragma link C++ class o2::emcal::RawReaderMemory < o2::emcal::RAWDataHeader> + ;
20+
//#pragma link C++ class o2::emcal::RawReaderMemory < o2::header::RAWDataHeaderV4> + ;
1921
#pragma link C++ class o2::emcal::AltroDecoder + ;
2022
#pragma link C++ class o2::emcal::Mapper + ;
2123

Detectors/EMCAL/reconstruction/src/RawBuffer.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ void RawBuffer::readFromStream(std::istream& in, uint32_t payloadsize)
4040
}
4141
}
4242

43+
void RawBuffer::readFromMemoryBuffer(const gsl::span<char> rawmemory) {
44+
flush();
45+
auto address = reinterpret_cast<uint32_t*>(rawmemory.data());
46+
for(auto iword = 0; iword < rawmemory.size() / sizeof(uint32_t); iword++) {
47+
if((address[iword] & 0xFFF) == 0x082) {
48+
// Termination word
49+
// should normally not be decoded in case the payload size
50+
// is determined correctly
51+
break;
52+
mDataWords[mNDataWords++] = address[iword];
53+
}
54+
}
55+
}
56+
4357
uint32_t RawBuffer::getWord(int index) const
4458
{
4559
if (index >= mNDataWords)

0 commit comments

Comments
 (0)