Skip to content

Commit 773b62b

Browse files
Adding workflow to read in integrated clusters from root files
- writing TFIDInfo to TTree - moving writer to workflowIO
1 parent 858a822 commit 773b62b

File tree

10 files changed

+246
-16
lines changed

10 files changed

+246
-16
lines changed

Detectors/TOF/workflow/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ o2_add_library(TOFWorkflowUtils
1616
src/CompressedAnalysisTask.cxx
1717
src/EntropyEncoderSpec.cxx
1818
src/EntropyDecoderSpec.cxx
19-
src/TOFIntegrateClusterWriterSpec.cxx
2019
src/TOFIntegrateClusterSpec.cxx
2120
src/TOFMergeIntegrateClusterSpec.cxx
2221
PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::TOFBase O2::DataFormatsTOF O2::TOFReconstruction O2::TOFWorkflowIO O2::Steer O2::TOFCalibration)
@@ -61,6 +60,11 @@ o2_add_executable(integrate-cluster-workflow
6160
COMPONENT_NAME tof
6261
PUBLIC_LINK_LIBRARIES O2::TOFWorkflowUtils)
6362

63+
o2_add_executable(integrate-cluster-reader-workflow
64+
SOURCES src/cluster-integrator-reader.cxx
65+
COMPONENT_NAME tof
66+
PUBLIC_LINK_LIBRARIES O2::TOFWorkflowUtils)
67+
6468
o2_add_executable(merge-integrate-cluster-workflow
6569
SOURCES src/cluster-merge-integrator.cxx
6670
COMPONENT_NAME tof

Detectors/TOF/workflow/include/TOFWorkflowUtils/TOFIntegrateClusterSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace o2
1919
namespace tof
2020
{
2121

22-
o2::framework::DataProcessorSpec getTOFIntegrateClusterSpec();
22+
o2::framework::DataProcessorSpec getTOFIntegrateClusterSpec(const bool disableWriter);
2323

2424
} // end namespace tof
2525
} // end namespace o2

Detectors/TOF/workflow/src/TOFIntegrateClusterSpec.cxx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "Framework/ConfigParamRegistry.h"
2121
#include "DetectorsBase/GRPGeomHelper.h"
2222
#include "TOFBase/Geo.h"
23+
#include "DetectorsBase/TFIDInfoHelper.h"
2324

2425
using namespace o2::framework;
2526

@@ -32,7 +33,7 @@ class TOFIntegrateClusters : public Task
3233
{
3334
public:
3435
/// \constructor
35-
TOFIntegrateClusters(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req){};
36+
TOFIntegrateClusters(std::shared_ptr<o2::base::GRPGeomRequest> req, const bool disableWriter) : mCCDBRequest(req), mDisableWriter(disableWriter){};
3637

3738
void init(framework::InitContext& ic) final
3839
{
@@ -72,7 +73,7 @@ class TOFIntegrateClusters : public Task
7273
std::transform(iTOFCNCl.begin(), iTOFCNCl.end(), iTOFCNCl.begin(), [sliceWidthMSinv](float& val) { return val * sliceWidthMSinv; });
7374
std::transform(iTOFCqTot.begin(), iTOFCqTot.end(), iTOFCqTot.begin(), [sliceWidthMSinv](float& val) { return val * sliceWidthMSinv; });
7475

75-
sendOutput(pc.outputs(), std::move(iTOFCNCl), std::move(iTOFCqTot));
76+
sendOutput(pc, std::move(iTOFCNCl), std::move(iTOFCqTot));
7677
}
7778

7879
void endOfStream(EndOfStreamContext& eos) final
@@ -84,16 +85,23 @@ class TOFIntegrateClusters : public Task
8485

8586
private:
8687
int mNSlicesTF = 11; ///< number of slices a TF is divided into
88+
const bool mDisableWriter{false}; ///< flag if no ROOT output will be written
8789
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest; ///< info for CCDB request
8890

89-
void sendOutput(DataAllocator& output, o2::pmr::vector<float> iTOFCNCl, o2::pmr::vector<float> iTOFCqTot)
91+
void sendOutput(ProcessingContext& pc, o2::pmr::vector<float> iTOFCNCl, o2::pmr::vector<float> iTOFCqTot)
9092
{
91-
output.adoptContainer(Output{header::gDataOriginTOF, "ITOFCN"}, std::move(iTOFCNCl));
92-
output.adoptContainer(Output{header::gDataOriginTOF, "ITOFCQ"}, std::move(iTOFCqTot));
93+
pc.outputs().adoptContainer(Output{header::gDataOriginTOF, "ITOFCN"}, std::move(iTOFCNCl));
94+
pc.outputs().adoptContainer(Output{header::gDataOriginTOF, "ITOFCQ"}, std::move(iTOFCqTot));
95+
// in case of ROOT output also store the TFinfo in the TTree
96+
if (!mDisableWriter) {
97+
o2::dataformats::TFIDInfo tfinfo;
98+
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, tfinfo);
99+
pc.outputs().snapshot(Output{header::gDataOriginTOF, "ITOFTFID"}, tfinfo);
100+
}
93101
}
94102
};
95103

