diff --git a/Detectors/MUON/MCH/Base/CMakeLists.txt b/Detectors/MUON/MCH/Base/CMakeLists.txt index cc0d6edc36f50..f1763de378c93 100644 --- a/Detectors/MUON/MCH/Base/CMakeLists.txt +++ b/Detectors/MUON/MCH/Base/CMakeLists.txt @@ -12,10 +12,9 @@ o2_add_library(MCHBase SOURCES src/ClusterBlock.cxx src/Digit.cxx - src/DigitBlock.cxx src/Mapping.cxx - src/PreClusterBlock.cxx - src/TrackBlock.cxx + src/PreClusterBlock.cxx + src/TrackBlock.cxx PUBLIC_LINK_LIBRARIES ROOT::Core FairRoot::Base FairMQ::FairMQ) o2_target_root_dictionary(MCHBase diff --git a/Detectors/MUON/MCH/Base/include/MCHBase/DigitBlock.h b/Detectors/MUON/MCH/Base/include/MCHBase/DigitBlock.h deleted file mode 100644 index d1d040035fbcf..0000000000000 --- a/Detectors/MUON/MCH/Base/include/MCHBase/DigitBlock.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -/// @since 2016-10-19 -/// @author P. Pillot -/// @brief Structures defining the digits and the data blocks to hold them - -#ifndef ALICEO2_MCH_DIGITBLOCK_H_ -#define ALICEO2_MCH_DIGITBLOCK_H_ - -#include -#include - -namespace o2 -{ -namespace mch -{ - -struct DataBlockHeader { - - uint16_t fType; // The type of the data block. Must contain a value defined by DataBlockType. - uint16_t fRecordWidth; // The number of bytes each record uses. - uint32_t fNrecords; // Number of records in this data block. - - bool operator==(const DataBlockHeader& that) const - { - return (fType == that.fType && fRecordWidth == that.fRecordWidth && fNrecords == that.fNrecords); - } - - bool operator!=(const DataBlockHeader& that) const { return not this->operator==(that); } -}; - -/** - * Gives the fired digit/pad information. - */ -struct DigitStruct { - - uint32_t uid; // Digit ID in the current mapping (from OCDB) - uint16_t index; // Digit index in the new mapping (produced internally) - uint16_t adc; // ADC value of signal - - bool operator==(const DigitStruct& that) const { return (uid == that.uid && index == that.index && adc == that.adc); } - - bool operator!=(const DigitStruct& that) const { return not this->operator==(that); } -}; - -/** - * DigitBlock defines the format of the internal digit data block. - */ -struct DigitBlock { - - DataBlockHeader header; // Common data block header - - // Array of digits/pads. - // DigitStruct fDigit[/*header.fNrecords*/]; - - bool operator==(const DigitBlock& that) const; - - bool operator!=(const DigitBlock& that) const { return not this->operator==(that); } -}; - -/** - * Stream operator for usage with std::ostream classes which prints the common - * data block header in the following format: - * {fType = xx, fRecordWidth = yy, fNrecords = zz} - */ -inline std::ostream& operator<<(std::ostream& stream, const DataBlockHeader& header) -{ - stream << "{fType = " << header.fType << ", fRecordWidth = " << header.fRecordWidth - << ", fNrecords = " << header.fNrecords << "}"; - return stream; -} - -/** - * Stream operator for usage with std::ostream classes which prints the - * DigitStruct in the following format: - * {uid = xx, index = yy, adc = zz} - */ -std::ostream& operator<<(std::ostream& stream, const DigitStruct& digit); - -/** - * Stream operator for usage with std::ostream classes which prints the - * DigitBlock in the following format: - * {header = xx, fDigit[] = [{..}, {..}, ...]} - */ -std::ostream& operator<<(std::ostream& stream, const DigitBlock& block); - -} // namespace mch -} // namespace o2 - -#endif // ALICEO2_MCH_DIGITBLOCK_H_ diff --git a/Detectors/MUON/MCH/Base/include/MCHBase/PreClusterBlock.h b/Detectors/MUON/MCH/Base/include/MCHBase/PreClusterBlock.h index 2af8eba3c73be..cd7ea172e0c5f 100644 --- a/Detectors/MUON/MCH/Base/include/MCHBase/PreClusterBlock.h +++ b/Detectors/MUON/MCH/Base/include/MCHBase/PreClusterBlock.h @@ -19,7 +19,7 @@ #include #include -#include "MCHBase/DigitBlock.h" +#include "MCHBase/Digit.h" namespace o2 { @@ -31,8 +31,8 @@ namespace mch * hit reconstruction and correlated into a common cluster. */ struct PreClusterStruct { - uint16_t nDigits; // number of digits attached to this precluster - const DigitStruct* digits; // pointer to the 1st element of the array of digits + uint16_t nDigits; // number of digits attached to this precluster + const Digit* digits; // pointer to the 1st element of the array of digits }; /** @@ -83,13 +83,13 @@ class PreClusterBlock * Method to fill the buffer with a new precluster and its first digit * @param digit Reference to the first digit to add to the new precluster. */ - int startPreCluster(const DigitStruct& digit); + int startPreCluster(const Digit& digit); /** * Method to add a new digit to the current precluster * @param digit Reference to the digit to add to the current precluster. */ - int addDigit(const DigitStruct& digit); + int addDigit(const Digit& digit); /** * Return the number of bytes currently used for the data block in the buffer. @@ -124,7 +124,7 @@ class PreClusterBlock int readBuffer(); static constexpr uint32_t SSizeOfUShort = sizeof(uint16_t); - static constexpr uint32_t SSizeOfDigit = sizeof(DigitStruct); + static constexpr uint32_t SSizeOfDigit = sizeof(Digit); /// running pointer on the buffer /** diff --git a/Detectors/MUON/MCH/Base/src/DigitBlock.cxx b/Detectors/MUON/MCH/Base/src/DigitBlock.cxx deleted file mode 100644 index 8ea8e6caf3d39..0000000000000 --- a/Detectors/MUON/MCH/Base/src/DigitBlock.cxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright CERN and copyright holders of ALICE O2. This software is -// distributed under the terms of the GNU General Public License v3 (GPL -// Version 3), copied verbatim in the file "COPYING". -// -// See http://alice-o2.web.cern.ch/license for full licensing information. -// -// In applying this license CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. - -#include "MCHBase/DigitBlock.h" - -namespace o2 -{ -namespace mch -{ - -std::ostream& operator<<(std::ostream& stream, const DigitStruct& digit) -{ - stream << "{uid = " << digit.uid << ", index = " << digit.index << ", adc = " << digit.adc << "}"; - return stream; -} - -std::ostream& operator<<(std::ostream& stream, const DigitBlock& block) -{ - auto digit = reinterpret_cast(&block + 1); - stream << "{header = " << block.header << ", fDigit[] = ["; - if (block.header.fNrecords > 0) { - stream << digit[0]; - } - for (uint32_t i = 1; i < block.header.fNrecords; ++i) { - stream << ", " << digit[i]; - } - stream << "]}"; - return stream; -} - -bool DigitBlock::operator==(const DigitBlock& that) const -{ - auto digitA = reinterpret_cast(this + 1); - auto digitB = reinterpret_cast(&that + 1); - - // First check if the blocks have the same header. If they do then check - // if every digit is the same. In either case if we find a difference - // return false. - if (header != that.header) { - return false; - } - for (uint32_t i = 0; i < header.fNrecords; ++i) { - if (digitA[i] != digitB[i]) { - return false; - } - } - return true; -} - -} // namespace mch -} // namespace o2 diff --git a/Detectors/MUON/MCH/Base/src/PreClusterBlock.cxx b/Detectors/MUON/MCH/Base/src/PreClusterBlock.cxx index a3e3301e7dbc4..d30ac5ab6ca0a 100644 --- a/Detectors/MUON/MCH/Base/src/PreClusterBlock.cxx +++ b/Detectors/MUON/MCH/Base/src/PreClusterBlock.cxx @@ -86,7 +86,7 @@ int PreClusterBlock::reset(void* buffer, uint32_t size, bool write) } //_________________________________________________________________________________________________ -int PreClusterBlock::startPreCluster(const DigitStruct& digit) +int PreClusterBlock::startPreCluster(const Digit& digit) { /// start a new precluster @@ -107,9 +107,9 @@ int PreClusterBlock::startPreCluster(const DigitStruct& digit) mCurrentSize += SSizeOfUShort; // store digit and increment buffer - auto lastDigit = reinterpret_cast(mBuffer); + auto lastDigit = reinterpret_cast(mBuffer); *lastDigit = digit; - mBuffer = (reinterpret_cast(mBuffer) + 1); + mBuffer = (reinterpret_cast(mBuffer) + 1); mCurrentSize += SSizeOfDigit; // increment number of pre-clusters @@ -123,7 +123,7 @@ int PreClusterBlock::startPreCluster(const DigitStruct& digit) } //_________________________________________________________________________________________________ -int PreClusterBlock::addDigit(const DigitStruct& digit) +int PreClusterBlock::addDigit(const Digit& digit) { /// add a new digit to the current precluster @@ -142,8 +142,8 @@ int PreClusterBlock::addDigit(const DigitStruct& digit) *mLastNDigits += 1; // assign digit to the buffer and increment buffer - *(reinterpret_cast(mBuffer)) = digit; - mBuffer = (reinterpret_cast(mBuffer) + 1); + *(reinterpret_cast(mBuffer)) = digit; + mBuffer = (reinterpret_cast(mBuffer) + 1); mCurrentSize += SSizeOfDigit; // increment number of digits in the stored cluster @@ -191,8 +191,8 @@ int PreClusterBlock::readBuffer() // read the digits if (nDigits && (*nDigits) > 0 && mCurrentSize + (*nDigits) * SSizeOfDigit <= mSize) { - auto digit = reinterpret_cast(mBuffer); - mBuffer = (reinterpret_cast(mBuffer) + (*nDigits)); + auto digit = reinterpret_cast(mBuffer); + mBuffer = (reinterpret_cast(mBuffer) + (*nDigits)); mCurrentSize += (*nDigits) * SSizeOfDigit; // store @@ -234,7 +234,7 @@ std::ostream& operator<<(std::ostream& stream, const PreClusterStruct& cluster) { stream << "{nDigits= " << cluster.nDigits; for (int i = 0; i < cluster.nDigits; ++i) { - stream << ", digit[" << i << "]= " << cluster.digits[i]; + stream << ", digit[" << i << "]= " << cluster.digits[i].getPadID(); } stream << "}"; diff --git a/Detectors/MUON/MCH/PreClustering/src/DigitSamplerSpec.cxx b/Detectors/MUON/MCH/PreClustering/src/DigitSamplerSpec.cxx index 363846e773282..4e3a02bdf9ece 100644 --- a/Detectors/MUON/MCH/PreClustering/src/DigitSamplerSpec.cxx +++ b/Detectors/MUON/MCH/PreClustering/src/DigitSamplerSpec.cxx @@ -28,7 +28,7 @@ #include "Framework/Output.h" #include "Framework/Task.h" -#include "MCHBase/DigitBlock.h" +#include "MCHBase/Digit.h" namespace o2 { @@ -37,7 +37,6 @@ namespace mch using namespace std; using namespace o2::framework; -using namespace o2::mch; class DigitSamplerTask { @@ -60,8 +59,6 @@ class DigitSamplerTask this->mInputFile.close(); }; ic.services().get().set(CallbackService::Id::Stop, stop); - - mPrint = ic.options().get("print"); } //_________________________________________________________________________________________________ @@ -69,47 +66,39 @@ class DigitSamplerTask { /// send the digits of the current event - DigitBlock digitBlock{}; - mInputFile.read(reinterpret_cast(&digitBlock), SSizeOfDigitBlock); + int nDigits(0); + mInputFile.read(reinterpret_cast(&nDigits), SSizeOfInt); if (mInputFile.fail()) { + pc.services().get().endOfStream(); return; // probably reached eof } - if (digitBlock.header.fRecordWidth != SSizeOfDigitStruct) { - throw length_error("incorrect size of digits. Content changed?"); - } - // create the output message - auto size = digitBlock.header.fNrecords * SSizeOfDigitStruct; - auto msgOut = pc.outputs().make(Output{"MCH", "DIGITS", 0, Lifetime::Timeframe}, SSizeOfDigitBlock + size); - if (msgOut.size() != SSizeOfDigitBlock + size) { + auto size = nDigits * SSizeOfDigit; + auto msgOut = pc.outputs().make(Output{"MCH", "DIGITS", 0, Lifetime::Timeframe}, SSizeOfInt + size); + if (msgOut.size() != SSizeOfInt + size) { throw length_error("incorrect message payload"); } auto bufferPtr = msgOut.data(); - // fill header info - memcpy(bufferPtr, &digitBlock, SSizeOfDigitBlock); - bufferPtr += SSizeOfDigitBlock; + // fill number of digits + memcpy(bufferPtr, &nDigits, SSizeOfInt); + bufferPtr += SSizeOfInt; - // fill digits info + // fill digits if any if (size > 0) { mInputFile.read(bufferPtr, size); } else { LOG(INFO) << "event is empty"; } - - if (mPrint) { - LOG(INFO) << "block: " << *reinterpret_cast(msgOut.data()); - } } private: - static constexpr uint32_t SSizeOfDigitBlock = sizeof(DigitBlock); - static constexpr uint32_t SSizeOfDigitStruct = sizeof(DigitStruct); + static constexpr uint32_t SSizeOfInt = sizeof(int); + static constexpr uint32_t SSizeOfDigit = sizeof(Digit); std::ifstream mInputFile{}; ///< input file - bool mPrint = false; ///< print digits }; //_________________________________________________________________________________________________ @@ -120,8 +109,7 @@ o2::framework::DataProcessorSpec getDigitSamplerSpec() Inputs{}, Outputs{OutputSpec{"MCH", "DIGITS", 0, Lifetime::Timeframe}}, AlgorithmSpec{adaptFromTask()}, - Options{{"infile", VariantType::String, "", {"input file name"}}, - {"print", VariantType::Bool, false, {"print digits"}}}}; + Options{{"infile", VariantType::String, "", {"input file name"}}}}; } } // end namespace mch diff --git a/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.cxx b/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.cxx index aa92d47b660d2..23b1746158bdf 100644 --- a/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.cxx +++ b/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.cxx @@ -88,7 +88,7 @@ void PreClusterFinder::reset() } //_________________________________________________________________________________________________ -void PreClusterFinder::loadDigits(const DigitStruct* digits, uint32_t nDigits) +void PreClusterFinder::loadDigits(const Digit* digits, int nDigits) { /// fill the Mapping::MpDE structure with fired pads @@ -96,19 +96,19 @@ void PreClusterFinder::loadDigits(const DigitStruct* digits, uint32_t nDigits) uint16_t iPad(0); // loop over digits - for (uint32_t i = 0; i < nDigits; ++i) { + for (int i = 0; i < nDigits; ++i) { - const DigitStruct& digit(digits[i]); + const Digit& digit(digits[i]); - int deIndex = mDEIndices[detectionElementId(digit.uid)]; + int deIndex = mDEIndices[digit.getDetID()]; assert(deIndex >= 0 && deIndex < SNDEs); DetectionElement& de(mDEs[deIndex]); - iPlane = (cathode(digit.uid) == de.mapping->iCath[0]) ? 0 : 1; - iPad = de.mapping->padIndices[iPlane].GetValue(digit.uid); + iPlane = (cathode(digit.getPadID()) == de.mapping->iCath[0]) ? 0 : 1; + iPad = de.mapping->padIndices[iPlane].GetValue(digit.getPadID()); if (iPad == 0) { - LOG(WARN) << "pad ID " << digit.uid << " does not exist in the mapping"; + LOG(WARN) << "pad ID " << digit.getPadID() << " does not exist in the mapping"; continue; } --iPad; diff --git a/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.h b/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.h index 6cdf6ab07716c..43d5a9a3ef616 100644 --- a/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.h +++ b/Detectors/MUON/MCH/PreClustering/src/PreClusterFinder.h @@ -20,7 +20,7 @@ #include #include -#include "MCHBase/DigitBlock.h" +#include "MCHBase/Digit.h" #include "MCHBase/Mapping.h" namespace o2 @@ -51,7 +51,7 @@ class PreClusterFinder void deinit(); void reset(); - void loadDigits(const DigitStruct* digits, uint32_t nDigits); + void loadDigits(const Digit* digits, int nDigits); int run(); @@ -59,7 +59,7 @@ class PreClusterFinder bool hasPreClusters(int iDE); int getNPreClusters(int iDE, int iPlane); const PreCluster* getPreCluster(int iDE, int iPlane, int iCluster); - const DigitStruct* getDigit(int iDE, uint16_t iOrderedPad); + const Digit* getDigit(int iDE, uint16_t iOrderedPad); /// return the number of detection elements in the internal structure static constexpr int getNDEs() { return SNDEs; } @@ -68,16 +68,13 @@ class PreClusterFinder private: struct DetectionElement { std::unique_ptr mapping; // mapping of this DE including the list of pads - std::vector digits; // list of pointers to digits (not owner) + std::vector digits; // list of pointers to digits (not owner) uint16_t nFiredPads[2]; // number of fired pads on each plane std::vector firedPads[2]; // indices of fired pads on each plane uint16_t nOrderedPads[2]; // current number of fired pads in the following arrays std::vector orderedPads[2]; // indices of fired pads ordered after preclustering and merging }; - /// Return detection element ID part of the unique ID - int detectionElementId(uint32_t uid) { return uid & 0xFFF; } - /// Return the cathode part of the unique ID int cathode(uint32_t uid) { return (uid & 0x40000000) >> 30; } @@ -150,7 +147,7 @@ inline const PreClusterFinder::PreCluster* PreClusterFinder::getPreCluster(int i } //_________________________________________________________________________________________________ -inline const DigitStruct* PreClusterFinder::getDigit(int iDE, uint16_t iOrderedPad) +inline const Digit* PreClusterFinder::getDigit(int iDE, uint16_t iOrderedPad) { /// return the digit associated to the pad registered at the index "iOrderedPad". /// This index must be in the range [firstPad, lastPad] associated to a precluster to be stored. diff --git a/Detectors/MUON/MCH/PreClustering/src/PreClusterFinderSpec.cxx b/Detectors/MUON/MCH/PreClustering/src/PreClusterFinderSpec.cxx index 81a3ccd827f2f..0b86175774eba 100644 --- a/Detectors/MUON/MCH/PreClustering/src/PreClusterFinderSpec.cxx +++ b/Detectors/MUON/MCH/PreClustering/src/PreClusterFinderSpec.cxx @@ -29,7 +29,7 @@ #include "Framework/Output.h" #include "Framework/Task.h" -#include "MCHBase/DigitBlock.h" +#include "MCHBase/Digit.h" #include "MCHBase/PreClusterBlock.h" #include "PreClusterFinder.h" @@ -85,22 +85,19 @@ class PreClusterFinderTask auto sizeIn = msgIn.size(); // get header info and check message consistency - if (sizeIn < SSizeOfDigitBlock) { - throw out_of_range("missing DigitBlock"); + if (sizeIn < SSizeOfInt) { + throw out_of_range("missing number of digits"); } - auto digitBlock(reinterpret_cast(bufferPtrIn)); - bufferPtrIn += SSizeOfDigitBlock; - sizeIn -= SSizeOfDigitBlock; - if (digitBlock->header.fRecordWidth != SSizeOfDigitStruct) { - throw length_error("incorrect size of digits. Corrupted message?"); - } - if (sizeIn != digitBlock->header.fNrecords * SSizeOfDigitStruct) { + auto& nDigits(*reinterpret_cast(bufferPtrIn)); + bufferPtrIn += SSizeOfInt; + sizeIn -= SSizeOfInt; + if (sizeIn != nDigits * SSizeOfDigit) { throw length_error("incorrect payload"); } // load the digits to get the fired pads - auto digits(reinterpret_cast(bufferPtrIn)); - mPreClusterFinder.loadDigits(digits, digitBlock->header.fNrecords); + auto digits(reinterpret_cast(bufferPtrIn)); + mPreClusterFinder.loadDigits(digits, nDigits); // preclusterize int nPreClusters = mPreClusterFinder.run(); @@ -138,7 +135,7 @@ class PreClusterFinderTask /// store the preclusters in the given buffer const PreClusterFinder::PreCluster* cluster(nullptr); - const DigitStruct* digit(nullptr); + const Digit* digit(nullptr); uint32_t* bytesUsed(nullptr); uint32_t totalBytesUsed(0); @@ -210,8 +207,7 @@ class PreClusterFinderTask } static constexpr uint32_t SSizeOfInt = sizeof(int); - static constexpr uint32_t SSizeOfDigitBlock = sizeof(DigitBlock); - static constexpr uint32_t SSizeOfDigitStruct = sizeof(DigitStruct); + static constexpr uint32_t SSizeOfDigit = sizeof(Digit); bool mPrint = false; ///< print preclusters PreClusterFinder mPreClusterFinder{}; ///< preclusterizer