Skip to content

Commit d747d02

Browse files
noferinishahor02
authored andcommitted
adjust TOF calib collector (speed up)
1 parent 0ef6f92 commit d747d02

3 files changed

Lines changed: 15 additions & 25 deletions

File tree

Detectors/TOF/calibration/include/TOFCalibration/TOFCalibCollector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
#include "DetectorsCalibration/TimeSlotCalibration.h"
1616
#include "DetectorsCalibration/TimeSlot.h"
17+
#include "TOFBase/Geo.h"
1718
#include "DataFormatsTOF/CalibInfoTOF.h"
1819
#include "DataFormatsTOF/CalibInfoCluster.h"
19-
#include "TOFBase/Geo.h"
2020
#include "DataFormatsTOF/CalibInfoTOFshort.h"
2121

2222
#include <array>
@@ -57,7 +57,7 @@ class TOFCalibInfoSlot
5757

5858
private:
5959
std::array<int, Geo::NCHANNELS> mEntriesSlot; // vector containing number of entries per channel
60-
std::vector<o2::dataformats::CalibInfoTOFshort> mTOFCollectedCalibInfoSlot; ///< output TOF calibration info
60+
std::vector<o2::dataformats::CalibInfoTOF> mTOFCollectedCalibInfoSlot; ///< output TOF calibration info
6161

6262
ClassDefNV(TOFCalibInfoSlot, 1);
6363
};
@@ -87,9 +87,9 @@ class TOFCalibCollector final : public o2::calibration::TimeSlotCalibration<o2::
8787
bool mTest = false; // flag to say whether we are in test mode or not
8888
bool mAbsMaxNumOfHits = true; // to decide if the mMaxNumOfHits should be multiplied by the number of TOF channels
8989
std::array<int, Geo::NCHANNELS> mEntries; // vector containing number of entries per channel
90-
std::vector<o2::dataformats::CalibInfoTOFshort> mTOFCollectedCalibInfo; ///< output TOF calibration info
90+
std::vector<o2::dataformats::CalibInfoTOF> mTOFCollectedCalibInfo; ///< output TOF calibration info
9191

92-
ClassDefOverride(TOFCalibCollector, 1);
92+
ClassDefOverride(TOFCalibCollector, 2);
9393
};
9494

9595
} // end namespace tof

Detectors/TOF/calibration/src/TOFCalibCollector.cxx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,10 @@ void TOFCalibInfoSlot::fill(const gsl::span<const o2::dataformats::CalibInfoTOF>
3333

3434
// we first order the data that arrived, to improve speed when filling
3535
int nd = data.size();
36-
LOG(debug) << "entries in incoming data = " << nd;
37-
std::vector<int> ord(nd);
38-
std::iota(ord.begin(), ord.end(), 0);
39-
std::sort(ord.begin(), ord.end(), [&data](int i, int j) { return data[i].getTOFChIndex() < data[j].getTOFChIndex(); });
40-
int chPrev = 0, offsPrev = 0;
36+
LOG(info) << "entries in incoming data = " << nd;
4137
for (int i = 0; i < nd; i++) {
42-
const auto& dti = data[ord[i]];
43-
auto ch = dti.getTOFChIndex();
44-
auto offset = offsPrev;
45-
if (ch > chPrev) {
46-
offset += std::accumulate(mEntriesSlot.begin() + chPrev, mEntriesSlot.begin() + ch, 0);
47-
}
48-
offsPrev = offset;
49-
chPrev = ch;
50-
mTOFCollectedCalibInfoSlot.emplace(mTOFCollectedCalibInfoSlot.begin() + offset, data[ord[i]].getTimestamp(), data[ord[i]].getDeltaTimePi(), data[ord[i]].getTot(), data[ord[i]].getFlags());
51-
mEntriesSlot[ch]++;
38+
mTOFCollectedCalibInfoSlot.emplace_back(data[i].getTOFChIndex(), data[i].getTimestamp(), data[i].getDeltaTimePi(), data[i].getTot(), data[i].getFlags());
39+
mEntriesSlot[data[i].getTOFChIndex()]++;
5240
}
5341
}
5442
//_____________________________________________
@@ -104,7 +92,7 @@ void TOFCalibInfoSlot::merge(const TOFCalibInfoSlot* prev)
10492
LOG(debug) << "Merging two slots with entries: current slot -> " << mTOFCollectedCalibInfoSlot.size() << " , previous slot -> " << prev->mTOFCollectedCalibInfoSlot.size();
10593

