Skip to content

Commit 6f88cd8

Browse files
committed
add back support for old format to RawEventOutputModuleForBU
DaqFakeReader reverted to FEDRawDataCollection so that this is also tested, as it is in use
1 parent 7e21eeb commit 6f88cd8

File tree

4 files changed

+141
-86
lines changed

4 files changed

+141
-86
lines changed

EventFilter/Utilities/plugins/DaqFakeReader.cc

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

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

14-
#include "DataFormats/FEDRawData/interface/RawDataBuffer.h"
14+
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
1515

1616
#include "FWCore/ParameterSet/interface/ParameterSet.h"
1717

@@ -26,6 +26,11 @@
2626
using namespace std;
2727
using namespace edm;
2828

29+
////////////////////////////////////////////////////////////////////////////////
30+
// construction/destruction
31+
////////////////////////////////////////////////////////////////////////////////
32+
33+
//______________________________________________________________________________
2934
DaqFakeReader::DaqFakeReader(const edm::ParameterSet& pset)
3035
: runNum(1),
3136
eventNum(1),
@@ -66,41 +71,27 @@ DaqFakeReader::DaqFakeReader(const edm::ParameterSet& pset)
6671
static_cast<long unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
6772
srand(time_count & 0xffffffff);
6873
}
69-
produces<RawDataBuffer>();
74+
produces<FEDRawDataCollection>();
7075
}
7176

