Skip to content

Commit 733efd9

Browse files
committed
Separate compressed TPC clusters output types for root-storage / flat-messaging
1 parent 52da847 commit 733efd9

File tree

10 files changed

+76
-35
lines changed

10 files changed

+76
-35
lines changed

Detectors/TPC/entropyCoding/run/decoder-standalone.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int main(int argc, char** argv)
9292
if (!comparisonFileName.empty()) {
9393
// read compressed clusters from ROOT file:
9494
TFile file{comparisonFileName.c_str()};
95-
o2::tpc::CompressedClusters* c;
95+
o2::tpc::CompressedClustersROOT* c;
9696
file.GetObject("TPCCompressedClusters", c);
9797

9898
size_t numErrors = 0;

Detectors/TPC/entropyCoding/run/encoder-standalone.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ int main(int argc, char** argv)
6060
// read compressed clusters from ROOT file:
6161
auto clusters = [&]() {
6262
TFile srcFile{inputFileName.c_str()};
63-
o2::tpc::CompressedClusters* c;
63+
o2::tpc::CompressedClustersROOT* c;
6464
srcFile.GetObject("TPCCompressedClusters", c);
6565
srcFile.Close();
66-
return std::unique_ptr<o2::tpc::CompressedClusters>(c);
66+
if (c == nullptr) {
67+
throw std::runtime_error("Cannot read clusters from root file");
68+
}
69+
return std::unique_ptr<o2::tpc::CompressedClustersROOT>(c);
6770
}();
6871

6972
std::cout << "nAttachedClusters: " << clusters->nAttachedClusters << std::endl;

Detectors/TPC/workflow/include/TPCWorkflow/CATrackerSpec.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ namespace ca
3131
// The CA tracker is now a wrapper to not only the actual tracking on GPU but
3232
// also the decoding of the zero-suppressed raw format and the clusterer.
3333
enum struct Operation {
34-
CAClusterer, // run the CA clusterer
35-
ZSDecoder, // run the ZS raw data decoder
36-
OutputTracks, // publish tracks
37-
OutputCAClusters, // publish the clusters produced by CA clusterer
38-
OutputCompClusters, // publish CompClusters container
39-
ProcessMC, // process MC labels
40-
Noop, // skip argument on the constructor
34+
CAClusterer, // run the CA clusterer
35+
ZSDecoder, // run the ZS raw data decoder
36+
OutputTracks, // publish tracks
37+
OutputCAClusters, // publish the clusters produced by CA clusterer
38+
OutputCompClusters, // publish CompClusters container
39+
OutputCompClustersFlat, // publish CompClusters container
40+
ProcessMC, // process MC labels
41+
Noop, // skip argument on the constructor
4142
};
4243

4344
/// Helper struct to pass the individual ca::Operation flags to
@@ -66,6 +67,9 @@ struct Config {
6667
case Operation::OutputCompClusters:
6768
outputCompClusters = true;
6869
break;
70+
case Operation::OutputCompClustersFlat:
71+
outputCompClustersFlat = true;
72+
break;
6973
case Operation::OutputCAClusters:
7074
outputCAClusters = true;
7175
break;
@@ -86,6 +90,7 @@ struct Config {
8690
bool zsDecoder = false;
8791
bool outputTracks = false;
8892
bool outputCompClusters = false;
93+
bool outputCompClustersFlat = false;
8994
bool outputCAClusters = false;
9095
bool processMC = false;
9196
};

Detectors/TPC/workflow/include/TPCWorkflow/EntropyEncoderSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace tpc
2323
{
2424

2525
/// create a processor spec
26-
framework::DataProcessorSpec getEntropyEncoderSpec();
26+
framework::DataProcessorSpec getEntropyEncoderSpec(bool inputFromFile);
2727

2828
} // end namespace tpc
2929
} // end namespace o2

Detectors/TPC/workflow/src/CATrackerSpec.cxx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ DataProcessorSpec getCATrackerSpec(ca::Config const& specconfig, std::vector<int
512512
}
513513
}
514514

