Skip to content

Commit 363651d

Browse files
committed
Merge branch 'dev' into stable-sync
2 parents 9c0278a + 2a47fa0 commit 363651d

File tree

485 files changed

+10720
-9965
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

485 files changed

+10720
-9965
lines changed

CCDB/include/CCDB/BasicCCDBManager.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ class CCDBManagerInstance
115115
return getForTimeStamp<T>(path, timestamp);
116116
}
117117

118+
/// retrieve an object of type T from CCDB as stored under path and using the timestamp in the middle of the run + metadata. The run number is provided separately to conform to typical analysis use (in which case metadata does not include runNumber)
119+
template <typename T>
120+
T* getSpecificForRun(std::string const& path, int runNumber, MD metaData = MD());
121+
118122
/// detect online processing modes (i.e. CCDB objects may be updated in the lifetime of the manager)
119123
bool isOnline() const { return mDeplMode == o2::framework::DeploymentMode::OnlineAUX || mDeplMode == o2::framework::DeploymentMode::OnlineDDS || mDeplMode == o2::framework::DeploymentMode::OnlineECS; }
120124

@@ -317,6 +321,14 @@ T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
317321

318322
template <typename T>
319323
T* CCDBManagerInstance::getForRun(std::string const& path, int runNumber, bool setRunMetadata)
324+
{
325+
auto metaData = setRunMetadata ? MD{{"runNumber", std::to_string(runNumber)}} : MD{};
326+
mMetaData = metaData;
327+
return getSpecificForRun<T>(path, runNumber, metaData);
328+
}
329+
330+
template <typename T>
331+
T* CCDBManagerInstance::getSpecificForRun(std::string const& path, int runNumber, MD metaData)
320332
{
321333
auto [start, stop] = getRunDuration(runNumber);
322334
if (start < 0 || stop < 0) {
@@ -325,8 +337,7 @@ T* CCDBManagerInstance::getForRun(std::string const& path, int runNumber, bool s
325337
}
326338
return nullptr;
327339
}
328-
mMetaData = setRunMetadata ? MD{{"runNumber", std::to_string(runNumber)}} : MD{};
329-
return getForTimeStamp<T>(path, start / 2 + stop / 2);
340+
return getSpecific<T>(path, start / 2 + stop / 2, metaData);
330341
}
331342

332343
class BasicCCDBManager : public CCDBManagerInstance

CCDB/include/CCDB/CcdbApi.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ class CcdbApi //: public DatabaseInterface
392392
// Loads files from alien and cvmfs into given destination.
393393
bool loadLocalContentToMemory(o2::pmr::vector<char>& dest, std::string& url) const;
394394

395+
// add annotated flattened headers in the end of the blob
396+
static void appendFlatHeader(o2::pmr::vector<char>& dest, const std::map<std::string, std::string>& headers);
397+
395398
// the failure to load the file to memory is signaled by 0 size and non-0 capacity
396399
static bool isMemoryFileInvalid(const o2::pmr::vector<char>& v) { return v.size() == 0 && v.capacity() > 0; }
397400
template <typename T>
@@ -610,6 +613,16 @@ class CcdbApi //: public DatabaseInterface
610613
return getSnapshotDir(topdir, path) + '/' + sfile;
611614
}
612615

616+
template <typename MAP> // can be either std::map or std::multimap
617+
static size_t getFlatHeaderSize(const MAP& Headers)
618+
{
619+
size_t hsize = sizeof(int) + sizeof(FlatHeaderAnnot); // annotation size
620+
for (auto& h : Headers) {
621+
hsize += h.first.length() + h.second.length() + 2; // 2*(string_buffer + terminating null character)
622+
}
623+
return hsize;
624+
}
625+
613626
// tmp helper and single point of entry for a CURL perform call
614627
// helps to switch between easy handle perform and multi handles in a single place
615628
CURLcode CURL_perform(CURL* handle) const;
@@ -632,6 +645,8 @@ class CcdbApi //: public DatabaseInterface
632645
size_t mCurlTimeoutDownload = 15; // download timeout in seconds, can be configured via ALICEO2_CCDB_CURL_TIMEOUT_DOWNLOAD, updated according to the deployment mode
633646
size_t mCurlTimeoutUpload = 15; // upload timeout in seconds, can be configured via ALICEO2_CCDB_CURL_TIMEOUT_UPLOAD, updated according to the deployment mode
634647

