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 =
92  theCabling ? RPCRecordFormatter(fedId, &theReadoutMappingSearch) : RPCRecordFormatter(fedId, nullptr);
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 }
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
RPCReadOutMappingWithFastSearch theReadoutMappingSearch
uint8_t triggerType() const
Event Trigger type identifier.
Definition: FEDHeader.cc:13
JetCorrectorParameters::Record record
Definition: classes.h:7
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
bool moreHeaders() const
Definition: FEDHeader.cc:23
bool check() const
Check that the header is OK.
Definition: FEDHeader.cc:44
#define nullptr
static MessageDrop * instance()
Definition: MessageDrop.cc:59
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:19
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:15
bool check() const
Check that the trailer is OK.
Definition: FEDTrailer.cc:45
bool ev
bool moreTrailers() const
Definition: FEDTrailer.cc:21
uint8_t version() const
Version identifier of the FED data format.
Definition: FEDHeader.cc:21
void init(const RPCReadOutMapping *arm)
takes ownership of map
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:13
RPCUnpackingModule(const edm::ParameterSet &pset)
Constructor.
uint64_t word
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const std::string & version() const
version as string
edm::InputTag dataLabel_
void produce(edm::Event &ev, const edm::EventSetup &es) override
uint64_t Word64
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
const RPCReadOutMapping * theCabling
#define LogTrace(id)
~RPCUnpackingModule() override
Destructor.
#define debug
Definition: HDRShower.cc:19
uint8_t ttsBits() const
Current value of the Trigger Throttling System bits.
Definition: FEDTrailer.cc:19
unsigned long long uint64_t
Definition: Time.h:13
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
uint8_t evtStatus() const
Event fragment status information.
Definition: FEDTrailer.cc:17
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
int recordUnpack(const rpcrawtodigi::EventRecords &event, RPCDigiCollection *prod, RPCRawDataCounts *counter, RPCRawSynchro::ProdItem *synchro)
uint16_t bxID() const
The bunch crossing number.
Definition: FEDHeader.cc:17
edm::EDGetTokenT< FEDRawDataCollection > fedToken_
std::string print() const
Definition: DataRecord.h:37
HLT enums.
T get() const
Definition: EventSetup.h:73
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
uint32_t lvl1ID() const
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:15
RPCReadOutMapping const * convert() const
Definition: RPCEMap.h:64
#define str(s)
DataRecordType type() const
Definition: DataRecord.cc:13
unsigned long eventCounter_
def move(src, dest)
Definition: eostools.py:511
edm::ESWatcher< RPCEMapRcd > theRecordWatcher
Definition: Run.h:45