2121#include " CPVBase/Geometry.h"
2222#include " CCDB/CCDBTimeStampUtils.h"
2323#include " CCDB/BasicCCDBManager.h"
24+ #include " DataFormatsCTP/TriggerOffsetsParam.h"
25+ #include " DetectorsRaw/HBFUtils.h"
2426
2527using namespace o2 ::cpv;
2628
@@ -40,7 +42,11 @@ void RawWriter::init()
4042 mRawWriter ->registerLink (link.feeId , link.cruId , link.linkId , link.endPointId , rawFileName.data ());
4143 }
4244
45+ // Lm-L0 delay
46+ mLM_L0_delay = o2::ctp::TriggerOffsetsParam::Instance ().LM_L0 ;
47+
4348 // CCDB setup
49+ const auto & hbfutils = o2::raw::HBFUtils::Instance ();
4450 LOG (info) << " CCDB Url: " << mCcdbUrl ;
4551 auto & ccdbMgr = o2::ccdb::BasicCCDBManager::instance ();
4652 ccdbMgr.setURL (mCcdbUrl );
@@ -59,8 +65,9 @@ void RawWriter::init()
5965 LOG (info) << " Successfully initializated BasicCCDBManager with caching option" ;
6066
6167 // read calibration from ccdb (for now do it only at the beginning of dataprocessing)
62- // TODO: setup timestam according to anchors
63- ccdbMgr.setTimestamp (o2::ccdb::getCurrentTimestamp ());
68+ // setup timestam according to anchors
69+ ccdbMgr.setTimestamp (hbfutils.startTime );
70+ LOG (info) << " Using time stamp " << ccdbMgr.getTimestamp ();
6471
6572 LOG (info) << " CCDB: Reading o2::cpv::CalibParams from CPV/Calib/Gains" ;
6673 mCalibParams = ccdbMgr.get <o2::cpv::CalibParams>(" CPV/Calib/Gains" );
@@ -94,16 +101,16 @@ void RawWriter::digitsToRaw(gsl::span<o2::cpv::Digit> digitsbranch, gsl::span<o2
94101 return ;
95102 }
96103
97- // process digits which belong to same orbit
104+ // process digits which belong to same orbit (taking into account )
98105 int iFirstTrgInCurrentOrbit = 0 ;
99- unsigned int currentOrbit = triggerbranch[0 ].getBCData ().orbit ;
106+ unsigned int currentOrbit = triggerbranch[iFirstTrgInCurrentOrbit ].getBCData ().orbit ;
100107 int nTrgsInCurrentOrbit = 1 ;
101108 for (unsigned int iTrg = 1 ; iTrg < triggerbranch.size (); iTrg++) {
102- if (triggerbranch[iTrg].getBCData ().orbit != currentOrbit) { // if orbit changed, write previous orbit to file
109+ if (( triggerbranch[iTrg].getBCData () + mLM_L0_delay ).orbit != currentOrbit) { // if orbit changed, write previous orbit to file
103110 processOrbit (digitsbranch, triggerbranch.subspan (iFirstTrgInCurrentOrbit, nTrgsInCurrentOrbit));
104111 iFirstTrgInCurrentOrbit = iTrg; // orbit changed
105112 nTrgsInCurrentOrbit = 1 ;
106- currentOrbit = triggerbranch[iTrg].getBCData ().orbit ;
113+ currentOrbit = ( triggerbranch[iTrg].getBCData () + mLM_L0_delay ).orbit ;
107114 } else {
108115 nTrgsInCurrentOrbit++;
109116 }
@@ -129,9 +136,11 @@ bool RawWriter::processOrbit(const gsl::span<o2::cpv::Digit> digitsbranch, const
129136 int gbtWordCounterBeforeCPVTrailer[kNGBTLinks ] = {0 , 0 , 0 };
130137 bool isHeaderClosedWithTrailer[kNGBTLinks ] = {false , false , false };
131138 for (auto & trg : trgs) {
139+ o2::InteractionRecord currentIR = trg.getBCData ();
140+ currentIR += mLM_L0_delay ;
132141 LOG (debug) << " RawWriter::processOrbit() : "
133- << " I start to process trigger record (orbit = " << trg. getBCData () .orbit
134- << " , BC = " << trg. getBCData () .bc << " )" ;
142+ << " I start to process trigger record (orbit = " << currentIR .orbit
143+ << " , BC = " << currentIR .bc << " )" ;
135144 LOG (debug) << " First entry = " << trg.getFirstEntry () << " , Number of objects = " << trg.getNumberOfObjects ();
136145
137146 // Clear array which is used to store digits
@@ -166,22 +175,22 @@ bool RawWriter::processOrbit(const gsl::span<o2::cpv::Digit> digitsbranch, const
166175 gbtWordCounterBeforeCPVTrailer[iLink] = 0 ;
167176 if (nMaxGbtWordsPerPage - gbtWordCounter[iLink] < 3 ) { // otherwise flush already prepared data to file
168177 LOG (debug) << " RawWriter::processOrbit() : before header: adding preformatted dma page of size " << mPayload [iLink].size ();
169- mRawWriter ->addData (links[iLink].feeId , links[iLink].cruId , links[iLink].linkId , links[iLink].endPointId , trg. getBCData () ,
178+ mRawWriter ->addData (links[iLink].feeId , links[iLink].cruId , links[iLink].linkId , links[iLink].endPointId , currentIR ,
170179 gsl::span<char >(mPayload [iLink].data (), mPayload [iLink].size ()), preformatted);
171180 mPayload [iLink].clear ();
172181 gbtWordCounter[iLink] = 0 ;
173182 gbtWordCounterBeforeCPVTrailer[iLink] = 0 ;
174183 }
175184
176185 // first, header goes
177- CpvHeader header (trg. getBCData () , false , false );
186+ CpvHeader header (currentIR , false , false );
178187 for (int i = 0 ; i < 16 ; i++) {
179188 mPayload [iLink].push_back (header.mBytes [i]);
180189 }
181190 isHeaderClosedWithTrailer[iLink] = false ;
182191 LOG (debug) << " RawWriter::processOrbit() : "
183- << " I wrote cpv header for orbit = " << trg. getBCData () .orbit
184- << " and BC = " << trg. getBCData () .bc ;
192+ << " I wrote cpv header for orbit = " << currentIR .orbit
193+ << " and BC = " << currentIR .bc ;
185194
186195 gbtWordCounter[iLink]++;
187196 gbtWordCounterBeforeCPVTrailer[iLink]++;
@@ -211,21 +220,21 @@ bool RawWriter::processOrbit(const gsl::span<o2::cpv::Digit> digitsbranch, const
211220 }
212221 gbtWordCounter[iLink]++;
213222 gbtWordCounterBeforeCPVTrailer[iLink]++;
214- if (nMaxGbtWordsPerPage - gbtWordCounter[iLink] == 1 ) { // the only space for trailer left on current page
215- CpvTrailer tr (gbtWordCounterBeforeCPVTrailer[iLink], trg. getBCData () .bc , nDigsToWriteLeft == 0 ); // add trailer and flush page to file
223+ if (nMaxGbtWordsPerPage - gbtWordCounter[iLink] == 1 ) { // the only space for trailer left on current page
224+ CpvTrailer tr (gbtWordCounterBeforeCPVTrailer[iLink], currentIR .bc , nDigsToWriteLeft == 0 ); // add trailer and flush page to file
216225 for (int i = 0 ; i < 16 ; i++) {
217226 mPayload [iLink].push_back (tr.mBytes [i]);
218227 }
219228 isHeaderClosedWithTrailer[iLink] = true ;
220229 LOG (debug) << " RawWriter::processOrbit() : middle of payload: adding preformatted dma page of size " << mPayload [iLink].size ();
221- mRawWriter ->addData (links[iLink].feeId , links[iLink].cruId , links[iLink].linkId , links[iLink].endPointId , trg. getBCData () ,
230+ mRawWriter ->addData (links[iLink].feeId , links[iLink].cruId , links[iLink].linkId , links[iLink].endPointId , currentIR ,
222231 gsl::span<char >(mPayload [iLink].data (), mPayload [iLink].size ()), preformatted);
223232
224233 mPayload [iLink].clear ();
225234 gbtWordCounter[iLink] = 0 ;
226235 gbtWordCounterBeforeCPVTrailer[iLink] = 0 ;
227236 if (nDigsToWriteLeft) { // some digits left for writing
228- CpvHeader newHeader (trg. getBCData () , false , true );
237+ CpvHeader newHeader (currentIR , false , true );
229238 for (int i = 0 ; i < 16 ; i++) { // so put a new header and continue
230239 mPayload [iLink].push_back (newHeader.mBytes [i]);
231240 }
@@ -251,14 +260,14 @@ bool RawWriter::processOrbit(const gsl::span<o2::cpv::Digit> digitsbranch, const
251260 }
252261 gbtWordCounter[iLink]++;
253262 gbtWordCounterBeforeCPVTrailer[iLink]++;
254- if (nMaxGbtWordsPerPage - gbtWordCounter[iLink] == 1 ) { // the only space for trailer left on current page
255- CpvTrailer tr (gbtWordCounterBeforeCPVTrailer[iLink], trg. getBCData () .bc , nDigsToWriteLeft == 0 ); // add trailer and flush page to file
263+ if (nMaxGbtWordsPerPage - gbtWordCounter[iLink] == 1 ) { // the only space for trailer left on current page
264+ CpvTrailer tr (gbtWordCounterBeforeCPVTrailer[iLink], currentIR .bc , nDigsToWriteLeft == 0 ); // add trailer and flush page to file
256265 for (int i = 0 ; i < 16 ; i++) {
257266 mPayload [iLink].push_back (tr.mBytes [i]);
258267 }
259268 isHeaderClosedWithTrailer[iLink] = true ;
260269 LOG (debug) << " RawWriter::processOrbit() : middle of payload (after filling empty words): adding preformatted dma page of size " << mPayload [iLink].size ();
261- mRawWriter ->addData (links[iLink].feeId , links[iLink].cruId , links[iLink].linkId , links[iLink].endPointId , trg. getBCData () ,
270+ mRawWriter ->addData (links[iLink].feeId , links[iLink].cruId , links[iLink].linkId , links[iLink].endPointId , currentIR ,
262271 gsl::span<char >(mPayload [iLink].data (), mPayload [iLink].size ()), preformatted);
263272 mPayload [iLink].clear ();
264273 gbtWordCounter[iLink] = 0 ;
@@ -275,7 +284,7 @@ bool RawWriter::processOrbit(const gsl::span<o2::cpv::Digit> digitsbranch, const
275284 }
276285 } // end of ccId cycle
277286 if (!isHeaderClosedWithTrailer[iLink]) {
278- CpvTrailer tr (gbtWordCounterBeforeCPVTrailer[iLink], trg. getBCData () .bc , true );
287+ CpvTrailer tr (gbtWordCounterBeforeCPVTrailer[iLink], currentIR .bc , true );
279288 for (int i = 0 ; i < 16 ; i++) {
280289 mPayload [iLink].push_back (tr.mBytes [i]);
281290 }
0 commit comments