72-
int DaqFakeReader::fillRawData(Event& e, RawDataBuffer*& data) {
73-
// a null pointer is passed, need to allocate the fed collection
74-
totSize_ = 0;
75-
logSizes_.clear();
76-
logSizeIndex_ = 0;
77+
//______________________________________________________________________________
78+
DaqFakeReader::~DaqFakeReader() {}
7779

78-
if (!empty_events) {
79-
getSizes(FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID, meansize, width);
80-
if (haveSiStrip_)
81-
getSizes(FEDNumbering::MINSiStripFEDID, FEDNumbering::MAXSiStripFEDID, meansize, width);
82-
if (haveECAL_)
83-
getSizes(FEDNumbering::MINECALFEDID, FEDNumbering::MAXECALFEDID, meansize, width);
84-
if (haveHCAL_)
85-
getSizes(FEDNumbering::MINHCALFEDID, FEDNumbering::MAXHCALFEDID, meansize, width);
86-
if (haveDT_)
87-
getSizes(FEDNumbering::MINDTFEDID, FEDNumbering::MAXDTFEDID, meansize, width);
88-
if (haveCSC_)
89-
getSizes(FEDNumbering::MINCSCFEDID, FEDNumbering::MAXCSCFEDID, meansize, width);
90-
if (haveRPC_)
91-
getSizes(FEDNumbering::MINRPCFEDID, FEDNumbering::MAXRPCFEDID, meansize, width);
92-
logSizes_.push_back(sizeof(tcds::Raw_v1) + 16);
93-
totSize_ += sizeof(tcds::Raw_v1) + 16;
94-
}
80+
////////////////////////////////////////////////////////////////////////////////
81+
// implementation of member functions
82+
////////////////////////////////////////////////////////////////////////////////
9583

96-
data = new RawDataBuffer(totSize_);
97-
data->setPhase1Range();
84+
//______________________________________________________________________________
85+
int DaqFakeReader::fillRawData(Event& e, FEDRawDataCollection*& data) {
86+
// a null pointer is passed, need to allocate the fed collection
87+
data = new FEDRawDataCollection();
9888
EventID eID = e.id();
9989
auto ls = e.luminosityBlock();
10090

10191
if (!empty_events) {
10292
// Fill the EventID
10393
eventNum++;
94+
// FIXME:
10495

10596
if (haveSiPixel_)
10697
fillFEDs(FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID, eID, *data, meansize, width);
@@ -126,81 +117,74 @@ int DaqFakeReader::fillRawData(Event& e, RawDataBuffer*& data) {
126117
}
127118

128119
void DaqFakeReader::produce(Event& e, EventSetup const& es) {
129-
RawDataBuffer* fedbuffer = nullptr;
130-
fillRawData(e, fedbuffer);
131-
std::unique_ptr<RawDataBuffer> bare_product(fedbuffer);
120+
edm::Handle<FEDRawDataCollection> rawdata;
121+
FEDRawDataCollection* fedcoll = nullptr;
122+
fillRawData(e, fedcoll);
123+
std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
132124
e.put(std::move(bare_product));
133125
}
134126

135-
void DaqFakeReader::getSizes(const int fedmin, const int fedmax, float meansize, float width) {
136-
// FIXME: last ID included?
137-
for (int fedId = fedmin; fedId <= fedmax; ++fedId) {
138-
// Generate size...
139-
float logsiz = CLHEP::RandGauss::shoot(std::log(meansize), std::log(meansize) - std::log(width / 2.));
140-
logSizes_.push_back(logsiz);
141-
size_t size = int(std::exp(logsiz));
142-
size -= size % 8; // all blocks aligned to 64 bit words
143-
totSize_ += size + 16;
144-
}
145-
}
146-
127+
//______________________________________________________________________________
147128
void DaqFakeReader::fillFEDs(
148-
const int fedmin, const int fedmax, EventID& eID, RawDataBuffer& data, float meansize, float width) {
129+
const int fedmin, const int fedmax, EventID& eID, FEDRawDataCollection& data, float meansize, float width) {
149130
// FIXME: last ID included?
150131
for (int fedId = fedmin; fedId <= fedmax; ++fedId) {
151132
// Generate size...
152-
assert(logSizeIndex_ < logSizes_.size());
153-
float logsiz = logSizes_[logSizeIndex_];
154-
logSizeIndex_++;
133+
float logsiz = CLHEP::RandGauss::shoot(std::log(meansize), std::log(meansize) - std::log(width / 2.));
155134
size_t size = int(std::exp(logsiz));
156135
size -= size % 8; // all blocks aligned to 64 bit words
157136

158-
unsigned char* feddata = data.addSource(fedId, nullptr, size + 16);
137+
FEDRawData& feddata = data.FEDData(fedId);
138+
// Allocate space for header+trailer+payload
139+
feddata.resize(size + 16);
159140

160141
if (fillRandom_) {
161142
//fill FED with random values
162143
size_t size_ui = size - size % sizeof(unsigned int);
163144
for (size_t i = 0; i < size_ui; i += sizeof(unsigned int)) {
164-
*((unsigned int*)(feddata + i)) = (unsigned int)rand();
145+
*((unsigned int*)(feddata.data() + i)) = (unsigned int)rand();
165146
}
166147
//remainder
167148
for (size_t i = size_ui; i < size; i++) {
168-
*(feddata + i) = rand() & 0xff;
149+
*(feddata.data() + i) = rand() & 0xff;
169150
}
170151
}
171152

172153
// Generate header
173-
FEDHeader::set(feddata,
154+
FEDHeader::set(feddata.data(),
174155
1, // Trigger type
175156
eID.event(), // LV1_id (24 bits)
176157
0, // BX_id
177158
fedId); // source_id
178159

160+
// Payload = all 0s...
161+
179162
// Generate trailer
180163
int crc = 0; // FIXME : get CRC
181-
FEDTrailer::set(feddata + 8 + size,
164+
FEDTrailer::set(feddata.data() + 8 + size,
182165
size / 8 + 2, // in 64 bit words!!!
183166
crc,
184167
0, // Evt_stat
185168
0); // TTS bits
186169
}
187170
}
188171

189-
void DaqFakeReader::fillTCDSFED(EventID& eID, RawDataBuffer& data, uint32_t ls, timeval* now) {
172+
void DaqFakeReader::fillTCDSFED(EventID& eID, FEDRawDataCollection& data, uint32_t ls, timeval* now) {
190173
uint32_t fedId = tcdsFEDID_;
174+
FEDRawData& feddata = data.FEDData(fedId);
191175
uint32_t size = sizeof(tcds::Raw_v1);
192-
unsigned char* feddata = data.addSource(fedId, nullptr, size + 16);
176+
feddata.resize(size + 16);
193177

194178
uint64_t orbitnr = 0;
195179
uint16_t bxid = 0;
196180

197-
FEDHeader::set(feddata,
181+
FEDHeader::set(feddata.data(),
198182
1, // Trigger type
199183
eID.event(), // LV1_id (24 bits)
200184
bxid, // BX_id
201185
fedId); // source_id
202186

203-
tcds::Raw_v1* tcds = reinterpret_cast<tcds::Raw_v1*>(feddata + FEDHeader::length);
187+
tcds::Raw_v1* tcds = reinterpret_cast<tcds::Raw_v1*>(feddata.data() + FEDHeader::length);
204188
tcds::BST_v1* bst = const_cast<tcds::BST_v1*>(&tcds->bst);
205189
tcds::Header_v1* header = const_cast<tcds::Header_v1*>(&tcds->header);
206190

@@ -217,7 +201,7 @@ void DaqFakeReader::fillTCDSFED(EventID& eID, RawDataBuffer& data, uint32_t ls,
217201
const_cast<uint32_t&>(header->lumiSection) = ls;
218202

219203
int crc = 0; // only full event crc32c checked in HLT, not FED CRC16
220-
FEDTrailer::set(feddata + 8 + size,
204+
FEDTrailer::set(feddata.data() + 8 + size,
221205
size / 8 + 2, // in 64 bit words!!!
222206
crc,
223207
0, // Evt_stat

EventFilter/Utilities/plugins/DaqFakeReader.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,40 @@
1414
#include "FWCore/Framework/interface/LuminosityBlock.h"
1515
#include "FWCore/Framework/interface/EventSetup.h"
1616
#include "DataFormats/Provenance/interface/EventID.h"
17-
#include "DataFormats/FEDRawData/interface/RawDataBuffer.h"
17+
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
1818
#include <algorithm>
1919

2020
class DaqFakeReader : public edm::one::EDProducer<> {
2121
public:
22+
//
23+
// construction/destruction
24+
//
2225
DaqFakeReader(const edm::ParameterSet& pset);
23-
~DaqFakeReader() override {}
26+
~DaqFakeReader() override;
27+
28+
//
29+
// public member functions
30+
//
2431

2532
// Generate and fill FED raw data for a full event
26-
virtual int fillRawData(edm::Event& e, RawDataBuffer*& data);
33+
virtual int fillRawData(edm::Event& e, FEDRawDataCollection*& data);
34+
2735
void produce(edm::Event&, edm::EventSetup const&) override;
36+
2837
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
2938

3039
private:
31-
void getSizes(const int, const int, float meansize, float width);
32-
void fillFEDs(const int, const int, edm::EventID& eID, RawDataBuffer& data, float meansize, float width);
33-
void fillTCDSFED(edm::EventID& eID, RawDataBuffer& data, uint32_t ls, timeval* now);
40+
//
41+
// private member functions
42+
//
43+
void fillFEDs(const int, const int, edm::EventID& eID, FEDRawDataCollection& data, float meansize, float width);
44+
void fillTCDSFED(edm::EventID& eID, FEDRawDataCollection& data, uint32_t ls, timeval* now);
3445
virtual void beginLuminosityBlock(edm::LuminosityBlock const& iL, edm::EventSetup const& iE);
3546

47+
private:
48+
//
49+
// member data
50+
//
3651
edm::RunNumber_t runNum;
3752
edm::EventNumber_t eventNum;
3853
bool empty_events;
@@ -52,10 +67,6 @@ class DaqFakeReader : public edm::one::EDProducer<> {
5267
bool haveDT_ = false;
5368
bool haveCSC_ = false;
5469
bool haveRPC_ = false;
55-
56-
uint32_t totSize_ = 0;
57-
std::vector<float> logSizes_;
58-
uint16_t logSizeIndex_;
5970
};
6071

6172
#endif

EventFilter/Utilities/plugins/RawEventOutputModuleForBU.h

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ class RawEventOutputModuleForBU : public edm::one::OutputModule<edm::one::WatchR
4747
void endLuminosityBlock(edm::LuminosityBlockForOutput const&) override;
4848

4949
std::unique_ptr<Consumer> templateConsumer_;
50+
const edm::EDGetTokenT<FEDRawDataCollection> tokenFRD_;
5051
const edm::EDGetTokenT<RawDataBuffer> token_;
5152
const unsigned int numEventsPerFile_;
5253
const unsigned int frdVersion_;
54+
std::string rawProductName_;
55+
unsigned int rawProductType_ = 0;
5356
std::vector<unsigned int> sourceIdList_;
5457
unsigned int totevents_ = 0;
5558
unsigned int index_ = 0;
@@ -60,10 +63,18 @@ RawEventOutputModuleForBU<Consumer>::RawEventOutputModuleForBU(edm::ParameterSet
6063
: edm::one::OutputModuleBase::OutputModuleBase(ps),
6164
edm::one::OutputModule<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks>(ps),
6265
templateConsumer_(new Consumer(ps)),
66+
tokenFRD_(consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("source"))),
6367
token_(consumes<RawDataBuffer>(ps.getParameter<edm::InputTag>("source"))),
6468
numEventsPerFile_(ps.getParameter<unsigned int>("numEventsPerFile")),
6569
frdVersion_(ps.getParameter<unsigned int>("frdVersion")),
70+
rawProductName_(ps.getUntrackedParameter<std::string>("rawProductName")),
6671
sourceIdList_(ps.getUntrackedParameter<std::vector<unsigned int>>("sourceIdList", std::vector<unsigned int>())) {
72+
if (rawProductName_ == "FEDRawDataCollection")
73+
rawProductType_ = 1;
74+
else if (rawProductName_ == "RawDataBuffer")
75+
rawProductType_ = 2;
76+
else
77+
throw cms::Exception("RawEventOutputModuleForBU") << "Unknown raw product specified";
6778
if (frdVersion_ > 0 && frdVersion_ < 5)
6879
throw cms::Exception("RawEventOutputModuleForBU")
6980
<< "Generating data with FRD version " << frdVersion_ << " is no longer supported";
@@ -89,23 +100,49 @@ void RawEventOutputModuleForBU<Consumer>::write(edm::EventForOutput const& e) {
89100
totevents_++;
90101
// serialize the FEDRawDataCollection into the format that we expect for
91102
// FRDEventMsgView objects (may be better ways to do this)
103+
edm::Handle<FEDRawDataCollection> fedBuffers;
92104
edm::Handle<RawDataBuffer> fedBuffer;
93-
e.getByToken(token_, fedBuffer);
105+
106+
unsigned int usedRawType = 0;
107+
if (rawProductType_ == 1) {
108+
e.getByToken(tokenFRD_, fedBuffers);
109+
usedRawType = 1;
110+
} else if (rawProductType_ == 2) {
111+
e.getByToken(token_, fedBuffer);
112+
usedRawType = 2;
113+
}
114+
assert(usedRawType);
94115

95116
// determine the expected size of the FRDEvent IN bytes
96117
int headerSize = edm::streamer::FRDHeaderVersionSize[frdVersion_];
97118
int expectedSize = headerSize;
98-
int nFeds = FEDNumbering::lastFEDId() + 1; //TODO!
119+
//for FEDRawDataCollection
120+
int nFeds = FEDNumbering::lastFEDId() + 1;
99121

100-
if (!sourceIdList_.empty()) {
101-
for (int idx : sourceIdList_) {
102-
auto singleFED = fedBuffer->fragmentData(idx);
103-
expectedSize += singleFED.size();
122+
if (usedRawType == 1) {
123+
if (!sourceIdList_.empty()) {
124+
for (int idx : sourceIdList_) {
125+
auto singleFED = fedBuffers->FEDData(idx);
126+
expectedSize += singleFED.size();
127+
}
128+
} else {
129+
for (int idx = 0; idx < nFeds; ++idx) {
130+
auto singleFED = fedBuffers->FEDData(idx);
131+
expectedSize += singleFED.size();
132+
}
104133
}
105-
} else {
106-
for (int idx = 0; idx < nFeds; ++idx) {
107-
auto singleFED = fedBuffer->fragmentData(idx);
108-
expectedSize += singleFED.size();
134+
} else if (usedRawType == 2) {
135+
if (!sourceIdList_.empty()) {
136+
for (int idx : sourceIdList_) {
137+
auto singleFED = fedBuffer->fragmentData(idx);
138+
expectedSize += singleFED.size();
139+
}
140+
} else {
141+
//for (int idx = 0; idx < nFeds; ++idx) {
142+
for (auto it = fedBuffer->map().begin(); it != fedBuffer->map().end(); it++) {
143+
auto singleFED = fedBuffer->fragmentData(it);
144+
expectedSize += singleFED.size();
145+
}
109146
}
110147
}
111148

@@ -134,17 +171,37 @@ void RawEventOutputModuleForBU<Consumer>::write(edm::EventForOutput const& e) {
134171
*bufPtr++ = 0;
135172
}
136173
uint32_t* payloadPtr = bufPtr;
137-
if (!sourceIdList_.empty()) {
138-
for (int idx : sourceIdList_) {
139-
auto singleFED = fedBuffer->fragmentData(idx);
140-
memcpy(bufPtr, &singleFED.data()[0], singleFED.size());
141-
bufPtr += singleFED.size() / 4;
174+
if (usedRawType == 1) {
175+
if (!sourceIdList_.empty()) {
176+
for (int idx : sourceIdList_) {
177+
FEDRawData singleFED = fedBuffers->FEDData(idx);
178+
if (singleFED.size() > 0) {
179+
memcpy(bufPtr, singleFED.data(), singleFED.size());
180+
bufPtr += singleFED.size() / 4;
181+
}
182+
}
183+
} else {
184+
for (int idx = 0; idx < nFeds; ++idx) {
185+
FEDRawData singleFED = fedBuffers->FEDData(idx);
186+
if (singleFED.size() > 0) {
187+
memcpy(bufPtr, singleFED.data(), singleFED.size());
188+
bufPtr += singleFED.size() / 4;
189+
}
190+
}
142191
}
143-
} else {
144-
for (auto it = fedBuffer->map().begin(); it != fedBuffer->map().end(); it++) {
145-
auto singleFED = fedBuffer->fragmentData(it);
146-
memcpy(bufPtr, &singleFED.data()[0], singleFED.size());
147-
bufPtr += singleFED.size() / 4;
192+
} else if (usedRawType == 2) {
193+
if (!sourceIdList_.empty()) {
194+
for (int idx : sourceIdList_) {
195+
auto singleFED = fedBuffer->fragmentData(idx);
196+
memcpy(bufPtr, &singleFED.data()[0], singleFED.size());
197+
bufPtr += singleFED.size() / 4;
198+
}
199+
} else {
200+
for (auto it = fedBuffer->map().begin(); it != fedBuffer->map().end(); it++) {
201+
auto singleFED = fedBuffer->fragmentData(it);
202+
memcpy(bufPtr, &singleFED.data()[0], singleFED.size());
203+
bufPtr += singleFED.size() / 4;
204+
}
148205
}
149206
}
150207
if (frdVersion_) {
@@ -195,6 +252,8 @@ void RawEventOutputModuleForBU<Consumer>::fillDescriptions(edm::ConfigurationDes
195252
desc.add<edm::InputTag>("source", edm::InputTag("rawDataCollector"));
196253
desc.add<unsigned int>("numEventsPerFile", 100);
197254
desc.add<unsigned int>("frdVersion", 6);
255+
desc.addUntracked<std::string>("rawProductName", "FEDRawDataCollection")
256+
->setComment("FEDRawDataCollection or RawDataBuffer");
198257
desc.addUntracked<std::vector<unsigned int>>("sourceIdList", std::vector<unsigned int>());
199258
Consumer::extendDescription(desc);
200259

0 commit comments

Comments
 (0)