96-
o2::framework::DataProcessorSpec getTOFIntegrateClusterSpec()
104+
o2::framework::DataProcessorSpec getTOFIntegrateClusterSpec(const bool disableWriter)
97105
{
98106
std::vector<InputSpec> inputs;
99107
inputs.emplace_back("tofcluster", o2::header::gDataOriginTOF, "CLUSTERS", 0, Lifetime::Timeframe);
@@ -109,12 +117,15 @@ o2::framework::DataProcessorSpec getTOFIntegrateClusterSpec()
109117
std::vector<OutputSpec> outputs;
110118
outputs.emplace_back(o2::header::gDataOriginTOF, "ITOFCN", 0, Lifetime::Sporadic);
111119
outputs.emplace_back(o2::header::gDataOriginTOF, "ITOFCQ", 0, Lifetime::Sporadic);
120+
if (!disableWriter) {
121+
outputs.emplace_back(o2::header::gDataOriginTOF, "ITOFTFID", 0, Lifetime::Sporadic);
122+
}
112123

113124
return DataProcessorSpec{
114125
"TOFIntegrateClusters",
115126
inputs,
116127
outputs,
117-
AlgorithmSpec{adaptFromTask<TOFIntegrateClusters>(ccdbRequest)},
128+
AlgorithmSpec{adaptFromTask<TOFIntegrateClusters>(ccdbRequest, disableWriter)},
118129
Options{{"nSlicesTF", VariantType::Int, 11, {"number of slices into which a TF is divided"}}}};
119130
}
120131

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#include "TOFWorkflowIO/TOFIntegrateClusterReaderSpec.h"
13+
#include "CommonUtils/ConfigurableParam.h"
14+
#include "Framework/ConfigParamSpec.h"
15+
16+
using namespace o2::framework;
17+
18+
#include "Framework/runDataProcessing.h"
19+
20+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
21+
{
22+
WorkflowSpec wf;
23+
wf.emplace_back(o2::tof::getTOFIntegrateClusterReaderSpec());
24+
return wf;
25+
}

Detectors/TOF/workflow/src/cluster-integrator.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// or submit itself to any jurisdiction.
1111

1212
#include "TOFWorkflowUtils/TOFIntegrateClusterSpec.h"
13-
#include "TOFWorkflowUtils/TOFIntegrateClusterWriterSpec.h"
13+
#include "TOFWorkflowIO/TOFIntegrateClusterWriterSpec.h"
1414
#include "CommonUtils/ConfigurableParam.h"
1515
#include "Framework/ConfigParamSpec.h"
1616

@@ -38,8 +38,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
3838
WorkflowSpec wf;
3939
// Update the (declared) parameters if changed from the command line
4040
o2::conf::ConfigurableParam::updateFromString(cfgc.options().get<std::string>("configKeyValues"));
41-
wf.emplace_back(o2::tof::getTOFIntegrateClusterSpec());
42-
if (!cfgc.options().get<bool>("disable-root-output")) {
41+
const bool disableWriter = cfgc.options().get<bool>("disable-root-output");
42+
wf.emplace_back(o2::tof::getTOFIntegrateClusterSpec(disableWriter));
43+
if (!disableWriter) {
4344
wf.emplace_back(o2::tof::getTOFIntegrateClusterWriterSpec());
4445
}
4546

Detectors/TOF/workflowIO/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ o2_add_library(TOFWorkflowIO
2121
src/TOFCalibWriterSpec.cxx
2222
src/TOFMatchedReaderSpec.cxx
2323
src/CalibInfoReaderSpec.cxx
24-
PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::TOFBase O2::DataFormatsTOF O2::TOFReconstruction)
24+
src/TOFIntegrateClusterWriterSpec.cxx
25+
src/TOFIntegrateClusterReaderSpec.cxx
26+
PUBLIC_LINK_LIBRARIES O2::Framework O2::DPLUtils O2::TOFBase O2::DataFormatsTOF O2::TOFReconstruction O2::Algorithm)
2527

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef O2_TOF_TOFINTEGRATECLUSTERREADERSPEC_SPEC
13+
#define O2_TOF_TOFINTEGRATECLUSTERREADERSPEC_SPEC
14+
15+
#include "Framework/DataProcessorSpec.h"
16+
17+
namespace o2
18+
{
19+
namespace tof
20+
{
21+
22+
o2::framework::DataProcessorSpec getTOFIntegrateClusterReaderSpec();
23+
24+
} // end namespace tof
25+
} // end namespace o2
26+
27+
#endif

