Skip to content

Commit 124dece

Browse files
wiechulashahor02
authored andcommitted
TPC: Add simple raw data filter for krypton clusters
1 parent 477151d commit 124dece

10 files changed

Lines changed: 510 additions & 46 deletions

File tree

Detectors/TPC/calibration/include/TPCCalibration/DigitDump.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ class DigitDump : public CalibRawBase
7777
Int_t updateCRU(const CRU& cru, const Int_t row, const Int_t pad,
7878
const Int_t timeBin, const Float_t signal) final;
7979

80+
/// Set a custom pedestal object
81+
void setPedestals(const CalPad* pedestal) { mPedestal.reset(pedestal); }
82+
83+
/// Set a custom noise object
84+
void setNoise(const CalPad* noise) { mNoise.reset(noise); }
85+
8086
/// Get the pedestal calibration object
8187
///
8288
/// \return pedestal calibration object
@@ -152,8 +158,8 @@ class DigitDump : public CalibRawBase
152158
void removeCEdigits(uint32_t removeNtimeBinsBefore = 10, uint32_t removeNtimeBinsAfter = 100, std::array<std::vector<Digit>, Sector::MAXSECTOR>* removedDigits = nullptr);
153159

154160
private:
155-
std::unique_ptr<CalPad> mPedestal{}; ///< CalDet object with pedestal information
156-
std::unique_ptr<CalPad> mNoise{}; ///< CalDet object with noise
161+
std::unique_ptr<const CalPad> mPedestal{}; ///< CalDet object with pedestal information
162+
std::unique_ptr<const CalPad> mNoise{}; ///< CalDet object with noise
157163

158164
TTree* mTree{nullptr}; ///< output tree
159165
std::unique_ptr<TFile> mFile{}; ///< output file

Detectors/TPC/calibration/src/DigitDump.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ void DigitDump::loadNoiseAndPedestal()
156156
f->GetObject("Pedestals", pedestal);
157157
f->GetObject("Noise", noise);
158158

159-
mPedestal = std::move(std::unique_ptr<CalPad>(pedestal));
160-
mNoise = std::move(std::unique_ptr<CalPad>(noise));
159+
mPedestal = std::move(std::unique_ptr<const CalPad>(pedestal));
160+
mNoise = std::move(std::unique_ptr<const CalPad>(noise));
161161
}
162162

163163
//______________________________________________________________________________

Detectors/TPC/workflow/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ o2_add_library(TPCWorkflow
2222
src/ClusterSharingMapSpec.cxx
2323
src/CalDetMergerPublisherSpec.cxx
2424
src/KryptonClustererSpec.cxx
25+
src/KryptonRawFilterSpec.cxx
2526
src/IDCToVectorSpec.cxx
2627
src/CalibdEdxSpec.cxx
2728
src/CalibratordEdxSpec.cxx
@@ -137,6 +138,11 @@ o2_add_executable(krypton-clusterer
137138
SOURCES src/tpc-krypton-clusterer.cxx
138139
PUBLIC_LINK_LIBRARIES O2::TPCWorkflow)
139140

141+
o2_add_executable(krypton-raw-filter
142+
COMPONENT_NAME tpc
143+
SOURCES src/tpc-krypton-raw-filter.cxx
144+
PUBLIC_LINK_LIBRARIES O2::TPCWorkflow)
145+
140146
o2_add_executable(idc-to-vector
141147
COMPONENT_NAME tpc
142148
SOURCES src/tpc-idc-to-vector.cxx

Detectors/TPC/workflow/include/TPCWorkflow/FileWriterSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace tpc
2626

2727
/// create a processor spec
2828
/// read simulated TPC clusters from file and publish
29-
o2::framework::DataProcessorSpec getFileWriterSpec(const std::string inputSpec);
29+
o2::framework::DataProcessorSpec getFileWriterSpec(const std::string inputSpec, const std::string branchType = "krypton");
3030

3131
} // end namespace tpc
3232
} // end namespace o2

Detectors/TPC/workflow/include/TPCWorkflow/KryptonClustererSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
/// @file RawToDigitsSpec.h
12+
/// @file KryptonClustererSpec.h
1313
/// @author Jens Wiechula
1414
/// @since 2021-02-26
1515
/// @brief Processor spec for running TPC Krypton cluster finder
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// @file KryptonRawFilterSpec.h
13+
/// @author Jens Wiechula
14+
/// @since 2021-11-19
15+
/// @brief Processor spec for filtering krypton raw data
16+
17+
#ifndef TPC_KrRawFilterSpec_H_
18+
#define TPC_KrRawFilterSpec_H_
19+
20+
#include "Framework/DataProcessorSpec.h"
21+
22+
namespace o2
23+
{
24+
namespace tpc
25+
{
26+
27+
o2::framework::DataProcessorSpec getKryptonRawFilterSpec();
28+
29+
} // end namespace tpc
30+
} // end namespace o2
31+
32+
#endif // TPC_RAWTODIGITSSPEC_H_

