Skip to content

Commit 709c48a

Browse files
committed
Optimize V0 finder loops, add multithreading
* Move some boiler-plate code to RecoContainer * Checker if track or match was loaded * Use RecoContainer in SVertexer * Build Track->Vertex table from external Vertex->Tracks references * OMP multithreading added
1 parent c46b0b4 commit 709c48a

File tree

16 files changed

+426
-255
lines changed

16 files changed

+426
-255
lines changed

DataFormats/Reconstruction/include/ReconstructionDataFormats/GlobalTrackID.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class GlobalTrackID : public AbstractRef<25, 5, 2>
8787
auto getSourceName() const { return getSourceName(getSource()); }
8888
static mask_t getSourcesMask(const std::string_view srcList);
8989
static bool includesSource(int s, mask_t srcm) { return srcm[s]; }
90-
90+
static std::string getSourcesNames(mask_t srcm);
9191
operator int() const { return int(getIndex()); }
9292

9393
std::string asString() const;

DataFormats/Reconstruction/include/ReconstructionDataFormats/VtxTrackIndex.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,18 @@ class VtxTrackIndex : public GlobalTrackID
5151
} // namespace dataformats
5252
} // namespace o2
5353

54+
namespace std
55+
{
56+
// defining std::hash for VtxTrackIndex to be used with std containers
57+
template <>
58+
struct hash<o2::dataformats::VtxTrackIndex> {
59+
public:
60+
size_t operator()(const o2::dataformats::VtxTrackIndex& id) const
61+
{
62+
return std::hash<o2::dataformats::GlobalTrackID>{}(id);
63+
//return id.getRawWOFlags();
64+
}
65+
};
66+
} // namespace std
67+
5468
#endif

DataFormats/Reconstruction/src/GlobalTrackID.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,17 @@ void GlobalTrackID::print() const
101101
{
102102
LOG(INFO) << asString();
103103
}
104+
105+
std::string GlobalTrackID::getSourcesNames(GlobalTrackID::mask_t srcm)
106+
{
107+
std::string s = "[";
108+
for (int i = 0; i < NSources; i++) {
109+
if (srcm[i]) {
110+
if (s.size() > 1) {
111+
s += ',';
112+
}
113+
s += getSourceName(i);
114+
}
115+
}
116+
return std::move(s);
117+
}

DataFormats/Reconstruction/src/V0.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace o2::dataformats;
1515
V0::V0(const std::array<float, 3>& xyz, const std::array<float, 3>& pxyz,
1616
const o2::track::TrackParCov& trPos, const o2::track::TrackParCov& trNeg,
1717
GIndex trPosID, GIndex trNegID)
18-
: o2::track::TrackParCov{xyz, pxyz, 0, false}, mProngIDs{trPosID, trNegID}, mProngs{trPos, trNeg}
18+
: o2::track::TrackParCov{xyz, pxyz, 0, true}, mProngIDs{trPosID, trNegID}, mProngs{trPos, trNeg}
1919
{
2020
}
2121

DataFormats/common/include/CommonDataFormat/AbstractRefAccessor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class AbstractRefAccessor
4242
mContainerPtr[src] = reinterpret_cast<const char*>(cont.data());
4343
}
4444

45+
bool isLoaded(int src) const
46+
{
47+
return mContainerPtr[src] != nullptr;
48+
}
49+
4550
/// get object as user provided type from explicitly provided source, index
4651
template <typename U>
4752
const U& get_as(int src, int idx) const