Detectors/TOF/workflow/include/TOFWorkflowUtils/TOFIntegrateClusterWriterSpec.h renamed to Detectors/TOF/workflowIO/include/TOFWorkflowIO/TOFIntegrateClusterWriterSpec.h

File renamed without changes.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// @file TOFIntegrateClusterReaderSpec.cxx
13+
14+
#include <vector>
15+
#include <boost/algorithm/string/predicate.hpp>
16+
17+
#include "TOFWorkflowIO/TOFIntegrateClusterReaderSpec.h"
18+
#include "Framework/Task.h"
19+
#include "Framework/ControlService.h"
20+
#include "Framework/ConfigParamRegistry.h"
21+
#include "CommonUtils/NameConf.h"
22+
#include "CommonDataFormat/TFIDInfo.h"
23+
#include "Algorithm/RangeTokenizer.h"
24+
#include "TChain.h"
25+
#include "TGrid.h"
26+
27+
using namespace o2::framework;
28+
29+
namespace o2
30+
{
31+
namespace tof
32+
{
33+
34+
class IntegratedClusterReader : public Task
35+
{
36+
public:
37+
IntegratedClusterReader() = default;
38+
~IntegratedClusterReader() override = default;
39+
void init(InitContext& ic) final;
40+
void run(ProcessingContext& pc) final;
41+
42+
private:
43+
void connectTrees();
44+
45+
int mChainEntry = 0; ///< processed entries in the chain
46+
std::unique_ptr<TChain> mChain; ///< input TChain
47+
std::vector<std::string> mFileNames; ///< input files
48+
std::vector<float> mTOFCNCl, *mTOFCNClPtr = &mTOFCNCl; ///< branch integrated number of cluster TOF currents
49+
std::vector<float> mTOFCqTot, *mTOFCqTotPtr = &mTOFCqTot; ///< branch integrated q TOF currents
50+
o2::dataformats::TFIDInfo mTFinfo, *mTFinfoPtr = &mTFinfo; ///< branch TFIDInfo for injecting correct time
51+
std::vector<std::pair<unsigned long, int>> mIndices; ///< firstTfOrbit, file, index
52+
};
53+
54+
void IntegratedClusterReader::init(InitContext& ic)
55+
{
56+
const auto dontCheckFileAccess = ic.options().get<bool>("dont-check-file-access");
57+
auto fileList = o2::RangeTokenizer::tokenize<std::string>(ic.options().get<std::string>("tofcurrents-infiles"));
58+
59+
// check if only one input file (a txt file contaning a list of files is provided)
60+
if (fileList.size() == 1) {
61+
if (boost::algorithm::ends_with(fileList.front(), "txt")) {
62+
LOGP(info, "Reading files from input file {}", fileList.front());
63+
std::ifstream is(fileList.front());
64+
std::istream_iterator<std::string> start(is);
65+
std::istream_iterator<std::string> end;
66+
std::vector<std::string> fileNamesTmp(start, end);
67+
fileList = fileNamesTmp;
68+
}
69+
}
70+
71+
const std::string inpDir = o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("input-dir"));
72+
for (const auto& file : fileList) {
73+
if ((file.find("alien://") == 0) && !gGrid && !TGrid::Connect("alien://")) {
74+
LOG(fatal) << "Failed to open alien connection";
75+
}
76+
const auto fileDir = o2::utils::Str::concat_string(inpDir, file);
77+
if (!dontCheckFileAccess) {
78+
std::unique_ptr<TFile> filePtr(TFile::Open(fileDir.data()));
79+
if (!filePtr || !filePtr->IsOpen() || filePtr->IsZombie()) {
80+
LOGP(warning, "Could not open file {}", fileDir);
81+
continue;
82+
}
83+
}
84+
mFileNames.emplace_back(fileDir);
85+
}
86+
87+
if (mFileNames.size() == 0) {
88+
LOGP(error, "No input files to process");
89+
}
90+
connectTrees();
91+
}
92+
93+
void IntegratedClusterReader::run(ProcessingContext& pc)
94+
{
95+
// check time order inside the TChain
96+
if (mChainEntry == 0) {
97+
mIndices.clear();
98+
mIndices.reserve(mChain->GetEntries());
99+
for (unsigned long i = 0; i < mChain->GetEntries(); i++) {
100+
mChain->GetEntry(i);
101+
mIndices.emplace_back(std::make_pair(mTFinfo.firstTForbit, i));
102+
}
103+
std::sort(mIndices.begin(), mIndices.end());
104+
}
105+
106+
LOGP(debug, "Processing entry {}", mIndices[mChainEntry].second);
107+
mChain->GetEntry(mIndices[mChainEntry++].second);
108+
109+
// inject correct timing informations
110+
auto& timingInfo = pc.services().get<o2::framework::TimingInfo>();
111+
timingInfo.firstTForbit = mTFinfo.firstTForbit;
112+
timingInfo.tfCounter = mTFinfo.tfCounter;
113+
timingInfo.runNumber = mTFinfo.runNumber;
114+
timingInfo.creation = mTFinfo.creation;
115+
116+
pc.outputs().snapshot(Output{header::gDataOriginTOF, "ITOFCN"}, mTOFCNCl);
117+
pc.outputs().snapshot(Output{header::gDataOriginTOF, "ITOFCQ"}, mTOFCqTot);
118+
usleep(100);
119+
120+
if (mChainEntry >= mChain->GetEntries()) {
121+
pc.services().get<ControlService>().endOfStream();
122+
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
123+
}
124+
}
125+
126+
void IntegratedClusterReader::connectTrees()
127+
{
128+
mChain.reset(new TChain("itofc"));
129+
for (const auto& file : mFileNames) {
130+
LOGP(info, "Adding file to chain: {}", file);
131+
mChain->AddFile(file.data());
132+
}
133+
assert(mChain->GetEntries());
134+
mChain->SetBranchAddress("ITOFCN", &mTOFCNClPtr);
135+
mChain->SetBranchAddress("ITOFCQ", &mTOFCqTotPtr);
136+
mChain->SetBranchAddress("tfID", &mTFinfoPtr);
137+
}
138+
139+
DataProcessorSpec getTOFIntegrateClusterReaderSpec()
140+
{
141+
std::vector<OutputSpec> outputs;
142+
outputs.emplace_back(o2::header::gDataOriginTOF, "ITOFCN", 0, Lifetime::Sporadic);
143+
outputs.emplace_back(o2::header::gDataOriginTOF, "ITOFCQ", 0, Lifetime::Sporadic);
144+
145+
return DataProcessorSpec{
146+
"tof-integrated-cluster-reader",
147+
Inputs{},
148+
outputs,
149+
AlgorithmSpec{adaptFromTask<IntegratedClusterReader>()},
150+
Options{
151+
{"tofcurrents-infiles", VariantType::String, "o2currents_tof.root", {"comma-separated list of input files or .txt file containing list of input files"}},
152+
{"input-dir", VariantType::String, "none", {"Input directory"}},
153+
{"dont-check-file-access", VariantType::Bool, false, {"Deactivate check if all files are accessible before adding them to the list of files"}},
154+
}};
155+
}
156+
157+
} // namespace tof
158+
} // namespace o2

