CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RPCUnpackingModule.cc
Go to the documentation of this file.
1 #include "RPCUnpackingModule.h"
13 //#include "FWCore/Framework/interface/ESHandle.h"
17 
22 
28 
29 #include <sstream>
30 #include <bitset>
31 
32 using namespace edm;
33 using namespace std;
34 using namespace rpcrawtodigi;
35 
36 typedef uint64_t Word64;
37 
39  : dataLabel_(pset.getParameter<edm::InputTag>("InputLabel")),
40  doSynchro_(pset.getParameter<bool>("doSynchro")),
41  eventCounter_(0),
42  theReadoutMappingToken(esConsumes<edm::Transition::BeginRun>()),
43  theCabling(nullptr) {
44  produces<RPCDigiCollection>();
45  produces<RPCRawDataCounts>();
46  if (doSynchro_)
47  produces<RPCRawSynchro::ProdItem>();
48  fedToken_ = consumes<FEDRawDataCollection>(dataLabel_);
49 }
50 
52 
55  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
56  desc.add<bool>("doSynchro", true);
57  descriptions.add("rpcUnpackingModule", desc);
58 }
59 
61  if (theRecordWatcher.check(es)) {
62  LogTrace("") << "record has CHANGED!!, (re)initialise readout map!";
63  delete theCabling;
65  theCabling = readoutMapping->convert();
67  LogTrace("") << " READOUT MAP VERSION: " << theCabling->version() << endl;
68  }
69 }
70 
73  eventCounter_++;
74  if (debug)
75  LogDebug("RPCUnpacker::produce") << "Beginning To Unpack Event: " << eventCounter_;
76 
77  Handle<FEDRawDataCollection> allFEDRawData;
78  ev.getByToken(fedToken_, allFEDRawData);
79 
80  auto producedRPCDigis = std::make_unique<RPCDigiCollection>();
81  auto producedRawDataCounts = std::make_unique<RPCRawDataCounts>();
82  std::unique_ptr<RPCRawSynchro::ProdItem> producedRawSynchoCounts;
83  if (doSynchro_)
84  producedRawSynchoCounts = std::make_unique<RPCRawSynchro::ProdItem>();
85 
86  int status = 0;
88  const FEDRawData& rawData = allFEDRawData->FEDData(fedId);
89  RPCRecordFormatter interpreter =
90  theCabling ? RPCRecordFormatter(fedId, &theReadoutMappingSearch) : RPCRecordFormatter(fedId, nullptr);
91  int triggerBX = 0;
92  unsigned int nWords = rawData.size() / sizeof(Word64);
93  if (nWords == 0)
94  continue;
95 
96  //
97  // check headers
98  //
99  const Word64* header = reinterpret_cast<const Word64*>(rawData.data());
100  header--;
101  bool moreHeaders = true;
102  while (moreHeaders) {
103  header++;
104  FEDHeader fedHeader(reinterpret_cast<const unsigned char*>(header));
105  if (!fedHeader.check()) {
106  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::HeaderCheckFail));
107  if (debug)
108  LogTrace("") << " ** PROBLEM **, header.check() failed, break";
109  break;
110  }
111  if (fedHeader.sourceID() != fedId) {
112  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::InconsitentFedId));
113  if (debug)
114  LogTrace("") << " ** PROBLEM **, fedHeader.sourceID() != fedId"
115  << "fedId = " << fedId << " sourceID=" << fedHeader.sourceID();
116  }
117  triggerBX = fedHeader.bxID();
118  moreHeaders = fedHeader.moreHeaders();
119  if (debug) {
120  stringstream str;
121  str << " header: " << *reinterpret_cast<const bitset<64>*>(header) << endl;
122  str << " header triggerType: " << fedHeader.triggerType() << endl;
123  str << " header lvl1ID: " << fedHeader.lvl1ID() << endl;
124  str << " header bxID: " << fedHeader.bxID() << endl;
125  str << " header sourceID: " << fedHeader.sourceID() << endl;
126  str << " header version: " << fedHeader.version() << endl;
127  LogTrace("") << str.str();
128  }
129  }
130 
131  //
132  // check trailers
133  //
134  const Word64* trailer = reinterpret_cast<const Word64*>(rawData.data()) + (nWords - 1);
135  trailer++;
136  bool moreTrailers = true;
137  while (moreTrailers) {
138  trailer--;
139  FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
140  if (!fedTrailer.check()) {
141  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::TrailerCheckFail));
142  if (debug)
143  LogTrace("") << " ** PROBLEM **, trailer.check() failed, break";
144  break;
145  }
146  if (fedTrailer.fragmentLength() != nWords) {
147  producedRawDataCounts->addReadoutError(fedId, ReadoutError(ReadoutError::InconsistentDataSize));
148  if (debug)
149  LogTrace("") << " ** PROBLEM **, fedTrailer.fragmentLength()!= nWords, break";
150  break;
151  }
152  moreTrailers = fedTrailer.moreTrailers();
153  if (debug) {
154  ostringstream str;
155  str << " trailer: " << *reinterpret_cast<const bitset<64>*>(trailer) << endl;
156  str << " trailer lenght: " << fedTrailer.fragmentLength() << endl;
157  str << " trailer crc: " << fedTrailer.crc() << endl;
158  str << " trailer evtStatus: " << fedTrailer.evtStatus() << endl;
159  str << " trailer ttsBits: " << fedTrailer.ttsBits() << endl;
160  LogTrace("") << str.str();
161  }
162  }
163 
164  //
165  // data records
166  //
167  if (debug) {
168  ostringstream str;
169  for (const Word64* word = header + 1; word != trailer; word++) {
170  str << " data: " << *reinterpret_cast<const bitset<64>*>(word) << endl;
171  }
172  LogTrace("") << str.str();
173  }
174  // if (triggerBX != 51) continue;
175  // if (triggerBX != 2316) continue;
176  EventRecords event(triggerBX);
177  for (const Word64* word = header + 1; word != trailer; word++) {
178  for (int iRecord = 1; iRecord <= 4; iRecord++) {
179  const DataRecord::Data* pRecord = reinterpret_cast<const DataRecord::Data*>(word + 1) - iRecord;
180  DataRecord record(*pRecord);
181  event.add(record);
182  if (debug) {
183  std::ostringstream str;
184  str << "record: " << record.print() << " hex: " << hex << *pRecord << dec;
185  str << " type:" << record.type() << DataRecord::print(record);
186  if (event.complete()) {
187  str << " --> dccId: " << fedId << " rmb: " << event.recordSLD().rmb()
188  << " lnk: " << event.recordSLD().tbLinkInputNumber() << " lb: " << event.recordCD().lbInLink()
189  << " part: " << event.recordCD().partitionNumber() << " data: " << event.recordCD().partitionData()
190  << " eod: " << event.recordCD().eod();
191  }
192  LogTrace("") << str.str();
193  }
194  producedRawDataCounts->addDccRecord(fedId, record);
195  int statusTMP = 0;
196  if (event.complete())
197  statusTMP = interpreter.recordUnpack(
198  event, producedRPCDigis.get(), producedRawDataCounts.get(), producedRawSynchoCounts.get());
199  if (statusTMP != 0)
200  status = statusTMP;
201  }
202  }
203  }
204  if (status && debug)
205  LogTrace("") << " RPCUnpackingModule - There was unpacking PROBLEM in this event" << endl;
206  if (debug)
207  LogTrace("") << DebugDigisPrintout()(producedRPCDigis.get()) << endl;
208  ev.put(std::move(producedRPCDigis));
209  ev.put(std::move(producedRawDataCounts));
210  if (doSynchro_)
211  ev.put(std::move(producedRawSynchoCounts));
212 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
RPCReadOutMappingWithFastSearch theReadoutMappingSearch
uint8_t triggerType() const
Event Trigger type identifier.
Definition: FEDHeader.cc:13
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
bool moreHeaders() const
Definition: FEDHeader.cc:23
bool check() const
Check that the header is OK.
Definition: FEDHeader.cc:44
static MessageDrop * instance()
Definition: MessageDrop.cc:33
list status
Definition: mps_update.py:107
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
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
#define LogTrace(id)
RPCUnpackingModule(const edm::ParameterSet &pset)
Constructor.
uint64_t word
const std::string & version() const
version as string
edm::ESGetToken< RPCEMap, RPCEMapRcd > theReadoutMappingToken
edm::InputTag dataLabel_
def move
Definition: eostools.py:511
void produce(edm::Event &ev, const edm::EventSetup &es) override
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Transition
Definition: Transition.h:12
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const RPCReadOutMapping * theCabling
~RPCUnpackingModule() override
Destructor.
uint64_t Word64
#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:57
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
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:168
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
#define str(s)
DataRecordType type() const
Definition: DataRecord.cc:13
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned long eventCounter_
edm::ESWatcher< RPCEMapRcd > theRecordWatcher
Definition: Run.h:45
cms_uint64_t Word64
#define LogDebug(id)