Skip to content

Commit

Permalink
Use helper to read TPC digits / clusters instead of copy / pasting code
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrohr committed Jan 19, 2021
1 parent 7e59391 commit d5312ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 337 deletions.
105 changes: 3 additions & 102 deletions Detectors/GlobalTrackingWorkflow/src/TPCITSMatchingSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <vector>

#include "Framework/ConfigParamRegistry.h"
#include "Framework/InputRecordWalker.h"
#include "GlobalTrackingWorkflow/TPCITSMatchingSpec.h"
#include "ReconstructionDataFormats/TrackTPCITS.h"
#include "SimulationDataFormat/MCCompLabel.h"
Expand All @@ -25,8 +24,7 @@
#include "DataFormatsITSMFT/ROFRecord.h"
#include "DataFormatsTPC/TrackTPC.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "DataFormatsTPC/ClusterNativeHelper.h"
#include "DataFormatsTPC/TPCSectorHeader.h"
#include "DataFormatsTPC/WorkflowHelper.h"
#include "DetectorsBase/GeometryManager.h"
#include "DetectorsBase/Propagator.h"
#include "ITSMFTBase/DPLAlpideParam.h"
Expand Down Expand Up @@ -115,104 +113,7 @@ void TPCITSMatchingDPL::run(ProcessingContext& pc)

const auto clusTPCShmap = pc.inputs().get<gsl::span<unsigned char>>("clusTPCshmap");

//---------------------------->> TPC Clusters loading >>------------------------------------------
int operation = 0;
uint64_t activeSectors = 0;
std::bitset<o2::tpc::constants::MAXSECTOR> validSectors = 0;
std::map<int, DataRef> datarefs;
std::vector<InputSpec> filter = {
{"check", ConcreteDataTypeMatcher{"TPC", "CLUSTERNATIVE"}, Lifetime::Timeframe},
};
for (auto const& ref : InputRecordWalker(pc.inputs(), filter)) {
auto const* sectorHeader = DataRefUtils::getHeader<o2::tpc::TPCSectorHeader*>(ref);
if (sectorHeader == nullptr) {
// FIXME: think about error policy
LOG(ERROR) << "sector header missing on header stack";
throw std::runtime_error("sector header missing on header stack");
}
int sector = sectorHeader->sector();
std::bitset<o2::tpc::constants::MAXSECTOR> sectorMask(sectorHeader->sectorBits);
LOG(INFO) << "Reading TPC cluster data, sector mask is " << sectorMask;
if ((validSectors & sectorMask).any()) {
// have already data for this sector, this should not happen in the current
// sequential implementation, for parallel path merged at the tracker stage
// multiple buffers need to be handled
throw std::runtime_error("can only have one data set per sector");
}
activeSectors |= sectorHeader->activeSectors;
validSectors |= sectorMask;
datarefs[sector] = ref;
}

auto printInputLog = [&validSectors, &activeSectors](auto& r, const char* comment, auto& s) {
LOG(INFO) << comment << " " << *(r.spec) << ", size " << DataRefUtils::getPayloadSize(r) //
<< " for sector " << s //
<< std::endl //
<< " input status: " << validSectors //
<< std::endl //
<< " active sectors: " << std::bitset<o2::tpc::constants::MAXSECTOR>(activeSectors);
};

if (activeSectors == 0 || (activeSectors & validSectors.to_ulong()) != activeSectors) {
// not all sectors available
// Since we expect complete input, this should not happen (why does the bufferization considered for TPC CA tracker? Ask Matthias)
throw std::runtime_error("Did not receive TPC clusters data for all sectors");
}
//------------------------------------------------------------------------------
std::vector<gsl::span<const char>> clustersTPC;

for (auto const& refentry : datarefs) {
auto& sector = refentry.first;
auto& ref = refentry.second;
clustersTPC.emplace_back(ref.payload, DataRefUtils::getPayloadSize(ref));
printInputLog(ref, "received", sector);
}

// Just print TPC clusters status
{
// make human readable information from the bitfield
std::string bitInfo;
auto nActiveBits = validSectors.count();
if (((uint64_t)0x1 << nActiveBits) == validSectors.to_ulong() + 1) {
// sectors 0 to some upper bound are active
bitInfo = "0-" + std::to_string(nActiveBits - 1);
} else {
int rangeStart = -1;
int rangeEnd = -1;
for (size_t sector = 0; sector < validSectors.size(); sector++) {
if (validSectors.test(sector)) {
if (rangeStart < 0) {
if (rangeEnd >= 0) {
bitInfo += ",";
}
bitInfo += std::to_string(sector);
if (nActiveBits == 1) {
break;
}
rangeStart = sector;
}
rangeEnd = sector;
} else {
if (rangeStart >= 0 && rangeEnd > rangeStart) {
bitInfo += "-" + std::to_string(rangeEnd);
}
rangeStart = -1;
}
}
if (rangeStart >= 0 && rangeEnd > rangeStart) {
bitInfo += "-" + std::to_string(rangeEnd);
}
}
LOG(INFO) << "running matching for sector(s) " << bitInfo;
}

