Skip to content

Commit 202c9a3

Browse files
chiarazampollishahor02
authored andcommitted
Workflow for TOFcalibCollector
It will reformat the calibration information coming from the matching saving them to file, to be subsequently processed to extract the time slewing (which does not seem appropriate for a data processor). Some changes implemented also in the TimeSlotCalibration, when the maxDelay is set to zero (--> we accept all data). Just not to lose work :-) compiling version Changing philosophy. Since we cannot send trees, the tree will have to be filled by the data processor that will then also write the output file. First version of the Spec also committed - but still using the tree. Now it is too late, I will go to bed and take care another time. Addng writer + other changes Things compile, but were not yet tested. Probably to change from std::vector to gsl::span. Fixing issues + new features. E.g.: using gsl::span for the output that goes in the tree. Workflow not yet working, but everything compiles. Fixes Going back to std::vectors (tree cannot contain gsl::span) Fixes to have the whole thing working. One change also to TimeSlotCalibration.h The change in TimeSlotCalibration.h is needed because we want to update at every TF, which means that the mMaxSlotsDelay should be 0. fix for size of vector I think this is correct, but I did not test it move resize fix for TOF channel offset calibration from reco flow Several changes. Main ones: - bug fixes (seg fault due to missing initialization; merging function fixed) - changes in the TimeSlotCalibration to not discard anything if maxDelay = 0 - force sending output at the end of the processing even if there is not necessarily the requested statistics Clang-format code checker clang-format O2 code checker
1 parent 8021ec6 commit 202c9a3

20 files changed

Lines changed: 663 additions & 86 deletions

‎DataFormats/Detectors/TOF/include/DataFormatsTOF/CalibInfoTOF.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CalibInfoTOF
3636
void setDeltaTimePi(float time) { mDeltaTimePi = time; }
3737
float getDeltaTimePi() const { return mDeltaTimePi; }
3838

39-
void setTot(int tot) { mTot = tot; }
39+
void setTot(float tot) { mTot = tot; }
4040
float getTot() const { return mTot; }
4141

4242
void setFlags(int flags) { mFlags = flags; }

‎DataFormats/Detectors/TOF/include/DataFormatsTOF/CalibInfoTOFshort.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#ifndef ALICEO2_CALIBINFOTOFSHORT_H
1515
#define ALICEO2_CALIBINFOTOFSHORT_H
1616

17+
#include "Rtypes.h"
18+
1719
namespace o2
1820
{
1921
namespace dataformats
@@ -43,7 +45,8 @@ class CalibInfoTOFshort
4345
float mDeltaTimePi; // raw tof time - expected time for pi hypotesis
4446
float mTot; // time-over-threshold
4547
unsigned char mFlags; // bit mask with quality flags (to be defined)
46-
// ClassDefNV(CalibInfoTOFshort, 1);
48+
49+
ClassDefNV(CalibInfoTOFshort, 1);
4750
};
4851
} // namespace dataformats
4952
} // namespace o2

‎Detectors/Calibration/include/DetectorsCalibration/TimeSlotCalibration.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class TimeSlotCalibration
3131
TimeSlotCalibration() = default;
3232
virtual ~TimeSlotCalibration() = default;
3333
uint32_t getMaxSlotsDelay() const { return mMaxSlotsDelay; }
34-
void setMaxSlotsDelay(uint32_t v) { mMaxSlotsDelay = v < 1 ? 1 : v; }
34+
void setMaxSlotsDelay(uint32_t v) { mMaxSlotsDelay = v; }
35+
//void setMaxSlotsDelay(uint32_t v) { (mSlotLength == 1 && mMaxSlotsDelay == 0) ? mMaxSlotsDelay = 0 : mMaxSlotsDelay = v < 1 ? 1 : v; }
36+
//void setMaxSlotsDelay(uint32_t v) { mSlotLength == 1 ? mMaxSlotsDelay = 0 : mMaxSlotsDelay = v < 1 ? 1 : v; }
3537

