52 : event_type_(
pset.getParameter<
int>(
"eventType")),
54 useDBEMap_(
pset.getParameter<
bool>(
"useDBEMap")) {
55 produces<FEDRawDataCollection>();
57 gemChMapToken_ = esConsumes<GEMChMap, GEMChMapRcd, edm::Transition::BeginRun>();
64 desc.add<
int>(
"eventType", 0);
65 desc.add<
bool>(
"useDBEMap",
false);
66 descriptions.
add(
"gemPackerDefault",
desc);
72 auto gemChMap = std::make_shared<GEMChMap>(eMap);
76 auto gemChMap = std::make_shared<GEMChMap>();
83 auto fedRawDataCol = std::make_unique<FEDRawDataCollection>();
87 if (!gemDigis.isValid()) {
92 auto gemChMap = runCache(
iEvent.getRun().index());
94 std::vector<std::unique_ptr<GEMAMC13>> amc13s;
97 int LV1_id =
iEvent.id().event();
98 uint8_t BX_id(
iEvent.bunchCrossing());
99 int OrN =
iEvent.orbitNumber();
103 std::map<int, GEMDigiCollection> gemBxMap;
104 for (
auto const& etaPart : *gemDigis) {
107 for (
auto digi = digis.first; digi != digis.second; ++digi) {
110 if (
search != gemBxMap.end()) {
111 search->second.insertDigi(gemId, *digi);
114 newGDC.insertDigi(gemId, *digi);
115 gemBxMap.insert(std::pair<int, GEMDigiCollection>(
bx, newGDC));
121 uint32_t amc13EvtLength = 0;
122 std::unique_ptr<GEMAMC13>
amc13 = std::make_unique<GEMAMC13>();
125 uint32_t amcSize = 0;
126 std::unique_ptr<GEMAMC>
amc = std::make_unique<GEMAMC>();
129 std::unique_ptr<GEMOptoHybrid> optoH = std::make_unique<GEMOptoHybrid>();
131 if (!gemChMap->isValidChamber(
fedId, amcNum, gebId))
134 auto geb_dc = gemChMap->chamberPos(
fedId, amcNum, gebId);
136 int chamberType = geb_dc.chamberType;
138 auto vfats = gemChMap->getVfats(chamberType);
140 for (
auto vfatId : vfats) {
141 auto iEtas = gemChMap->getIEtas(chamberType, vfatId);
142 for (
auto iEta : iEtas) {
145 for (
auto const& gemBx : gemBxMap) {
146 int bc = BX_id + gemBx.first;
148 bool hasDigi =
false;
156 const GEMDigi& digi = (*digiIt);
162 if (!gemChMap->isValidStrip(chamberType,
iEta,
strip))
164 auto chMap = gemChMap->getChannel(chamberType,
iEta,
strip);
166 if (chMap.vfatAdd != vfatId)
169 if (chMap.chNum < 64)
170 lsData |= 1UL << chMap.chNum;
172 msData |= 1UL << (chMap.chNum - 64);
175 <<
"fed: " <<
fedId <<
" amc:" <<
int(amcNum) <<
" geb:" <<
int(gebId) <<
" vfat id:" <<
int(vfatId)
176 <<
",type:" << chamberType <<
" id:" << gemId <<
" ch:" << chMap.chNum <<
" st:" << digi.
strip()
177 <<
" bx:" << digi.
bx();
184 int vfatVersion = (chamberType < 10) ? 2 : 3;
185 auto vfat = std::make_unique<GEMVFAT>(vfatVersion, bc, LV1_id, vfatId, lsData, msData);
186 optoH->addVFAT(*vfat);
191 if (!optoH->vFATs()->empty()) {
193 optoH->setChamberHeader(optoH->vFATs()->size() * 3, gebId);
194 optoH->setChamberTrailer(LV1_id, BX_id, optoH->vFATs()->size() * 3);
199 if (!
amc->gebs()->empty()) {
201 amc->setAMCheader1(amcSize, BX_id, LV1_id, amcNum);
202 amc->setAMCheader2(amcNum, OrN, 1);
203 amc->setGEMeventHeader(
amc->gebs()->size(), 0);
206 amc13->addAMCheader(amcSize, 0, amcNum, 0);
207 amc13EvtLength += amcSize + 1;
211 if (!
amc13->getAMCpayloads()->empty()) {
215 uint8_t nAMC =
amc13->getAMCpayloads()->size();
216 amc13->setAMC13Header(1, nAMC, OrN);
217 amc13->setAMC13Trailer(BX_id, LV1_id, BX_id);
219 uint32_t EvtLength = amc13EvtLength + 4;
220 amc13->setCDFTrailer(EvtLength);
226 for (
const auto& amc13e : amc13s) {
227 std::vector<uint64_t> words;
228 words.emplace_back(amc13e->getCDFHeader());
229 words.emplace_back(amc13e->getAMC13Header());
231 for (
const auto&
w : *amc13e->getAMCheaders())
232 words.emplace_back(
w);
234 for (
const auto&
amc : *amc13e->getAMCpayloads()) {
235 words.emplace_back(
amc.getAMCheader1());
236 words.emplace_back(
amc.getAMCheader2());
237 words.emplace_back(
amc.getGEMeventHeader());
239 for (
const auto& geb : *
amc.gebs()) {
240 words.emplace_back(geb.getChamberHeader());
242 for (
const auto& vfat : *geb.vFATs()) {
243 words.emplace_back(vfat.get_fw());
244 words.emplace_back(vfat.get_sw());
245 words.emplace_back(vfat.get_tw());
248 words.emplace_back(geb.getChamberTrailer());
251 words.emplace_back(
amc.getGEMeventTrailer());
252 words.emplace_back(
amc.getAMCTrailer());
255 words.emplace_back(amc13e->getAMC13Trailer());
256 words.emplace_back(amc13e->getCDFTrailer());
260 int dataSize = (words.size()) *
sizeof(
uint64_t);
264 for (
const auto&
word : words) {
267 LogDebug(
"GEMDigiToRawModule") <<
"fedId:" << amc13e->sourceId() <<
" words:" << words.size();
edm::EDGetTokenT< GEMDigiCollection > digi_token
constexpr int station() const
constexpr int region() const
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
edm::ESGetToken< GEMChMap, GEMChMapRcd > gemChMapToken_
#define DEFINE_FWK_MODULE(type)
constexpr int layer() const
constexpr int chamber() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::shared_ptr< GEMChMap > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
constexpr int ring() const
bool getData(T &iHolder) const
GEMDigiToRawModule(const edm::ParameterSet &pset)
Constructor.
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
static const int maxAMCs_