o2::tpc::ClusterNativeAccess clusterIndex;
std::unique_ptr<o2::tpc::ClusterNative[]> clusterBuffer;
memset(&clusterIndex, 0, sizeof(clusterIndex));
o2::tpc::ClusterNativeHelper::ConstMCLabelContainerViewWithBuffer dummyMCOutput;
std::vector<o2::tpc::ClusterNativeHelper::ConstMCLabelContainerView> dummyMCInput;
o2::tpc::ClusterNativeHelper::Reader::fillIndex(clusterIndex, clusterBuffer, dummyMCOutput, clustersTPC, dummyMCInput);
//----------------------------<< TPC Clusters loading <<------------------------------------------
const auto& inputsTPCclusters = o2::tpc::getWorkflowTPCInput(pc);

//
MCLabelsTr lblITS;
Expand Down Expand Up @@ -243,7 +144,7 @@ void TPCITSMatchingDPL::run(ProcessingContext& pc)
mMatching.setITSClusterROFRecInp(clusITSROF);
mMatching.setTPCTracksInp(tracksTPC);
mMatching.setTPCTrackClusIdxInp(tracksTPCClRefs);
mMatching.setTPCClustersInp(&clusterIndex);
mMatching.setTPCClustersInp(&inputsTPCclusters->clusterIndex);
mMatching.setTPCClustersSharingMap(clusTPCShmap);

if (mUseMC) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

#include <vector>

#include "Framework/InputRecordWalker.h"
#include "DataFormatsITS/TrackITS.h"
#include "ReconstructionDataFormats/TrackTPCITS.h"
#include "DataFormatsTPC/TrackTPC.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "DataFormatsTPC/ClusterNativeHelper.h"
#include "DataFormatsTPC/TPCSectorHeader.h"
#include "DataFormatsTPC/WorkflowHelper.h"
#include "DetectorsBase/GeometryManager.h"
#include "DetectorsBase/Propagator.h"
#include "TPCInterpolationWorkflow/TPCInterpolationSpec.h"
Expand Down Expand Up @@ -50,111 +48,13 @@ void TPCInterpolationDPL::run(ProcessingContext& pc)
const auto trackMatchesTOF = pc.inputs().get<gsl::span<o2::dataformats::MatchInfoTOF>>("matchTOF"); // FIXME missing reader
const auto clustersTOF = pc.inputs().get<gsl::span<o2::tof::Cluster>>("clustersTOF");

// TPC Cluster loading part is copied from TPCITSMatchingSpec.cxx
//---------------------------->> TPC Clusters loading >>------------------------------------------
int operation = 0;
uint64_t activeSectors = 0;
std::bitset<o2::tpc::constants::MAXSECTOR> validSectors = 0;
std::map<int, DataRef> datarefs;
std::vector<InputSpec> filter = {
{"check", ConcreteDataTypeMatcher{"TPC", "CLUSTERNATIVE"}, Lifetime::Timeframe},
};
for (auto const& ref : InputRecordWalker(pc.inputs(), filter)) {
auto const* sectorHeader = DataRefUtils::getHeader<o2::tpc::TPCSectorHeader*>(ref);
if (sectorHeader == nullptr) {
// FIXME: think about error policy
LOG(ERROR) << "sector header missing on header stack";
throw std::runtime_error("sector header missing on header stack");
}
const int& sector = sectorHeader->sector();
std::bitset<o2::tpc::constants::MAXSECTOR> sectorMask(sectorHeader->sectorBits);
LOG(INFO) << "Reading TPC cluster data, sector mask is " << sectorMask;
if ((validSectors & sectorMask).any()) {
// have already data for this sector, this should not happen in the current
// sequential implementation, for parallel path merged at the tracker stage
// multiple buffers need to be handled
throw std::runtime_error("can only have one data set per sector");
}
activeSectors |= sectorHeader->activeSectors;
validSectors |= sectorMask;
datarefs[sector] = ref;
}

auto printInputLog = [&validSectors, &activeSectors](auto& r, const char* comment, auto& s) {
LOG(INFO) << comment << " " << *(r.spec) << ", size " << DataRefUtils::getPayloadSize(r) //
<< " for sector " << s //
<< std::endl //
<< " input status: " << validSectors //
<< std::endl //
<< " active sectors: " << std::bitset<o2::tpc::constants::MAXSECTOR>(activeSectors);
};

