1818#include " Framework/Task.h"
1919#include " Framework/DataAllocator.h"
2020#include " Framework/ControlService.h"
21+ #include " Framework/InputRecord.h"
22+ #include " Framework/InputRecordWalker.h"
2123#include " DataFormatsTPC/Digit.h"
24+ #include " DataFormatsTPC/TPCSectorHeader.h"
2225#include " CommonUtils/ConfigurableParam.h"
2326#include " DetectorsRaw/HBFUtilsInitializer.h"
2427#include " TPCReaderWorkflow/PublisherSpec.h"
2528#include " TPCSimulation/CommonMode.h"
2629#include " DetectorsBase/Detector.h"
2730#include " DPLUtils/MakeRootTreeWriterSpec.h"
31+ #include " DPLUtils/RootTreeWriter.h"
32+ #include " CommonDataFormat/RangeReference.h"
2833#include < SimulationDataFormat/MCCompLabel.h>
2934#include < SimulationDataFormat/MCTruthContainer.h>
3035#include < SimulationDataFormat/ConstMCTruthContainer.h>
36+ #include < SimulationDataFormat/IOMCTruthContainerView.h>
3137#include < CommonUtils/FileSystemUtils.h>
3238#include " Algorithm/RangeTokenizer.h"
3339#include " TPCBase/Sector.h"
@@ -54,6 +60,9 @@ using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
5460using namespace o2 ::framework;
5561using namespace o2 ::header;
5662
63+ using namespace o2 ::framework;
64+ using namespace o2 ::header;
65+
5766template <typename T>
5867using BranchDefinition = MakeRootTreeWriterSpec::BranchDefinition<T>;
5968using DigitOutputType = std::vector<o2::tpc::Digit>;
@@ -283,8 +292,10 @@ void getSpec(WorkflowSpec& specs, std::vector<int> const& laneConfiguration, std
283292 specs.emplace_back (DataProcessorSpec{" TPCDigitMerger" , {}, outputs, AlgorithmSpec{o2::framework::adaptFromTask<Task>(laneConfiguration, tpcsectors, mctruth)}, Options{}});
284293
285294 if (writeDigitsFile) {
286- // Using publishing logic from TPC: RecoWorkflow.cxx
287- auto getIndex = [tpcsectors](o2::framework::DataRef const & ref) {
295+ // Simplified approach for ChunkedDigitPublisher - no trigger handling needed
296+ // since we're merging pre-processed digit chunks
297+
298+ auto getIndex = [tpcsectors](o2::framework::DataRef const & ref) -> size_t {
288299 auto const * tpcSectorHeader = o2::framework::DataRefUtils::getHeader<o2::tpc::TPCSectorHeader*>(ref);
289300 if (!tpcSectorHeader) {
290301 throw std::runtime_error (" TPC sector header missing in header stack" );
@@ -302,52 +313,27 @@ void getSpec(WorkflowSpec& specs, std::vector<int> const& laneConfiguration, std
302313 }
303314 throw std::runtime_error (" sector " + std::to_string (tpcSectorHeader->sector ()) + " not configured for writing" );
304315 };
305- auto getName = [tpcsectors](std::string base, size_t index) {
306- return base + " _" + std::to_string (tpcsectors.at (index));
307- };
308- auto makeWriterSpec = [tpcsectors, laneConfiguration, mctruth, getIndex, getName](const char * processName,
309- const char * defaultFileName,
310- const char * defaultTreeName,
311- auto && databranch,
312- auto && mcbranch,
313- bool singleBranch = false ) {
314- if (tpcsectors.size () == 0 ) {
315- throw std::invalid_argument (std::string (" writer process configuration needs list of TPC sectors" ));
316- }
317316
318- auto amendInput = [tpcsectors, laneConfiguration](InputSpec& input, size_t index) {
319- input.binding += std::to_string (laneConfiguration[index]);
320- DataSpecUtils::updateMatchingSubspec (input, laneConfiguration[index]);
321- };
322- auto amendBranchDef = [laneConfiguration, amendInput, tpcsectors, getIndex, getName, singleBranch](auto && def, bool enableMC = true ) {
323- if (!singleBranch) {
324- def.keys = mergeInputs (def.keys , laneConfiguration.size (), amendInput);
325- // the branch is disabled if set to 0
326- def.nofBranches = enableMC ? tpcsectors.size () : 0 ;
327- def.getIndex = getIndex;
328- def.getName = getName;
329- } else {
330- // instead of the separate sector branches only one is going to be written
331- def.nofBranches = enableMC ? 1 : 0 ;
332- }
333- return std::move (def);
334- };
335-
336- return std::move (MakeRootTreeWriterSpec (processName, defaultFileName, defaultTreeName,
337- std::move (amendBranchDef (databranch)),
338- std::move (amendBranchDef (mcbranch, mctruth)))());
317+ auto getName = [tpcsectors](std::string base, size_t index) -> std::string {
318+ return base + " _" + std::to_string (tpcsectors.at (index));
339319 };
340320
341- using DigitOutputType = std::vector<o2::tpc::Digit>;
342- specs.push_back (makeWriterSpec (" tpc-digits-writer" ,
343- " tpcdigits.root" ,
344- " o2sim" ,
345- BranchDefinition<DigitOutputType>{InputSpec{" data" , " TPC" , " DIGITS" , 0 },
346- " TPCDigit" ,
347- " digit-branch-name" },
348- BranchDefinition<o2::dataformats::MCLabelContainer>{InputSpec{" mc" , " TPC" , " DIGITSMCTR" , 0 },
349- " TPCDigitMCTruth" ,
350- " digitmc-branch-name" }));
321+ // Simple branch definitions without custom fill handlers
322+ auto digitsdef = BranchDefinition<DigitsOutputType>{InputSpec{" digits" , ConcreteDataTypeMatcher{" TPC" , " DIGITS" }},
323+ " TPCDigit" , " digits-branch-name" ,
324+ tpcsectors.size (),
325+ getIndex,
326+ getName};
327+
328+ // MC truth branch: write ConstMCTruthContainer directly
329+ auto labelsdef = BranchDefinition<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>{InputSpec{" labelinput" , ConcreteDataTypeMatcher{" TPC" , " DIGITSMCTR" }},
330+ " TPCDigitMCTruth" , " labels-branch-name" ,
331+ (mctruth ? tpcsectors.size () : 0 ),
332+ getIndex,
333+ getName};
334+
335+ specs.push_back (MakeRootTreeWriterSpec (" TPCDigitWriter" , " tpcdigits.root" , " o2sim" ,
336+ std::move (digitsdef), std::move (labelsdef))());
351337 }
352338}
353339
0 commit comments