Detectors/GlobalTracking/include/GlobalTracking/RecoContainer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ struct DataRequest {
3535
std::vector<o2::framework::InputSpec> inputs;
3636
std::unordered_map<std::string, bool> requestMap;
3737
void addInput(const o2::framework::InputSpec&& isp);
38+
39+
void requestTracks(o2::dataformats::GlobalTrackID::mask_t src, bool mc);
40+
void requestClusters(o2::dataformats::GlobalTrackID::mask_t src, bool useMC);
41+
3842
void requestITSTracks(bool mc);
3943
void requestTPCTracks(bool mc);
4044
void requestITSTPCTracks(bool mc);
@@ -94,6 +98,15 @@ struct RecoContainer {
9498
// get contributors from single detectors
9599
GlobalIDSet getSingleDetectorRefs(GTrackID gidx) const;
96100

101+
// check if track source attached
102+
bool isTrackSourceLoaded(int src) const;
103+
104+
// check if match source attached
105+
bool isMatchSourceLoaded(int src) const
106+
{
107+
return miscPool.isLoaded(src);
108+
}
109+
97110
// fetch track param
98111
const o2::track::TrackParCov& getTrack(GTrackID gidx) const;
99112

Detectors/GlobalTracking/src/RecoContainer.cxx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
/// \author ruben.shahoyan@cern.ch
1414

1515
#include <fmt/format.h>
16+
#include <chrono>
17+
#include "DetectorsCommonDataFormats/DetID.h"
1618
#include "GlobalTracking/RecoContainer.h"
1719
#include "DataFormatsITSMFT/CompCluster.h"
1820
#include "DataFormatsITS/TrackITS.h"
@@ -31,6 +33,7 @@ using namespace o2::framework;
3133
namespace o2d = o2::dataformats;
3234

3335
using GTrackID = o2d::GlobalTrackID;
36+
using DetID = o2::detectors::DetID;
3437

3538
void DataRequest::addInput(const InputSpec&& isp)
3639
{
@@ -127,6 +130,43 @@ void DataRequest::requestFT0RecPoints(bool mc)
127130
requestMap["FT0"] = false;
128131
}
129132

133+
void DataRequest::requestTracks(GTrackID::mask_t src, bool useMC)
134+
{
135+
// request tracks for sources probided by the mask
136+
if (src[GTrackID::ITS]) {
137+
requestITSTracks(useMC);
138+
}
139+
if (src[GTrackID::TPC]) {
140+
requestTPCTracks(useMC);
141+
}
142+
if (src[GTrackID::ITSTPC] || src[GTrackID::ITSTPCTOF]) {
143+
requestITSTPCTracks(useMC);
144+
}
145+
if (src[GTrackID::TPCTOF]) {
146+
requestTPCTOFTracks(useMC);
147+
}
148+
if (src[GTrackID::ITSTPCTOF]) {
149+
requestTOFMatches(useMC);
150+
requestTOFClusters(false); // RSTODO Needed just to set the time of ITSTPC track, consider moving to MatchInfoTOF
151+
}
152+
}
153+
154+
void DataRequest::requestClusters(GTrackID::mask_t src, bool useMC)
155+
{
156+
// request clusters for detectors of the sources probided by the mask
157+
158+
// clusters needed for refits
159+
if (GTrackID::includesDet(DetID::ITS, src)) {
160+
requestITSClusters(useMC);
161+
}
162+
if (GTrackID::includesDet(DetID::TPC, src)) {
163+
requestTPCClusters(useMC);
164+
}
165+
if (GTrackID::includesDet(DetID::TOF, src)) {
166+
requestTOFClusters(useMC);
167+
}
168+
}
169+
130170
//__________________________________________________________________
131171
void RecoContainer::collectData(ProcessingContext& pc, const DataRequest& requests)
132172
{
@@ -292,6 +332,15 @@ const o2::track::TrackParCov& RecoContainer::getTrackParamOut(GTrackID gidx) con
292332
}
293333
}
294334

335+
//__________________________________________________________
336+
bool RecoContainer::isTrackSourceLoaded(int src) const
337+
{
338+
if (src == GTrackID::ITSTPCTOF && isMatchSourceLoaded(src)) { // the physical tracks are in ITS-TPC, need to get reference from match info
339+
src = GTrackID::ITSTPC;
340+
}
341+
return tracksPool.isLoaded(src);
342+
}
343+
295344
//__________________________________________________________
296345
const o2::track::TrackParCov& RecoContainer::getTrack(GTrackID gidx) const
297346
{
@@ -320,6 +369,8 @@ void RecoContainer::createTracks(std::function<void(const o2::track::TrackParCov
320369
// We go from most complete tracks to least complete ones, taking into account that some track times
321370
// do not bear their own kinematics but just constrain the time
322371
// As we get more track types functional, this method should be completed
372+
373+
auto start_time = std::chrono::high_resolution_clock::now();
323374
constexpr float PS2MUS = 1e-6;
324375
std::array<std::vector<uint8_t>, GTrackID::NSources> usedData;
325376
auto flagUsed = [&usedData](const GTrackID gidx) { auto src = gidx.getSource();
@@ -419,6 +470,8 @@ void RecoContainer::createTracks(std::function<void(const o2::track::TrackParCov
419470
}
420471
}
421472
}
473+
auto current_time = std::chrono::high_resolution_clock::now();
474+
LOG(INFO) << "RecoContainer::createTracks took " << std::chrono::duration_cast<std::chrono::microseconds>(current_time - start_time).count() * 1e-6 << " CPU s.";
422475
}
423476

424477
// get contributors from single detectors

Detectors/GlobalTrackingWorkflow/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ o2_add_executable(vertex-reader-workflow
6262
o2_add_executable(vertexing-workflow
6363
COMPONENT_NAME secondary
6464
SOURCES src/secondary-vertexing-workflow.cxx
65-
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow )
65+
PUBLIC_LINK_LIBRARIES O2::GlobalTrackingWorkflow O2::TOFWorkflow O2::TOFWorkflowUtils)
6666

6767

6868
add_subdirectory(tofworkflow)

Detectors/GlobalTrackingWorkflow/include/GlobalTrackingWorkflow/SecondaryVertexingSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SecondaryVertexingSpec : public Task
4040
};
4141

4242
/// create a processor spec
43-
DataProcessorSpec getSecondaryVertexingSpec();
43+
DataProcessorSpec getSecondaryVertexingSpec(o2::dataformats::GlobalTrackID::mask_t src);
4444

4545
} // namespace vertexing
4646
} // namespace o2

