Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCDS multi-fed support in DAQ and unpacker #30457

Merged
merged 12 commits into from
Aug 14, 2020
4 changes: 4 additions & 0 deletions DataFormats/TCDS/interface/TCDSRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class TCDSRecord {
// The BST message as received from the LHC
const BSTRecord& getBST() const { return bst_; }

// Source FED ID
uint16_t getSourceID() const { return sourceid_; }

// List of active paritions, currently not implemented
typedef std::bitset<96> ActivePartitions;
ActivePartitions getActivePartitions() const { return activePartitions_; }
Expand Down Expand Up @@ -146,6 +149,7 @@ class TCDSRecord {
uint16_t triggerTypeFlags_;
uint16_t inputs_;
uint16_t bxid_;
uint16_t sourceid_;

ActivePartitions activePartitions_;
L1aHistory l1aHistory_;
Expand Down
1 change: 1 addition & 0 deletions DataFormats/TCDS/src/TCDSRecord.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TCDSRecord::TCDSRecord(const unsigned char* rawData) {
triggerTypeFlags_ = tcdsRaw->header.triggerTypeFlags;
inputs_ = tcdsRaw->header.inputs;
bxid_ = tcdsRaw->header.bxid;
sourceid_ = fedHeader.sourceID();

activePartitions_ = ActivePartitions(tcdsRaw->header.activePartitions0);
activePartitions_ |= ActivePartitions(tcdsRaw->header.activePartitions1) << 32;
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/TCDS/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<version ClassVersion="4" checksum="3132515293"/>
</class>

<class name="TCDSRecord" ClassVersion="3">
<class name="TCDSRecord" ClassVersion="4">
<version ClassVersion="4" checksum="850266115"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove version 3, for back-compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed back ClassVersion to 3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed back ClassVersion to 3.

Sorry @smorovic , I was not clear. You should list both versions, so that the new one is inserted, and the old one is kept for back compatibility:

  <class name="TCDSRecord" ClassVersion="4">
    <version ClassVersion="4" checksum="850266115"/>
    <version ClassVersion="3" checksum="1408516613"/>
  </class>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, no problem. Thanks for clarification. I included both.

<version ClassVersion="3" checksum="1408516613"/>
</class>

Expand Down
5 changes: 5 additions & 0 deletions EventFilter/Utilities/interface/FedRawDataInputSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "IOPool/Streamer/interface/FRDEventMessage.h"

#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/Provenance/interface/LuminosityBlockAuxiliary.h"

class FEDRawDataCollection;
Expand Down Expand Up @@ -92,6 +93,7 @@ class FedRawDataInputSource : public edm::RawInputSource {
const bool alwaysStartFromFirstLS_;
const bool verifyChecksum_;
const bool useL1EventID_;
const std::vector<unsigned int> testTCDSFEDRange_;
std::vector<std::string> fileNames_;
bool useFileBroker_;
//std::vector<std::string> fileNamesSorted_;
Expand Down Expand Up @@ -119,6 +121,9 @@ class FedRawDataInputSource : public edm::RawInputSource {
unsigned int eventsThisLumi_;
unsigned long eventsThisRun_ = 0;

uint16_t MINTCDSuTCAFEDID_ = FEDNumbering::MINTCDSuTCAFEDID;
uint16_t MAXTCDSuTCAFEDID_ = FEDNumbering::MAXTCDSuTCAFEDID;

/*
*
* Multithreaded file reader
Expand Down
53 changes: 31 additions & 22 deletions EventFilter/Utilities/plugins/DaqFakeReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DataFormats/FEDRawData/interface/FEDHeader.h"
#include "DataFormats/FEDRawData/interface/FEDTrailer.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/TCDS/interface/TCDSRaw.h"

#include "EventFilter/Utilities/interface/GlobalEventNumber.h"

Expand Down Expand Up @@ -35,9 +36,13 @@ DaqFakeReader::DaqFakeReader(const edm::ParameterSet& pset)
meansize(pset.getUntrackedParameter<unsigned int>("meanSize", 1024)),
width(pset.getUntrackedParameter<unsigned int>("width", 1024)),
injected_errors_per_million_events(pset.getUntrackedParameter<unsigned int>("injectErrPpm", 0)),
tcdsFEDID_(pset.getUntrackedParameter<unsigned int>("tcdsFEDID", 1024)),
modulo_error_events(injected_errors_per_million_events ? 1000000 / injected_errors_per_million_events
: 0xffffffff) {
// mean = pset.getParameter<float>("mean");
if (tcdsFEDID_ < FEDNumbering::MINTCDSuTCAFEDID)
throw cms::Exception("DaqFakeReader::DaqFakeReader")
<< " TCDS FED ID lower than " << FEDNumbering::MINTCDSuTCAFEDID;
produces<FEDRawDataCollection>();
}

Expand All @@ -53,6 +58,7 @@ int DaqFakeReader::fillRawData(Event& e, FEDRawDataCollection*& data) {
// a null pointer is passed, need to allocate the fed collection
data = new FEDRawDataCollection();
EventID eID = e.id();
auto ls = e.luminosityBlock();

if (!empty_events) {
// Fill the EventID
Expand All @@ -69,8 +75,7 @@ int DaqFakeReader::fillRawData(Event& e, FEDRawDataCollection*& data) {

timeval now;
gettimeofday(&now, nullptr);
fillGTPFED(eID, *data, &now);
//TODO: write fake TCDS FED filler
fillTCDSFED(eID, *data, ls, &now);
}
return 1;
}
Expand Down Expand Up @@ -116,39 +121,43 @@ void DaqFakeReader::fillFEDs(
}
}

void DaqFakeReader::fillGTPFED(EventID& eID, FEDRawDataCollection& data, timeval* now) {
uint32_t fedId = FEDNumbering::MINTriggerGTPFEDID;
void DaqFakeReader::fillTCDSFED(EventID& eID, FEDRawDataCollection& data, uint32_t ls, timeval* now) {
uint32_t fedId = tcdsFEDID_;
FEDRawData& feddata = data.FEDData(fedId);
uint32_t size = evf::evtn::SLINK_WORD_SIZE * 37 - 16; //BST52_3BX
uint32_t size = sizeof(tcds::Raw_v1);
feddata.resize(size + 16);

uint64_t orbitnr = 0;
uint16_t bxid = 0;

FEDHeader::set(feddata.data(),
1, // Trigger type
eID.event(), // LV1_id (24 bits)
0, // BX_id
bxid, // BX_id
fedId); // source_id

int crc = 0; // FIXME : get CRC
tcds::Raw_v1* tcds = reinterpret_cast<tcds::Raw_v1*>(feddata.data() + FEDHeader::length);
tcds::BST_v1* bst = const_cast<tcds::BST_v1*>(&tcds->bst);
tcds::Header_v1* header = const_cast<tcds::Header_v1*>(&tcds->header);

const_cast<uint32_t&>(bst->gpstimehigh) = now->tv_sec;
const_cast<uint32_t&>(bst->gpstimelow) = now->tv_usec;
const_cast<uint16_t&>(bst->lhcFillHigh) = 0;
const_cast<uint16_t&>(bst->lhcFillLow) = 0;

const_cast<uint32_t&>(header->orbitHigh) = orbitnr & 0xffff00;
const_cast<uint16_t&>(header->orbitLow) = orbitnr & 0xff;
const_cast<uint16_t&>(header->bxid) = bxid;

const_cast<uint64_t&>(header->eventNumber) = eID.event();
const_cast<uint32_t&>(header->lumiSection) = ls;

int crc = 0; // only full event crc32c checked in HLT, not FED CRC16
FEDTrailer::set(feddata.data() + 8 + size,
size / 8 + 2, // in 64 bit words!!!
crc,
0, // Evt_stat
0); // TTS bits

unsigned char* pOffset = feddata.data() + FEDHeader::length;
//fill in event ID
*((uint32_t*)(pOffset + evf::evtn::EVM_BOARDID_OFFSET * evf::evtn::SLINK_WORD_SIZE / 2)) =
evf::evtn::EVM_BOARDID_VALUE << evf::evtn::EVM_BOARDID_SHIFT;
*((uint32_t*)(pOffset + FEDHeader::length +
(9 * 2 + evf::evtn::EVM_TCS_TRIGNR_OFFSET) * evf::evtn::SLINK_WORD_SIZE / 2)) = eID.event();
//fill in timestamp
*((uint32_t*)(pOffset + evf::evtn::EVM_GTFE_BSTGPS_OFFSET * evf::evtn::SLINK_WORD_SIZE / 2)) = now->tv_sec;
*((uint32_t*)(pOffset + FEDHeader::length + evf::evtn::EVM_GTFE_BSTGPS_OFFSET * evf::evtn::SLINK_WORD_SIZE / 2 +
evf::evtn::SLINK_HALFWORD_SIZE)) = now->tv_usec;

//*( (uint16_t*) (pOffset + (evtn::EVM_GTFE_BLOCK*2 + evtn::EVM_TCS_LSBLNR_OFFSET)*evtn::SLINK_HALFWORD_SIZE)) = (unsigned short)fakeLs_-1;

//we could also generate lumiblock, bcr, orbit,... but they are not currently used by the FRD input source
}

void DaqFakeReader::beginLuminosityBlock(LuminosityBlock const& iL, EventSetup const& iE) {
Expand Down
3 changes: 2 additions & 1 deletion EventFilter/Utilities/plugins/DaqFakeReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DaqFakeReader : public edm::one::EDProducer<> {
// private member functions
//
void fillFEDs(const int, const int, edm::EventID& eID, FEDRawDataCollection& data, float meansize, float width);
void fillGTPFED(edm::EventID& eID, FEDRawDataCollection& data, timeval* now);
void fillTCDSFED(edm::EventID& eID, FEDRawDataCollection& data, uint32_t ls, timeval* now);
virtual void beginLuminosityBlock(edm::LuminosityBlock const& iL, edm::EventSetup const& iE);

private:
Expand All @@ -51,6 +51,7 @@ class DaqFakeReader : public edm::one::EDProducer<> {
unsigned int meansize; // in bytes
unsigned int width;
unsigned int injected_errors_per_million_events;
unsigned int tcdsFEDID_;
unsigned int modulo_error_events;
unsigned int fakeLs_ = 0;
};
Expand Down
13 changes: 10 additions & 3 deletions EventFilter/Utilities/plugins/TcdsRawToDigi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ void TcdsRawToDigi::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {

TCDSRecord tcdsRecord;
if (rawdata.isValid()) {
const FEDRawData& tcdsData = rawdata->FEDData(FEDNumbering::MINTCDSuTCAFEDID);
if (tcdsData.size() > 0) {
tcdsRecord = TCDSRecord(tcdsData.data());
uint16_t selectedId = 0;
for (uint16_t fedId = FEDNumbering::MINTCDSuTCAFEDID; fedId <= FEDNumbering::MAXTCDSuTCAFEDID; fedId++) {
const FEDRawData& tcdsData = rawdata->FEDData(fedId);
if (tcdsData.size() > 0) {
if (selectedId)
throw cms::Exception("TcdsRawToDigi::produce")
<< "Second TCDS FED ID " << fedId << " found. First ID: " << selectedId;
tcdsRecord = TCDSRecord(tcdsData.data());
selectedId = fedId;
}
}
}
iEvent.put(std::make_unique<TCDSRecord>(tcdsRecord), "tcdsRecord");
Expand Down
35 changes: 30 additions & 5 deletions EventFilter/Utilities/src/FedRawDataInputSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/fstream.hpp>

#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/FEDRawData/interface/FEDHeader.h"
#include "DataFormats/FEDRawData/interface/FEDTrailer.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
Expand Down Expand Up @@ -61,6 +60,8 @@ FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset, edm:
alwaysStartFromFirstLS_(pset.getUntrackedParameter<bool>("alwaysStartFromFirstLS", false)),
verifyChecksum_(pset.getUntrackedParameter<bool>("verifyChecksum", true)),
useL1EventID_(pset.getUntrackedParameter<bool>("useL1EventID", false)),
testTCDSFEDRange_(
pset.getUntrackedParameter<std::vector<unsigned int>>("testTCDSFEDRange", std::vector<unsigned int>())),
fileNames_(pset.getUntrackedParameter<std::vector<std::string>>("fileNames", std::vector<std::string>())),
fileListMode_(pset.getUntrackedParameter<bool>("fileListMode", false)),
fileListLoopMode_(pset.getUntrackedParameter<bool>("fileListLoopMode", false)),
Expand All @@ -76,6 +77,15 @@ FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset, edm:
edm::LogInfo("FedRawDataInputSource") << "Construction. read-ahead chunk size -: " << std::endl
<< (eventChunkSize_ / 1048576) << " MB on host " << thishost;

if (!testTCDSFEDRange_.empty()) {
if (testTCDSFEDRange_.size() != 2) {
throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
<< "Invalid TCDS Test FED range parameter";
}
MINTCDSuTCAFEDID_ = testTCDSFEDRange_[0];
MAXTCDSuTCAFEDID_ = testTCDSFEDRange_[1];
}

long autoRunNumber = -1;
if (fileListMode_) {
autoRunNumber = initFileList();
Expand Down Expand Up @@ -207,6 +217,8 @@ void FedRawDataInputSource::fillDescriptions(edm::ConfigurationDescriptions& des
->setComment("Verify event CRC-32C checksum of FRDv5 and higher or Adler32 with v3 and v4");
desc.addUntracked<bool>("useL1EventID", false)
->setComment("Use L1 event ID from FED header if true or from TCDS FED if false");
desc.addUntracked<std::vector<unsigned int>>("testTCDSFEDRange", std::vector<unsigned int>())
->setComment("[min, max] range to search for TCDS FED ID in test setup");
desc.addUntracked<bool>("fileListMode", false)
->setComment("Use fileNames parameter to directly specify raw files to open");
desc.addUntracked<std::vector<std::string>>("fileNames", std::vector<std::string>())
Expand Down Expand Up @@ -614,7 +626,10 @@ void FedRawDataInputSource::read(edm::EventPrincipal& eventPrincipal) {
aux.setProcessHistoryID(processHistoryID_);
makeEvent(eventPrincipal, aux);
} else if (tcds_pointer_ == nullptr) {
assert(GTPEventID_);
if (!GTPEventID_) {
throw cms::Exception("FedRawDataInputSource::read")
<< "No TCDS or GTP FED in event with FEDHeader EID -: " << L1EventID_;
}
eventID_ = edm::EventID(eventRunNumber_, currentLumiSection_, GTPEventID_);
edm::EventAuxiliary aux(eventID_, processGUID(), tstamp, true, edm::EventAuxiliary::PhysicsTrigger);
aux.setProcessHistoryID(processHistoryID_);
Expand Down Expand Up @@ -687,6 +702,7 @@ edm::Timestamp FedRawDataInputSource::fillFEDRawDataCollection(FEDRawDataCollect
unsigned char* event = (unsigned char*)event_->payload();
GTPEventID_ = 0;
tcds_pointer_ = nullptr;
uint16_t selectedTCDSFed = 0;
while (eventSize > 0) {
assert(eventSize >= FEDTrailer::length);
eventSize -= FEDTrailer::length;
Expand All @@ -698,9 +714,13 @@ edm::Timestamp FedRawDataInputSource::fillFEDRawDataCollection(FEDRawDataCollect
const uint16_t fedId = fedHeader.sourceID();
if (fedId > FEDNumbering::MAXFEDID) {
throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection") << "Out of range FED ID : " << fedId;
}
if (fedId == FEDNumbering::MINTCDSuTCAFEDID) {
tcds_pointer_ = event + eventSize;
} else if (fedId >= MINTCDSuTCAFEDID_ && fedId <= MAXTCDSuTCAFEDID_) {
if (!selectedTCDSFed) {
selectedTCDSFed = fedId;
tcds_pointer_ = event + eventSize;
} else
throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
<< "Second TCDS FED ID " << fedId << " found. First ID: " << selectedTCDSFed;
}
if (fedId == FEDNumbering::MINTriggerGTPFEDID) {
if (evf::evtn::evm_board_sense(event + eventSize, fedSize))
Expand Down Expand Up @@ -1509,7 +1529,12 @@ long FedRawDataInputSource::initFileList() {
//get run number from first file in the vector
std::filesystem::path fileName = fileNames_[0];
std::string fileStem = fileName.stem().string();
if (fileStem.find("file://") == 0)
fileStem = fileStem.substr(7);
else if (fileStem.find("file:") == 0)
fileStem = fileStem.substr(5);
auto end = fileStem.find('_');

if (fileStem.find("run") == 0) {
std::string runStr = fileStem.substr(3, end - 3);
try {
Expand Down
1 change: 1 addition & 0 deletions EventFilter/Utilities/test/startBU.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
process.s = cms.EDProducer("DaqFakeReader",
meanSize = cms.untracked.uint32(options.fedMeanSize),
width = cms.untracked.uint32(int(math.ceil(options.fedMeanSize/2.))),
tcdsFEDID = cms.untracked.uint32(1024),
injectErrPpm = cms.untracked.uint32(0)
)

Expand Down
9 changes: 7 additions & 2 deletions EventFilter/Utilities/test/startFU.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
process.source = cms.Source("FedRawDataInputSource",
getLSFromFilename = cms.untracked.bool(True),
verifyChecksum = cms.untracked.bool(True),
useL1EventID = cms.untracked.bool(True),
useL1EventID = cms.untracked.bool(False),
eventChunkSize = cms.untracked.uint32(8),
eventChunkBlock = cms.untracked.uint32(8),
numBuffers = cms.untracked.uint32(2),
Expand Down Expand Up @@ -120,7 +120,12 @@
defaultAction = cms.untracked.int32(0),
defaultQualifier = cms.untracked.int32(5))

process.p1 = cms.Path(process.a*process.filter1)

process.tcdsRawToDigi = cms.EDProducer("TcdsRawToDigi",
InputLabel = cms.InputTag("rawDataCollector")
)

process.p1 = cms.Path(process.a*process.tcdsRawToDigi*process.filter1)
process.p2 = cms.Path(process.b*process.filter2)

process.streamA = cms.OutputModule("EvFOutputModule",
Expand Down
8 changes: 6 additions & 2 deletions EventFilter/Utilities/test/unittest_FU.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
process.source = cms.Source("FedRawDataInputSource",
getLSFromFilename = cms.untracked.bool(True),
verifyChecksum = cms.untracked.bool(True),
useL1EventID = cms.untracked.bool(True),
useL1EventID = cms.untracked.bool(False),
eventChunkSize = cms.untracked.uint32(8),
eventChunkBlock = cms.untracked.uint32(8),
numBuffers = cms.untracked.uint32(2),
Expand Down Expand Up @@ -130,7 +130,11 @@
defaultAction = cms.untracked.int32(0),
defaultQualifier = cms.untracked.int32(5))

process.p1 = cms.Path(process.a*process.filter1)
process.tcdsRawToDigi = cms.EDProducer("TcdsRawToDigi",
InputLabel = cms.InputTag("rawDataCollector")
)

process.p1 = cms.Path(process.a*process.tcdsRawToDigi*process.filter1)
process.p2 = cms.Path(process.b*process.filter2)

process.streamA = cms.OutputModule("EvFOutputModule",
Expand Down