Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions Common/TableProducer/timestampTester.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.

Check failure on line 1 in Common/TableProducer/timestampTester.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/workflow-file]

Name of a workflow file must match the name of the main struct in it (without the PWG prefix). (Class implementation files should be in "Core" directories.)

Check failure on line 1 in Common/TableProducer/timestampTester.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[doc/file]

Provide mandatory file documentation.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
Expand All @@ -15,16 +15,19 @@
/// \since 2020-06-22
/// \brief A task to fill the timestamp table from run number.
/// Uses headers from CCDB
///

Check failure on line 18 in Common/TableProducer/timestampTester.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[doc/file]

Documentation for \file is missing, incorrect or misplaced.
#include <vector>
#include <map>
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include "MetadataHelper.h"

#include "Common/Tools/timestampModule.h"

#include "CCDB/BasicCCDBManager.h"
#include "CommonDataFormat/InteractionRecord.h"
#include "DetectorsRaw/HBFUtils.h"
#include "MetadataHelper.h"
#include "Common/Tools/timestampModule.h"
#include "Framework/AnalysisTask.h"
#include "Framework/runDataProcessing.h"

#include <map>
#include <vector>

using namespace o2::framework;
using namespace o2::header;
Expand All @@ -33,11 +36,11 @@
MetadataHelper metadataInfo; // Metadata helper

struct TimestampTask {
Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task
Service<o2::ccdb::BasicCCDBManager> ccdb; /// CCDB manager to access orbit-reset timestamp
o2::ccdb::CcdbApi ccdb_api; /// API to access CCDB headers
Produces<aod::Timestamps> timestampTable; /// Table with SOR timestamps produced by the task
Service<o2::ccdb::BasicCCDBManager> ccdb; /// CCDB manager to access orbit-reset timestamp
o2::ccdb::CcdbApi ccdb_api; /// API to access CCDB headers

Check failure on line 41 in Common/TableProducer/timestampTester.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/function-variable]

Use lowerCamelCase for names of functions and variables.

Configurable<std::string> ccdb_url{"ccdb-url", "http://alice-ccdb.cern.ch", "URL of the CCDB database"};

Check failure on line 43 in Common/TableProducer/timestampTester.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)

Check failure on line 43 in Common/TableProducer/timestampTester.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/function-variable]

Use lowerCamelCase for names of functions and variables.

o2::common::timestamp::timestampConfigurables timestampConfigurables;
o2::common::timestamp::TimestampModule timestampMod;
Expand Down
31 changes: 17 additions & 14 deletions Common/Tools/timestampModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
#ifndef COMMON_TOOLS_TIMESTAMPMODULEH_
#define COMMON_TOOLS_TIMESTAMPMODULEH_

#include <cstdlib>
#include <cmath>
#include <array>
#include "Framework/AnalysisDataModel.h"

#include <array>
#include <cmath>
#include <cstdlib>

namespace o2
{
namespace common
Expand All @@ -31,13 +32,13 @@
o2::framework::Configurable<bool> fatalOnInvalidTimestamp{"fatalOnInvalidTimestamp", false, "Generate fatal error for invalid timestamps"};
o2::framework::Configurable<std::string> rct_path{"rct-path", "RCT/Info/RunInformation", "path to the ccdb RCT objects for the SOR timestamps"};
o2::framework::Configurable<std::string> orbit_reset_path{"orbit-reset-path", "CTP/Calib/OrbitReset", "path to the ccdb orbit-reset objects"};
o2::framework::Configurable<int> isRun2MC{"isRun2MC", -1, "Running mode: enable only for Run 2 MC. Timestamps are set to SOR timestamp. Default: -1 (autoset from metadata) 0 (Standard) 1 (Run 2 MC)"}; // o2-linter: disable=name/configurable (temporary fix)
o2::framework::Configurable<int> isRun2MC{"isRun2MC", -1, "Running mode: enable only for Run 2 MC. Timestamps are set to SOR timestamp. Default: -1 (autoset from metadata) 0 (Standard) 1 (Run 2 MC)"}; // o2-linter: disable=name/configurable (temporary fix)
};

//__________________________________________
// time stamp module
//
// class to acquire time stamps to be used in
//
// class to acquire time stamps to be used in
// modular (plugin) fashion

