Skip to content

Commit

Permalink
Store TFIDInfo TTree together with the vector
Browse files Browse the repository at this point in the history
  • Loading branch information
shahor02 committed Oct 7, 2023
1 parent 5cc20ee commit e1f6469
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions Detectors/GlobalTrackingWorkflow/src/tfidinfo-writer-workflow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ void customize(std::vector<o2::framework::CompletionPolicy>& policies)
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
{
// option allowing to set parameters
std::vector<ConfigParamSpec> options{
ConfigParamSpec{"dataspec", VariantType::String, "tfidinfo:FLP/DISTSUBTIMEFRAME/0xccdb", {"spec from which the TFIDInfo will be extracted"}},
ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}};
std::vector<ConfigParamSpec> options{ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}};

std::swap(workflowOptions, options);
}
Expand All @@ -37,7 +35,10 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
#include "Framework/DataProcessingHeader.h"
#include "Framework/Task.h"
#include "CommonDataFormat/TFIDInfo.h"
#include "CommonUtils/TreeStreamRedirector.h"
#include "CommonUtils/NameConf.h"
#include "CommonConstants/LHCConstants.h"
#include "Framework/CCDBParamSpec.h"
#include <vector>
#include <TFile.h>

Expand All @@ -53,17 +54,31 @@ class TFIDInfoWriter : public o2::framework::Task

void run(o2::framework::ProcessingContext& pc) final
{
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
if (tinfo.globalRunNumberChanged) { // new run is starting
auto v = pc.inputs().get<std::vector<Long64_t>*>("orbitReset");
mOrbitReset = (*v)[0];
}
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mData.emplace_back());
}

void endOfStream(EndOfStreamContext& ec) final
{
o2::utils::TreeStreamRedirector pcstream;
TFile fl(mOutFileName.c_str(), "recreate");
fl.WriteObjectAny(&mData, "std::vector<o2::dataformats::TFIDInfo>", "tfidinfo");
LOGP(info, "Wrote TFIDInfo vector with {} entries to {}", mData.size(), fl.GetName());
pcstream.SetFile(&fl);
for (const auto& info : mData) {
long ts = (mOrbitReset + long(info.firstTForbit * o2::constants::lhc::LHCOrbitMUS)) / 1000;
pcstream << "tfidTree"
<< "tfidinfo=" << info << "ts=" << ts << "\n";
}
pcstream.Close();
LOGP(info, "Wrote tfidinfo vector and tfidTree with {} entries to {}", mData.size(), fl.GetName());
}

private:
long mOrbitReset = 0;
std::string mOutFileName{};
std::vector<o2::dataformats::TFIDInfo> mData;
};
Expand All @@ -72,8 +87,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
WorkflowSpec wf;
o2::conf::ConfigurableParam::updateFromString(cfgc.options().get<std::string>("configKeyValues"));
wf.emplace_back(DataProcessorSpec{"tfid-info-writer", o2::framework::select(cfgc.options().get<std::string>("dataspec").c_str()),
std::vector<OutputSpec>{}, AlgorithmSpec{adaptFromTask<TFIDInfoWriter>()},
wf.emplace_back(DataProcessorSpec{"tfid-info-writer",
{{"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}},
std::vector<OutputSpec>{},
AlgorithmSpec{adaptFromTask<TFIDInfoWriter>()},
Options{{"tfidinfo-file-name", VariantType::String, o2::base::NameConf::getTFIDInfoFileName(), {"output file for TFIDInfo"}}}});
return wf;
}

0 comments on commit e1f6469

Please sign in to comment.