515+
bool doOutputCompressedClustersFlat = pc.outputs().isAllowed({gDataOriginTPC, "COMPCLUSTERSFLAT", 0});
516+
bool doOutputCompressedClustersROOT = pc.outputs().isAllowed({gDataOriginTPC, "COMPCLUSTERS", 0});
517+
515518
std::vector<TrackTPC> tracks;
516519
std::vector<uint32_t> clusRefs;
517520
MCLabelContainer tracksMCTruth;
@@ -541,9 +544,11 @@ DataProcessorSpec getCATrackerSpec(ca::Config const& specconfig, std::vector<int
541544
}
542545
GPUInterfaceOutputs outputRegions;
543546
size_t bufferSize = 2048ul * 1024 * 1024; // TODO: Just allocated some large buffer for now, should estimate this correctly;
544-
auto& bufferCompressedClusters = pc.outputs().make<std::vector<char>>(Output{gDataOriginTPC, "COMPCLUSTERS", 0}, bufferSize);
545-
outputRegions.compressedClusters.ptr = bufferCompressedClusters.data();
546-
outputRegions.compressedClusters.size = bufferCompressedClusters.size();
547+
auto* bufferCompressedClusters = doOutputCompressedClustersFlat ? &pc.outputs().make<std::vector<char>>(Output{gDataOriginTPC, "COMPCLUSTERSFLAT", 0}, bufferSize) : nullptr;
548+
if (doOutputCompressedClustersFlat) {
549+
outputRegions.compressedClusters.ptr = bufferCompressedClusters->data();
550+
outputRegions.compressedClusters.size = bufferCompressedClusters->size();
551+
}
547552
int retVal = tracker->runTracking(&ptrs, &outputRegions);
548553
if (retVal != 0) {
549554
throw std::runtime_error("tracker returned error code " + std::to_string(retVal));
@@ -566,16 +571,20 @@ DataProcessorSpec getCATrackerSpec(ca::Config const& specconfig, std::vector<int
566571
//o2::tpc::ClusterNativeAccess clustersNativeDecoded; // Cluster native access structure as used by the tracker
567572
//std::vector<o2::tpc::ClusterNative> clusterBuffer; // std::vector that will hold the actual clusters, clustersNativeDecoded will point inside here
568573
//mDecoder.decompress(clustersCompressed, clustersNativeDecoded, clusterBuffer, param); // Run decompressor
569-
if (pc.outputs().isAllowed({gDataOriginTPC, "COMPCLUSTERS", 0})) {
570-
if (ptrs.compressedClusters != nullptr) {
571-
if ((void*)ptrs.compressedClusters != (void*)bufferCompressedClusters.data()) {
574+
if (ptrs.compressedClusters != nullptr) {
575+
if (doOutputCompressedClustersFlat) {
576+
if ((void*)ptrs.compressedClusters != (void*)bufferCompressedClusters->data()) {
572577
throw std::runtime_error("output ptrs out of sync"); // sanity check
573578
}
574-
bufferCompressedClusters.resize(outputRegions.compressedClusters.size);
575-
CompressedClustersFlat* tmp = (CompressedClustersFlat*)bufferCompressedClusters.data();
576-
} else {
577-
LOG(ERROR) << "unable to get compressed cluster info from track";
579+
bufferCompressedClusters->resize(outputRegions.compressedClusters.size);
578580
}
581+
if (doOutputCompressedClustersROOT) {
582+
o2::tpc::CompressedClustersROOT compressedClusters = *ptrs.compressedClusters;
583+
printf("FOOOO %d\n", compressedClusters.nTracks);
584+
pc.outputs().snapshot(Output{gDataOriginTPC, "COMPCLUSTERS", 0}, ROOTSerialized<o2::tpc::CompressedClustersROOT const>(compressedClusters));
585+
}
586+
} else {
587+
LOG(ERROR) << "unable to get compressed cluster info from track";
579588
}
580589

581590
// publish clusters produced by CA clusterer sector-wise if the outputs are configured
@@ -670,6 +679,9 @@ DataProcessorSpec getCATrackerSpec(ca::Config const& specconfig, std::vector<int
670679
if (specconfig.outputCompClusters) {
671680
outputSpecs.emplace_back(gDataOriginTPC, "COMPCLUSTERS", 0, Lifetime::Timeframe);
672681
}
682+
if (specconfig.outputCompClustersFlat) {
683+
outputSpecs.emplace_back(gDataOriginTPC, "COMPCLUSTERSFLAT", 0, Lifetime::Timeframe);
684+
}
673685
if (specconfig.outputCAClusters) {
674686
for (auto const& sector : tpcsectors) {
675687
o2::header::DataHeader::SubSpecificationType id = sector;

Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,33 @@ namespace o2
4242
namespace tpc
4343
{
4444

45-
DataProcessorSpec getEntropyEncoderSpec()
45+
DataProcessorSpec getEntropyEncoderSpec(bool inputFromFile)
4646
{
4747
struct ProcessAttributes {
4848
int verbosity = 1;
4949
};
5050

51-
auto initFunction = [](InitContext& ic) {
51+
auto initFunction = [inputFromFile](InitContext& ic) {
5252
auto processAttributes = std::make_shared<ProcessAttributes>();
5353

54-
auto processingFct = [processAttributes](ProcessingContext& pc) {
55-
auto tmp = pc.inputs().get<CompressedClustersFlat*>("input");
56-
if (tmp == nullptr) {
57-
LOG(ERROR) << "invalid input";
58-
return;
54+
auto processingFct = [processAttributes, inputFromFile](ProcessingContext& pc) {
55+
CompressedClusters clusters;
56+
57+
if (inputFromFile) {
58+
auto tmp = pc.inputs().get<CompressedClustersROOT*>("input");
59+
if (tmp == nullptr) {
60+
LOG(ERROR) << "invalid input";
61+
return;
62+
}
63+
clusters = *tmp;
64+
} else {
65+
auto tmp = pc.inputs().get<CompressedClustersFlat*>("input");
66+
if (tmp == nullptr) {
67+
LOG(ERROR) << "invalid input";
68+
return;
69+
}
70+
clusters = *tmp;
5971
}
60-
CompressedClusters clusters(*tmp);
6172

6273
auto encodedClusters = o2::tpc::TPCEntropyEncoder::encode(clusters);
6374

@@ -74,8 +85,9 @@ DataProcessorSpec getEntropyEncoderSpec()
7485
return processingFct;
7586
};
7687

88+
header::DataDescription inputType = inputFromFile ? header::DataDescription("COMPCLUSTERS") : header::DataDescription("COMPCLUSTERSFLAT");
7789
return DataProcessorSpec{"tpc-entropy-encoder", // process id
78-
{{"input", "TPC", "COMPCLUSTERS", 0, Lifetime::Timeframe}},
90+
{{"input", "TPC", inputType, 0, Lifetime::Timeframe}},
7991
{},
8092
AlgorithmSpec(initFunction)};
8193
}

Detectors/TPC/workflow/src/RecoWorkflow.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ framework::WorkflowSpec getWorkflow(std::vector<int> const& tpcSectors, std::vec
194194
// output matrix
195195
// Note: the ClusterHardware format is probably a deprecated legacy format and also the
196196
// ClusterDecoderRawSpec
197-
bool produceCompClusters = isEnabled(OutputType::CompClusters) || isEnabled(OutputType::EncodedClusters);
197+
bool produceCompClusters = isEnabled(OutputType::CompClusters);
198198
bool produceTracks = isEnabled(OutputType::Tracks);
199199
bool runTracker = produceTracks || produceCompClusters;
200200
bool runHWDecoder = !caClusterer && (runTracker || isEnabled(OutputType::Clusters));
@@ -394,6 +394,7 @@ framework::WorkflowSpec getWorkflow(std::vector<int> const& tpcSectors, std::vec
394394
zsDecoder ? ca::Operation::ZSDecoder : ca::Operation::Noop,
395395
produceTracks ? ca::Operation::OutputTracks : ca::Operation::Noop,
396396
produceCompClusters ? ca::Operation::OutputCompClusters : ca::Operation::Noop,
397+
runClusterEncoder ? ca::Operation::OutputCompClustersFlat : ca::Operation::Noop,
397398
isEnabled(OutputType::Clusters) && caClusterer ? ca::Operation::OutputCAClusters : ca::Operation::Noop,
398399
},
399400
laneConfiguration));
@@ -405,7 +406,7 @@ framework::WorkflowSpec getWorkflow(std::vector<int> const& tpcSectors, std::vec
405406
//
406407
// selected by output type 'encoded-clusters'
407408
if (runClusterEncoder) {
408-
specs.emplace_back(o2::tpc::getEntropyEncoderSpec());
409+
specs.emplace_back(o2::tpc::getEntropyEncoderSpec(!runTracker));
409410
}
410411

411412
//////////////////////////////////////////////////////////////////////////////////////////////

Detectors/TPC/workflow/src/tpc-reco-workflow.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
4141
using namespace o2::framework;
4242

4343
std::vector<ConfigParamSpec> options{
44-
{"input-type", VariantType::String, "digits", {"digitizer, digits, clustershw, clustersnative, zsraw"}},
45-
{"output-type", VariantType::String, "tracks", {"digits, clustershw, clustersnative, tracks, disable-writer"}},
44+
{"input-type", VariantType::String, "digits", {"digitizer, digits, zsraw, clustershw, clustersnative, compressed-clusters"}},
45+
{"output-type", VariantType::String, "tracks", {"digits, clustershw, clustersnative, tracks, compressed-clusters, encoded-clusters, disable-writer"}},
4646
{"ca-clusterer", VariantType::Bool, false, {"Use clusterer of GPUCATracking"}},
4747
{"disable-mc", VariantType::Bool, false, {"disable sending of MC information"}},
4848
{"tpc-sectors", VariantType::String, "0-35", {"TPC sector range, e.g. 5-7,8,9"}},

GPU/GPUTracking/Base/GPUOutputControl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ struct GPUOutputControl {
3636
OutputBase = OutputPtr = (char*)ptr;
3737
OutputMaxSize = size;
3838
}
39+
void reset()
40+
{
41+
new (this) GPUOutputControl;
42+
}
3943
#endif
4044

4145
void* OutputBase = nullptr; // Base ptr to memory pool, occupied size is OutputPtr - OutputBase

GPU/GPUTracking/Interface/GPUO2Interface.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ int GPUTPCO2Interface::RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceO
101101

102102
mChain->mIOPtrs = *data;
103103
if (mConfig->configInterface.outputToPreallocatedBuffers) {
104-
mOutputCompressedClusters->set(outputs->compressedClusters.ptr, outputs->compressedClusters.size);
104+
if (outputs->compressedClusters.ptr) {
105+
mOutputCompressedClusters->set(outputs->compressedClusters.ptr, outputs->compressedClusters.size);
106+
} else {
107+
mOutputCompressedClusters->reset();
108+
}
105109
}
106110
int retVal = mRec->RunChains();
107111
if (retVal == 2) {

0 commit comments

Comments
 (0)