CMS 3D CMS Logo

RPCUnpackingModule.cc
Go to the documentation of this file.
1 #include "RPCUnpackingModule.h"
13 //#include "FWCore/Framework/interface/ESHandle.h"
17 
22 
30 
31 #include <sstream>
32 #include <bitset>
33 
34 using namespace edm;
35 using namespace std;
36 using namespace rpcrawtodigi;
37 
38 typedef uint64_t Word64;
39 
41  : dataLabel_(pset.getParameter<edm::InputTag>("InputLabel")),
42  doSynchro_(pset.getParameter<bool>("doSynchro")),
43  eventCounter_(0),
44  theCabling(nullptr) {
45  produces<RPCDigiCollection>();
46  produces<RPCRawDataCounts>();
47  if (doSynchro_)
48  produces<RPCRawSynchro::ProdItem>();
49  fedToken_ = consumes<FEDRawDataCollection>(dataLabel_);
50 }
51 
53 
56  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
57  desc.add<bool>("doSynchro", true);
58  descriptions.add("rpcUnpackingModule", desc);
59 }
60 
62  if (theRecordWatcher.check(es)) {
63  LogTrace("") << "record has CHANGED!!, (re)initialise readout map!";
64  delete theCabling;
65  ESTransientHandle<RPCEMap> readoutMapping;
66  es.get<RPCEMapRcd>().get(readoutMapping);
67  theCabling = readoutMapping->convert();
69  LogTrace("") << " READOUT MAP VERSION: " << theCabling->version() << endl;
70  }
71 }
72 
75  eventCounter_++;
76  if (debug)
77  LogDebug("RPCUnpacker::produce") << "Beginning To Unpack Event: " << eventCounter_;
78 
79  Handle<FEDRawDataCollection> allFEDRawData;
80  ev.getByToken(fedToken_, allFEDRawData);
81 
82  auto producedRPCDigis = std::make_unique<RPCDigiCollection>();
83  auto producedRawDataCounts = std::make_unique<RPCRawDataCounts>();
84  std::unique_ptr<RPCRawSynchro::ProdItem> producedRawSynchoCounts;
85  if (doSynchro_)
86  producedRawSynchoCounts = std::make_unique<RPCRawSynchro::ProdItem>();
87 
88  int status = 0;
90  const FEDRawData& rawData = allFEDRawData->FEDData(fedId);
91  RPCRecordFormatter interpreter =
93  int triggerBX = 0;
94  unsigned int nWords = rawData.size() / sizeof(Word64);
95  if (nWords == 0)
96  continue;
97 
98  //
99  // check headers
100  //
101  const Word64* header = reinterpret_cast<const Word64*>(rawData.data());
102  header--;
103  bool moreHeaders = true;
104  while (moreHeaders) {
105  header++;
106  FEDHeader fedHeader(reinterpret_cast<const unsigned char*>(header));
107  if (!fedHeader.check()) {
108  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::HeaderCheckFail));
109  if (debug)
110  LogTrace("") << " ** PROBLEM **, header.check() failed, break";
111  break;
112  }
113  if (fedHeader.sourceID() != fedId) {
114  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::InconsitentFedId));
115  if (debug)
116  LogTrace("") << " ** PROBLEM **, fedHeader.sourceID() != fedId"
117  << "fedId = " << fedId << " sourceID=" << fedHeader.sourceID();
118  }
119  triggerBX = fedHeader.bxID();
120  moreHeaders = fedHeader.moreHeaders();
121  if (debug) {
122  stringstream str;
123  str << " header: " << *reinterpret_cast<const bitset<64>*>(header) << endl;
124  str << " header triggerType: " << fedHeader.triggerType() << endl;
125  str << " header lvl1ID: " << fedHeader.lvl1ID() << endl;
126  str << " header bxID: " << fedHeader.bxID() << endl;
127  str << " header sourceID: " << fedHeader.sourceID() << endl;
128  str << " header version: " << fedHeader.version() << endl;
129  LogTrace("") << str.str();
130  }
131  }
132 
133  //
134  // check trailers
135  //
136  const Word64* trailer = reinterpret_cast<const Word64*>(rawData.data()) + (nWords - 1);
137  trailer++;
138  bool moreTrailers = true;
139  while (moreTrailers) {
140  trailer--;
141  FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
142  if (!fedTrailer.check()) {
143  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::TrailerCheckFail));
144  if (debug)
145  LogTrace("") << " ** PROBLEM **, trailer.check() failed, break";
146  break;
147  }
148  if (fedTrailer.fragmentLength() != nWords) {
149  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::InconsistentDataSize));
150  if (debug)
151  LogTrace("") << " ** PROBLEM **, fedTrailer.fragmentLength()!= nWords, break";
152  break;
153  }
154  moreTrailers = fedTrailer.moreTrailers();
155  if (debug) {
156  ostringstream str;
157  str << " trailer: " << *reinterpret_cast<const bitset<64>*>(trailer) << endl;
158  str << " trailer lenght: " << fedTrailer.fragmentLength() << endl;
159  str << " trailer crc: " << fedTrailer.crc() << endl;
160  str << " trailer evtStatus: " << fedTrailer.evtStatus() << endl;
161  str << " trailer ttsBits: " << fedTrailer.ttsBits() << endl;
162  LogTrace("") << str.str();
163  }
164  }
165 
166  //
167  // data records
168  //
169  if (debug) {
170  ostringstream str;
171  for (const Word64* word = header + 1; word != trailer; word++) {
172  str << " data: " << *reinterpret_cast<const bitset<64>*>(word) << endl;
173  }
174  LogTrace("") << str.str();
175  }
176  // if (triggerBX != 51) continue;
177  // if (triggerBX != 2316) continue;
178  EventRecords event(triggerBX);
179  for (const Word64* word = header + 1; word != trailer; word++) {
180  for (int iRecord = 1; iRecord <= 4; iRecord++) {
181  const DataRecord::Data* pRecord = reinterpret_cast<const DataRecord::Data*>(word + 1) - iRecord;
182  DataRecord record(*pRecord);
183  event.add(record);
184  if (debug) {
185  std::ostringstream str;
186  str << "record: " << record.print() << " hex: " << hex << *pRecord << dec;
187  str << " type:" << record.type() << DataRecord::print(record);
188  if (event.complete()) {
189  str << " --> dccId: " << fedId << " rmb: " << event.recordSLD().rmb()
190  << " lnk: " << event.recordSLD().tbLinkInputNumber() << " lb: " << event.recordCD().lbInLink()
191  << " part: " << event.recordCD().partitionNumber() << " data: " << event.recordCD().partitionData()
192  << " eod: " << event.recordCD().eod();
193  }
194  LogTrace("") << str.str();
195  }
196  producedRawDataCounts->addDccRecord(fedId, record);
197  int statusTMP = 0;
198  if (event.complete())
199  statusTMP = interpreter.recordUnpack(
200  event, producedRPCDigis.get(), producedRawDataCounts.get(), producedRawSynchoCounts.get());
201  if (statusTMP != 0)
202  status = statusTMP;
203  }
204  }
205  }
206  if (status && debug)
207  LogTrace("") << " RPCUnpackingModule - There was unpacking PROBLEM in this event" << endl;
208  if (debug)
209  LogTrace("") << DebugDigisPrintout()(producedRPCDigis.get()) << endl;
210  ev.put(std::move(producedRPCDigis));
211  ev.put(std::move(producedRawDataCounts));
212  if (doSynchro_)
213  ev.put(std::move(producedRawSynchoCounts));
214 }
ConfigurationDescriptions.h
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
FEDNumbering.h
RPCRecordFormatter
Definition: RPCRecordFormatter.h:15
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
RPCUnpackingModule::eventCounter_
unsigned long eventCounter_
Definition: RPCUnpackingModule.h:42
ESTransientHandle.h
MessageLogger.h
RPCReadOutMapping.h
FEDHeader::moreHeaders
bool moreHeaders() const
Definition: FEDHeader.cc:23
rpcrawtodigi::DataRecord
Definition: DataRecord.h:10
RPCEMap::convert
RPCReadOutMapping const * convert() const
Definition: RPCEMap.h:64
RPCRecordFormatter.h
mps_update.status
status
Definition: mps_update.py:69
edm::Run
Definition: Run.h:45
edm::MessageDrop::debugEnabled
bool debugEnabled
Definition: MessageDrop.h:103
edm
HLT enums.
Definition: AlignableModifier.h:19
FEDTrailer::crc
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:15
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
l1tstage2_dqm_sourceclient-live_cfg.rawData
rawData
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:156
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
FEDHeader::version
uint8_t version() const
Version identifier of the FED data format.
Definition: FEDHeader.cc:21
RPCUnpackingModule::doSynchro_
bool doSynchro_
Definition: RPCUnpackingModule.h:41
RPCUnpackingModule::theRecordWatcher
edm::ESWatcher< RPCEMapRcd > theRecordWatcher
Definition: RPCUnpackingModule.h:44
rpcrawtodigi::ReadoutError
Definition: ReadoutError.h:8
FEDTrailer::evtStatus
uint8_t evtStatus() const
Event fragment status information.
Definition: FEDTrailer.cc:17
RPCRecordFormatter::recordUnpack
int recordUnpack(const rpcrawtodigi::EventRecords &event, RPCDigiCollection *prod, RPCRawDataCounts *counter, RPCRawSynchro::ProdItem *synchro)
Definition: RPCRecordFormatter.cc:74
FEDHeader::lvl1ID
uint32_t lvl1ID() const
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:15
FEDRawData.h
edm::Handle
Definition: AssociativeIterator.h:50
rpcrawtodigi
Definition: DataRecord.h:9
DebugDigisPrintout.h
FEDNumbering::MINRPCFEDID
Definition: FEDNumbering.h:59
RPCReadOutMapping::version
const std::string & version() const
version as string
Definition: RPCReadOutMapping.h:43
RPCEMapRcd.h
RPCUnpackingModule::produce
void produce(edm::Event &ev, const edm::EventSetup &es) override
Definition: RPCUnpackingModule.cc:73
FEDRawData
Definition: FEDRawData.h:19
FEDTrailer::check
bool check() const
Check that the trailer is OK.
Definition: FEDTrailer.cc:45
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
debug
#define debug
Definition: HDRShower.cc:19
RPCUnpackingModule::theReadoutMappingSearch
RPCReadOutMappingWithFastSearch theReadoutMappingSearch
Definition: RPCUnpackingModule.h:46
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
RPCReadOutMappingWithFastSearch::init
void init(const RPCReadOutMapping *arm)
takes ownership of map
Definition: RPCReadOutMappingWithFastSearch.cc:30
RPCUnpackingModule::~RPCUnpackingModule
~RPCUnpackingModule() override
Destructor.
Definition: RPCUnpackingModule.cc:52
RPCRawDataCounts.h
str
#define str(s)
Definition: TestProcessor.cc:48
ParameterSetDescription.h
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
rpcrawtodigi::DataRecord::Data
uint16_t Data
Definition: DataRecord.h:12
RPCUnpackingModule::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: RPCUnpackingModule.cc:54
ReadoutError.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
FEDTrailer
Definition: FEDTrailer.h:14
RPCUnpackingModule::RPCUnpackingModule
RPCUnpackingModule(const edm::ParameterSet &pset)
Constructor.
Definition: RPCUnpackingModule.cc:40
Event.h
FEDHeader::triggerType
uint8_t triggerType() const
Event Trigger type identifier.
Definition: FEDHeader.cc:13
rpcrawtodigi::EventRecords
Definition: EventRecords.h:11
Word64
uint64_t Word64
Definition: RPCUnpackingModule.cc:38
FEDTrailer::moreTrailers
bool moreTrailers() const
Definition: FEDTrailer.cc:21
FEDRawDataCollection.h
RPCUnpackingModule::dataLabel_
edm::InputTag dataLabel_
Definition: RPCUnpackingModule.h:40
edm::EventSetup
Definition: EventSetup.h:57
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:82
get
#define get
RPCEMapRcd
Definition: RPCEMapRcd.h:5
RPCUnpackingModule::fedToken_
edm::EDGetTokenT< FEDRawDataCollection > fedToken_
Definition: RPCUnpackingModule.h:47
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
FEDHeader::bxID
uint16_t bxID() const
The bunch crossing number.
Definition: FEDHeader.cc:17
edm::ESTransientHandle
Definition: ESTransientHandle.h:41
RPCUnpackingModule.h
RPCUnpackingModule::theCabling
const RPCReadOutMapping * theCabling
Definition: RPCUnpackingModule.h:45
DataRecord.h
RPCRawSynchro.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
ESWatcher.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
edm::MessageDrop::instance
static MessageDrop * instance()
Definition: MessageDrop.cc:60
EventSetup.h
RPCDigiCollection.h
FEDHeader::check
bool check() const
Check that the header is OK.
Definition: FEDHeader.cc:44
RPCUnpackingModule::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: RPCUnpackingModule.cc:61
FEDHeader::sourceID
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:19
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:292
rpcrawtodigi::DebugDigisPrintout
Definition: DebugDigisPrintout.h:11
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
FEDNumbering::MAXRPCFEDID
Definition: FEDNumbering.h:60
RPCEMap.h
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
ParameterSet.h
EventRecords.h
FEDTrailer::ttsBits
uint8_t ttsBits() const
Current value of the Trigger Throttling System bits.
Definition: FEDTrailer.cc:19
event
Definition: event.py:1
FEDHeader
Definition: FEDHeader.h:14
edm::Event
Definition: Event.h:73
FEDHeader.h
event
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of "!*" before the partial wildcard feature was incorporated). The per-event "cost" of each negative criterion with multiple relevant triggers is about the same as ! *was in the past
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
FEDTrailer::fragmentLength
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:13
FEDTrailer.h