CMS 3D CMS Logo

OmtfUnpacker.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <iomanip>
4 #include <sstream>
5 #include <bitset>
6 #include <string>
7 
8 // user include files
14 
18 
24 
27 
34 
40 
45 
46 namespace omtf {
47 
49 public:
50 
52 
53  ~OmtfUnpacker() override {}
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57  void produce(edm::Event & ev, const edm::EventSetup& es) override;
58 
59  void beginRun(const edm::Run &run, const edm::EventSetup& es) override;
60 
61 private:
62 
63  unsigned long theEventCounter;
64 
66 
71 
74 
76 };
77 
78 
80  theOutputTag = pset.getParameter<std::string>("outputTag");
81 
82  produces<RPCDigiCollection>(theOutputTag);
83  produces<CSCCorrelatedLCTDigiCollection>(theOutputTag);
84  produces<l1t::RegionalMuonCandBxCollection >(theOutputTag);
85  produces<L1MuDTChambPhContainer>(theOutputTag);
86  produces<L1MuDTChambThContainer>(theOutputTag);
87 
88  theSkipDt = pset.getParameter<bool>("skipDt");
89  theSkipRpc = pset.getParameter<bool>("skipRpc");
90  theSkipCsc = pset.getParameter<bool>("skipCsc");
91  theSkipMuon = pset.getParameter<bool>("skipMuon");
92 
93  theFedDataToken = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("inputLabel"));
94 }
95 
98  desc.add<edm::InputTag>("inputLabel",edm::InputTag("rawDataCollector"));
99  desc.add<bool>("skipRpc",false);
100  desc.add<bool>("skipCsc",false);
101  desc.add<bool>("skipDt",false);
102  desc.add<bool>("skipMuon",false);
103  desc.add<bool>("useRpcConnectionFile",false);
104  desc.add<std::string>("rpcConnectionFile","");
105  desc.add<std::string>("outputTag","");
106  descriptions.add("omtfUnpacker",desc);
107 }
108 
109 
111 
112  //
113  // rpc unpacker
114  //
115  if (!theSkipRpc) {
116  if (theConfig.getParameter<bool>("useRpcConnectionFile")) {
118  } else {
119  theRpcUnpacker.init(es);
120  }
121  }
122 
123 
124  //
125  // csc unpacker
126  //
128 
129 }
130 
131 
133 {
134 
136  theEventCounter++;
137  if (debug) LogDebug ("OmtfUnpacker::produce") <<"Beginning To Unpack Event: "<<theEventCounter;
138 
139  edm::Handle<FEDRawDataCollection> allFEDRawData;
140  event.getByToken(theFedDataToken,allFEDRawData);
141 
142  auto producedRPCDigis = std::make_unique<RPCDigiCollection>();
143  auto producedCscLctDigis = std::make_unique<CSCCorrelatedLCTDigiCollection>();
144  auto producedMuonDigis = std::make_unique<l1t::RegionalMuonCandBxCollection>();
145  producedMuonDigis->setBXRange(-3,4);
146  auto producedDTPhDigis = std::make_unique<L1MuDTChambPhContainer>();
147  auto producedDTThDigis = std::make_unique<L1MuDTChambThContainer>();
148  std::vector<L1MuDTChambPhDigi> phi_Container;
149  std::vector<L1MuDTChambThDigi> the_Container;
150 
151  for (int fedId= 1380; fedId<= 1381; ++fedId) {
152 
153  const FEDRawData & rawData = allFEDRawData->FEDData(fedId);
154  unsigned int nWords = rawData.size()/sizeof(Word64);
155  LogTrace("") <<"FED : " << fedId <<" words: " << nWords;
156  if (nWords==0) continue;
157 
158  //
159  // FED header
160  //
161  const Word64* header = reinterpret_cast<const Word64* >(rawData.data());
162  FEDHeader fedHeader( reinterpret_cast<const unsigned char*>(header));
163  if (!fedHeader.check()) { LogTrace("") <<" ** PROBLEM **, header.check() failed, break"; break; }
164  if ( fedHeader.sourceID() != fedId) {
165  LogTrace("") <<" ** PROBLEM **, fedHeader.sourceID() != fedId"
166  << "fedId = " << fedId<<" sourceID="<<fedHeader.sourceID();
167  }
168  int triggerBX = fedHeader.bxID();
169  if (debug) {
170  std::ostringstream str;
171  str <<" header: "<< *reinterpret_cast<const std::bitset<64>*> (header) << std::endl;
172  str <<" header triggerType: " << fedHeader.triggerType()<< std::endl;
173  str <<" header lvl1ID: " << fedHeader.lvl1ID() << std::endl;
174  str <<" header bxID: " << fedHeader.bxID() << std::endl;
175  str <<" header sourceID: " << fedHeader.sourceID() << std::endl;
176  str <<" header version: " << fedHeader.version() << std::endl;
177  str <<" header more : " << fedHeader.moreHeaders() << std::endl;
178  str << " triggerBx "<< triggerBX << std::endl;
179  LogTrace("") << str.str();
180  }
181 
182  //
183  // FED trailer
184  //
185  const Word64* trailer=reinterpret_cast<const Word64* >(rawData.data())+(nWords-1); trailer++;
186  bool moreTrailers = true;
187  while (moreTrailers) {
188  trailer--;
189  FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
190  if ( !fedTrailer.check()) {
191  if (debug) LogTrace("") <<" ** PROBLEM **, trailer.check() failed, break";
192  break;
193  }
194  if ( fedTrailer.fragmentLength()!= nWords) {
195  if (debug) LogTrace("")<<" ** PROBLEM **, fedTrailer.fragmentLength()!= nWords, break";
196  break;
197  }
198  moreTrailers = fedTrailer.moreTrailers();
199  if (debug) {
200  std::ostringstream str;
201  str <<" trailer: "<< *reinterpret_cast<const std::bitset<64>*> (trailer) << std::endl;
202  str <<" trailer lenght: "<<fedTrailer.fragmentLength()<< std::endl;
203  str <<" trailer crc: "<<fedTrailer.crc()<< std::endl;
204  str <<" trailer evtStatus: "<<fedTrailer.evtStatus()<< std::endl;
205  str <<" trailer ttsBits: "<<fedTrailer.ttsBits()<< std::endl;
206  LogTrace("") << str.str();
207  }
208  }
209 
210  //
211  // dump all FED data for debug
212  //
213  if (debug) {
214  std::ostringstream str;
215  for (const Word64* word = header+1; word != trailer; word++) {
216  str<<" data: "<<*reinterpret_cast<const std::bitset<64>*>(word) << std::endl;
217  }
218  LogTrace("") << str.str();
219  }
220 
221  //
222  // AMC13 header
223  //
224  const Word64* headerAmc13raw = header+1;
225  amc13::Header headerAmc13(headerAmc13raw);
226  if (debug) {
227  std::ostringstream str;
228  str <<" headerAMC13: "<< *reinterpret_cast<const std::bitset<64>*> (headerAmc13raw) << std::endl;
229  str <<" amc13 check: "<< headerAmc13.check() << std::endl;
230  str <<" amc13 format: "<< headerAmc13.getFormatVersion() << std::endl;
231  str <<" amc13 nAMCs: "<< headerAmc13.getNumberOfAMCs() << std::endl;
232  str <<" amc13 orbit: "<< headerAmc13.getOrbitNumber() << std::endl;
233  LogTrace("") << str.str();
234  }
235  //unsigned int nAMCs = headerAmc13.getNumberOfAMCs();
236  //for (unsigned int iAMC = 0; iAMC <nAMCs; iAMC++) {
237  // const Word64* raw = header+1 +(iAMC+1);
238  //}
239 
240 
241  //
242  // AMC13 trailer
243  //
244  const Word64* trailerAmc13raw = trailer-1;
245  amc13::Trailer trailerAmc13(trailerAmc13raw);
246  if (debug) {
247  std::ostringstream str;
248  str <<" trailerAMC13: "<< *reinterpret_cast<const std::bitset<64>*> (trailerAmc13raw) << std::endl;
249  str <<" crc: "<< trailerAmc13.getCRC() << std::endl;
250  str <<" block: "<< trailerAmc13.getBlock() << std::endl;
251  str <<" LV1ID: "<< trailerAmc13.getLV1ID() << std::endl;
252  str <<" BX: "<< trailerAmc13.getBX() << std::endl;
253  LogTrace("") << str.str();
254  }
255 
256 
257  //
258  // get AMC13 payload (-> AMC's data)
259  //
260  amc13::Packet packetAmc13;
261  if (!packetAmc13.parse( header, header+1, nWords-2, fedHeader.lvl1ID(), fedHeader.bxID(), true, false)) {
262  edm::LogError("OMTF") << "Could not extract AMC13 Packet.";
263  return;
264  }
265  //LogTrace("") <<"AMC13 Packet: "<< packetAmc13.blocks() << " size "<<packetAmc13.size() << std::endl;
266 
267 
268  //
269  // loop over AMC's
270  //
271  unsigned int blockNum=0;
272  for (auto amc: packetAmc13.payload()) {
273  amc::BlockHeader bh = amc.blockHeader();
274  if (debug) {
275  std::ostringstream str;
276  str <<" ----------- #"<<blockNum++ << std::endl;
277  str <<" blockheader: "<< std::bitset<64>(bh.raw()) << std::endl;
278  str <<" boardID: "<< bh.getBoardID() << std::endl;
279  str <<" amcNumber: "<< bh.getAMCNumber() << std::endl;
280  str <<" size: "<< bh.getSize(); // << std::endl;
281  LogTrace("") << str.str();
282  }
283 
284  //
285  // AMC header
286  //
287  amc::Header headerAmc = amc.header();
288  if (debug) {
289  std::ostringstream str;
290  str <<" AMC header[0]: "<< std::bitset<64>(headerAmc.raw()[0]) << std::endl;
291  str <<" AMC header[1]: "<< std::bitset<64>(headerAmc.raw()[1]) << std::endl;
292  str <<" AMC number: "<< headerAmc.getAMCNumber(); // << std::endl;
293  LogTrace("") << str.str();
294  }
295 
296 
297  //
298  // AMC trailer
299  //
300  //amc::Trailer trailerAmc = amc.trailer(); //this is the expected way but does not work
301  amc::Trailer trailerAmc(amc.data().get()+amc.size()-1); //FIXME: the above is prefered but this works (CMSSW900)
302  if (debug) {
303  std::ostringstream str;
304  str <<" AMC trailer: "<< std::bitset<64>(trailerAmc.raw()) << std::endl;
305  str <<" getLV1ID: "<< trailerAmc.getLV1ID() << std::endl;
306  str <<" size: "<< trailerAmc.getSize() << std::endl;
307  LogTrace("") << str.str();
308  }
309 
310  //
311  // AMC payload
312  //
313  const auto & payload64 = amc.data();
314  const Word64* word = payload64.get();
315  for (unsigned int iWord= 1; iWord<= amc.size(); iWord++, word++) {
316  if (iWord<=2 ) continue; // two header words for each AMC
317  if (iWord==amc.size() ) continue; // trailer for each AMC
318 
319  LogTrace("") <<" payload: " << *reinterpret_cast<const std::bitset<64>*>(word);
320  DataWord64::Type recordType = DataWord64::type(*word);
321 
322  unsigned int fedId = fedHeader.sourceID();
323  unsigned int amcId = bh.getAMCNumber()/2+1; // in OMTF convertsion 1-6
324  //
325  // RPC data
326  //
327  if (DataWord64::rpc==recordType && !theSkipRpc) {
328  theRpcUnpacker.unpack(triggerBX, fedId, amcId, RpcDataWord64(*word), producedRPCDigis.get());
329  }
330 
331  //
332  // CSC data
333  //
334  if (DataWord64::csc==recordType && !theSkipCsc) {
335  theCscUnpacker.unpack(fedId, amcId, CscDataWord64(*word), producedCscLctDigis.get() );
336  }
337 
338  //
339  // DT data
340  //
341  if (DataWord64::dt==recordType && !theSkipDt) {
342  theDtUnpacker.unpack(fedId, amcId, DtDataWord64(*word), phi_Container, the_Container );
343  }
344 
345  //
346  // OMTF (muon) data
347  //
348  if (DataWord64::omtf==recordType && !theSkipMuon) {
349  theMuonUnpacker.unpack(fedId, amcId, MuonDataWord64(*word), producedMuonDigis.get());
350  }
351  }
352  }
353 
354  }
355  event.put(std::move(producedRPCDigis),theOutputTag);
356  event.put(std::move(producedCscLctDigis),theOutputTag);
357  event.put(std::move(producedMuonDigis),theOutputTag);
358  producedDTPhDigis->setContainer(phi_Container);
359  event.put(std::move(producedDTPhDigis),theOutputTag);
360  producedDTThDigis->setContainer(the_Container);
361  event.put(std::move(producedDTThDigis),theOutputTag);
362 
363 }
364 
365 }
366 
367 using namespace omtf;
#define LogDebug(id)
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:80
T getParameter(std::string const &) const
uint64_t raw() const
Definition: AMCSpec.h:23
void init(const edm::EventSetup &es)
unsigned int getAMCNumber() const
Definition: AMCSpec.h:66
uint8_t triggerType() const
Event Trigger type identifier.
Definition: FEDHeader.cc:17
void unpack(unsigned int fed, unsigned int amc, const CscDataWord64 &raw, CSCCorrelatedLCTDigiCollection *prod)
bool moreHeaders() const
Definition: FEDHeader.cc:42
unsigned int getCRC() const
Definition: AMC13Spec.h:47
bool check() const
Check that the header is OK.
Definition: FEDHeader.cc:72
static MessageDrop * instance()
Definition: MessageDrop.cc:59
uint16_t sourceID() const
Identifier of the FED.
Definition: FEDHeader.cc:32
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
Definition: FEDTrailer.cc:22
bool check() const
Check that the trailer is OK.
Definition: FEDTrailer.cc:83
bool ev
bool moreTrailers() const
Definition: FEDTrailer.cc:37
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
uint8_t version() const
Version identifier of the FED data format.
Definition: FEDHeader.cc:37
unsigned int getAMCNumber() const
Definition: AMCSpec.h:28
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
Definition: FEDTrailer.cc:17
void unpack(int triggerBX, unsigned int fed, unsigned int amc, const RpcDataWord64 &raw, RPCDigiCollection *prod)
MuonUnpacker theMuonUnpacker
Definition: OmtfUnpacker.cc:70
unsigned int getBX() const
Definition: AMC13Spec.h:50
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
unsigned int getBlock() const
Definition: AMC13Spec.h:48
std::vector< uint64_t > raw() const
Definition: AMCSpec.h:74
RpcUnpacker theRpcUnpacker
Definition: OmtfUnpacker.cc:67
OmtfUnpacker(const edm::ParameterSet &pset)
Definition: OmtfUnpacker.cc:79
unsigned int getLV1ID() const
Definition: AMC13Spec.h:49
Type type(const T &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define LogTrace(id)
~OmtfUnpacker() override
Definition: OmtfUnpacker.cc:53
uint64_t Word64
#define debug
Definition: HDRShower.cc:19
unsigned long theEventCounter
Definition: OmtfUnpacker.cc:63
unsigned int getOrbitNumber() const
Definition: AMC13Spec.h:26
uint8_t ttsBits() const
Current value of the Trigger Throttling System bits.
Definition: FEDTrailer.cc:32
unsigned int getSize() const
Definition: AMCSpec.h:30
DtUnpacker theDtUnpacker
Definition: OmtfUnpacker.cc:69
edm::EDGetTokenT< FEDRawDataCollection > theFedDataToken
Definition: OmtfUnpacker.cc:65
bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
Definition: AMC13Spec.cc:70
uint8_t evtStatus() const
Event fragment status information.
Definition: FEDTrailer.cc:27
void add(std::string const &label, ParameterSetDescription const &psetDescription)
unsigned int getBoardID() const
Definition: AMCSpec.h:29
uint16_t bxID() const
The bunch crossing number.
Definition: FEDHeader.cc:27
unsigned int getNumberOfAMCs() const
Definition: AMC13Spec.h:25
std::string theOutputTag
Definition: OmtfUnpacker.cc:73
void unpack(unsigned int fed, unsigned int amc, const DtDataWord64 &raw, std::vector< L1MuDTChambPhDigi > &phi_Container, std::vector< L1MuDTChambThDigi > &the_Container)
unsigned int getFormatVersion() const
Definition: AMC13Spec.h:24
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::string fullPath() const
Definition: FileInPath.cc:163
uint32_t lvl1ID() const
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:22
edm::ParameterSet theConfig
Definition: OmtfUnpacker.cc:72
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: OmtfUnpacker.cc:96
Definition: AMCSpec.h:8
void unpack(unsigned int fed, unsigned int amc, const MuonDataWord64 &raw, l1t::RegionalMuonCandBxCollection *muColl)
#define str(s)
bool check() const
Definition: AMC13Spec.cc:22
void produce(edm::Event &ev, const edm::EventSetup &es) override
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45
CscUnpacker theCscUnpacker
Definition: OmtfUnpacker.cc:68