Detectors/GlobalTrackingWorkflow/src/CosmicsMatchingSpec.cxx

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace o2
5151
namespace globaltracking
5252
{
5353

54-
DataRequest dataRequest;
54+
DataRequest dataRequestCosm;
5555

5656
void CosmicsMatchingSpec::init(InitContext& ic)
5757
{
@@ -100,7 +100,7 @@ void CosmicsMatchingSpec::run(ProcessingContext& pc)
100100
mTimer.Start(false);
101101

102102
RecoContainer recoData;
103-
recoData.collectData(pc, dataRequest);
103+
recoData.collectData(pc, dataRequestCosm);
104104
mMatching.process(recoData);
105105
pc.outputs().snapshot(Output{"GLO", "COSMICTRC", 0, Lifetime::Timeframe}, mMatching.getCosmicTracks());
106106
if (mUseMC) {
@@ -121,30 +121,8 @@ DataProcessorSpec getCosmicsMatchingSpec(GTrackID::mask_t src, bool useMC)
121121
std::vector<InputSpec> inputs;
122122
std::vector<OutputSpec> outputs;
123123

124-
if (src[GTrackID::ITS]) {
125-
dataRequest.requestITSTracks(useMC);
126-
}
127-
if (src[GTrackID::TPC]) {
128-
dataRequest.requestTPCTracks(useMC);
129-
}
130-
if (src[GTrackID::ITSTPC]) {
131-
dataRequest.requestITSTPCTracks(useMC);
132-
}
133-
if (src[GTrackID::TPCTOF]) {
134-
dataRequest.requestTPCTOFTracks(useMC);
135-
}
136-
if (src[GTrackID::ITSTPCTOF]) {
137-
dataRequest.requestTOFMatches(useMC);
138-
dataRequest.requestTOFClusters(false); // RSTODO Needed just to set the time of ITSTPC track, consider moving to MatchInfoTOF
139-
}
140-
141-
// clusters needed for refits
142-
if (GTrackID::includesDet(DetID::ITS, src)) {
143-
dataRequest.requestITSClusters(false);
144-
}
145-
if (GTrackID::includesDet(DetID::TPC, src)) {
146-
dataRequest.requestTPCClusters(false);
147-
}
124+
dataRequestCosm.requestTracks(src, useMC);
125+
dataRequestCosm.requestClusters(src, false); // no MC labels for clusters needed for refit only
148126

149127
outputs.emplace_back("GLO", "COSMICTRC", 0, Lifetime::Timeframe);
150128
if (useMC) {
@@ -153,7 +131,7 @@ DataProcessorSpec getCosmicsMatchingSpec(GTrackID::mask_t src, bool useMC)
153131

154132
return DataProcessorSpec{
155133
"cosmics-matcher",
156-
dataRequest.inputs,
134+
dataRequestCosm.inputs,
157135
outputs,
158136
AlgorithmSpec{adaptFromTask<CosmicsMatchingSpec>(useMC)},
159137
Options{

0 commit comments

Comments
 (0)