@@ -178,37 +178,26 @@ void Trap2CRU::readTrapData()
178178
179179 openInputFiles ();
180180
181- if (mDigitsTree ->GetEntries () != 1 ) {
182- LOG (fatal) << " more than one entry in digits tree " << mDigitsTree ->GetEntries ();
183- }
184- if (mTrackletsTree ->GetEntries () != 1 ) {
185- LOG (fatal) << " more than one entry in tracklets tree " << mTrackletsTree ->GetEntries ();
181+ if (mTrackletsTree ->GetEntries () != mDigitsTree ->GetEntries ()) {
182+ LOG (fatal) << " Entry counts in mTrackletsTree and Digits Tree dont match " << mTrackletsTree ->GetEntries () << " !=" << mDigitsTree ->GetEntries ();
186183 }
187184
188- for (int entry = 0 ; entry < mDigitsTree ->GetEntries (); entry++) {
189- mDigitsTree ->GetEntry (entry);
190- uint32_t linkcount = 0 ;
191- }
185+ int triggercount = 42 ; // triggercount is here so that we can span timeframes. The actual number is of no consequence,but must increase.
192186 for (int entry = 0 ; entry < mTrackletsTree ->GetEntries (); entry++) {
193187 mTrackletsTree ->GetEntry (entry);
194- }
195- sortDataToLinks ();
196- // everything is passed as the first entry in the tree.
197- // and then work with the resulting vectors from the branches.
198- uint32_t linkcount = 0 ;
199- for (auto tracklettrigger : mTrackletTriggerRecords ) {
200- // get the event limits from TriggerRecord;
201- uint32_t eventstart = tracklettrigger.getFirstEntry ();
202- uint32_t eventend = tracklettrigger.getFirstEntry () + tracklettrigger.getNumberOfObjects ();
203- LOG (debug) << " looping over tracklet trigger : " << eventstart << " -> " << eventend << " with bc of " << tracklettrigger.getBCData ().bc << " orbit of : " << tracklettrigger.getBCData ().orbit ;
204- for (auto digitstrigger : mDigitTriggerRecords ) {
205- // get the event limits from TriggerRecord;
206- uint32_t eventstart = digitstrigger.getFirstEntry ();
207- uint32_t eventend = digitstrigger.getFirstEntry () + digitstrigger.getNumberOfObjects ();
208- if (digitstrigger.getBCData () == tracklettrigger.getBCData ()) {
209- LOG (debug) << " we have a match for bc : " << tracklettrigger.getBCData ().bc << " orbit of : " << tracklettrigger.getBCData ().orbit ;
210- convertTrapData (tracklettrigger, digitstrigger);
188+ mDigitsTree ->GetEntry (entry);
189+ // TODO figure out if want to care about unaligned trees.
190+ sortDataToLinks ();
191+ // each entry is a timeframe
192+ uint32_t linkcount = 0 ;
193+ for (auto tracklettrigger : mTrackletTriggerRecords ) {
194+ for (auto digitstrigger : mDigitTriggerRecords ) {
195+ // get the event limits from TriggerRecord;
196+ if (digitstrigger.getBCData () == tracklettrigger.getBCData ()) {
197+ convertTrapData (tracklettrigger, digitstrigger, triggercount);
198+ }
211199 }
200+ triggercount++;
212201 }
213202 }
214203}
@@ -253,6 +242,7 @@ uint32_t Trap2CRU::buildHalfCRUHeader(HalfCRUHeader& header, const uint32_t bc,
253242 uint32_t crudatasize = 0 ; // link size in units of 256 bits.
254243 int endpoint = halfcru % 2 ? 1 : 0 ;
255244 uint32_t padding = 0 ;
245+ // TODO this bunchcrossing is not the same as the bunchcrossing in the rdh, which is effectively the bc coming in the parameter list to this function.
256246 setHalfCRUHeader (header, crurdhversion, bunchcrossing, stopbits, endpoint, eventtype, feeid, cruid); // TODO come back and pull this from somewhere.
257247
258248 return 1 ;
@@ -278,9 +268,9 @@ bool Trap2CRU::isDigitOnLink(const int linkid, const int currentdigitpos)
278268 return false ;
279269}
280270
281- int Trap2CRU::buildDigitRawData (const int digitindex, const std::array<int64_t , o2::trd::constants::NADCMCM>& localParsedDigits, const uint32_t bc )
271+ int Trap2CRU::buildDigitRawData (const int digitindex, const std::array<int64_t , o2::trd::constants::NADCMCM>& localParsedDigits, const uint32_t triggerrecordcount )
282272{
283- LOG (debug) << __func__ << " digitindex:" << digitindex << " and bc of" << bc ;
273+ LOG (debug) << __func__ << " digitindex:" << digitindex << " and triggercount of" << triggerrecordcount ;
284274 // this is not zero suppressed.
285275 int digitswritten = 0 ;
286276 // Digit
@@ -294,7 +284,7 @@ int Trap2CRU::buildDigitRawData(const int digitindex, const std::array<int64_t,
294284 header.mcm = startmcm;
295285 header.rob = startrob;
296286 header.yearflag = 1 ; // >2007
297- header.eventcount = bc ;
287+ header.eventcount = triggerrecordcount ;
298288 header.yearflag = 1 ;
299289 memcpy (mRawDataPtr , (char *)&header, 4 ); // 32 bits -- 4 bytes.
300290 LOG (debug) << " writing data to digit stream of " << std::hex << header.word ;
@@ -413,7 +403,7 @@ int Trap2CRU::writeTrackletEndMarker()
413403 return wordswritten;
414404}
415405
416- int Trap2CRU::writeHCHeader (uint64_t bc, uint32_t linkid)
406+ int Trap2CRU::writeHCHeader (const int eventcount, const uint32_t linkid)
417407{ // we have 2 HCHeaders defined Tracklet and Digit in Rawdata.h
418408 // TODO is it a case of run2 and run3 ? for digithcheader and tracklethcheader?
419409 // The parsing I am doing of CRU raw data only has a DigitHCHeader in it after the TrackletEndMarker ... confusion?
@@ -426,7 +416,7 @@ int Trap2CRU::writeHCHeader(uint64_t bc, uint32_t linkid)
426416 trackletheader.layer = linkid;
427417 trackletheader.one = 1 ;
428418 trackletheader.side = (linkid % 2 ) ? 1 : 0 ;
429- trackletheader.MCLK = bc ; // just has to be a consistant increasing number per event.
419+ trackletheader.MCLK = eventcount * 42 ; // just has to be a consistant increasing number per event.
430420 trackletheader.format = 12 ;
431421
432422 DigitHCHeader digitheader;
@@ -435,14 +425,14 @@ int Trap2CRU::writeHCHeader(uint64_t bc, uint32_t linkid)
435425 digitheader.stack = (detector % (o2::trd::constants::NLAYER * o2::trd::constants::NSTACK)) / o2::trd::constants::NLAYER;
436426 digitheader.layer = (detector % o2::trd::constants::NLAYER);
437427 digitheader.supermodule = linkid / 60 ;
438- digitheader.numberHCW = 1 ;
439- digitheader.minor = 42 ;
440- digitheader.major = 42 ;
441- digitheader.version = 1 ;
428+ digitheader.numberHCW = 1 ; // TODO put something more real in here?
429+ digitheader.minor = 42 ; // TODO put something more real in here?
430+ digitheader.major = 42 ; // TODO put something more real in here?
431+ digitheader.version = 1 ; // TODO put something more real in here?
442432 digitheader.res1 = 1 ;
443- digitheader.ptrigcount = 1 ;
444- digitheader.ptrigphase = 1 ;
445- digitheader.bunchcrossing = bc;
433+ digitheader.ptrigcount = 1 ; // TODO put something more real in here?
434+ digitheader.ptrigphase = 1 ; // TODO put something more real in here?
435+ digitheader.bunchcrossing = eventcount; // NB this is not the same as the bunchcrossing the rdh.
446436 digitheader.numtimebins = 30 ;
447437 if (mUseTrackletHCHeader ) { // run 3 we also have a TrackletHalfChamber, that comes after thetracklet endmarker.
448438 memcpy (mRawDataPtr , (char *)&trackletheader, sizeof (TrackletHCHeader));
@@ -455,7 +445,7 @@ int Trap2CRU::writeHCHeader(uint64_t bc, uint32_t linkid)
455445 return wordswritten;
456446}
457447
458- void Trap2CRU::convertTrapData (o2::trd::TriggerRecord const & trackletTriggerRecord, o2::trd::TriggerRecord const & digitTriggerRecord)
448+ void Trap2CRU::convertTrapData (o2::trd::TriggerRecord const & trackletTriggerRecord, o2::trd::TriggerRecord const & digitTriggerRecord, const int & triggercount )
459449{
460450 // LOG(info) << "starting :" << __func__ ; //<<
461451 // build a HalfCRUHeader for this event/cru/endpoint
@@ -519,7 +509,7 @@ void Trap2CRU::convertTrapData(o2::trd::TriggerRecord const& trackletTriggerReco
519509 int trackletendmarker = writeTrackletEndMarker ();
520510 linkwordswritten += trackletendmarker;
521511 rawwords += trackletendmarker;
522- int hcheaderwords = writeHCHeader (trackletTriggerRecord. getBCData (). bc , linkid);
512+ int hcheaderwords = writeHCHeader (triggercount , linkid);
523513 linkwordswritten += hcheaderwords;
524514 rawwords += hcheaderwords;
525515 while (isDigitOnLink (linkid, mDigitsIndex [mCurrentDigit ])) {
@@ -543,7 +533,7 @@ void Trap2CRU::convertTrapData(o2::trd::TriggerRecord const& trackletTriggerReco
543533 // mcm digits are full, now write it out.
544534 char * preptr;
545535 preptr = mRawDataPtr ;
546- int digits = buildDigitRawData (mDigitsIndex [mCurrentDigit ], localParsedDigitsindex, digitTriggerRecord. getBCData (). bc );
536+ int digits = buildDigitRawData (mDigitsIndex [mCurrentDigit ], localParsedDigitsindex, triggercount );
547537 // mCurrentDigit += digits;
548538 // due to not being zero suppressed, digits returned from buildDigitRawData should *always* be 21.
549539 if (digits != 21 ) {
0 commit comments