55 : event_type_(
pset.getParameter<
int>(
"eventType")),
56 minBunch_(
pset.getParameter<
int>(
"minBunch")),
57 maxBunch_(
pset.getParameter<
int>(
"maxBunch")),
59 useDBEMap_(
pset.getParameter<
bool>(
"useDBEMap")),
60 simulatePulseStretching_(
pset.getParameter<
bool>(
"simulatePulseStretching")) {
61 produces<FEDRawDataCollection>();
63 gemChMapToken_ = esConsumes<GEMChMap, GEMChMapRcd, edm::Transition::BeginRun>();
70 desc.add<
int>(
"eventType", 0);
73 desc.add<
int>(
"minBunch", -3);
74 desc.add<
int>(
"maxBunch", 4);
76 desc.add<
bool>(
"useDBEMap",
false);
77 desc.add<
bool>(
"simulatePulseStretching",
false);
78 descriptions.
add(
"gemPackerDefault",
desc);
84 auto gemChMap = std::make_shared<GEMChMap>(eMap);
88 auto gemChMap = std::make_shared<GEMChMap>();
95 auto fedRawDataCol = std::make_unique<FEDRawDataCollection>();
99 if (!gemDigis.isValid()) {
104 auto gemChMap = runCache(
iEvent.getRun().index());
106 std::vector<std::unique_ptr<GEMAMC13>> amc13s;
109 int LV1_id =
iEvent.id().event();
110 uint8_t BX_id(
iEvent.bunchCrossing());
111 int OrN =
iEvent.orbitNumber();
115 std::map<int, GEMDigiCollection> gemBxMap;
116 for (
auto const& etaPart : *gemDigis) {
119 for (
auto digi = digis.first; digi != digis.second; ++digi) {
128 if (
search != gemBxMap.end()) {
129 search->second.insertDigi(gemId, *digi);
132 newGDC.insertDigi(gemId, *digi);
133 gemBxMap.insert(std::pair<int, GEMDigiCollection>(
bx, newGDC));
139 uint32_t amc13EvtLength = 0;
140 std::unique_ptr<GEMAMC13>
amc13 = std::make_unique<GEMAMC13>();
143 uint32_t amcSize = 0;
144 std::unique_ptr<GEMAMC>
amc = std::make_unique<GEMAMC>();
147 std::unique_ptr<GEMOptoHybrid> optoH = std::make_unique<GEMOptoHybrid>();
149 if (!gemChMap->isValidChamber(
fedId, amcNum, gebId))
152 auto geb_dc = gemChMap->chamberPos(
fedId, amcNum, gebId);
158 for (
auto vfatId : vfats) {
159 auto iEtas = gemChMap->getIEtas(
chamberType, vfatId);
160 for (
auto iEta : iEtas) {
163 for (
auto const& gemBx : gemBxMap) {
164 int bc = BX_id + gemBx.first;
166 bool hasDigi =
false;
174 const GEMDigi& digi = (*digiIt);
184 if (chMap.vfatAdd != vfatId)
187 if (chMap.chNum < 64)
188 lsData |= 1UL << chMap.chNum;
190 msData |= 1UL << (chMap.chNum - 64);
193 <<
"fed: " <<
fedId <<
" amc:" <<
int(amcNum) <<
" geb:" <<
int(gebId) <<
" vfat id:" <<
int(vfatId)
194 <<
",type:" <<
chamberType <<
" id:" << gemId <<
" ch:" << chMap.chNum <<
" st:" << digi.
strip()
195 <<
" bx:" << digi.
bx();
203 auto vfat = std::make_unique<GEMVFAT>(vfatVersion, bc, LV1_id, vfatId, lsData, msData);
204 optoH->addVFAT(*vfat);
209 if (!optoH->vFATs()->empty()) {
211 optoH->setChamberHeader(optoH->vFATs()->size() * 3, gebId);
212 optoH->setChamberTrailer(LV1_id, BX_id, optoH->vFATs()->size() * 3);
217 if (!
amc->gebs()->empty()) {
219 amc->setAMCheader1(amcSize, BX_id, LV1_id, amcNum);
220 amc->setAMCheader2(amcNum, OrN, 1);
221 amc->setGEMeventHeader(
amc->gebs()->size(), 0);
224 amc13->addAMCheader(amcSize, 0, amcNum, 0);
225 amc13EvtLength += amcSize + 1;
229 if (!
amc13->getAMCpayloads()->empty()) {
233 uint8_t nAMC =
amc13->getAMCpayloads()->size();
234 amc13->setAMC13Header(1, nAMC, OrN);
235 amc13->setAMC13Trailer(BX_id, LV1_id, BX_id);
237 uint32_t EvtLength = amc13EvtLength + 4;
238 amc13->setCDFTrailer(EvtLength);
244 for (
const auto& amc13e : amc13s) {
245 std::vector<uint64_t> words;
246 words.emplace_back(amc13e->getCDFHeader());
247 words.emplace_back(amc13e->getAMC13Header());
249 for (
const auto&
w : *amc13e->getAMCheaders())
250 words.emplace_back(
w);
252 for (
const auto&
amc : *amc13e->getAMCpayloads()) {
253 words.emplace_back(
amc.getAMCheader1());
254 words.emplace_back(
amc.getAMCheader2());
255 words.emplace_back(
amc.getGEMeventHeader());
257 for (
const auto& geb : *
amc.gebs()) {
258 words.emplace_back(geb.getChamberHeader());
260 for (
const auto& vfat : *geb.vFATs()) {
261 words.emplace_back(vfat.get_fw());
262 words.emplace_back(vfat.get_sw());
263 words.emplace_back(vfat.get_tw());
266 words.emplace_back(geb.getChamberTrailer());
269 words.emplace_back(
amc.getGEMeventTrailer());
270 words.emplace_back(
amc.getAMCTrailer());
273 words.emplace_back(amc13e->getAMC13Trailer());
274 words.emplace_back(amc13e->getCDFTrailer());
278 int dataSize = (words.size()) *
sizeof(
uint64_t);
282 for (
const auto&
word : words) {
285 LogDebug(
"GEMDigiToRawModule") <<
"fedId:" << amc13e->sourceId() <<
" words:" << words.size();
constexpr int station() const
constexpr int region() const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
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_
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
#define DEFINE_FWK_MODULE(type)
GEMDigiToRawModule(const edm::ParameterSet &pset)
Constructor.
static const int maxGEBs_
const bool simulatePulseStretching_
const edm::EDGetTokenT< GEMDigiCollection > digiToken_
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_