3638
uint32_t getSlotLength() const { return mSlotLength; }
3739
void setSlotLength(uint32_t v) { mSlotLength = v < 1 ? 1 : v; }
@@ -88,7 +90,7 @@ bool TimeSlotCalibration<Input, Container>::process(TFType tf, const gsl::span<c
8890
if (!mUpdateAtTheEndOfRunOnly) {
8991
int maxDelay = mMaxSlotsDelay * mSlotLength;
9092
// if (tf<mLastClosedTF || (!mSlots.empty() && getSlot(0).getTFStart() > tf + maxDelay)) { // ignore TF
91-
if (tf < mLastClosedTF || (!mSlots.empty() && getLastSlot().getTFStart() > tf + maxDelay)) { // ignore TF
93+
if (maxDelay != 0 && (tf < mLastClosedTF || (!mSlots.empty() && getLastSlot().getTFStart() > tf + maxDelay))) { // ignore TF
9294
LOG(INFO) << "Ignoring TF " << tf;
9395
return false;
9496
}
@@ -111,7 +113,7 @@ void TimeSlotCalibration<Input, Container>::checkSlotsToFinalize(TFType tf, int
111113
// Check which slots can be finalized, provided the newly arrived TF is tf
112114
// check if some slots are done
113115
for (auto slot = mSlots.begin(); slot != mSlots.end(); slot++) {
114-
if ((slot->getTFEnd() + maxDelay) < tf) {
116+
if (maxDelay == 0 || (slot->getTFEnd() + maxDelay) < tf) {
115117
if (hasEnoughData(*slot)) {
116118
finalizeSlot(*slot); // will be removed after finalization
117119
} else if ((slot + 1) != mSlots.end()) {

‎Detectors/GlobalTrackingWorkflow/tofworkflow/include/TOFWorkflow/CalibInfoReaderSpec.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "Framework/Task.h"
2020
#include "DataFormatsTOF/CalibInfoTOF.h"
2121

22+
class TTree;
23+
2224
using namespace o2::framework;
2325

2426
namespace o2
@@ -40,6 +42,7 @@ class CalibInfoReader : public Task
4042
int mNinstances;
4143
const char* mFileName = nullptr;
4244
FILE* mFile = nullptr;
45+
TTree* mTree = nullptr;
4346
int mCurrentEntry = 0;
4447
int mGlobalEntry = 0;
4548
std::vector<o2::dataformats::CalibInfoTOF> mVect, *mPvect = &mVect;

‎Detectors/GlobalTrackingWorkflow/tofworkflow/src/CalibInfoReaderSpec.cxx‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/// @file DigitReaderSpec.cxx
1212

1313
#include <vector>
14+
#include <unistd.h>
1415

1516
#include "TChain.h"
1617
#include "TTree.h"
@@ -46,30 +47,33 @@ void CalibInfoReader::run(ProcessingContext& pc)
4647
}
4748

4849
char filename[100];
49-
int ientry = 0;
50-
while (fscanf(mFile, "%s", filename) == 1) {
51-
TFile* fin = TFile::Open(filename);
52-
TTree* tin = (TTree*)fin->Get("calibTOF");
53-
tin->SetBranchAddress("TOFCalibInfo", &mPvect);
54-
for (int i = 0; i < tin->GetEntries(); i += mNinstances) {
55-
if ((ientry % mNinstances) == mInstance) {
56-
tin->GetEvent(i);
57-
LOG(INFO) << "Send " << mVect.size() << " calib infos";
58-
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBINFOS", 0, Lifetime::Timeframe}, mVect);
59-
}
60-
ientry++;
50+
51+
if ((mTree && mCurrentEntry < mTree->GetEntries()) || fscanf(mFile, "%s", filename) == 1) {
52+
if (!mTree || mCurrentEntry >= mTree->GetEntries()) {
53+
TFile* fin = TFile::Open(filename);
54+
mTree = (TTree*)fin->Get("calibTOF");
55+
mCurrentEntry = 0;
56+
mTree->SetBranchAddress("TOFCalibInfo", &mPvect);
57+
}
58+
if ((mGlobalEntry % mNinstances) == mInstance) {
59+
mTree->GetEvent(mCurrentEntry);
60+
LOG(INFO) << "Send " << mVect.size() << " calib infos";
61+
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe}, mVect);
62+
usleep(10000);
6163
}
64+
mGlobalEntry++;
65+
mCurrentEntry++;
66+
} else {
67+
mState = 2;
68+
pc.services().get<ControlService>().endOfStream();
6269
}
63-
64-
mState = 2;
65-
pc.services().get<ControlService>().endOfStream();
6670
return;
6771
}
6872

6973
DataProcessorSpec getCalibInfoReaderSpec(int instance, int ninstances, const char* filename)
7074
{
7175
std::vector<OutputSpec> outputs;
72-
outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBINFOS", 0, Lifetime::Timeframe);
76+
outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe);
7377

7478
const char* nameSpec;
7579
if (ninstances == 1)

‎Detectors/GlobalTrackingWorkflow/tofworkflow/src/RecoWorkflowSpec.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class TOFDPLRecoWorkflowTask
115115
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHTPCINFOSMC", 0, Lifetime::Timeframe}, mMatcher.getMatchedTPCLabelsVector());
116116
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHITSINFOSMC", 0, Lifetime::Timeframe}, mMatcher.getMatchedITSLabelsVector());
117117
}
118-
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBINFOS", 0, Lifetime::Timeframe}, mMatcher.getCalibVector());
118+
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe}, mMatcher.getCalibVector());
119119
mTimer.Stop();
120120
}
121121

@@ -152,7 +152,7 @@ o2::framework::DataProcessorSpec getTOFRecoWorkflowSpec(bool useMC, bool useFIT)
152152
outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHTPCINFOSMC", 0, Lifetime::Timeframe);
153153
outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHITSINFOSMC", 0, Lifetime::Timeframe);
154154
}
155-
outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBINFOS", 0, Lifetime::Timeframe);
155+
outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe);
156156