Detectors/TOF/workflow/src/TOFIntegrateClusterWriterSpec.cxx renamed to Detectors/TOF/workflowIO/src/TOFIntegrateClusterWriterSpec.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
/// @file TOFIntegrateClusterWriterSpec.cxx
1313

1414
#include <vector>
15-
#include "TOFWorkflowUtils/TOFIntegrateClusterWriterSpec.h"
15+
#include "TOFWorkflowIO/TOFIntegrateClusterWriterSpec.h"
1616
#include "DPLUtils/MakeRootTreeWriterSpec.h"
17+
#include "CommonDataFormat/TFIDInfo.h"
1718

1819
using namespace o2::framework;
1920

@@ -28,9 +29,10 @@ DataProcessorSpec getTOFIntegrateClusterWriterSpec()
2829
{
2930
return MakeRootTreeWriterSpec("tof-currents-writer",
3031
"o2currents_tof.root",
31-
"ITOFC",
32+
"itofc",
3233
BranchDefinition<std::vector<float>>{InputSpec{"itofcn", o2::header::gDataOriginTOF, "ITOFCN", 0}, "ITOFCN", 1},
33-
BranchDefinition<std::vector<float>>{InputSpec{"itofcq", o2::header::gDataOriginTOF, "ITOFCQ", 0}, "ITOFCQ", 1})();
34+
BranchDefinition<std::vector<float>>{InputSpec{"itofcq", o2::header::gDataOriginTOF, "ITOFCQ", 0}, "ITOFCQ", 1},
35+
BranchDefinition<o2::dataformats::TFIDInfo>{InputSpec{"itoftfid", o2::header::gDataOriginTOF, "ITOFTFID", 0}, "tfID", 1})();
3436
}
3537

3638
} // namespace tof

0 commit comments

Comments
 (0)