Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions DataFormats/Detectors/CTP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@

o2_add_library(DataFormatsCTP
SOURCES src/Digits.cxx
SOURCES src/Configuration.cxx
SOURCES src/Scalers.cxx
src/Configuration.cxx
src/Scalers.cxx
src/CTF.cxx
PUBLIC_LINK_LIBRARIES O2::CommonDataFormat
O2::Headers
O2::SimulationDataFormat
O2::CommonConstants
O2::DataFormatsFT0)
O2::CommonConstants)
o2_target_root_dictionary(DataFormatsCTP
HEADERS include/DataFormatsCTP/Digits.h
include/DataFormatsCTP/Configuration.h
include/DataFormatsCTP/Scalers.h)
include/DataFormatsCTP/Scalers.h
include/DataFormatsCTP/CTF.h)

52 changes: 52 additions & 0 deletions DataFormats/Detectors/CTP/include/DataFormatsCTP/CTF.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

/// \file CTF.h
/// \author ruben.shahoyan@cern.ch
/// \brief Definitions for CTP CTF data

#ifndef O2_CTP_CTF_H
#define O2_CTP_CTF_H

#include <vector>
#include <Rtypes.h>
#include "DetectorsCommonDataFormats/EncodedBlocks.h"

namespace o2
{
namespace ctp
{

/// Header for a single CTF
struct CTFHeader : public o2::ctf::CTFDictHeader {
uint32_t nTriggers = 0; /// number of triggers
uint32_t firstOrbit = 0; /// orbit of 1st trigger
uint16_t firstBC = 0; /// bc of 1st trigger

ClassDefNV(CTFHeader, 1);
};

/// wrapper for the Entropy-encoded trigger inputs and classes of the TF
struct CTF : public o2::ctf::EncodedBlocks<CTFHeader, 4, uint32_t> {

static constexpr size_t N = getNBlocks();
enum Slots { BLC_bcIncTrig,
BLC_orbitIncTrig,
BLC_bytesInput, // bytes of the CTPInputMask bitset (6 bytes from lowest to highest)
BLC_bytesClass // bytes of the CTPClassMask bitset (8 bytes from lowest to highest)
};
ClassDefNV(CTF, 1);
};

} // namespace ctp
} // namespace o2

#endif
9 changes: 8 additions & 1 deletion DataFormats/Detectors/CTP/include/DataFormatsCTP/Digits.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#define _CTP_DIGITS_H_
#include "DetectorsCommonDataFormats/DetID.h"
#include "CommonDataFormat/InteractionRecord.h"
#include "DataFormatsFT0/Digit.h"
#include <bitset>
#include <iosfwd>

Expand Down Expand Up @@ -53,8 +52,16 @@ struct CTPDigit {
void printStream(std::ostream& stream) const;
void setInputMask(gbtword80_t mask);
void setClassMask(gbtword80_t mask);
bool operator==(const CTPDigit& d) const
{
return intRecord == d.intRecord && CTPInputMask == d.CTPInputMask && CTPClassMask == d.CTPClassMask;
}

ClassDefNV(CTPDigit, 2);
};

std::ostream& operator<<(std::ostream& os, const CTPDigit& d);