Detectors/TPC/workflow/src/FileWriterSpec.cxx

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,40 @@ using o2::dataformats::FileMetaData;
4747
using SubSpecificationType = DataAllocator::SubSpecificationType;
4848
using DetID = o2::detectors::DetID;
4949

50+
enum class BranchType {
51+
Krypton,
52+
Digits,
53+
};
54+
55+
const std::unordered_map<std::string, BranchType> BranchTypeMap{
56+
{"krypton", BranchType::Krypton},
57+
{"digits", BranchType::Digits},
58+
};
59+
60+
const std::unordered_map<BranchType, std::string> BranchName{
61+
{BranchType::Krypton, "TPCBoxCluster"},
62+
{BranchType::Digits, "TPCDigit"},
63+
};
64+
65+
const std::unordered_map<BranchType, std::string> TreeName{
66+
{BranchType::Krypton, "Clusters"},
67+
{BranchType::Digits, "o2sim"},
68+
};
69+
5070
namespace o2::tpc
5171
{
5272

5373
class FileWriterDevice : public Task
5474
{
5575
public:
56-
FileWriterDevice() = default;
76+
FileWriterDevice(const std::string branchType)
77+
{
78+
try {
79+
mBranchType = BranchTypeMap.at(branchType);
80+
} catch (std::out_of_range&) {
81+
throw std::invalid_argument(std::string("invalid writer-type type: ") + branchType);
82+
}
83+
}
5784

5885
void init(InitContext& ic) final
5986
{
@@ -68,6 +95,22 @@ class FileWriterDevice : public Task
6895
}
6996
}
7097

98+
template <typename T>
99+
void fillBranch(int sector, InputRecord& inputs, const DataRef& inputRef)
100+
{
101+
auto inData = inputs.get<std::vector<T>>(inputRef);
102+
auto dataPtr = &inData;
103+
104+
if (!mDataBranches[sector]) {
105+
mDataBranches[sector] = mTreeOut->Branch(fmt::format("{}_{}", BranchName.at(mBranchType), sector).data(), &inData);
106+
} else {
107+
mDataBranches[sector]->SetAddress(&dataPtr);
108+
}
109+
110+
mDataBranches[sector]->Fill();
111+
mDataBranches[sector]->ResetAddress();
112+
}
113+
71114
void run(ProcessingContext& pc) final
72115
{
73116
const std::string NAStr = "NA";
@@ -79,8 +122,6 @@ class FileWriterDevice : public Task
79122
mPresentTF = dh->tfCounter;
80123
mFirstTForbit = dh->firstTForbit;
81124

82-
LOGP(info, "run: {}, TF: {}, Orbit: {} ({}), info branches: {}", mRun, mPresentTF, mFirstTForbit, oldOrbit, mInfoBranches.size());
83-
84125
auto oldEnv = mEnvironmentID;
85126
{
86127
auto envN = pc.services().get<RawDeviceService>().device()->fConfig->GetProperty<std::string>("environment_id", NAStr);
@@ -92,6 +133,7 @@ class FileWriterDevice : public Task
92133
LOGP(WARNING, "RunNumber/Environment changed from {}/{} to {}/{}", oldRun, oldEnv, mRun, mEnvironmentID);
93134
closeTreeAndFile();
94135
}
136+
95137
// check for the LHCPeriod
96138
if (mLHCPeriod.empty()) {
97139
auto LHCPeriodStr = pc.services().get<RawDeviceService>().device()->fConfig->GetProperty<std::string>("LHCPeriod", NAStr);
@@ -112,13 +154,11 @@ class FileWriterDevice : public Task
112154

113155
for (auto br : mInfoBranches) {
114156
br->Fill();
115-
LOGP(info, "Filling branch {}", br->GetName());
116157
}
117158
mTFOrbits.push_back(mFirstTForbit);
118159
++mNTFs;
119160
}
120161

121-
bool hasData = false;
122162
for (auto const& inputRef : InputRecordWalker(pc.inputs())) {
123163
auto const* sectorHeader = DataRefUtils::getHeader<TPCSectorHeader*>(inputRef);
124164
if (sectorHeader == nullptr) {
@@ -127,30 +167,12 @@ class FileWriterDevice : public Task
127167
}
128168

129169
const int sector = sectorHeader->sector();
130-
auto inData = pc.inputs().get<std::vector<o2::tpc::KrCluster>>(inputRef);
131-
auto dataPtr = &inData;
132-
133-
if (!mDataBranches[sector]) {
134-
mDataBranches[sector] = mTreeOut->Branch(fmt::format("TPCBoxCluster_{}", sector).data(), &inData);
135-
} else {
136-
mDataBranches[sector]->SetAddress(&dataPtr);
170+
if (mBranchType == BranchType::Krypton) {
171+
fillBranch<KrCluster>(sector, pc.inputs(), inputRef);
172+
} else if (mBranchType == BranchType::Digits) {
173+
fillBranch<Digit>(sector, pc.inputs(), inputRef);
137174
}
138-
mDataBranches[sector]->Fill();
139-
mDataBranches[sector]->ResetAddress();
140-
141-
LOGP(info, "getting data for sector {}", sector);
142-
hasData = true;
143175
}
144-
145-
//if (hasData && mTreeOut) {
146-
//LOGP(info, "fill tree");
147-
//mTreeOut->Fill();
148-
//}
149-
//for (auto br : mDataBranches) {
150-
//if (br) {
151-
//br->ResetAddress();
152-
//}
153-
//}
154176
}
155177

156178
void endOfStream(EndOfStreamContext& ec) final
@@ -185,6 +207,7 @@ class FileWriterDevice : public Task
185207
bool mStoreMetaFile = false; ///< store the meata data file?
186208
bool mWrite = true; ///< write data
187209
bool mCreateRunEnvDir = true; ///< create the output directory structure?
210+
BranchType mBranchType; ///< output branch type
188211

189212
static constexpr std::string_view TMPFileEnding{".part"};
190213

@@ -232,17 +255,11 @@ void FileWriterDevice::prepareTreeAndFile(const o2::header::DataHeader* dh)
232255
mCurrentFileName = o2::base::NameConf::getCTFFileName(mRun, dh->firstTForbit, dh->tfCounter, "tpc_krypton");
233256
mCurrentFileNameFull = fmt::format("{}{}", ctfDir, mCurrentFileName);
234257
mFileOut.reset(TFile::Open(fmt::format("{}{}", mCurrentFileNameFull, TMPFileEnding).c_str(), "recreate")); // to prevent premature external usage, use temporary name
235-
mTreeOut = std::make_unique<TTree>("Clusters", "O2 tree");
258+
mTreeOut = std::make_unique<TTree>(TreeName.at(mBranchType).data(), "O2 tree");
236259
mInfoBranches.emplace_back(mTreeOut->Branch("run", &mRun));
237260
mInfoBranches.emplace_back(mTreeOut->Branch("tfCounter", &mPresentTF));
238261
mInfoBranches.emplace_back(mTreeOut->Branch("firstOrbit", &mFirstTForbit));
239262
LOGP(info, "created {} info branches", mInfoBranches.size());
240-
//for (int iSec = 0; iSec < Sector::MAXSECTOR; ++iSec) {
241-
//std::vector<KrCluster> clusters;
242-
//LOGP(info, "creating branch for sector {} on tree {} with name {}", iSec, (void*)mTreeOut.get(), fmt::format("TPCBoxCluster_{}", iSec).data());
243-
//mDataBranches[iSec] = mTreeOut->Branch(fmt::format("TPCBoxCluster_{}", iSec).data(), &clusters);
244-
//mDataBranches[iSec]->ResetAddress();
245-
//}
246263
if (mStoreMetaFile) {
247264
mFileMetaData = std::make_unique<o2::dataformats::FileMetaData>();
248265
}
@@ -302,13 +319,13 @@ void FileWriterDevice::closeTreeAndFile()
302319
//removeLockFile();
303320
}
304321

305-
DataProcessorSpec getFileWriterSpec(const std::string inputSpec)
322+
DataProcessorSpec getFileWriterSpec(const std::string inputSpec, const std::string branchType)
306323
{
307324
return DataProcessorSpec{
308325
"file-writer",
309326
select(inputSpec.data()),
310327
Outputs{},
311-
AlgorithmSpec{adaptFromTask<FileWriterDevice>()},
328+
AlgorithmSpec{adaptFromTask<FileWriterDevice>(branchType)},
312329
Options{
313330
{"output-dir", VariantType::String, "none", {" output directory, must exist"}},
314331
{"meta-output-dir", VariantType::String, "/dev/null", {" metadata output directory, must exist (if not /dev/null)"}},

0 commit comments

Comments
 (0)