10694
int offset = 0, offsetPrev = 0;
107-
std::vector<o2::dataformats::CalibInfoTOFshort> tmpVector;
95+
std::vector<o2::dataformats::CalibInfoTOF> tmpVector;
10896
for (int ch = 0; ch < Geo::NCHANNELS; ch++) {
10997
if (mEntriesSlot[ch] != 0) {
11098
for (int i = offset; i < offset + mEntriesSlot[ch]; i++) {
@@ -195,6 +183,8 @@ void TOFCalibCollector::finalizeSlot(Slot& slot)
195183

196184
o2::tof::TOFCalibInfoSlot* c = slot.getContainer();
197185
mTOFCollectedCalibInfo = c->getCollectedCalibInfoSlot();
186+
// let's sort before to write
187+
std::sort(mTOFCollectedCalibInfo.begin(), mTOFCollectedCalibInfo.end(), [](const o2::dataformats::CalibInfoTOF& a, const o2::dataformats::CalibInfoTOF& b) { return a.getTOFChIndex() < b.getTOFChIndex(); });
198188
LOG(debug) << "vector of CalibTOFInfoShort received with size = " << mTOFCollectedCalibInfo.size();
199189
mEntries = c->getEntriesPerChannel();
200190
return;

Detectors/TOF/calibration/testWorkflow/TOFCalibCollectorWriterSpec.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/// @brief Device to write to tree the information for TOF time slewing calibration.
1717

1818
#include "TOFCalibration/TOFCalibCollector.h"
19-
#include "DataFormatsTOF/CalibInfoTOFshort.h"
19+
#include "DataFormatsTOF/CalibInfoTOF.h"
2020
#include <TTree.h>
2121
#include <gsl/span>
2222

@@ -51,16 +51,16 @@ class TOFCalibCollectorWriter : public o2::framework::Task
5151

5252
void run(o2::framework::ProcessingContext& pc) final
5353
{
54-
auto collectedInfo = pc.inputs().get<gsl::span<o2::dataformats::CalibInfoTOFshort>>("collectedInfo");
54+
auto collectedInfo = pc.inputs().get<gsl::span<o2::dataformats::CalibInfoTOF>>("collectedInfo");
5555
auto entriesPerChannel = pc.inputs().get<gsl::span<int>>("entriesCh");
5656
int offsetStart = 0;
5757
for (int ich = 0; ich < o2::tof::Geo::NCHANNELS; ich++) {
5858
mTOFCalibInfoOut.clear();
5959
if (entriesPerChannel[ich] > 0) {
6060
mTOFCalibInfoOut.resize(entriesPerChannel[ich]);
6161
auto subSpanVect = collectedInfo.subspan(offsetStart, entriesPerChannel[ich]);
62-
memcpy(&mTOFCalibInfoOut[0], subSpanVect.data(), sizeof(o2::dataformats::CalibInfoTOFshort) * subSpanVect.size());
63-
const o2::dataformats::CalibInfoTOFshort* tmp = subSpanVect.data();
62+
memcpy(&mTOFCalibInfoOut[0], subSpanVect.data(), sizeof(o2::dataformats::CalibInfoTOF) * subSpanVect.size());
63+
const o2::dataformats::CalibInfoTOF* tmp = subSpanVect.data();
6464
}
6565
mOutputTree->Fill();
6666
offsetStart += entriesPerChannel[ich];
@@ -77,7 +77,7 @@ class TOFCalibCollectorWriter : public o2::framework::Task
7777
private:
7878
int mCount = 0; // how many times we filled the tree
7979
bool mIsEndOfStream = false;
80-
std::vector<o2::dataformats::CalibInfoTOFshort> mTOFCalibInfoOut, *mPTOFCalibInfoOut = &mTOFCalibInfoOut; ///< these are the object and pointer to the CalibInfo of a specific channel that we need to fill the output tree
80+
std::vector<o2::dataformats::CalibInfoTOF> mTOFCalibInfoOut, *mPTOFCalibInfoOut = &mTOFCalibInfoOut; ///< these are the object and pointer to the CalibInfo of a specific channel that we need to fill the output tree
8181
std::unique_ptr<TTree> mOutputTree; ///< tree for the collected calib tof info
8282
std::string mTOFCalibInfoBranchName = "TOFCalibInfo"; ///< name of branch containing input TOF calib infos
8383
std::string mOutputBranchName = "TOFCollectedCalibInfo"; ///< name of branch containing output

0 commit comments

Comments
 (0)