class TimestampModule
Expand All @@ -53,14 +54,15 @@
o2::common::timestamp::timestampConfigurables timestampOpts;

// objects necessary during processing
std::map<int, int64_t> mapRunToOrbitReset; /// Cache of orbit reset timestamps
std::map<int, int64_t> mapRunToOrbitReset; /// Cache of orbit reset timestamps
std::map<int, std::pair<int64_t, int64_t>> mapRunToRunDuration; /// Cache of run duration timestamps
int lastRunNumber; /// Last run number processed
int64_t orbitResetTimestamp; /// Orbit-reset timestamp in us
std::pair<int64_t, int64_t> runDuration; /// Pair of SOR and EOR timestamps
int lastRunNumber; /// Last run number processed
int64_t orbitResetTimestamp; /// Orbit-reset timestamp in us
std::pair<int64_t, int64_t> runDuration; /// Pair of SOR and EOR timestamps

template <typename TTimestampOpts, typename TMetadatahelper>
void init(TTimestampOpts const& external_timestampOpts, TMetadatahelper const& metadataInfo ){
void init(TTimestampOpts const& external_timestampOpts, TMetadatahelper const& metadataInfo)
{
timestampOpts = external_timestampOpts;

if (timestampOpts.isRun2MC.value == -1) {
Expand All @@ -74,9 +76,10 @@
}

template <typename TBCs, typename Tccdb, typename TTimestampBuffer, typename TCursor>
void process(TBCs const& bcs, Tccdb const& ccdb, TTimestampBuffer& timestampbuffer, TCursor& timestampTable){
void process(TBCs const& bcs, Tccdb const& ccdb, TTimestampBuffer& timestampbuffer, TCursor& timestampTable)
{
timestampbuffer.clear();
for(auto const& bc : bcs){
for (auto const& bc : bcs) {
int runNumber = bc.runNumber();
// We need to set the orbit-reset timestamp for the run number.
// This is done with caching if the run number was already processed before.
Expand All @@ -93,20 +96,20 @@
int64_t sorTimestamp = runDuration.first; // timestamp of the SOR/SOX/STF in ms
int64_t eorTimestamp = runDuration.second; // timestamp of the EOR/EOX/ETF in ms

const bool isUnanchoredRun3MC = runNumber >= 300000 && runNumber < 500000;

Check failure on line 99 in Common/Tools/timestampModule.h

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
if (timestampOpts.isRun2MC.value == 1 || isUnanchoredRun3MC) {
// isRun2MC: bc/orbit distributions are not simulated in Run2 MC. All bcs are set to 0.
// isUnanchoredRun3MC: assuming orbit-reset is done in the beginning of each run
// Setting orbit-reset timestamp to start-of-run timestamp
orbitResetTimestamp = sorTimestamp * 1000; // from ms to us
} else if (runNumber < 300000) { // Run 2

Check failure on line 105 in Common/Tools/timestampModule.h

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
LOGF(debug, "Getting orbit-reset timestamp using start-of-run timestamp from CCDB");
auto ctp = ccdb->template getForTimeStamp<std::vector<Long64_t>>(timestampOpts.orbit_reset_path.value.data(), sorTimestamp);

Check failure on line 107 in Common/Tools/timestampModule.h

View workflow job for this annotation

GitHub Actions / O2 linter

[root/entity]

Replace ROOT entities with equivalents from standard C++ or from O2.
orbitResetTimestamp = (*ctp)[0];
} else {
// sometimes orbit is reset after SOR. Using EOR timestamps for orbitReset query is more reliable
LOGF(debug, "Getting orbit-reset timestamp using end-of-run timestamp from CCDB");
auto ctp = ccdb->template getForTimeStamp<std::vector<Long64_t>>(timestampOpts.orbit_reset_path.value.data(), eorTimestamp / 2 + sorTimestamp / 2);

Check failure on line 112 in Common/Tools/timestampModule.h

View workflow job for this annotation

GitHub Actions / O2 linter

[root/entity]

Replace ROOT entities with equivalents from standard C++ or from O2.
orbitResetTimestamp = (*ctp)[0];
}

Expand Down Expand Up @@ -141,4 +144,4 @@
} // namespace common
} // namespace o2

#endif // COMMON_TOOLS_TIMESTAMPMODULEH_
#endif // COMMON_TOOLS_TIMESTAMPMODULEH_
Loading