if (activeSectors == 0 || (activeSectors & validSectors.to_ulong()) != activeSectors) {
// not all sectors available
// Since we expect complete input, this should not happen (why does the bufferization considered for TPC CA tracker? Ask Matthias)
throw std::runtime_error("Did not receive TPC clusters data for all sectors");
}
//------------------------------------------------------------------------------
std::vector<gsl::span<const char>> clustersTPC;

for (auto const& refentry : datarefs) {
auto& sector = refentry.first;
auto& ref = refentry.second;
clustersTPC.emplace_back(ref.payload, DataRefUtils::getPayloadSize(ref));
printInputLog(ref, "received", sector);
}

// Just print TPC clusters status
{
// make human readable information from the bitfield
std::string bitInfo;
auto nActiveBits = validSectors.count();
if (((uint64_t)0x1 << nActiveBits) == validSectors.to_ulong() + 1) {
// sectors 0 to some upper bound are active
bitInfo = "0-" + std::to_string(nActiveBits - 1);
} else {
int rangeStart = -1;
int rangeEnd = -1;
for (size_t sector = 0; sector < validSectors.size(); sector++) {
if (validSectors.test(sector)) {
if (rangeStart < 0) {
if (rangeEnd >= 0) {
bitInfo += ",";
}
bitInfo += std::to_string(sector);
if (nActiveBits == 1) {
break;
}
rangeStart = sector;
}
rangeEnd = sector;
} else {
if (rangeStart >= 0 && rangeEnd > rangeStart) {
bitInfo += "-" + std::to_string(rangeEnd);
}
rangeStart = -1;
}
}
if (rangeStart >= 0 && rangeEnd > rangeStart) {
bitInfo += "-" + std::to_string(rangeEnd);
}
}
LOG(INFO) << "running matching for sector(s) " << bitInfo;
}

o2::tpc::ClusterNativeAccess clusterIndex;
std::unique_ptr<o2::tpc::ClusterNative[]> clusterBuffer;
memset(&clusterIndex, 0, sizeof(clusterIndex));
o2::tpc::ClusterNativeHelper::ConstMCLabelContainerViewWithBuffer dummyMCOutput;
std::vector<o2::tpc::ClusterNativeHelper::ConstMCLabelContainerView> dummyMCInput;
o2::tpc::ClusterNativeHelper::Reader::fillIndex(clusterIndex, clusterBuffer, dummyMCOutput, clustersTPC, dummyMCInput);
//----------------------------<< TPC Clusters loading <<------------------------------------------
const auto& inputsTPCclusters = getWorkflowTPCInput(pc);

// pass input data to TrackInterpolation object
mInterpolation.setITSTracksInp(tracksITS);
mInterpolation.setTPCTracksInp(tracksTPC);
mInterpolation.setTPCTrackClusIdxInp(tracksTPCClRefs);
mInterpolation.setTPCClustersInp(&clusterIndex);
mInterpolation.setTPCClustersInp(&inputsTPCclusters->clusterIndex);
mInterpolation.setTOFMatchesInp(trackMatchesTOF);
mInterpolation.setITSTPCTrackMatchesInp(tracksITSTPC);
mInterpolation.setTOFClustersInp(clustersTOF);
Expand Down
109 changes: 4 additions & 105 deletions Detectors/TPC/workflow/src/ClusterSharingMapSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
#include <gsl/span>
#include <TStopwatch.h>
#include <vector>
#include "Framework/InputRecordWalker.h"
#include "DataFormatsTPC/ClusterNativeHelper.h"
#include "DataFormatsTPC/WorkflowHelper.h"
#include "DataFormatsTPC/TrackTPC.h"
#include "DataFormatsTPC/TPCSectorHeader.h"
#include "GPUO2InterfaceRefit.h"
#include "TPCWorkflow/ClusterSharingMapSpec.h"

Expand All @@ -31,109 +29,10 @@ void ClusterSharingMapSpec::run(ProcessingContext& pc)

const auto tracksTPC = pc.inputs().get<gsl::span<o2::tpc::TrackTPC>>("trackTPC");
const auto tracksTPCClRefs = pc.inputs().get<gsl::span<o2::tpc::TPCClRefElem>>("trackTPCClRefs");
const auto& clustersTPC = getWorkflowTPCInput(pc);

