Skip to content

Commit 091fbfb

Browse files
chiarazampollishahor02
authored andcommitted
Following review to PR
clang-format
1 parent 202c9a3 commit 091fbfb

6 files changed

Lines changed: 52 additions & 33 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ class TOFCalibCollector final : public o2::calibration::TimeSlotCalibration<o2::
7373
void initOutput() final;
7474
void finalizeSlot(Slot& slot) final;
7575
Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final;
76-
void isTest(bool istest) { mTest = istest; }
76+
void setIsTest(bool istest) { mTest = istest; }
7777
auto& getCollectedCalibInfo() const { return mTOFCollectedCalibInfo; }
7878
auto& getEntriesPerChannel() const { return mEntries; }
79-
void isMaxNumberOfHitsAbsolute(bool absNumber) { mAbsMaxNumOfHits = absNumber; }
79+
void setIsMaxNumberOfHitsAbsolute(bool absNumber) { mAbsMaxNumOfHits = absNumber; }
8080

8181
private:
8282
bool mTFsendingPolicy = false; // whether we will send information at every TF or only when we have a certain statistics

‎Detectors/TOF/calibration/include/TOFCalibration/TOFChannelCalibrator.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<o
120120
const CcdbObjectInfoVector& getTimeSlewingInfoVector() const { return mInfoVector; }
121121
CcdbObjectInfoVector& getTimeSlewingInfoVector() { return mInfoVector; }
122122

123-
void isTest(bool isTest) { mTest = isTest; }
123+
void setIsTest(bool isTest) { mTest = isTest; }
124124
bool isTest() const { return mTest; }
125125

126126
void setCalibTOFapi(CalibTOFapi* api) { mCalibTOFapi = api; }

