53 : event_type_(pset.getParameter<int>(
"eventType")),
55 useDBEMap_(pset.getParameter<bool>(
"useDBEMap")) {
56 produces<FEDRawDataCollection>();
58 gemEMapToken_ = esConsumes<GEMeMap, GEMeMapRcd, edm::Transition::BeginRun>();
65 desc.
add<
int>(
"eventType", 0);
66 desc.
add<
bool>(
"useDBEMap",
false);
67 descriptions.
add(
"gemPackerDefault", desc);
71 auto gemROmap = std::make_shared<GEMROMapping>();
74 auto gemEMap = std::make_unique<GEMeMap>(eMap);
75 gemEMap->convert(*gemROmap);
79 auto gemEMap = std::make_unique<GEMeMap>();
80 gemEMap->convertDummy(*gemROmap);
87 auto fedRawDataCol = std::make_unique<FEDRawDataCollection>();
91 if (!gemDigis.isValid()) {
98 std::vector<std::unique_ptr<GEMAMC13>> amc13s;
101 int LV1_id = iEvent.
id().
event();
107 std::map<int, GEMDigiCollection> gemBxMap;
108 for (
auto const& etaPart : *gemDigis) {
111 for (
auto digi = digis.first; digi != digis.second; ++digi) {
113 auto search = gemBxMap.find(bx);
114 if (
search != gemBxMap.end()) {
115 search->second.insertDigi(gemId, *digi);
118 newGDC.insertDigi(gemId, *digi);
119 gemBxMap.insert(std::pair<int, GEMDigiCollection>(bx, newGDC));
125 uint32_t amc13EvtLength = 0;
126 std::unique_ptr<GEMAMC13> amc13 = std::make_unique<GEMAMC13>();
129 uint32_t amcSize = 0;
130 std::unique_ptr<GEMAMC>
amc = std::make_unique<GEMAMC>();
133 std::unique_ptr<GEMOptoHybrid> optoH = std::make_unique<GEMOptoHybrid>();
136 if (!gemROMap->isValidChamber(geb_ec))
140 auto vfats = gemROMap->getVfats(geb_dc.
detId);
141 for (
auto const& vfat_ec : vfats) {
144 uint16_t vfatId = vfat_ec.vfatAdd;
146 for (
auto const& gemBx : gemBxMap) {
147 int bc = BX_id + gemBx.first;
149 bool hasDigi =
false;
156 const GEMDigi& digi = (*digiIt);
168 if (chMap.
chNum < 64)
169 lsData |= 1UL << chMap.
chNum;
171 msData |= 1UL << (chMap.
chNum - 64);
174 <<
"fed: " <<
fedId <<
" amc:" << int(amcNum) <<
" geb:" << int(gebId) <<
" vfat id:" << int(vfatId)
175 <<
",type:" << vfat_dc.
vfatType <<
" id:" << gemId <<
" ch:" << chMap.
chNum <<
" st:" << digi.
strip()
176 <<
" bx:" << digi.
bx();
183 auto vfat = std::make_unique<GEMVFAT>(geb_dc.
vfatVer, bc, LV1_id, vfatId, lsData, msData);
184 optoH->addVFAT(*vfat);
188 if (!optoH->vFATs()->empty()) {
190 optoH->setChamberHeader(optoH->vFATs()->size() * 3, gebId);
191 optoH->setChamberTrailer(LV1_id, BX_id, optoH->vFATs()->size() * 3);
196 if (!amc->gebs()->empty()) {
198 amc->setAMCheader1(amcSize, BX_id, LV1_id, amcNum);
199 amc->setAMCheader2(amcNum, OrN, 1);
200 amc->setGEMeventHeader(amc->gebs()->size(), 0);
201 amc13->addAMCpayload(*amc);
203 amc13->addAMCheader(amcSize, 0, amcNum, 0);
204 amc13EvtLength += amcSize + 1;
208 if (!amc13->getAMCpayloads()->empty()) {
212 uint8_t nAMC = amc13->getAMCpayloads()->size();
213 amc13->setAMC13Header(1, nAMC, OrN);
214 amc13->setAMC13Trailer(BX_id, LV1_id, BX_id);
216 uint32_t EvtLength = amc13EvtLength + 4;
217 amc13->setCDFTrailer(EvtLength);
223 for (
const auto& amc13e : amc13s) {
224 std::vector<uint64_t> words;
225 words.emplace_back(amc13e->getCDFHeader());
226 words.emplace_back(amc13e->getAMC13Header());
228 for (
const auto&
w : *amc13e->getAMCheaders())
229 words.emplace_back(
w);
231 for (
const auto&
amc : *amc13e->getAMCpayloads()) {
232 words.emplace_back(
amc.getAMCheader1());
233 words.emplace_back(
amc.getAMCheader2());
234 words.emplace_back(
amc.getGEMeventHeader());
236 for (
const auto& geb : *
amc.gebs()) {
237 words.emplace_back(geb.getChamberHeader());
239 for (
const auto& vfat : *geb.vFATs()) {
240 words.emplace_back(vfat.get_fw());
241 words.emplace_back(vfat.get_sw());
242 words.emplace_back(vfat.get_tw());
245 words.emplace_back(geb.getChamberTrailer());
248 words.emplace_back(
amc.getGEMeventTrailer());
249 words.emplace_back(
amc.getAMCTrailer());
252 words.emplace_back(amc13e->getAMC13Trailer());
253 words.emplace_back(amc13e->getCDFTrailer());
255 FEDRawData& fedRawData = fedRawDataCol->FEDData(amc13e->sourceId());
257 int dataSize = (words.size()) *
sizeof(
uint64_t);
258 fedRawData.
resize(dataSize);
261 for (
const auto&
word : words) {
264 LogDebug(
"GEMDigiToRawModule") <<
"fedId:" << amc13e->sourceId() <<
" words:" << words.size();
edm::ESGetToken< GEMeMap, GEMeMapRcd > gemEMapToken_
EventNumber_t event() const
edm::EDGetTokenT< GEMDigiCollection > digi_token
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
#define DEFINE_FWK_MODULE(type)
int bunchCrossing() const
Run const & getRun() const
static const int maxChan_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const uint16_t range(const Frame &aFrame)
bool getData(T &iHolder) const
void resize(size_t newsize)
GEMDigiToRawModule(const edm::ParameterSet &pset)
Constructor.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static const int maxAMCs_
static const int maxGEBs_
unsigned long long uint64_t
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
std::shared_ptr< GEMROMapping > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override