//---------------------------->> TPC Clusters loading >>------------------------------------------
// FIXME: this is a copy-paste from TPCITSMatchingSpec version of TPC cluster reading, later to be organized in a better way
int operation = 0;
uint64_t activeSectors = 0;
std::bitset<o2::tpc::constants::MAXSECTOR> validSectors = 0;
std::map<int, DataRef> datarefs;
std::vector<InputSpec> filter = {
{"check", ConcreteDataTypeMatcher{"TPC", "CLUSTERNATIVE"}, Lifetime::Timeframe},
};
for (auto const& ref : InputRecordWalker(pc.inputs(), filter)) {
auto const* sectorHeader = DataRefUtils::getHeader<o2::tpc::TPCSectorHeader*>(ref);
if (sectorHeader == nullptr) {
// FIXME: think about error policy
LOG(ERROR) << "sector header missing on header stack";
throw std::runtime_error("sector header missing on header stack");
}
int sector = sectorHeader->sector();
std::bitset<o2::tpc::constants::MAXSECTOR> sectorMask(sectorHeader->sectorBits);
LOG(INFO) << "Reading TPC cluster data, sector mask is " << sectorMask;
if ((validSectors & sectorMask).any()) {
// have already data for this sector, this should not happen in the current
// sequential implementation, for parallel path merged at the tracker stage
// multiple buffers need to be handled
throw std::runtime_error("can only have one data set per sector");
}
activeSectors |= sectorHeader->activeSectors;
validSectors |= sectorMask;
datarefs[sector] = ref;
}

auto printInputLog = [&validSectors, &activeSectors](auto& r, const char* comment, auto& s) {
LOG(INFO) << comment << " " << *(r.spec) << ", size " << DataRefUtils::getPayloadSize(r) //
<< " for sector " << s //
<< std::endl //
<< " input status: " << validSectors //
<< std::endl //
<< " active sectors: " << std::bitset<o2::tpc::constants::MAXSECTOR>(activeSectors);
};

if (activeSectors == 0 || (activeSectors & validSectors.to_ulong()) != activeSectors) {
// not all sectors available
// Since we expect complete input, this should not happen (why does the bufferization considered for TPC CA tracker? Ask Matthias)
throw std::runtime_error("Did not receive TPC clusters data for all sectors");
}
//------------------------------------------------------------------------------
std::vector<gsl::span<const char>> clustersTPC;

for (auto const& refentry : datarefs) {
auto& sector = refentry.first;
auto& ref = refentry.second;
clustersTPC.emplace_back(ref.payload, DataRefUtils::getPayloadSize(ref));
printInputLog(ref, "received", sector);
}

// Just print TPC clusters status
{
// make human readable information from the bitfield
std::string bitInfo;
auto nActiveBits = validSectors.count();
if (((uint64_t)0x1 << nActiveBits) == validSectors.to_ulong() + 1) {
// sectors 0 to some upper bound are active
bitInfo = "0-" + std::to_string(nActiveBits - 1);
} else {
int rangeStart = -1;
int rangeEnd = -1;
for (size_t sector = 0; sector < validSectors.size(); sector++) {
if (validSectors.test(sector)) {
if (rangeStart < 0) {
if (rangeEnd >= 0) {
bitInfo += ",";
}
bitInfo += std::to_string(sector);
if (nActiveBits == 1) {
break;
}
rangeStart = sector;
}
rangeEnd = sector;
} else {
if (rangeStart >= 0 && rangeEnd > rangeStart) {
bitInfo += "-" + std::to_string(rangeEnd);
}
rangeStart = -1;
}
}
if (rangeStart >= 0 && rangeEnd > rangeStart) {
bitInfo += "-" + std::to_string(rangeEnd);
}
}
LOG(INFO) << "running matching for sector(s) " << bitInfo;
}

o2::tpc::ClusterNativeAccess clusterIndex;
std::unique_ptr<o2::tpc::ClusterNative[]> clusterBuffer;
memset(&clusterIndex, 0, sizeof(clusterIndex));
o2::tpc::ClusterNativeHelper::ConstMCLabelContainerViewWithBuffer dummyMCOutput;
std::vector<o2::tpc::ClusterNativeHelper::ConstMCLabelContainerView> dummyMCInput;
o2::tpc::ClusterNativeHelper::Reader::fillIndex(clusterIndex, clusterBuffer, dummyMCOutput, clustersTPC, dummyMCInput);
//----------------------------<< TPC Clusters loading <<------------------------------------------

auto& bufVec = pc.outputs().make<std::vector<unsigned char>>(Output{o2::header::gDataOriginTPC, "CLSHAREDMAP", 0}, clusterIndex.nClustersTotal);
o2::gpu::GPUTPCO2InterfaceRefit::fillSharedClustersMap(&clusterIndex, tracksTPC, tracksTPCClRefs.data(), bufVec.data());
auto& bufVec = pc.outputs().make<std::vector<unsigned char>>(Output{o2::header::gDataOriginTPC, "CLSHAREDMAP", 0}, clustersTPC->clusterIndex.nClustersTotal);
o2::gpu::GPUTPCO2InterfaceRefit::fillSharedClustersMap(&clustersTPC->clusterIndex, tracksTPC, tracksTPCClRefs.data(), bufVec.data());

timer.Stop();
LOGF(INFO, "Timing for TPC clusters sharing map creation: Cpu: %.3e Real: %.3e s", timer.CpuTime(), timer.RealTime());
Expand Down

0 comments on commit d5312ed

Please sign in to comment.