struct CTPInputDigit {
o2::InteractionRecord intRecord;
std::bitset<CTP_MAXTRIGINPPERDET> inputsMask;
Expand Down
16 changes: 16 additions & 0 deletions DataFormats/Detectors/CTP/src/CTF.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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 <stdexcept>
#include <cstring>
#include "DataFormatsCTP/CTF.h"

using namespace o2::ctp;
5 changes: 5 additions & 0 deletions DataFormats/Detectors/CTP/src/DataFormatsCTPLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@
#pragma link C++ class o2::ctp::CTPScalerRecordO2 + ;
#pragma link C++ class vector < o2::ctp::CTPScalerRecordO2> + ;
#pragma link C++ class o2::ctp::CTPRunScalers + ;

#pragma link C++ struct o2::ctp::CTFHeader + ;
#pragma link C++ struct o2::ctp::CTF + ;
#pragma link C++ class o2::ctf::EncodedBlocks < o2::ctp::CTFHeader, 4, uint32_t> + ;

#endif
11 changes: 8 additions & 3 deletions DataFormats/Detectors/CTP/src/Digits.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@

using namespace o2::ctp;

std::ostream& o2::ctp::operator<<(std::ostream& os, const o2::ctp::CTPDigit& d)
{
os << "CTP Digit: " << d.intRecord << " Input Mask: " << d.CTPInputMask << " Class Mask: " << d.CTPClassMask;
return os;
}

void CTPDigit::printStream(std::ostream& stream) const
{
stream << "CTP Digit: BC " << intRecord.bc << " orbit " << intRecord.orbit << std::endl;
stream << "Input Mask: " << CTPInputMask << std::endl;
stream << "Class Mask: " << CTPClassMask << std::endl;
stream << *this << std::endl;
}

void CTPDigit::setInputMask(gbtword80_t mask)
{
for (int i = 0; i < CTP_NINPUTS; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ template <typename H, int N, typename W>
std::vector<char> EncodedBlocks<H, N, W>::createDictionaryBlocks(const std::vector<o2::rans::FrequencyTable>& vfreq, const std::vector<Metadata>& vmd)
{
if (vfreq.size() != N) {
throw std::runtime_error("mismatch between the size of frequencies vector and number of blocks");
throw std::runtime_error(fmt::format("mismatch between the size of frequencies vector {} and number of blocks {}", vfreq.size(), N));
}
size_t sz = alignSize(sizeof(EncodedBlocks<H, N, W>));
for (int ib = 0; ib < N; ib++) {
Expand Down
22 changes: 15 additions & 7 deletions Detectors/CTF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ o2_add_test(tpc
SOURCES test/test_ctf_io_tpc.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(ft0
PUBLIC_LINK_LIBRARIES O2::FT0Reconstruction
O2::DataFormatsFT0
SOURCES test/test_ctf_io_ft0.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(fv0
PUBLIC_LINK_LIBRARIES O2::FV0Reconstruction
O2::DataFormatsFV0
SOURCES test/test_ctf_io_fv0.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(fdd
PUBLIC_LINK_LIBRARIES O2::FDDReconstruction
O2::DataFormatsFDD
Expand Down Expand Up @@ -73,7 +73,7 @@ o2_add_test(emcal
SOURCES test/test_ctf_io_emcal.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(phos
PUBLIC_LINK_LIBRARIES O2::DataFormatsPHOS
O2::PHOSReconstruction
Expand All @@ -87,26 +87,34 @@ o2_add_test(cpv
SOURCES test/test_ctf_io_cpv.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(zdc
PUBLIC_LINK_LIBRARIES O2::DataFormatsZDC
O2::ZDCReconstruction
SOURCES test/test_ctf_io_zdc.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(trd
PUBLIC_LINK_LIBRARIES O2::CTFWorkflow
O2::DataFormatsTRD
O2::TRDReconstruction
SOURCES test/test_ctf_io_trd.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(hmpid
PUBLIC_LINK_LIBRARIES O2::CTFWorkflow
O2::DataFormatsHMP
O2::HMPIDReconstruction
SOURCES test/test_ctf_io_hmpid.cxx
COMPONENT_NAME ctf
LABELS ctf)

o2_add_test(ctp
PUBLIC_LINK_LIBRARIES O2::CTPWorkflow
O2::DataFormatsCTP
O2::CTPReconstruction
SOURCES test/test_ctf_io_ctp.cxx
COMPONENT_NAME ctf
LABELS ctf)
96 changes: 96 additions & 0 deletions Detectors/CTF/test/test_ctf_io_ctp.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.

#define BOOST_TEST_MODULE Test CTPCTFIO
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "DetectorsCommonDataFormats/NameConf.h"
#include "CTPReconstruction/CTFCoder.h"
#include "DataFormatsCTP/CTF.h"
#include "DataFormatsCTP/Digits.h"
#include "Framework/Logger.h"
#include <TFile.h>
#include <TStopwatch.h>
#include <TSystem.h>
#include <cstring>
#include <random>

using namespace o2::ctp;

BOOST_AUTO_TEST_CASE(CTFTest, *boost::unit_test::enabled())
{
std::vector<CTPDigit> digits;
TStopwatch sw;
sw.Start();
o2::InteractionRecord ir0(3, 5), ir(ir0);

std::random_device rd;
std::mt19937_64 eng(rd());
std::uniform_int_distribution<unsigned long long> distr;

for (int itrg = 0; itrg < 1000; itrg++) {
ir += 1 + distr(eng) % 200;
auto& dig = digits.emplace_back();
dig.intRecord = ir;
dig.CTPInputMask |= distr(eng);
dig.CTPClassMask |= distr(eng);
}

sw.Start();
std::vector<o2::ctf::BufferType> vec;
{
CTFCoder coder;
coder.encode(vec, digits); // compress
}
sw.Stop();
LOG(INFO) << "Compressed in " << sw.CpuTime() << " s";

// writing
{
sw.Start();
auto* ctfImage = o2::ctp::CTF::get(vec.data());
TFile flOut("test_ctf_ctp.root", "recreate");
TTree ctfTree(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
ctfImage->print();
ctfImage->appendToTree(ctfTree, "CTP");
ctfTree.Write();
sw.Stop();
LOG(INFO) << "Wrote to tree in " << sw.CpuTime() << " s";
}

// reading
vec.clear();
{
sw.Start();
TFile flIn("test_ctf_ctp.root");
std::unique_ptr<TTree> tree((TTree*)flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()));
BOOST_CHECK(tree);
o2::ctp::CTF::readFromTree(vec, *(tree.get()), "CTP");
sw.Stop();
LOG(INFO) << "Read back from tree in " << sw.CpuTime() << " s";
}

std::vector<CTPDigit> digitsD;

sw.Start();
const auto ctfImage = o2::ctp::CTF::getImage(vec.data());
{
CTFCoder coder;
coder.decode(ctfImage, digitsD); // decompress
}
sw.Stop();
LOG(INFO) << "Decompressed in " << sw.CpuTime() << " s";

LOG(INFO) << " BOOST_CHECK(digitsD.size() " << digitsD.size() << " digigits.size()) " << digits.size();

BOOST_TEST(digits == digitsD, boost::test_tools::per_element());
}
2 changes: 2 additions & 0 deletions Detectors/CTF/workflow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ o2_add_library(CTFWorkflow
O2::DataFormatsCPV
O2::DataFormatsZDC
O2::DataFormatsHMP
O2::DataFormatsCTP
O2::DataFormatsParameters
O2::ITSMFTWorkflow
O2::TPCWorkflow
Expand All @@ -40,6 +41,7 @@ o2_add_library(CTFWorkflow
O2::CPVWorkflow
O2::ZDCWorkflow
O2::HMPIDWorkflow
O2::CTPWorkflow
O2::Algorithm
O2::CommonUtils)

Expand Down
9 changes: 9 additions & 0 deletions Detectors/CTF/workflow/src/CTFReaderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "DataFormatsCPV/CTF.h"
#include "DataFormatsZDC/CTF.h"
#include "DataFormatsHMP/CTF.h"
#include "DataFormatsCTP/CTF.h"
#include "Algorithm/RangeTokenizer.h"
#include <TStopwatch.h>

Expand Down Expand Up @@ -312,6 +313,14 @@ void CTFReaderSpec::processTF(ProcessingContext& pc)
o2::hmpid::CTF::readFromTree(bufVec, *(mCTFTree.get()), det.getName(), mCurrTreeEntry);
setFirstTFOrbit(det.getName());
}

det = DetID::CTP;
if (detsTF[det]) {
auto& bufVec = pc.outputs().make<std::vector<o2::ctf::BufferType>>({det.getName()}, sizeof(o2::ctp::CTF));
o2::ctp::CTF::readFromTree(bufVec, *(mCTFTree.get()), det.getName(), mCurrTreeEntry);
setFirstTFOrbit(det.getName());
}

auto entryStr = fmt::format("({} of {} in {})", mCurrTreeEntry, mCTFTree->GetEntries(), mCTFFile->GetName());
if (++mCurrTreeEntry >= mCTFTree->GetEntries()) { // this file is done, check if there are other files
mCTFTree.reset();
Expand Down
3 changes: 3 additions & 0 deletions Detectors/CTF/workflow/src/CTFWriterSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "DataFormatsPHOS/CTF.h"
#include "DataFormatsCPV/CTF.h"
#include "DataFormatsZDC/CTF.h"
#include "DataFormatsCTP/CTF.h"
#include "rANS/rans.h"
#include <vector>
#include <array>
Expand Down Expand Up @@ -368,6 +369,7 @@ void CTFWriterSpec::run(ProcessingContext& pc)
szCTF += processDet<o2::cpv::CTF>(pc, DetID::CPV, header, mCTFTreeOut.get());
szCTF += processDet<o2::zdc::CTF>(pc, DetID::ZDC, header, mCTFTreeOut.get());
szCTF += processDet<o2::hmpid::CTF>(pc, DetID::HMP, header, mCTFTreeOut.get());
szCTF += processDet<o2::ctp::CTF>(pc, DetID::CTP, header, mCTFTreeOut.get());

mTimer.Stop();

Expand Down Expand Up @@ -548,6 +550,7 @@ void CTFWriterSpec::storeDictionaries()
storeDictionary<o2::cpv::CTF>(DetID::CPV, header);
storeDictionary<o2::zdc::CTF>(DetID::ZDC, header);
storeDictionary<o2::hmpid::CTF>(DetID::HMP, header);
storeDictionary<o2::ctp::CTF>(DetID::CTP, header);

// close remnants
if (mDictTreeOut) {
Expand Down
Loading