‎Detectors/TOF/calibration/src/TOFCalibCollector.cxx‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,51 @@ void TOFCalibInfoSlot::fill(const gsl::span<const o2::dataformats::CalibInfoTOF>
2929
// we do not apply any calibration at this stage, it will be applied when we
3030
// process the data before filling the CCDB in the separate process
3131

32-
for (int i = data.size(); i--;) {
33-
auto ch = data[i].getTOFChIndex();
34-
auto offset = std::accumulate(mEntriesSlot.begin(), mEntriesSlot.begin() + ch, 0);
35-
mTOFCollectedCalibInfoSlot.emplace(mTOFCollectedCalibInfoSlot.begin() + offset, data[i].getTimestamp(), data[i].getDeltaTimePi(), data[i].getTot(), data[i].getFlags());
32+
// we first order the data that arrived, to improve speed when filling
33+
int nd = data.size();
34+
LOG(DEBUG) << "entries in incoming data = " << nd;
35+
std::vector<int> ord(nd);
36+
std::iota(ord.begin(), ord.end(), 0);
37+
std::sort(ord.begin(), ord.end(), [&data](int i, int j) { return data[i].getTOFChIndex() < data[j].getTOFChIndex(); });
38+
int chPrev = 0, offsPrev = 0;
39+
for (int i = 0; i < nd; i++) {
40+
const auto& dti = data[ord[i]];
41+
auto ch = dti.getTOFChIndex();
42+
auto offset = offsPrev;
43+
if (ch > chPrev) {
44+
offset += std::accumulate(mEntriesSlot.begin() + chPrev, mEntriesSlot.begin() + ch, 0);
45+
}
46+
offsPrev = offset;
47+
chPrev = ch;
48+
mTOFCollectedCalibInfoSlot.emplace(mTOFCollectedCalibInfoSlot.begin() + offset, data[ord[i]].getTimestamp(), data[ord[i]].getDeltaTimePi(), data[ord[i]].getTot(), data[ord[i]].getFlags());
3649
mEntriesSlot[ch]++;
3750
}
3851
}
39-
4052
//_____________________________________________
4153
void TOFCalibInfoSlot::merge(const TOFCalibInfoSlot* prev)
4254
{
4355
// merge data of 2 slots
4456

45-
int addedPerChannel = 0;
46-
int offset = 0;
47-
4857
LOG(DEBUG) << "Merging two slots with entries: current slot -> " << mTOFCollectedCalibInfoSlot.size() << " , previous slot -> " << prev->mTOFCollectedCalibInfoSlot.size();
58+
59+
int offset = 0, offsetPrev = 0;
60+
std::vector<o2::dataformats::CalibInfoTOFshort> tmpVector;
4961
for (int ch = 0; ch < Geo::NCHANNELS; ch++) {
50-
offset += mEntriesSlot[ch];
51-
if (prev->mEntriesSlot[ch] == 0)
52-
continue;
53-
auto offsetprevStart = addedPerChannel;
54-
auto offsetprevEnd = addedPerChannel + prev->mEntriesSlot[ch];
55-
addedPerChannel += prev->mEntriesSlot[ch];
56-
mTOFCollectedCalibInfoSlot.insert(mTOFCollectedCalibInfoSlot.begin() + offset, prev->mTOFCollectedCalibInfoSlot.begin() + offsetprevStart, prev->mTOFCollectedCalibInfoSlot.begin() + offsetprevEnd);
57-
mEntriesSlot[ch] += prev->mEntriesSlot[ch];
62+
if (mEntriesSlot[ch] != 0) {
63+
for (int i = offset; i < offset + mEntriesSlot[ch]; i++) {
64+
tmpVector.emplace_back(mTOFCollectedCalibInfoSlot[i]);
65+
}
66+
offset += mEntriesSlot[ch];
67+
}
68+
if (prev->mEntriesSlot[ch] != 0) {
69+
for (int i = offsetPrev; i < offsetPrev + prev->mEntriesSlot[ch]; i++) {
70+
tmpVector.emplace_back(prev->mTOFCollectedCalibInfoSlot[i]);
71+
}
72+
offsetPrev += prev->mEntriesSlot[ch];
73+
mEntriesSlot[ch] += prev->mEntriesSlot[ch];
74+
}
5875
}
76+
mTOFCollectedCalibInfoSlot.swap(tmpVector);
5977
LOG(DEBUG) << "After merging the size is " << mTOFCollectedCalibInfoSlot.size();
6078
return;
6179
}
@@ -114,7 +132,7 @@ bool TOFCalibCollector::hasEnoughData(const Slot& slot) const
114132
if (mTest)
115133
return true;
116134
const o2::tof::TOFCalibInfoSlot* c = slot.getContainer();
117-
LOG(DEBUG) << "we have " << c->getCollectedCalibInfoSlot().size() << " entries";
135+
LOG(INFO) << "we have " << c->getCollectedCalibInfoSlot().size() << " entries";
118136
int maxNumberOfHits = mAbsMaxNumOfHits ? mMaxNumOfHits : mMaxNumOfHits * o2::tof::Geo::NCHANNELS;
119137
if (mTFsendingPolicy || c->getCollectedCalibInfoSlot().size() > maxNumberOfHits)
120138
return true;

‎Detectors/TOF/calibration/testWorkflow/TOFCalibCollectorSpec.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class TOFCalibCollectorDevice : public o2::framework::Task
4141
bool isTest = ic.options().get<bool>("running-in-test-mode");
4242
bool absMaxEnt = ic.options().get<bool>("is-max-number-hits-to-fill-tree-absolute");
4343
mCollector = std::make_unique<o2::tof::TOFCalibCollector>(isTFsendingPolicy, maxEnt);
44-
mCollector->isTest(isTest);
45-
mCollector->isMaxNumberOfHitsAbsolute(absMaxEnt);
44+
mCollector->setIsTest(isTest);
45+
mCollector->setIsMaxNumberOfHitsAbsolute(absMaxEnt);
4646
mCollector->setSlotLength(1);
4747
mCollector->setMaxSlotsDelay(0);
4848
}

‎Detectors/TOF/calibration/testWorkflow/TOFCalibCollectorWriterSpec.h‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,30 @@ class TOFCalibCollectorWriter : public o2::framework::Task
3636
{
3737
TString filename = TString::Format("collTOF_%d.root", mCount);
3838
LOG(DEBUG) << "opening file " << filename.Data();
39-
mfileOut = new TFile(TString::Format("%s", filename.Data()), "RECREATE");
40-
mOutputTree = new TTree("treeCollectedCalibInfo", "Tree with TOF calib info for Time Slewing");
39+
mfileOut.reset(TFile::Open(TString::Format("%s", filename.Data()), "RECREATE"));
40+
mOutputTree = std::make_unique<TTree>("treeCollectedCalibInfo", "Tree with TOF calib info for Time Slewing");
4141
mOutputTree->Branch(mOutputBranchName.data(), &mPTOFCalibInfoOut);
4242
}
4343

