Skip to content

Commit 905b487

Browse files
author
Prottay Das
committed
added a linked table for time
1 parent 674404d commit 905b487

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

PWGLF/DataModel/ZDCCalTables.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,21 @@ DECLARE_SOA_TABLE(ZDCEnergyTables, "AOD", "ZDCENERGY",
8585

8686
using ZDCEnergyTable = ZDCEnergyTables::iterator;
8787

88+
// Extra optional linked table for time information.
89+
// It only stores timestamp and relative time, linked back to ZDCCalTables.
90+
namespace zdctimetable
91+
{
92+
DECLARE_SOA_INDEX_COLUMN(ZDCCalTable, zdcCalTable);
93+
94+
DECLARE_SOA_COLUMN(Timestamp, timestamp, uint64_t); // bc.timestamp(), in ms
95+
DECLARE_SOA_COLUMN(TimeMin, timeMin, float); // time from first event seen in this run, in minutes
96+
} // namespace zdctimetable
97+
98+
DECLARE_SOA_TABLE(ZDCTimeTables, "AOD", "ZDCTIME",
99+
zdctimetable::ZDCCalTableId,
100+
zdctimetable::Timestamp,
101+
zdctimetable::TimeMin);
102+
103+
using ZDCTimeTable = ZDCTimeTables::iterator;
88104
} // namespace o2::aod
89105
#endif // PWGLF_DATAMODEL_ZDCCALTABLES_H_

PWGLF/TableProducer/Common/zdcvector.cxx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
#include <chrono>
4545
#include <cmath>
4646
#include <cstddef>
47+
#include <cstdint>
4748
#include <string>
49+
#include <unordered_map>
4850
#include <vector>
4951

5052
using namespace o2;
@@ -59,6 +61,7 @@ struct zdcvector {
5961

6062
Produces<aod::ZDCCalTables> zdccaltable;
6163
Produces<aod::ZDCEnergyTables> zdcenergytable;
64+
Produces<aod::ZDCTimeTables> zdctimetable;
6265

6366
// Configurables.
6467
struct : ConfigurableGroup {
@@ -100,8 +103,10 @@ struct zdcvector {
100103
} rctCut;
101104

102105
Configurable<bool> storeZdcEnergy{"storeZdcEnergy", true, "Store ZDC tower/common energies in a linked extra table"};
106+
Configurable<bool> storeZdcTime{"storeZdcTime", true, "Store timestamp and time from first event of run"};
103107

104108
RCTFlagsChecker rctChecker;
109+
std::unordered_map<int, uint64_t> runStartTime;
105110

106111
void init(o2::framework::InitContext&)
107112
{
@@ -194,6 +199,17 @@ struct zdcvector {
194199
float znc3 = 0.f;
195200

196201
auto bc = collision.foundBC_as<BCsRun3>();
202+
const uint64_t timestampzdc = bc.timestamp(); // in milliseconds
203+
204+
float timeInMinutes = 0.f;
205+
206+
auto itStart = runStartTime.find(currentRunNumber);
207+
if (itStart == runStartTime.end()) {
208+
runStartTime[currentRunNumber] = timestampzdc;
209+
timeInMinutes = 0.f;
210+
} else {
211+
timeInMinutes = static_cast<float>(timestampzdc - itStart->second) / 60000.f;
212+
}
197213

198214
// Helper to keep your early-return structure unchanged.
199215
// Every time ZDCCalTables is filled, the optional linked energy table is also filled.
@@ -213,8 +229,10 @@ struct zdcvector {
213229
qyA,
214230
qyC);
215231

232+
auto zdcCalIndex = zdccaltable.lastIndex();
233+
216234
if (storeZdcEnergy) {
217-
zdcenergytable(zdccaltable.lastIndex(),
235+
zdcenergytable(zdcCalIndex,
218236
znaEnergycommon,
219237
zncEnergycommon,
220238
zna0,
@@ -226,6 +244,11 @@ struct zdcvector {
226244
znc2,
227245
znc3);
228246
}
247+
if (storeZdcTime) {
248+
zdctimetable(zdcCalIndex,
249+
timestampzdc,
250+
timeInMinutes);
251+
}
229252
};
230253

231254
if (!bc.has_zdc()) {

0 commit comments

Comments
 (0)