648+
static constexpr char FlatHeaderAnnot[] = "$HEADER$"; // annotation for flat header
649+
635650
ClassDefNV(CcdbApi, 1);
636651
};
637652

CCDB/src/CcdbApi.cxx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,12 +1687,15 @@ void CcdbApi::scheduleDownload(RequestContext& requestContext, size_t* requestCo
16871687
ho.counter++;
16881688
try {
16891689
if (chunk.capacity() < chunk.size() + realsize) {
1690+
// estimate headers size when converted to annotated text string
1691+
const char hannot[] = "header";
1692+
size_t hsize = getFlatHeaderSize(ho.header);
16901693
auto cl = ho.header.find("Content-Length");
16911694
if (cl != ho.header.end()) {
16921695
size_t sizeFromHeader = std::stol(cl->second);
1693-
sz = std::max(chunk.size() * (sizeFromHeader ? 1 : 2) + realsize, sizeFromHeader);
1696+
sz = hsize + std::max(chunk.size() * (sizeFromHeader ? 1 : 2) + realsize, sizeFromHeader);
16941697
} else {
1695-
sz = std::max(chunk.size() * 2, chunk.size() + realsize);
1698+
sz = hsize + std::max(chunk.size() * 2, chunk.size() + realsize);
16961699
// LOGP(debug, "SIZE IS NOT IN HEADER, allocate {}", sz);
16971700
}
16981701
chunk.reserve(sz);
@@ -1885,6 +1888,25 @@ void CcdbApi::loadFileToMemory(o2::pmr::vector<char>& dest, std::string const& p
18851888
vectoredLoadFileToMemory(contexts);
18861889
}
18871890

1891+
void CcdbApi::appendFlatHeader(o2::pmr::vector<char>& dest, const std::map<std::string, std::string>& headers)
1892+
{
1893+
size_t hsize = getFlatHeaderSize(headers), cnt = dest.size();
1894+
dest.resize(cnt + hsize);
1895+
auto addString = [&dest, &cnt](const std::string& s) {
1896+
for (char c : s) {
1897+
dest[cnt++] = c;
1898+
}
1899+
dest[cnt++] = 0;
1900+
};
1901+
1902+
for (auto& h : headers) {
1903+
addString(h.first);
1904+
addString(h.second);
1905+
}
1906+
*reinterpret_cast<int*>(&dest[cnt]) = hsize; // store size
1907+
std::memcpy(&dest[cnt + sizeof(int)], FlatHeaderAnnot, sizeof(FlatHeaderAnnot)); // annotate the flattened headers map
1908+
}
1909+
18881910
void CcdbApi::navigateSourcesAndLoadFile(RequestContext& requestContext, int& fromSnapshot, size_t* requestCounter) const
18891911
{
18901912
LOGP(debug, "loadFileToMemory {} ETag=[{}]", requestContext.path, requestContext.etag);

DataFormats/Detectors/CTP/include/DataFormatsCTP/Scalers.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ class CTPRunScalers
130130
/// same with absolute timestamp (not orbit) as argument
131131
std::pair<double, double> getRateGivenT(double timestamp, int classindex, int type) const;
132132

133+
/// retrieves integral for class
134+
std::array<uint64_t, 7> getIntegralForClass(int i) const
135+
{
136+
return {
137+
mScalerRecordO2[0].scalers[i].classIndex,
138+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].lmBefore - mScalerRecordO2[0].scalers[i].lmBefore,
139+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].lmAfter - mScalerRecordO2[0].scalers[i].lmAfter,
140+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l0Before - mScalerRecordO2[0].scalers[i].l0Before,
141+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l0After - mScalerRecordO2[0].scalers[i].l0After,
142+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l1Before - mScalerRecordO2[0].scalers[i].l1Before,
143+
mScalerRecordO2[mScalerRecordO2.size() - 1].scalers[i].l1After - mScalerRecordO2[0].scalers[i].l1After,
144+
};
145+
}
133146
/// retrieves time boundaries of this scaler object from O2 scalers
134147
std::pair<unsigned long, unsigned long> getTimeLimit() const
135148
{

DataFormats/Detectors/TRD/include/DataFormatsTRD/RecoInputContainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ inline void RecoInputContainer::fillGPUIOPtr(o2::gpu::GPUTrackingInOutPointers*
8888
ptrs->nTRDTriggerRecords = mNTriggerRecords;
8989
ptrs->trdTriggerTimes = &(trdTriggerTimes[0]);
9090
ptrs->trdTrackletIdxFirst = &(trdTriggerIndices[0]);
91-
ptrs->trdTrigRecMask = reinterpret_cast<const char*>(mTrigRecMask.data());
91+
ptrs->trdTrigRecMask = reinterpret_cast<const uint8_t*>(mTrigRecMask.data());
9292
ptrs->nTRDTracklets = mNTracklets;
9393
ptrs->trdTracklets = reinterpret_cast<const o2::gpu::GPUTRDTrackletWord*>(mTracklets.data());
9494
ptrs->trdSpacePoints = reinterpret_cast<const o2::gpu::GPUTRDSpacePoint*>(mSpacePoints.data());

DataFormats/Parameters/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ o2_add_library(DataFormatsParameters
1414
src/GRPLHCIFData.cxx
1515
src/GRPECSObject.cxx
1616
src/GRPMagField.cxx
17-
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants
17+
src/AggregatedRunInfo.cxx
18+
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants
1819
O2::CommonTypes O2::CCDB
1920
O2::DetectorsCommonDataFormats)
2021

@@ -24,6 +25,7 @@ o2_target_root_dictionary(DataFormatsParameters
2425
include/DataFormatsParameters/GRPLHCIFData.h
2526
include/DataFormatsParameters/GRPECSObject.h
2627
include/DataFormatsParameters/GRPMagField.h
28+
include/DataFormatsParameters/AggregatedRunInfo.h
2729
LINKDEF src/ParametersDataLinkDef.h)
2830

2931
o2_add_executable(simgrp-tool
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 GRPECSObject.h
13+
/// \brief Header of the AggregatedRunInfo struct
14+
/// \author ruben.shahoyan@cern.ch sandro.wenzel@cern.ch
15+
16+
#ifndef ALICEO2_DATA_AGGREGATEDRUNINFO_H_
17+
#define ALICEO2_DATA_AGGREGATEDRUNINFO_H_
18+
19+
#include <cstdint>
20+
#include "CCDB/BasicCCDBManager.h"
21+
22+
namespace o2::parameters
23+
{
24+
25+
/// Composite struct where one may collect important global properties of data "runs"
26+
/// aggregated from various sources (GRPECS, RunInformation CCDB entries, etc.).
27+
/// Also offers the authoritative algorithms to collect these information for easy reuse
28+
/// across various algorithms (anchoredMC, analysis, ...)
29+
struct AggregatedRunInfo {
30+
int runNumber; // run number
31+
int64_t sor; // best known timestamp for the start of run
32+
int64_t eor; // best known timestamp for end of run
33+
int64_t orbitsPerTF; // number of orbits per TF
34+
int64_t orbitReset; // timestamp of orbit reset before run
35+
int64_t orbitSOR; // orbit when run starts after orbit reset
36+
int64_t orbitEOR; // orbit when run ends after orbit reset
37+
38+
// we may have pointers to actual data source objects GRPECS, ...
39+
40+
// fills and returns AggregatedRunInfo for a given run number.
41+
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);
42+
};
43+
44+
} // namespace o2::parameters
45+
46+
#endif
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 AggregatedRunInfo.cxx
13+
/// \author sandro.wenzel@cern.ch
14+
15+
#include "DataFormatsParameters/AggregatedRunInfo.h"
16+
#include "CCDB/BasicCCDBManager.h"
17+
#include "DataFormatsParameters/GRPECSObject.h"
18+
#include "CommonConstants/LHCConstants.h"
19+
#include "Framework/Logger.h"
20+
21+
using namespace o2::parameters;
22+
23+
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber)
24+
{
25+
// TODO: could think about caching results per runnumber to
26+
// avoid going to CCDB multiple times ---> but should be done inside the CCDBManagerInstance
27+
28+
// we calculate the first orbit of a run based on sor (start-of-run) and eor
29+
// we obtain these by calling getRunDuration
30+
auto [sor, eor] = ccdb.getRunDuration(runnumber);
31+
32+
// determine a good timestamp to query OrbitReset for this run
33+
// --> the middle of the run is very appropriate and safer than just sor
34+
auto run_mid_timestamp = sor + (eor - sor) / 2;
35+
36+
// query the time of the orbit reset (when orbit is defined to be 0)
37+
auto ctpx = ccdb.getForTimeStamp<std::vector<Long64_t>>("CTP/Calib/OrbitReset", run_mid_timestamp);
38+
int64_t tsOrbitReset = (*ctpx)[0]; // us
39+
40+
// get timeframe length from GRPECS
41+
std::map<std::string, std::string> metadata;
42+
metadata["runNumber"] = Form("%d", runnumber);
43+
auto grpecs = ccdb.getSpecific<o2::parameters::GRPECSObject>("GLO/Config/GRPECS", run_mid_timestamp, metadata);
44+
auto nOrbitsPerTF = grpecs->getNHBFPerTF();
45+
46+
// calculate SOR orbit
47+
int64_t orbitSOR = (sor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
48+
int64_t orbitEOR = (eor * 1000 - tsOrbitReset) / o2::constants::lhc::LHCOrbitMUS;
49+
50+
// adjust to the nearest TF edge to satisfy condition (orbitSOR % nOrbitsPerTF == 0)
51+
orbitSOR = (orbitSOR / nOrbitsPerTF + 1) * nOrbitsPerTF; // +1 to choose the safe boundary ... towards run middle
52+
orbitEOR = orbitEOR / nOrbitsPerTF * nOrbitsPerTF;
53+
54+
// fetch SOR directly from CTP entry on CCDB
55+
bool oldFatalState = ccdb.getFatalWhenNull();
56+
ccdb.setFatalWhenNull(false);
57+
auto ctp_first_run_orbit = ccdb.getForTimeStamp<std::vector<int64_t>>("CTP/Calib/FirstRunOrbit", run_mid_timestamp);
58+
ccdb.setFatalWhenNull(oldFatalState);
59+
if (ctp_first_run_orbit && ctp_first_run_orbit->size() >= 3) {
60+
// if we have CTP first run orbit available, we should use it
61+
62+
// int64_t creation_time = (*ctp_first_run_orbit)[0];
63+
int64_t ctp_run_number = (*ctp_first_run_orbit)[1];
64+
int64_t ctp_orbitSOR = (*ctp_first_run_orbit)[2];
65+
66+
if (ctp_run_number != runnumber) {
67+
LOG(error) << "AggregatedRunInfo: run number inconsistency found (asked: " << runnumber << " vs CTP found: " << ctp_run_number << ")";
68+
}
69+
70+
// overwrite orbitSOR
71+
if (ctp_orbitSOR != orbitSOR) {
72+
LOG(warn) << "The calculated orbitSOR " << orbitSOR << " differs from CTP orbitSOR " << ctp_orbitSOR;
73+
// reasons for this is different unit of time storage in RunInformation (ms) and orbitReset (us), etc.
74+
75+
// so we need to adjust the SOR timings to be consistent
76+
auto sor_new = (int64_t)((tsOrbitReset + ctp_orbitSOR * o2::constants::lhc::LHCOrbitMUS) / 1000.);
77+
if (sor_new != sor) {
78+
LOG(warn) << "Adjusting SOR from " << sor << " to " << sor_new;
79+
sor = sor_new;
80+
}
81+
}
82+
orbitSOR = ctp_orbitSOR;
83+
}
84+
85+
return AggregatedRunInfo{runnumber, sor, eor, nOrbitsPerTF, tsOrbitReset, orbitSOR, orbitEOR};
86+
}

DataFormats/Parameters/src/ParametersDataLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
#pragma link C++ class o2::parameters::GRPMagField + ;
3131
#pragma link C++ class std::unordered_map < unsigned int, unsigned int> + ;
3232
#pragma link C++ class std::pair < unsigned long, std::string> + ;
33+
#pragma link C++ struct o2::parameters::AggregatedRunInfo + ;
3334

3435
#endif

DataFormats/common/include/CommonDataFormat/IRFrame.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@ namespace dataformats
2828
// We could just alias it to the bracket specialization, but this would create
2929
// problems with fwd.declaration
3030
struct IRFrame : public o2::math_utils::detail::Bracket<o2::InteractionRecord> {
31+
static constexpr uint64_t LastIRFrame = uint64_t(0x1) << 63;
32+
3133
using o2::math_utils::detail::Bracket<o2::InteractionRecord>::Bracket;
3234

33-
uint64_t info = 0;
35+
uint64_t info = uint64_t(0);
36+
37+
void setLast(bool v = true)
38+
{
39+
if (v) {
40+
info |= LastIRFrame;
41+
} else {
42+
v &= ~LastIRFrame;
43+
}
44+
}
45+
46+
bool isLast() const { return (info & LastIRFrame) != 0UL; }
3447

3548
ClassDefNV(IRFrame, 2);
3649
};

0 commit comments

Comments
 (0)