4444
void init(o2::framework::InitContext& ic) final
4545
{
4646
mCount = 0;
4747
createAndOpenFileAndTree();
48+
mTOFCalibInfoOut.reserve(500 * o2::tof::Geo::NCHANNELS); // should be a reasonable number of entries per channel, which allows 1 GB of data
4849
}
4950

5051
void run(o2::framework::ProcessingContext& pc) final
5152
{
5253
auto collectedInfo = pc.inputs().get<std::vector<o2::dataformats::CalibInfoTOFshort>>("collectedInfo");
53-
//auto collectedInfo = pc.inputs().get<gsl::span<const o2::dataformats::CalibInfoTOFshort>>("collectedInfo");
5454
auto entriesPerChannel = pc.inputs().get<std::array<int, Geo::NCHANNELS>>("entriesCh");
5555
int offsetStart = 0;
5656
for (int ich = 0; ich < o2::tof::Geo::NCHANNELS; ich++) {
5757
mTOFCalibInfoOut.clear();
58-
auto offsetEnd = offsetStart + entriesPerChannel[ich] - 1;
59-
if (offsetEnd >= offsetStart) {
58+
if (entriesPerChannel[ich] > 0) {
6059
mTOFCalibInfoOut.resize(entriesPerChannel[ich]);
61-
std::copy(collectedInfo.begin() + offsetStart, collectedInfo.begin() + offsetEnd + 1, mTOFCalibInfoOut.begin()); //mTOFCalibInfoOut->begin()); // this is very inefficient; maybe instead of vectors, using span and then one could avoid copying? https://solarianprogrammer.com/2019/11/03/cpp-20-span-tutorial/ --> did not work
60+
auto subSpanVect = gsl::span<const o2::dataformats::CalibInfoTOFshort>(&collectedInfo[offsetStart], entriesPerChannel[ich]);
61+
memcpy(&mTOFCalibInfoOut[0], subSpanVect.data(), sizeof(o2::dataformats::CalibInfoTOFshort) * subSpanVect.size());
62+
const o2::dataformats::CalibInfoTOFshort* tmp = subSpanVect.data();
6263
}
6364
mOutputTree->Fill();
6465
offsetStart += entriesPerChannel[ich];
@@ -76,10 +77,10 @@ class TOFCalibCollectorWriter : public o2::framework::Task
7677
int mCount = 0; // how many times we filled the tree
7778
bool mIsEndOfStream = false;
7879
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
79-
TTree* mOutputTree; ///< tree for the collected calib tof info
80+
std::unique_ptr<TTree> mOutputTree; ///< tree for the collected calib tof info
8081
std::string mTOFCalibInfoBranchName = "TOFCalibInfo"; ///< name of branch containing input TOF calib infos
8182
std::string mOutputBranchName = "TOFCollectedCalibInfo"; ///< name of branch containing output
82-
TFile* mfileOut = nullptr; // file in which to write the output
83+
std::unique_ptr<TFile> mfileOut = nullptr; // file in which to write the output
8384

8485
//________________________________________________________________
8586
void sendOutput(DataAllocator& output)
@@ -91,8 +92,8 @@ class TOFCalibCollectorWriter : public o2::framework::Task
9192

9293
mfileOut->cd();
9394
mOutputTree->Write();
94-
mfileOut->Close();
95-
delete mfileOut;
95+
mOutputTree.reset();
96+
mfileOut.reset();
9697
mCount++;
9798
if (!mIsEndOfStream)
9899
createAndOpenFileAndTree();

‎Detectors/TOF/calibration/testWorkflow/TOFChannelCalibratorSpec.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class TOFChannelCalibDevice : public o2::framework::Task
4949
int isTest = ic.options().get<bool>("do-TOF-channel-calib-in-test-mode");
5050
mCalibrator = std::make_unique<o2::tof::TOFChannelCalibrator>(minEnt, nb, range);
5151
mCalibrator->setUpdateAtTheEndOfRunOnly();
52-
mCalibrator->isTest(isTest);
52+
mCalibrator->setIsTest(isTest);
5353

5454
// calibration objects set to zero
5555
mPhase.addLHCphase(0, 0);

0 commit comments

Comments
 (0)