forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtpc-reco-workflow.cxx
More file actions
194 lines (176 loc) · 10.8 KB
/
tpc-reco-workflow.cxx
File metadata and controls
194 lines (176 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// 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 tpc-reco-workflow.cxx
/// @author Matthias Richter
/// @since 2018-03-15
/// @brief Basic DPL workflow for TPC reconstruction starting from digits
#include "Framework/WorkflowSpec.h"
#include "Framework/DeviceSpec.h"
#include "Framework/ConfigParamSpec.h"
#include "Framework/CompletionPolicyHelpers.h"
#include "Framework/DispatchPolicy.h"
#include "Framework/PartRef.h"
#include "Framework/ConcreteDataMatcher.h"
#include "TPCWorkflow/RecoWorkflow.h"
#include "TPCReaderWorkflow/TPCSectorCompletionPolicy.h"
#include "TPCCalibration/CorrectionMapsLoader.h"
#include "Framework/CustomWorkflowTerminationHook.h"
#include "DataFormatsTPC/TPCSectorHeader.h"
#include "Algorithm/RangeTokenizer.h"
#include "CommonUtils/ConfigurableParam.h"
#include "DetectorsRaw/HBFUtilsInitializer.h"
#include "Framework/CallbacksPolicy.h"
#include <string>
#include <stdexcept>
#include <unordered_map>
#include <regex>
#include <cstdint>
// we need a global variable to propagate the type the message dispatching of the
// publisher will trigger on. This is dependent on the input type
static o2::framework::ConcreteDataTypeMatcher gDispatchTrigger{"", ""};
// Global variable used to transport data to the completion policy
static o2::tpc::reco_workflow::CompletionPolicyData gPolicyData;
static uint64_t gTpcSectorMask = 0xFFFFFFFFF;
void customize(std::vector<o2::framework::CallbacksPolicy>& policies)
{
o2::raw::HBFUtilsInitializer::addNewTimeSliceCallback(policies);
}
// add workflow options, note that customization needs to be declared before
// including Framework/runDataProcessing
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
{
using namespace o2::framework;
std::vector<ConfigParamSpec> options{
{"input-type", VariantType::String, "digits", {"digitizer, digits, zsraw, clustershw, clusters, compressed-clusters-root, compressed-clusters-flat, compressed-clusters-flat-for-encode, pass-through"}},
{"output-type", VariantType::String, "tracks", {"digits, zsraw, clustershw, clusters, tracks, compressed-clusters-root, compressed-clusters-flat, encoded-clusters, disable-writer, send-clusters-per-sector, qa, no-shared-cluster-map, tpc-triggers"}},
{"disable-root-input", o2::framework::VariantType::Bool, false, {"disable root-files input reader"}},
{"no-ca-clusterer", VariantType::Bool, false, {"Use HardwareClusterer instead of clusterer of GPUCATracking"}},
{"disable-mc", VariantType::Bool, false, {"disable sending of MC information"}},
{"tpc-sectors", VariantType::String, "0-35", {"TPC sector range, e.g. 5-7,8,9"}},
{"tpc-lanes", VariantType::Int, 1, {"number of parallel lanes up to the tracker"}},
{"dispatching-mode", VariantType::String, "prompt", {"determines when to dispatch: prompt, complete"}},
{"no-tpc-zs-on-the-fly", VariantType::Bool, false, {"Do not use TPC zero suppression on the fly"}},
{"ignore-dist-stf", VariantType::Bool, false, {"do not subscribe to FLP/DISTSUBTIMEFRAME/0 message (no lost TF recovery)"}},
{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings (e.g.: 'TPCHwClusterer.peakChargeThreshold=4;...')"}},
{"configFile", VariantType::String, "", {"configuration file for configurable parameters"}},
{"filtered-input", VariantType::Bool, false, {"Filtered tracks, clusters input, prefix dataDescriptors with F"}},
{"select-ir-frames", VariantType::Bool, false, {"Subscribe and filter according to external IR Frames"}},
{"tpc-deadMap-sources", VariantType::Int, -1, {"Sources to consider for TPC dead channel map creation; -1=all, 0=deactivated"}},
{"tpc-mc-time-gain", VariantType::Bool, false, {"use time gain calibration for MC (true) or for data (false)"}},
};
o2::tpc::CorrectionMapsLoader::addGlobalOptions(options);
o2::raw::HBFUtilsInitializer::addConfigOption(options);
std::swap(workflowOptions, options);
}
// customize dispatch policy, dispatch immediately what is ready
void customize(std::vector<o2::framework::DispatchPolicy>& policies)
{
using DispatchOp = o2::framework::DispatchPolicy::DispatchOp;
// we customize all devices to dispatch data immediately
auto readerMatcher = [](auto const& spec) {
return std::regex_match(spec.name.begin(), spec.name.end(), std::regex(".*-reader"));
};
auto triggerMatcher = [](auto const& query) {
// a bit of a hack but we want this to be configurable from the command line,
// however DispatchPolicy is inserted before all other setup. Triggering depending
// on the global variable set from the command line option. If scheduled messages
// are not triggered they are sent out at the end of the computation
return gDispatchTrigger.origin == query.origin && gDispatchTrigger.description == query.description;
};
policies.push_back({"prompt-for-reader", readerMatcher, DispatchOp::WhenReady, triggerMatcher});
}
// customize clusterers and cluster decoders to process immediately what comes in
void customize(std::vector<o2::framework::CompletionPolicy>& policies)
{
// we customize the pipeline processors to consume data as it comes
using CompletionPolicy = o2::framework::CompletionPolicy;
using CompletionPolicyHelpers = o2::framework::CompletionPolicyHelpers;
policies.push_back(CompletionPolicyHelpers::defineByName("tpc-cluster-decoder.*", CompletionPolicy::CompletionOp::Consume));
policies.push_back(CompletionPolicyHelpers::defineByName("tpc-clusterer.*", CompletionPolicy::CompletionOp::Consume));
// ordered policies for the writers
policies.push_back(CompletionPolicyHelpers::consumeWhenAllOrdered(".*(?:TPC|tpc).*[w,W]riter.*"));
// the custom completion policy for the tracker
policies.push_back(o2::tpc::TPCSectorCompletionPolicy("tpc-tracker.*", o2::tpc::TPCSectorCompletionPolicy::Config::RequireAll, &gPolicyData, &gTpcSectorMask)());
}
void customize(o2::framework::OnWorkflowTerminationHook& hook)
{
hook = [](const char* idstring) {
o2::tpc::reco_workflow::cleanupCallback();
};
}
#include "Framework/runDataProcessing.h" // the main driver
using namespace o2::framework;
/// The workflow executable for the stand alone TPC reconstruction workflow
/// The basic workflow for TPC reconstruction is defined in RecoWorkflow.cxx
/// and contains the following default processors
/// - digit reader
/// - clusterer
/// - ClusterHardware Decoder
/// - CA tracker
///
/// The default workflow can be customized by specifying input and output types
/// e.g. digits, clustershw, tracks.
///
/// MC info is processed by default, disabled by using command line option `--disable-mc`
///
/// This function hooks up the the workflow specifications into the DPL driver.
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
std::vector<int> tpcSectors = o2::RangeTokenizer::tokenize<int>(cfgc.options().get<std::string>("tpc-sectors"));
// the lane configuration defines the subspecification ids to be distributed among the lanes.
std::vector<int> laneConfiguration = tpcSectors; // Currently just a copy of the tpcSectors, why?
auto nLanes = cfgc.options().get<int>("tpc-lanes");
auto inputType = cfgc.options().get<std::string>("input-type");
// depending on whether to dispatch early (prompt) and on the input type, we
// set the matcher. Note that this has to be in accordance with the OutputSpecs
// configured for the PublisherSpec
auto dispmode = cfgc.options().get<std::string>("dispatching-mode");
if (dispmode == "complete") {
// nothing to do we leave the matcher empty which will suppress the dispatch
// trigger and all messages will be sent out together at end of computation
} else if (inputType == "digits") {
gDispatchTrigger = o2::framework::ConcreteDataTypeMatcher{"TPC", "DIGITS"};
} else if (inputType == "clustershw") {
gDispatchTrigger = o2::framework::ConcreteDataTypeMatcher{"TPC", "CLUSTERHW"};
} else if (inputType == "zsraw") {
gDispatchTrigger = o2::framework::ConcreteDataTypeMatcher{"TPC", "RAWDATA"};
}
// set up configuration
o2::conf::ConfigurableParam::updateFromFile(cfgc.options().get<std::string>("configFile"));
o2::conf::ConfigurableParam::updateFromString(cfgc.options().get<std::string>("configKeyValues"));
o2::conf::ConfigurableParam::writeINI("o2tpcrecoworkflow_configuration.ini");
gTpcSectorMask = 0;
for (auto s : tpcSectors) {
gTpcSectorMask |= (1ul << s);
}
bool doMC = not cfgc.options().get<bool>("disable-mc");
auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(cfgc.options());
auto wf = o2::tpc::reco_workflow::getWorkflow(&gPolicyData, //
tpcSectors, // sector configuration
gTpcSectorMask, // same as bitmask
laneConfiguration, // lane configuration
sclOpt, // scaling options
doMC, //
nLanes, //
inputType, //
cfgc.options().get<std::string>("output-type"), //
cfgc.options().get<bool>("disable-root-input"), //
!cfgc.options().get<bool>("no-ca-clusterer"), //
!cfgc.options().get<bool>("no-tpc-zs-on-the-fly"), //
!cfgc.options().get<bool>("ignore-dist-stf"), //
cfgc.options().get<bool>("select-ir-frames"),
cfgc.options().get<bool>("filtered-input"),
cfgc.options().get<int>("tpc-deadMap-sources"),
cfgc.options().get<bool>("tpc-mc-time-gain"));
// configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit
o2::raw::HBFUtilsInitializer hbfIni(cfgc, wf);
return std::move(wf);
}