Skip to content

Commit 90dd1f5

Browse files
bazinskidavidrohr
authored andcommitted
fix event counter and multiple timeframes
1 parent 1b5fcae commit 90dd1f5

File tree

3 files changed

+34
-45
lines changed

3 files changed

+34
-45
lines changed

Detectors/TRD/base/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,3 @@ o2_add_test(Digit
9595
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage
9696
LABELS trd
9797
)
98-

Detectors/TRD/simulation/include/TRDSimulation/Trap2CRU.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Trap2CRU
3939
Trap2CRU(const std::string& outputDir, const std::string& inputDigitsFilename, const std::string& inputTrackletsFilename);
4040
//Trap2CRU(const std::string& outputDir, const std::string& inputFilename, const std::string& inputDigitsFilename, const std::string& inputTrackletsFilename);
4141
void readTrapData();
42-
void convertTrapData(o2::trd::TriggerRecord const& trackletTrigRecord, o2::trd::TriggerRecord const& digitTriggerRecord);
42+
void convertTrapData(o2::trd::TriggerRecord const& trackletTrigRecord, o2::trd::TriggerRecord const& digitTriggerRecord, const int& triggercount);
4343
// default for now will be file per half cru as per the files Guido did for us.
4444
void setFilePer(std::string fileper) { mFilePer = fileper; };
4545
std::string getFilePer() { return mFilePer; };
@@ -55,11 +55,11 @@ class Trap2CRU
5555
void setTrackletHCHeader(bool tracklethcheader) { mUseTrackletHCHeader = tracklethcheader; }
5656
bool isTrackletOnLink(int link, int trackletpos); // is the current tracklet on the the current link
5757
bool isDigitOnLink(int link, int digitpos); // is the current digit on the current link
58-
int buildDigitRawData(const int digitindex, const std::array<int64_t, 21>& localParseDigits, const uint32_t bc);
58+
int buildDigitRawData(const int digitindex, const std::array<int64_t, 21>& localParseDigits, const uint32_t triggercount);
5959
int buildTrackletRawData(const int trackletindex, const int linkid); // from the current position in the tracklet vector, build the outgoing data for the current mcm the tracklet is on.
6060
int writeDigitEndMarker(); // write the digit end marker 0x0 0x0
6161
int writeTrackletEndMarker(); // write the tracklet end maker 0x10001000 0x10001000
62-
int writeHCHeader(uint64_t bc, uint32_t linkid); // write the HalfChamberHeader into the stream, after the tracklet endmarker and before the digits.
62+
int writeHCHeader(const int eventcount, uint32_t linkid); // write the HalfChamberHeader into the stream, after the tracklet endmarker and before the digits.
6363

6464
bool digitindexcompare(const o2::trd::Digit& A, const o2::trd::Digit& B);
6565
//boohhl digitindexcompare(const unsigned int A, const unsigned int B);

Detectors/TRD/simulation/src/Trap2CRU.cxx

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)