51 bool upstream =
false;
52 std::string rootFileInput{};
53 std::string hbfuInput{};
55 auto updateHBFUtils = [&configcontext, &upstream, &hbfuInput, &rootFileInput]() {
56 static bool done =
false;
63 for (
const auto& optStr : vopts) {
73 hbfu.checkConsistency();
77 hbfu.checkConsistency();
80 rootFileInput = optStr;
83 if (!nopts && !helpasked) {
84 LOGP(fatal,
"No source was provided for timing input of --hbfutils-config");
102 for (
auto& spec : wf) {
103 if (spec.inputs.empty()) {
106 if (!hbfuInput.empty()) {
107 o2f::ConfigParamsHelper::addOptionIfMissing(spec.options,
o2f::ConfigParamSpec{HBFTFInfoOpt, o2f::VariantType::String, HBFUSrc, {
"HBFUtils input"}});
109 o2f::ConfigParamsHelper::addOptionIfMissing(spec.options,
o2f::ConfigParamSpec{HBFIRFrameOpt, o2f::VariantType::String, rootFileInput, {
"root file with selected IR-frames"}});
112 o2f::ConfigParamsHelper::addOptionIfMissing(spec.options,
o2f::ConfigParamSpec{HBFTFInfoOpt, o2f::VariantType::String, rootFileInput, {
"root file with per-TF info"}});
114 o2f::ConfigParamsHelper::addOptionIfMissing(spec.options,
o2f::ConfigParamSpec{DelayOpt, o2f::VariantType::Float, 0.f, {
"delay in seconds between consecutive TFs sending"}});
116 spec.inputs.emplace_back(
o2f::InputSpec{
"driverInfo",
"GLO",
"READER_DRIVER", 0, o2f::Lifetime::Timeframe});
117 if (!hbfuInput.empty() && !rootFileInput.empty()) {
118 o2f::ConfigParamsHelper::addOptionIfMissing(spec.options,
o2f::ConfigParamSpec{IgnoreIRFramesOpt, o2f::VariantType::Bool, false, {
"ignore IR-frames info"}});
130 if (!optString.empty()) {
137 }
else if (optString ==
HBFUSrc) {
139 }
else if (optString !=
"none" && throwOnFailure) {
140 throw std::runtime_error(fmt::format(
"invalid option {} for {}", optString,
HBFConfOpt));
150 LOGP(fatal,
"could not open alien connection to read {}", fname);
152 std::unique_ptr<TFile> fl(TFile::Open(fname.c_str()));
153 auto vptr = (std::vector<o2::dataformats::TFIDInfo>*)fl->GetObjectChecked(
"tfidinfo",
"std::vector<o2::dataformats::TFIDInfo>");
155 throw std::runtime_error(fmt::format(
"Failed to read tfidinfo vector from {}", fname));
157 std::vector<o2::dataformats::TFIDInfo>
v(*vptr);
166 LOGP(fatal,
"could not open alien connection to read {}", fname);
168 std::unique_ptr<TFile> fl(TFile::Open(fname.c_str()));
169 auto vptr = (std::vector<o2::dataformats::IRFrame>*)fl->GetObjectChecked(
"irframes",
"std::vector<o2::dataformats::IRFrame>");
171 throw std::runtime_error(fmt::format(
"Failed to read irframes vector from {}", fname));
173 std::vector<o2::dataformats::IRFrame>
v(*vptr);
182 const auto tfinf = tfinfoVec[dh.
tfCounter % tfinfoVec.size()];
183 LOGP(
debug,
"Setting DH for {}/{} from tfCounter={} firstTForbit={} runNumber={} to tfCounter={} firstTForbit={} runNumber={}",
195 auto offset = hbfu.getFirstIRofTF({0, hbfu.orbitFirstSampled}).
orbit;
199 LOGP(
debug,
"SETTING DH for {}/{} from tfCounter={} firstTForbit={} runNumber={}",
207 static int64_t
offset = hbfu.getFirstIRofTF({0, hbfu.orbitFirstSampled}).
orbit;
222 LOGP(warn,
"IRFrame#{} ({}-{}) precedes 1st sampled TF {}, skipping",
226 hbfu.getFirstIRofTF({0, hbfu.orbitFirstSampled}).asString());
230 LOGP(warn,
"IRFrame#{} ({}-{}) start precedes 1st sampled TF {}, overriding start",
LastIRFrameIndex,
233 hbfu.getFirstIRofTF({0, hbfu.orbitFirstSampled}).asString());
234 ir0Mn = hbfu.getFirstIRofTF({0, hbfu.orbitFirstSampled});
240 LOGP(warn,
"IRFrame#{} ({}-{}) is split to ({}-{}) and ({}-{})",
252 LOGP(warn,
"Failed to define IRFrame");
261 LOGP(
debug,
"SETTING DH for {}/{} from tfCounter={} firstTForbit={} runNumber={} and IRFrame ({}-{})",
271 return (!context.helpOnCommandLine() && o2f::ConfigParamsHelper::hasOption(spec.
options,
HBFTFInfoOpt));
274 std::string irFrames, tfInput = context.options().get<std::string>(
HBFTFInfoOpt);
276 irFrames = context.options().get<std::string>(
HBFIRFrameOpt);
278 uint32_t delay = context.options().hasOption(
DelayOpt) && context.options().isSet(
DelayOpt) ? uint32_t(1e6 * context.options().get<
float>(
DelayOpt)) : 0;
279 if (!tfInput.empty()) {
281 if (irFrames.empty()) {
285 static size_t tfcount = 0;
286 if (tfcount++ && delay > 0) {
292 throw std::runtime_error(fmt::format(
"file {} does not exist", irFrames));
298 static size_t tfcount = 0;
299 if (tfcount++ && delay > 0) {
306 throw std::runtime_error(fmt::format(
"file {} does not exist", tfInput));
311 static size_t tfcount = 0;
312 if (tfcount++ && delay > 0) {
325 o2f::ConfigParamsHelper::addOptionIfMissing(opts,
o2f::ConfigParamSpec{
HBFConfOpt, o2f::VariantType::String, defOpt, {R
"(ConfigurableParam ini file or "hbfutils" for HBFUtils, root file with per-TF info (augmented with ,upstream if reader-driver is used) or "none")"}});
static const HBFUtils & Instance()
static void updateFromFile(std::string const &, std::string const ¶msList="", bool unchangedOnly=false)
bool helpOnCommandLine() const
ConfigParamRegistry & options() const
bool hasOption(const char *key) const
bool isSet(const char *key) const
T get(const char *key) const
void setMax(T v) noexcept
void setMin(T v) noexcept
constexpr int LHCMaxBunches
constexpr double LHCOrbitMUS
Defining PrimaryVertex explicitly as messageable.
std::vector< DataProcessorSpec > WorkflowSpec
std::string asString() const
std::vector< ConfigParamSpec > options
static std::vector< o2::dataformats::IRFrame > IRFrames
static void assignDataHeaderFromHBFUtilWithIRFrames(o2::header::DataHeader &dh, o2::framework::DataProcessingHeader &dph)
static constexpr char HBFConfOpt[]
static void readIRFramesVector(const std::string &fname)
static constexpr char HBFUSrc[]
static long LastIRFrameIndex
static constexpr char DelayOpt[]
static constexpr char UpstreamOpt[]
static void assignDataHeaderFromTFIDInfo(const std::vector< o2::dataformats::TFIDInfo > &tfinfoVec, o2::header::DataHeader &dh, o2::framework::DataProcessingHeader &dph)
HBFUtilsInitializer(const o2::framework::ConfigContext &configcontext, o2::framework::WorkflowSpec &wf)
static HBFOpt getOptType(const std::string &optString, bool throwOnFailure=true)
static constexpr char ReaderDriverDevice[]
static constexpr char HBFIRFrameOpt[]
static void addNewTimeSliceCallback(std::vector< o2::framework::CallbacksPolicy > &policies)
static std::vector< o2::dataformats::TFIDInfo > readTFIDInfoVector(const std::string &fname)
static bool LastIRFrameSplit
static void assignDataHeaderFromHBFUtils(o2::header::DataHeader &dh, o2::framework::DataProcessingHeader &dph)
static void addConfigOption(std::vector< o2::framework::ConfigParamSpec > &opts, const std::string &defOpt=std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE))
static o2::dataformats::IRFrame IRFrameSel
static constexpr char HBFTFInfoOpt[]
static bool pathExists(const std::string_view p)
static bool beginsWith(const std::string &s, const std::string &start)
static std::vector< std::string > tokenize(const std::string &src, char delim, bool trimToken=true, bool skipEmpty=true)
static bool endsWith(const std::string &s, const std::string &ending)