CMS 3D CMS Logo

RPCTwinMuxDigiToRaw.cc
Go to the documentation of this file.
2 
3 #include <cstdint>
4 #include <cstring>
5 #include <memory>
6 
16 
30 
32  : bx_min_(config.getParameter<int>("bxMin")),
33  bx_max_(config.getParameter<int>("bxMax")),
34  ignore_eod_(config.getParameter<bool>("ignoreEOD")),
35  event_type_(config.getParameter<int>("eventType")),
36  ufov_(config.getParameter<unsigned int>("uFOV")) {
37  produces<FEDRawDataCollection>();
38  digi_token_ = consumes<RPCDigiCollection>(config.getParameter<edm::InputTag>("inputTag"));
39 }
40 
42 
45  desc.add<edm::InputTag>("inputTag", edm::InputTag("simMuonRPCDigis", ""));
46  desc.add<int>("bxMin", -2);
47  desc.add<int>("bxMax", 2);
48  desc.add<bool>("ignoreEOD", true);
49  desc.add<int>("eventType", 1);
50  desc.add<unsigned int>("uFOV", 1);
51  descs.add("RPCTwinMuxDigiToRaw", desc);
52 }
53 
56  edm::ESHandle<RPCAMCLinkMap> es_tm_link_map;
57  setup.get<RPCTwinMuxLinkMapRcd>().get(es_tm_link_map);
58  fed_amcs_.clear();
59  for (auto const& tm_link : es_tm_link_map->getMap()) {
60  RPCAMCLink amc(tm_link.first);
61  amc.setAMCInput();
62  fed_amcs_[amc.getFED()].push_back(amc);
63  }
64  for (auto& fed_amcs : fed_amcs_) {
65  std::sort(fed_amcs.second.begin(), fed_amcs.second.end());
66  fed_amcs.second.erase(std::unique(fed_amcs.second.begin(), fed_amcs.second.end()), fed_amcs.second.end());
67  }
68  }
69 }
70 
72  // Get EventSetup Electronics Maps
75 
76  setup.get<RPCInverseTwinMuxLinkMapRcd>().get(es_tm_link_map_);
77  setup.get<RPCInverseLBLinkMapRcd>().get(es_lb_link_map);
78 
79  // Get Digi Collection
80  edm::Handle<RPCDigiCollection> digi_collection;
81  event.getByToken(digi_token_, digi_collection);
82 
83  // Create output
84  std::unique_ptr<FEDRawDataCollection> data_collection(new FEDRawDataCollection());
85 
86  std::map<RPCAMCLink, std::vector<std::pair<int, rpctwinmux::RPCRecord> > > amc_bx_tmrecord;
88  *es_tm_link_map_,
89  bx_min_,
90  bx_max_,
91  event.bunchCrossing(),
92  *digi_collection,
93  amc_bx_tmrecord,
94  ignore_eod_);
95 
96  std::map<int, FEDRawData> fed_data;
97  // Loop over the FEDs
98  for (std::pair<const int, std::vector<RPCAMCLink> > const& fed_amcs : fed_amcs_) {
99  FEDRawData& data = data_collection->FEDData(fed_amcs.first);
100  unsigned int size(0);
101 
102  // FED Header + BLOCK Header (1 word + 1 word)
103  data.resize((size + 2) * 8);
104  // FED Header
105  FEDHeader::set(data.data() + size * 8, event_type_, event.id().event(), event.bunchCrossing(), fed_amcs.first);
106  ++size;
107  // BLOCK Header
108  rpctwinmux::BlockHeader block_header(ufov_, fed_amcs.second.size(), event.eventAuxiliary().orbitNumber());
109  std::memcpy(data.data() + size * 8, &block_header.getRecord(), 8);
110  ++size;
111 
112  // BLOCK AMC Content - 1 word each
113  data.resize((size + fed_amcs.second.size()) * 8);
114  unsigned int block_content_size(0);
115  for (RPCAMCLink const& amc : fed_amcs.second) {
116  std::map<RPCAMCLink, std::vector<std::pair<int, rpctwinmux::RPCRecord> > >::const_iterator bx_tmrecord(
117  amc_bx_tmrecord.find(amc));
118  unsigned int block_amc_size(3 + 2 * (bx_tmrecord == amc_bx_tmrecord.end() ? 0 : bx_tmrecord->second.size()));
119  block_content_size += block_amc_size;
120  rpctwinmux::BlockAMCContent amc_content(
121  true, true, true, true, true, true, true, block_amc_size, 0, amc.getAMCNumber(), 0);
122  std::memcpy(data.data() + size * 8, &amc_content.getRecord(), 8);
123  ++size;
124  }
125 
126  // AMC Payload - 2 words header, 1 word trailer, 2 words per RPCRecord
127  data.resize((size + block_content_size) * 8);
128  for (RPCAMCLink const& amc : fed_amcs.second) {
129  // TwinMux Header
130  std::map<RPCAMCLink, std::vector<std::pair<int, rpctwinmux::RPCRecord> > >::const_iterator bx_tmrecord(
131  amc_bx_tmrecord.find(amc));
132  unsigned int block_amc_size(3 + 2 * (bx_tmrecord == amc_bx_tmrecord.end() ? 0 : bx_tmrecord->second.size()));
133 
134  rpctwinmux::TwinMuxHeader tm_header(amc.getAMCNumber(),
135  event.id().event(),
136  event.bunchCrossing(),
137  block_amc_size,
138  event.eventAuxiliary().orbitNumber(),
139  0);
140  tm_header.setRPCBXWindow(bx_min_, bx_min_);
141  std::memcpy(data.data() + size * 8, tm_header.getRecord(), 16);
142  size += 2;
143 
144  if (bx_tmrecord != amc_bx_tmrecord.end()) {
145  for (std::vector<std::pair<int, rpctwinmux::RPCRecord> >::const_iterator tmrecord = bx_tmrecord->second.begin();
146  tmrecord != bx_tmrecord->second.end();
147  ++tmrecord) {
148  std::memcpy(data.data() + size * 8, tmrecord->second.getRecord(), 16);
149  size += 2;
150  }
151  }
152 
153  rpctwinmux::TwinMuxTrailer tm_trailer(0x0, event.id().event(), 3 + 2 * block_amc_size);
154  std::memcpy(data.data() + size * 8, &tm_trailer.getRecord(), 8);
155  ++size;
156  // CRC32 not calculated (for now)
157  }
158 
159  // BLOCK Trailer + FED Trailer (1 word + 1 word)
160  data.resize((size + 2) * 8);
161  // BLOCK Trailer
162  rpctwinmux::BlockTrailer block_trailer(0x0, 0, event.id().event(), event.bunchCrossing());
163  std::memcpy(data.data() + size * 8, &block_trailer.getRecord(), 8);
164  ++size;
165  // CRC32 not calculated (for now)
166 
167  // FED Trailer
168  ++size;
169  FEDTrailer::set(data.data() + (size - 1) * 8, size, 0x0, 0, 0);
170  std::uint16_t crc(evf::compute_crc(data.data(), size * 8));
171  FEDTrailer::set(data.data() + (size - 1) * 8, size, crc, 0, 0);
172  }
173 
174  event.put(std::move(data_collection));
175 }
176 
ConfigurationDescriptions.h
RPCTwinMuxDigiToRaw::bx_min_
int bx_min_
Definition: RPCTwinMuxDigiToRaw.h:36
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
MessageLogger.h
rpctwinmux::TwinMuxTrailer
Definition: RPCTwinMuxRecord.h:250
rpctwinmux::TwinMuxHeader
Definition: RPCTwinMuxRecord.h:170
RPCTwinMuxDigiToRaw::bx_max_
int bx_max_
Definition: RPCTwinMuxDigiToRaw.h:36
RPCTwinMuxDigiToRaw::fed_amcs_
std::map< int, std::vector< RPCAMCLink > > fed_amcs_
Definition: RPCTwinMuxDigiToRaw.h:42
edm::Run
Definition: Run.h:45
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RPCTwinMuxDigiToRaw::ignore_eod_
bool ignore_eod_
Definition: RPCTwinMuxDigiToRaw.h:37
RPCTwinMuxDigiToRaw::produce
void produce(edm::Event &event, edm::EventSetup const &setup) override
Definition: RPCTwinMuxDigiToRaw.cc:71
FEDRawData.h
edm::Handle< RPCDigiCollection >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
RPCTwinMuxPacker.h
RPCTwinMuxDigiToRaw::digi_token_
edm::EDGetTokenT< RPCDigiCollection > digi_token_
Definition: RPCTwinMuxDigiToRaw.h:34
FEDRawData
Definition: FEDRawData.h:19
RPCTwinMuxDigiToRaw::es_tm_link_map_watcher_
edm::ESWatcher< RPCTwinMuxLinkMapRcd > es_tm_link_map_watcher_
Definition: RPCTwinMuxDigiToRaw.h:41
RPCTwinMuxRecord.h
RPCAMCLinkMap.h
config
Definition: config.py:1
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
RPCInverseLBLinkMapRcd.h
RPCTwinMuxDigiToRaw::event_type_
int event_type_
Definition: RPCTwinMuxDigiToRaw.h:38
RPCTwinMuxPacker::getRPCTwinMuxRecords
static void getRPCTwinMuxRecords(RPCInverseLBLinkMap const &lb_map, RPCInverseAMCLinkMap const &amc_map, int min_bx, int max_bx, unsigned int bcn, RPCDigiCollection const &digis, std::map< RPCAMCLink, std::vector< std::pair< int, rpctwinmux::RPCRecord > > > &amc_bx_tmrecord, bool ignore_eod=false)
Definition: RPCTwinMuxPacker.cc:6
edm::ESHandle< RPCAMCLinkMap >
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
ParameterSetDescription.h
RPCTwinMuxDigiToRaw::beginRun
void beginRun(edm::Run const &run, edm::EventSetup const &setup) override
Definition: RPCTwinMuxDigiToRaw.cc:54
RPCInverseLBLinkMap.h
evf::compute_crc
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
rpctwinmux::TwinMuxHeader::setRPCBXWindow
void setRPCBXWindow(int bx_min=10, int bx_max=5)
RPCTwinMuxDigiToRaw
Definition: RPCTwinMuxDigiToRaw.h:23
RPCTwinMuxDigiToRaw::~RPCTwinMuxDigiToRaw
~RPCTwinMuxDigiToRaw() override
Definition: RPCTwinMuxDigiToRaw.cc:41
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
RPCInverseTwinMuxLinkMapRcd.h
Event.h
createfilelist.int
int
Definition: createfilelist.py:10
FEDRawDataCollection.h
RPCInverseLBLinkMapRcd
Definition: RPCInverseLBLinkMapRcd.h:9
rpctwinmux::BlockTrailer
Definition: RPCTwinMuxRecord.h:69
edm::EventSetup
Definition: EventSetup.h:57
FEDTrailer::set
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:31
get
#define get
InputTag.h
RPCTwinMuxDigiToRaw::RPCTwinMuxDigiToRaw
RPCTwinMuxDigiToRaw(edm::ParameterSet const &config)
Definition: RPCTwinMuxDigiToRaw.cc:31
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
FEDHeader::set
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:25
RPCInverseTwinMuxLinkMapRcd
Definition: RPCInverseTwinMuxLinkMapRcd.h:9
RPCTwinMuxDigiToRaw.h
EventSetup.h
RPCDigiCollection.h
amc
Definition: AMCSpec.h:8
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
rpctwinmux::BlockAMCContent
Definition: RPCTwinMuxRecord.h:104
RPCInverseAMCLinkMap.h
RPCAMCLinkMap::getMap
map_type & getMap()
Definition: RPCAMCLinkMap.h:27
amc
double amc
Definition: hdecay.h:20
ParameterSet.h
event
Definition: event.py:1
RPCTwinMuxDigiToRaw::ufov_
unsigned int ufov_
Definition: RPCTwinMuxDigiToRaw.h:39
edm::Event
Definition: Event.h:73
RPCTwinMuxLinkMapRcd
Definition: RPCTwinMuxLinkMapRcd.h:6
FEDHeader.h
edm::InputTag
Definition: InputTag.h:15
RPCTwinMuxDigiToRaw::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descs)
Definition: RPCTwinMuxDigiToRaw.cc:43
rpctwinmux::BlockHeader
Definition: RPCTwinMuxRecord.h:38
CRC16.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
FEDTrailer.h