Project
Loading...
Searching...
No Matches
KrClusterWriterSpec.h
Go to the documentation of this file.
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#ifndef O2_TRD_KRWRITERSPEC_H
13#define O2_TRD_KRWRITERSPEC_H
14
21
22#include <TFile.h>
23#include <TTree.h>
24#include <filesystem>
25#include <mutex>
26#include <fmt/format.h>
27
28namespace o2
29{
30namespace trd
31{
32
34{
35 public:
36 TRDKrClsWriterTask() = default;
37
39 {
40 mOutputDir = o2::utils::Str::rectifyDirectory(ic.options().get<std::string>("output-dir"));
41
42 // should we write meta files for epn2eos?
43 mMetaFileDir = ic.options().get<std::string>("meta-output-dir");
44 if (mMetaFileDir != "/dev/null") {
45 mMetaFileDir = o2::utils::Str::rectifyDirectory(mMetaFileDir);
46 mStoreMetaFile = true;
47 }
48
49 LOGP(info, "Storing output in {}, meta file writing enabled: {}", mOutputDir, mStoreMetaFile);
50 mAutoSave = ic.options().get<int>("autosave-interval");
51
52 char hostname[_POSIX_HOST_NAME_MAX];
53 gethostname(hostname, _POSIX_HOST_NAME_MAX);
54 mHostName = hostname;
55 mHostName = mHostName.substr(0, mHostName.find('.'));
56 }
57
59 {
60 mFileName = fmt::format("o2_trdKrCls_run{}_{}.root", runNumber, mHostName);
61 auto fileNameTmp = o2::utils::Str::concat_string(mOutputDir, mFileName, ".part");
62 mFileOut = std::make_unique<TFile>(fileNameTmp.c_str(), "recreate");
63 mTreeOut = std::make_unique<TTree>("krData", "TRD krypton cluster data");
64 mTreeOut->Branch("cluster", &krClusterPtr);
65 mTreeOut->Branch("trigRec", &krTrigRecPtr);
66 mDataTakingContext = pc.services().get<DataTakingContext>();
67 mOutputFileCreated = true;
68 }
69
71 {
72 if (!mOutputFileCreated) {
73 return;
74 }
75 mFileOut->cd();
76 mTreeOut->Write();
77 }
78
80 {
81 if (!mOutputFileCreated || mOutputFileClosed) {
82 return;
83 }
84 std::lock_guard<std::mutex> guard(mMutex);
86 mTreeOut.reset();
87 mFileOut->Close();
88 mFileOut.reset();
89 auto fileNameWithPath = mOutputDir + mFileName;
90 std::filesystem::rename(o2::utils::Str::concat_string(mOutputDir, mFileName, ".part"), fileNameWithPath);
91 if (mStoreMetaFile) {
92 o2::dataformats::FileMetaData fileMetaData; // object with information for meta data file
93 fileMetaData.fillFileData(fileNameWithPath);
94 fileMetaData.setDataTakingContext(mDataTakingContext);
95 fileMetaData.type = "calib";
96 fileMetaData.priority = "high";
97 auto metaFileNameTmp = fmt::format("{}{}.tmp", mMetaFileDir, mFileName);
98 auto metaFileName = fmt::format("{}{}.done", mMetaFileDir, mFileName);
99 try {
100 std::ofstream metaFileOut(metaFileNameTmp);
101 metaFileOut << fileMetaData;
102 metaFileOut.close();
103 std::filesystem::rename(metaFileNameTmp, metaFileName);
104 } catch (std::exception const& e) {
105 LOG(error) << "Failed to store meta data file " << metaFileName << ", reason: " << e.what();
106 }
107 }
108 mOutputFileClosed = true;
109 }
110
112 {
113 if (!mOutputFileCreated) {
114 auto tInfo = pc.services().get<o2::framework::TimingInfo>();
115 createOutputFile(tInfo.runNumber, pc);
116 }
117 if (mRunStopRequested) {
118 return;
119 }
120 if (pc.transitionState() == TransitionHandlingState::Requested) {
121 LOG(info) << "Run stop requested, closing output file";
122 mRunStopRequested = true;
124 return;
125 }
126 auto cluster = pc.inputs().get<gsl::span<KrCluster>>("krcluster");
127 auto triggerRecords = pc.inputs().get<gsl::span<KrClusterTriggerRecord>>("krtrigrec");
128 for (const auto& cls : cluster) {
129 krCluster.push_back(cls);
130 }
131 for (const auto& trig : triggerRecords) {
132 krTrigRec.push_back(trig);
133 }
134 mTreeOut->Fill();
135 krCluster.clear();
136 krTrigRec.clear();
137 if (mAutoSave > 0 && ++mTFCounter % mAutoSave == 0) {
138 writeToFile();
139 }
140 }
141
143 {
144 if (mRunStopRequested) {
145 return;
146 }
147 LOG(info) << "End of stream received, closing output file";
149 }
150
151 private:
152 bool mRunStopRequested{false};
153 bool mStoreMetaFile{false};
154 bool mOutputFileCreated{false};
155 bool mOutputFileClosed{false};
156 int mAutoSave{0};
157 uint64_t mTFCounter{0};
158 std::mutex mMutex;
159 std::string mOutputDir{"none"};
160 std::string mMetaFileDir{"/dev/null"};
161 std::string mHostName{};
162 std::string mFileName{};
163 std::unique_ptr<TFile> mFileOut{};
164 std::unique_ptr<TTree> mTreeOut{};
165 std::vector<KrCluster> krCluster, *krClusterPtr{&krCluster};
166 std::vector<KrClusterTriggerRecord> krTrigRec, *krTrigRecPtr{&krTrigRec};
167 o2::framework::DataTakingContext mDataTakingContext;
168};
169
171{
172 std::vector<InputSpec> inputs;
173 inputs.emplace_back("krcluster", "TRD", "KRCLUSTER");
174 inputs.emplace_back("krtrigrec", "TRD", "TRGKRCLS");
175
176 return DataProcessorSpec{"kr-cluster-writer",
177 inputs,
178 Outputs{},
179 AlgorithmSpec{adaptFromTask<o2::trd::TRDKrClsWriterTask>()},
180 Options{
181 {"output-dir", VariantType::String, "none", {"Output directory for data. Defaults to current working directory"}},
182 {"meta-output-dir", VariantType::String, "/dev/null", {"metadata output directory, must exist (if not /dev/null)"}},
183 {"autosave-interval", VariantType::Int, 0, {"Write output to file for every n-th TF. 0 means this feature is OFF"}}}};
184}
185
186} // end namespace trd
187} // end namespace o2
188
189#endif // O2_TRD_KRWRITERSPEC_H
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h trd
char error[CURL_ERROR_SIZE]
A cluster formed from digits during TRD Krypton calibration.
ServiceRegistryRef services()
The services registry associated with this processing context.
void run(o2::framework::ProcessingContext &pc) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void createOutputFile(int runNumber, o2::framework::ProcessingContext &pc)
void init(o2::framework::InitContext &ic) final
std::vector< OutputSpec > Outputs
framework::DataProcessorSpec getKrClusterWriterSpec()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool fillFileData(const std::string &fname, bool fillmd5=false, const std::string &tmpEnding="")
void setDataTakingContext(const o2::framework::DataTakingContext &dtc)
static std::string rectifyDirectory(const std::string_view p)
static std::string concat_string(Ts const &... ts)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"