4444#include < chrono>
4545#include < cmath>
4646#include < cstddef>
47+ #include < cstdint>
4748#include < string>
49+ #include < unordered_map>
4850#include < vector>
4951
5052using 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