28 if (lower == mFrames.end() || *lower > fr) {
32 return {&*lower, size_t(std::distance(lower, upper))};
46 auto fullcheck = [&fr,
this]() ->
long {
47 auto lower = std::lower_bound(this->mFrames.begin(), this->mFrames.end(), fr);
48 if (lower == this->mFrames.end()) {
49 this->mLastBoundID = this->mFrames.size();
51 this->mLastBoundID = std::distance(this->mFrames.begin(), lower);
57 if (mLastBoundID < 0) {
61 constexpr int MaxSteps = 3;
63 for (; mLastBoundID < (
long)mFrames.size(); mLastBoundID++) {
71 if (++steps == MaxSteps) {
77 if (mLastBoundID >= (
long)mFrames.size()) {
78 mLastBoundID = (
long)mFrames.size() - 1;
80 for (; mLastBoundID >= 0; mLastBoundID--) {
89 if (++steps == MaxSteps) {
94 if (mLastBoundID < 0) {
99 mLastIRFrameChecked = fr;
106 std::unique_ptr<TFile> tfl(TFile::Open(fname.c_str()));
107 if (!tfl || tfl->IsZombie()) {
108 LOGP(fatal,
"Cannot open selected IRFrames file {}", fname);
110 auto klst = gDirectory->GetListOfKeys();
113 std::string clVec{TClass::GetClass(
"std::vector<o2::dataformats::IRFrame>")->GetName()};
115 bool toBeSorted =
false;
116 while ((
key = (TKey*)nextkey())) {
117 std::string kcl(
key->GetClassName());
119 auto*
v = (std::vector<o2::dataformats::IRFrame>*)tfl->GetObjectUnchecked(
key->GetName());
121 LOGP(fatal,
"Failed to extract IRFrames vector {} from {}",
key->GetName(), fname);
123 mOwnList.insert(mOwnList.end(),
v->begin(),
v->end());
124 LOGP(info,
"Loaded {} IRFrames from vector {} of {}", mOwnList.size(),
key->GetName(), fname);
127 }
else if (kcl ==
"TTree") {
128 std::unique_ptr<TTree> tr((TTree*)tfl->Get(
key->GetName()));
129 if (!tr->GetBranch(
"IRFrames")) {
130 LOGP(fatal,
"Did not find branch IRFrames in the tree {}",
key->GetName());
132 std::vector<o2::dataformats::IRFrame> tmpv, *tpmvPtr = &tmpv;
133 tr->SetBranchAddress(
"IRFrames", &tpmvPtr);
134 for (
int i = 0;
i < (
int)tr->GetEntries();
i++) {
136 mOwnList.insert(mOwnList.end(), tmpv.begin(), tmpv.end());
139 LOGP(info,
"Loaded {} IRFrames from tree {} of {}", mOwnList.size(),
key->GetName(), fname);
141 }
else if (kcl ==
"TDirectoryFile") {
142 TTree* bcRanges = (TTree*)tfl->Get(fmt::format(
"{}/O2bcranges",
key->GetName()).data());
146 LOGP(info,
"Loading BCrange trees in the directory {}",
key->GetName());
147 ULong64_t minBC, maxBC;
148 bcRanges->SetBranchAddress(
"fBCstart", &minBC);
149 bcRanges->SetBranchAddress(
"fBCend", &maxBC);
150 for (
int i = 0;
i < (
int)bcRanges->GetEntries();
i++) {
151 bcRanges->GetEntry(
i);
160 LOGP(info,
"Sorting {} IRFrames", mOwnList.size());
161 std::sort(mOwnList.begin(), mOwnList.end(), [](
const auto&
a,
const auto&
b) { return a.getMin() < b.getMin(); });
164 LOGP(fatal,
"Did not find neither tree nor vector of IRFrames in {}", fname);
167 return mOwnList.size();
173 mOwnList.insert(mOwnList.end(), lst.begin(), lst.end());
175 std::sort(mOwnList.begin(), mOwnList.end(), [](
const auto&
a,
const auto&
b) { return a.getMin() < b.getMin(); });
182 LOGP(info,
"Last query stopped at entry {} for IRFrame {}:{}", mLastBoundID,
186 for (
const auto&
f : mFrames) {
187 LOGP(info,
"Frame#{}: {}:{}",
i++,
f.getMin().asString(),
f.getMax().asString());
204 LOGP(
debug,
"applyMargins({},{},{})", bwd, fwd, removeOverlaps);
205 if ((!fwd && !bwd && !shift) || !mIsSet || !mFrames.size()) {
209 std::vector<o2::dataformats::IRFrame> lst;
210 long shiftBwd = bwd - shift, shiftFwd = fwd + shift;
212 for (
const auto& fr : mFrames) {
213 auto irmin = fr.getMin();
214 auto irmax = fr.getMax();
225 LOGP(
debug,
"before removerlap: {}:{} -> {}:{}", fr.getMin().toLong(), fr.getMax().toLong(), irmin.toLong(), irmax.toLong());
226 if (removeOverlaps && lst.size() && lst.back().getMax() >= irmin) {
227 lst.back().setMax(irmax);
229 lst.emplace_back(irmin, irmax).info = fr.info;
233 mFrames = gsl::span<const o2::dataformats::IRFrame>(mOwnList.data(), mOwnList.size());
Class to check if give InteractionRecord or IRFrame is selected by the external IRFrame vector.
Relation isOutside(const Bracket< T > &t) const
void setMax(T v) noexcept
void setMin(T v) noexcept
void setOwnList(const std::vector< o2::dataformats::IRFrame > &lst, bool toBeSorted)
void print(bool lst=false) const
size_t loadIRFrames(const std::string &fname)
void applyMargins(size_t bwd, size_t fwd, long shift, bool removeOverlaps=true)
long check(o2::dataformats::IRFrame fr, size_t bwd=0, size_t fwd=0)
gsl::span< const o2::dataformats::IRFrame > getMatchingFrames(const o2::dataformats::IRFrame &fr)
void setSelectedIRFrames(const SPAN &sp, size_t bwd=0, size_t fwd=0, long shift=0, bool removeOverlaps=true)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
static constexpr InteractionRecord getIRMaxBC()
std::string asString() const
static constexpr int64_t MaxGlobalBCs
static InteractionRecord long2IR(int64_t l)