157157
return DataProcessorSpec{
158158
"TOFRecoWorkflow",

‎Detectors/GlobalTrackingWorkflow/tofworkflow/src/TOFCalibWriterSpec.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ DataProcessorSpec getTOFCalibWriterSpec()
4343
return MakeRootTreeWriterSpec("TOFCalibWriter",
4444
"o2calib_tof.root",
4545
"calibTOF",
46-
BranchDefinition<CalibInfosType>{InputSpec{"input", o2::header::gDataOriginTOF, "CALIBINFOS", 0},
46+
BranchDefinition<CalibInfosType>{InputSpec{"input", o2::header::gDataOriginTOF, "CALIBDATA", 0},
4747
"TOFCalibInfo",
4848
"calibinfo-branch-name",
4949
1,

‎Detectors/TOF/calibration/CMakeLists.txt‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ o2_add_library(TOFCalibration
1414
src/CollectCalibInfoTOF.cxx
1515
src/LHCClockCalibrator.cxx
1616
src/TOFChannelCalibrator.cxx
17+
src/TOFCalibCollector.cxx
1718
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF O2::TOFBase
1819
O2::CCDB
1920
O2::DetectorsCalibration
@@ -26,6 +27,7 @@ o2_target_root_dictionary(TOFCalibration
2627
include/TOFCalibration/CalibTOF.h
2728
include/TOFCalibration/LHCClockCalibrator.h
2829
include/TOFCalibration/TOFChannelCalibrator.h
30+
include/TOFCalibration/TOFCalibCollector.h
2931
include/TOFCalibration/CollectCalibInfoTOF.h)
3032

3133

@@ -64,3 +66,10 @@ o2_add_executable(tof-dummy-ccdb-for-calib
6466
PUBLIC_LINK_LIBRARIES O2::Framework
6567
O2::TOFCalibration
6668
O2::DetectorsCalibration)
69+
70+
o2_add_executable(tof-collect-calib-workflow
71+
COMPONENT_NAME calibration
72+
SOURCES testWorkflow/tof-collect-calib-workflow.cxx
73+
PUBLIC_LINK_LIBRARIES O2::Framework
74+
O2::TOFCalibration
75+
O2::DetectorsCalibration)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class CalibTOFapi
5858

5959
SlewParam* getSlewParam() { return mSlewParam; }
6060
SlewParam& getSlewParamObj() { return *mSlewParam; }
61+
LhcPhase* getLhcPhase() { return mLHCphase; }
6162

6263
private:
6364
long mTimeStamp; ///< timeStamp for queries
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#ifndef TOF_CALIB_COLLECTOR_H_
12+
#define TOF_CALIB_COLLECTOR_H_
13+
14+
#include "DetectorsCalibration/TimeSlotCalibration.h"
15+
#include "DetectorsCalibration/TimeSlot.h"
16+
#include "DataFormatsTOF/CalibInfoTOF.h"
17+
#include "TOFBase/Geo.h"
18+
#include "DataFormatsTOF/CalibInfoTOFshort.h"
19+
20+
#include <array>
21+
22+
namespace o2
23+
{
24+
namespace tof
25+
{
26+
27+
class TOFCalibInfoSlot
28+
{
29+
30+
using Slot = o2::calibration::TimeSlot<o2::tof::TOFCalibInfoSlot>;
31+
using Geo = o2::tof::Geo;
32+
33+
public:
34+
static constexpr int NCHANNELSXSECTOR = o2::tof::Geo::NCHANNELS / o2::tof::Geo::NSECTORS;
35+
36+
TOFCalibInfoSlot()
37+
{
38+
for (int ch = 0; ch < Geo::NCHANNELS; ch++) {
39+
mEntriesSlot[ch] = 0;
40+
}
41+
}
42+
43+
~TOFCalibInfoSlot() = default;
44+
45+
void print() const;
46+
void printEntries() const;
47+
void fill(const gsl::span<const o2::dataformats::CalibInfoTOF> data);
48+
void merge(const TOFCalibInfoSlot* prev);
49+
50+
auto& getEntriesPerChannel() const { return mEntriesSlot; }
51+
auto& getEntriesPerChannel() { return mEntriesSlot; }
52+
auto& getCollectedCalibInfoSlot() { return mTOFCollectedCalibInfoSlot; }
53+
auto& getCollectedCalibInfoSlot() const { return mTOFCollectedCalibInfoSlot; }
54+
55+
private:
56+
std::array<int, Geo::NCHANNELS> mEntriesSlot; // vector containing number of entries per channel
57+
std::vector<o2::dataformats::CalibInfoTOFshort> mTOFCollectedCalibInfoSlot; ///< output TOF calibration info
58+
59+
ClassDefNV(TOFCalibInfoSlot, 1);
60+
};
61+
62+
class TOFCalibCollector final : public o2::calibration::TimeSlotCalibration<o2::dataformats::CalibInfoTOF, o2::tof::TOFCalibInfoSlot>
63+
{
64+
using TFType = uint64_t;
65+
using Slot = o2::calibration::TimeSlot<o2::tof::TOFCalibInfoSlot>;
66+
67+
public:
68+
TOFCalibCollector(bool TFsendingPolicy, int maxNumOfHits, bool test = false) : mTFsendingPolicy(TFsendingPolicy), mMaxNumOfHits(maxNumOfHits), mTest(test){};
69+
70+
~TOFCalibCollector() final = default;
71+
72+
bool hasEnoughData(const Slot& slot) const final;
73+
void initOutput() final;
74+
void finalizeSlot(Slot& slot) final;
75+
Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final;
76+
void isTest(bool istest) { mTest = istest; }
77+
auto& getCollectedCalibInfo() const { return mTOFCollectedCalibInfo; }
78+
auto& getEntriesPerChannel() const { return mEntries; }
79+
void isMaxNumberOfHitsAbsolute(bool absNumber) { mAbsMaxNumOfHits = absNumber; }
80+
81+
private:
82+
bool mTFsendingPolicy = false; // whether we will send information at every TF or only when we have a certain statistics
83+
int mMaxNumOfHits = 500; // maximum number of hits for one single channel to trigger the sending of the information (if mTFsendingPolicy = false)
84+
bool mTest = false; // flag to say whether we are in test mode or not
85+
bool mAbsMaxNumOfHits = true; // to decide if the mMaxNumOfHits should be multiplied by the number of TOF channels
86+
std::array<int, Geo::NCHANNELS> mEntries; // vector containing number of entries per channel
87+
std::vector<o2::dataformats::CalibInfoTOFshort> mTOFCollectedCalibInfo; ///< output TOF calibration info
88+
89+
ClassDefOverride(TOFCalibCollector, 1);
90+
};
91+
92+
} // end namespace tof
93+
} // end namespace o2
94+
95+
#endif /* TOF_CHANNEL_CALIBRATOR_H_ */

0 commit comments

Comments
 (0)