CMS 3D CMS Logo

RPCPackingModule.cc
Go to the documentation of this file.
2 
5 
9 
12 
15 
17 
21 
22 #include <string>
23 #include <sstream>
24 
25 using namespace std;
26 using namespace edm;
27 using namespace rpcrawtodigi;
28 
29 typedef uint64_t Word64;
30 
32  dataLabel_ = consumes<RPCDigiCollection>(pset.getParameter<edm::InputTag>("InputLabel"));
33  readoutMappingToken_ = esConsumes<RPCEMap, RPCEMapRcd>();
34  theCabling = new RPCReadOutMapping("");
35  produces<FEDRawDataCollection>();
36 }
37 
38 RPCPackingModule::~RPCPackingModule() { delete theCabling; }
39 
42  ev.getByToken(dataLabel_, digiCollection);
43  LogDebug("") << DebugDigisPrintout()(digiCollection.product());
44 
45  if (recordWatcher_.check(es)) {
46  delete theCabling;
47  LogTrace("") << "record has CHANGED!!, initialise readout map!";
48  ESHandle<RPCEMap> readoutMapping = es.getHandle(readoutMappingToken_);
49  theCabling = readoutMapping->convert();
50  LogTrace("") << " READOUT MAP VERSION: " << theCabling->version() << endl;
51  }
52 
53  auto buffers = std::make_unique<FEDRawDataCollection>();
54 
55  // pair<int,int> rpcFEDS=FEDNumbering::getRPCFEDIds();
56  pair<int, int> rpcFEDS(790, 792);
57  for (int id = rpcFEDS.first; id <= rpcFEDS.second; ++id) {
58  RPCRecordFormatter formatter(id, theCabling);
59  unsigned int lvl1_ID = ev.id().event();
60  FEDRawData* rawData = RPCPackingModule::rawData(id, lvl1_ID, digiCollection.product(), formatter);
61  FEDRawData& fedRawData = buffers->FEDData(id);
62 
64  delete rawData;
65  }
66  ev.put(std::move(buffers));
67 }
68 
70  unsigned int lvl1_ID,
71  const RPCDigiCollection* digis,
72  const RPCRecordFormatter& formatter) const {
73  //
74  // get merged records
75  //
76  int trigger_BX = 200; // FIXME - set event by event but correct bx assigment in digi
77  vector<EventRecords> merged = RPCPackingModule::eventRecords(fedId, trigger_BX, digis, formatter);
78 
79  //
80  // create data words
81  //
82  vector<Word64> dataWords;
84  typedef vector<EventRecords>::const_iterator IR;
85  for (IR ir = merged.begin(), irEnd = merged.end(); ir != irEnd; ++ir) {
86  Word64 w = (((Word64(ir->recordBX().data()) << 16) | ir->recordSLD().data()) << 16 | ir->recordCD().data()) << 16 |
87  empty.data();
88  dataWords.push_back(w);
89  }
90 
91  //
92  // create raw data
93  //
94  int nHeaders = 1;
95  int nTrailers = 1;
96  int dataSize = (nHeaders + nTrailers + dataWords.size()) * sizeof(Word64);
97  FEDRawData* raw = new FEDRawData(dataSize);
98 
99  //
100  // add header
101  //
102  unsigned char* pHeader = raw->data();
103  int evt_ty = 3;
104  int source_ID = fedId;
105  FEDHeader::set(pHeader, evt_ty, lvl1_ID, trigger_BX, source_ID);
106 
107  //
108  // add datawords
109  //
110  for (unsigned int idata = 0; idata < dataWords.size(); idata++) {
111  Word64* word = reinterpret_cast<Word64*>(pHeader + (idata + 1) * sizeof(Word64));
112  *word = dataWords[idata];
113  }
114 
115  //
116  // add trailer
117  //
118  unsigned char* pTrailer = pHeader + raw->size() - sizeof(Word64);
119  int crc = 0;
120  int evt_stat = 15;
121  int tts = 0;
122  int datasize = raw->size() / sizeof(Word64);
123  FEDTrailer::set(pTrailer, datasize, crc, evt_stat, tts);
124 
125  return raw;
126 }
127 
128 vector<EventRecords> RPCPackingModule::eventRecords(int fedId,
129  int trigger_BX,
130  const RPCDigiCollection* digis,
131  const RPCRecordFormatter& formatter) {
132  typedef DigiContainerIterator<RPCDetId, RPCDigi> DigiRangeIterator;
133  vector<EventRecords> dataRecords;
134 
135  LogDebug("RPCRawDataPacker") << "Packing Fed id=" << fedId;
136  for (DigiRangeIterator it = digis->begin(); it != digis->end(); it++) {
137  RPCDetId rpcDetId = (*it).first;
138  uint32_t rawDetId = rpcDetId.rawId();
139  RPCDigiCollection::Range range = digis->get(rpcDetId);
140  for (vector<RPCDigi>::const_iterator id = range.first; id != range.second; id++) {
141  const RPCDigi& digi = (*id);
142  vector<EventRecords> rawFromDigi = formatter.recordPack(rawDetId, digi, trigger_BX);
143  dataRecords.insert(dataRecords.end(), rawFromDigi.begin(), rawFromDigi.end());
144  }
145  }
146 
147  //
148  // merge data words
149  //
150  LogTrace("RPCRawDataPacker") << " size of data: " << dataRecords.size();
151  vector<EventRecords> merged = EventRecords::mergeRecords(dataRecords);
152  LogTrace("") << " size of megred: " << merged.size();
153 
154  return merged;
155 }
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
RPCRecordFormatter
Definition: RPCRecordFormatter.h:15
Handle.h
MessageLogger.h
RPCPackingModule::rawData
FEDRawData * rawData(int fedId, unsigned int lvl1_ID, const RPCDigiCollection *, const RPCRecordFormatter &) const
Definition: RPCPackingModule.cc:69
RPCReadOutMapping.h
ESHandle.h
RPCEMap::convert
RPCReadOutMapping const * convert() const
Definition: RPCEMap.h:64
RPCRecordFormatter.h
Word64
uint64_t Word64
Definition: RPCPackingModule.cc:29
edm
HLT enums.
Definition: AlignableModifier.h:19
RPCDetId
Definition: RPCDetId.h:16
l1tstage2_dqm_sourceclient-live_cfg.rawData
rawData
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:162
rpcrawtodigi::EmptyWord
Definition: EmptyWord.h:8
RPCPackingModule::produce
void produce(edm::Event &, const edm::EventSetup &) override
get data, convert to raw event, attach again to Event
Definition: RPCPackingModule.cc:40
edm::Handle< RPCDigiCollection >
rpcrawtodigi
Definition: DataRecord.h:9
DebugDigisPrintout.h
RPCRecordFormatter::recordPack
std::vector< rpcrawtodigi::EventRecords > recordPack(uint32_t rawDetId, const RPCDigi &digi, int trigger_BX) const
Definition: RPCRecordFormatter.cc:32
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
RPCDigiCollection
RPCPackingModule::RPCPackingModule
RPCPackingModule(const edm::ParameterSet &)
ctor
Definition: RPCPackingModule.cc:31
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
w
const double w
Definition: UKUtility.cc:23
edm::ESHandle
Definition: DTSurvey.h:22
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
RPCPackingModule::~RPCPackingModule
~RPCPackingModule() override
dtor
Definition: RPCPackingModule.cc:38
Word64
uint64_t Word64
Definition: RPCUnpackingModule.cc:38
FEDRawDataCollection.h
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
RPCReadOutMapping
Definition: RPCReadOutMapping.h:22
apvshotsanalyzer_cfi.digiCollection
digiCollection
Definition: apvshotsanalyzer_cfi.py:4
edm::EventSetup
Definition: EventSetup.h:58
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
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
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
RPCPackingModule.h
RPCDigi
Definition: RPCDigi.h:19
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
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
EventSetup.h
MuonDigiCollection< RPCDetId, RPCDigi >::Range
std::pair< const_iterator, const_iterator > Range
Definition: MuonDigiCollection.h:95
EmptyWord.h
rpcrawtodigi::DebugDigisPrintout
Definition: DebugDigisPrintout.h:11
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
RPCPackingModule::eventRecords
static std::vector< rpcrawtodigi::EventRecords > eventRecords(int fedId, int trigger_BX, const RPCDigiCollection *, const RPCRecordFormatter &)
Definition: RPCPackingModule.cc:128
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ParameterSet.h
DigiContainerIterator
Definition: MuonDigiCollection.h:30
edm::Event
Definition: Event.h:73
FEDHeader.h
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
FEDTrailer.h