CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GctDigiToRaw.cc
Go to the documentation of this file.
2 
3 // system
4 #include <vector>
5 #include <sstream>
6 #include <iostream>
7 #include <iomanip>
8 
9 // framework
13 
14 // Raw data collection
19 
20 // Header needed to computer CRCs
22 
23 // GCT input data formats
28 
29 // GCT output data formats
31 
32 // Raw data collection
34 
35 using std::cout;
36 using std::endl;
37 using std::vector;
38 
40  : packRctEm_(iConfig.getUntrackedParameter<bool>("packRctEm", true)),
41  packRctCalo_(iConfig.getUntrackedParameter<bool>("packRctCalo", true)),
42  fedId_(iConfig.getParameter<int>("gctFedId")),
43  verbose_(iConfig.getUntrackedParameter<bool>("verbose", false)),
44  counter_(0) {
45  LogDebug("GCT") << "GctDigiToRaw will pack FED Id " << fedId_;
46 
47  //register the products
48  tokenPut_ = produces<FEDRawDataCollection>();
49  const edm::InputTag rctInputTag = iConfig.getParameter<edm::InputTag>("rctInputLabel");
50  const edm::InputTag gctInputTag = iConfig.getParameter<edm::InputTag>("gctInputLabel");
51  const std::string& gctInputLabelStr = gctInputTag.label();
52  tokenL1GctEmCand_isoEm_ = consumes<L1GctEmCandCollection>(edm::InputTag(gctInputLabelStr, "isoEm"));
53  tokenL1GctEmCand_nonIsoEm_ = consumes<L1GctEmCandCollection>(edm::InputTag(gctInputLabelStr, "nonIsoEm"));
54  tokenGctJetCand_cenJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "cenJets"));
55  tokenGctJetCand_forJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "forJets"));
56  tokenGctJetCand_tauJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "tauJets"));
57  tokenGctEtTotal_ = consumes<L1GctEtTotalCollection>(gctInputTag);
58  tokenGctEtHad_ = consumes<L1GctEtHadCollection>(gctInputTag);
59  tokenGctEtMiss_ = consumes<L1GctEtMissCollection>(gctInputTag);
60  tokenGctHFRingEtSums_ = consumes<L1GctHFRingEtSumsCollection>(gctInputTag);
61  tokenGctHFBitCounts_ = consumes<L1GctHFBitCountsCollection>(gctInputTag);
62  tokenGctHtMiss_ = consumes<L1GctHtMissCollection>(gctInputTag);
63  tokenGctJetCounts_ = consumes<L1GctJetCountsCollection>(gctInputTag);
64  if (packRctEm_) {
65  tokenCaloEm_ = consumes<L1CaloEmCollection>(rctInputTag);
66  }
67  if (packRctCalo_) {
68  tokenCaloRegion_ = consumes<L1CaloRegionCollection>(rctInputTag);
69  }
70 }
71 
72 //
73 // member functions
74 //
75 
76 // ------------ method called to produce the data ------------
78  using namespace edm;
79 
80  auto counter = counter_++; // To "simulate" bunch crossings for now...
81  unsigned int bx = counter % 3564; // What's the proper way of doing this?
82  EventNumber_t eventNumber = iEvent.id().event();
83 
84  // digi to block converter
85  // Supply bx and EvID to the packer so it can make internal capture block headers.
86  GctFormatTranslateMCLegacy formatTranslator;
87  formatTranslator.setPackingBxId(bx);
88  formatTranslator.setPackingEventId(eventNumber);
89 
90  // get GCT digis
92  iEvent.getByToken(tokenL1GctEmCand_isoEm_, isoEm);
94  iEvent.getByToken(tokenL1GctEmCand_nonIsoEm_, nonIsoEm);
96  iEvent.getByToken(tokenGctJetCand_cenJets_, cenJets);
98  iEvent.getByToken(tokenGctJetCand_forJets_, forJets);
100  iEvent.getByToken(tokenGctJetCand_tauJets_, tauJets);
102  iEvent.getByToken(tokenGctEtTotal_, etTotal);
104  iEvent.getByToken(tokenGctEtHad_, etHad);
106  iEvent.getByToken(tokenGctEtMiss_, etMiss);
108  iEvent.getByToken(tokenGctHFRingEtSums_, hfRingSums);
110  iEvent.getByToken(tokenGctHFBitCounts_, hfBitCounts);
112  iEvent.getByToken(tokenGctHtMiss_, htMiss);
114  iEvent.getByToken(tokenGctJetCounts_, jetCounts);
115 
116  // get RCT EM Cand digi
117  bool packRctEmThisEvent = packRctEm_;
119  if (packRctEmThisEvent) {
120  iEvent.getByToken(tokenCaloEm_, rctEm);
121  if (rctEm.failedToGet()) {
122  packRctEmThisEvent = false;
123  LogDebug("GCT") << "RCT EM Candidate packing requested, but failed to get them from event!";
124  }
125  }
126 
127  // get RCT Calo region digi
128  bool packRctCaloThisEvent = packRctCalo_;
130  if (packRctCaloThisEvent) {
131  iEvent.getByToken(tokenCaloRegion_, rctCalo);
132  if (rctCalo.failedToGet()) {
133  packRctCaloThisEvent = false;
134  LogDebug("GCT") << "RCT Calo Region packing requested, but failed to get them from event!";
135  }
136  }
137 
138  // create the raw data collection
139  FEDRawDataCollection rawColl;
140 
141  // get the GCT buffer
142  FEDRawData& fedRawData = rawColl.FEDData(fedId_);
143 
144  // set the size & make pointers to the header, beginning of payload, and footer.
145  unsigned int rawSize = 88; // MUST BE MULTIPLE OF 8! (slink packets are 64 bit, but using 8-bit data struct).
146  if (packRctEmThisEvent) {
147  rawSize += 232;
148  } // Space for RCT EM Cands.
149  if (packRctCaloThisEvent) {
150  rawSize += 800;
151  } // Space for RCT Calo Regions (plus a 32-bit word of padding to make divisible by 8)
152  fedRawData.resize(rawSize);
153  unsigned char* pHeader = fedRawData.data();
154  unsigned char* pPayload = pHeader + 16; // 16 = 8 for slink header + 8 for Greg's versioning header.
155  unsigned char* pFooter = pHeader + rawSize - 8;
156 
157  // Write CDF header (exactly as told by Marco Zanetti)
158  FEDHeader fedHeader(pHeader);
159  fedHeader.set(pHeader, 1, eventNumber, bx, fedId_); // what should the bx_ID be?
160 
161  // Pack GCT jet output digis
162  formatTranslator.writeGctOutJetBlock(pPayload,
163  cenJets.product(),
164  forJets.product(),
165  tauJets.product(),
166  hfRingSums.product(),
167  hfBitCounts.product(),
168  htMiss.product());
169 
170  pPayload += 36; //advance payload pointer
171 
172  // Pack GCT EM and energy sums digis.
173  formatTranslator.writeGctOutEmAndEnergyBlock(
174  pPayload, isoEm.product(), nonIsoEm.product(), etTotal.product(), etHad.product(), etMiss.product());
175 
176  pPayload += 28; //advance payload pointer
177 
178  // Pack RCT EM Cands
179  if (packRctEmThisEvent) {
180  formatTranslator.writeRctEmCandBlocks(pPayload, rctEm.product());
181  pPayload += 232; //advance payload pointer
182  }
183 
184  // Pack RCT Calo Regions
185  if (packRctCaloThisEvent) {
186  formatTranslator.writeAllRctCaloRegionBlock(pPayload, rctCalo.product());
187  }
188 
189  // Write CDF footer (exactly as told by Marco Zanetti)
190  FEDTrailer fedTrailer(pFooter);
191  fedTrailer.set(pFooter, rawSize / 8, evf::compute_crc(pHeader, rawSize), 0, 0);
192 
193  // Debug output.
194  if (verbose_) {
195  print(fedRawData);
196  }
197 
198  // Put the collection in the event.
199  iEvent.emplace(tokenPut_, std::move(rawColl));
200 }
201 
203  const unsigned char* d = data.data();
204 
205  for (unsigned int i = 0; i < data.size(); i = i + 4) {
206  uint32_t w = (uint32_t)d[i] + (uint32_t)(d[i + 1] << 8) + (uint32_t)(d[i + 2] << 16) + (uint32_t)(d[i + 3] << 24);
207  cout << std::hex << std::setw(4) << i / 4 << " " << std::setw(8) << w << endl;
208  }
209 }
210 
edm::EDGetTokenT< L1GctHFBitCountsCollection > tokenGctHFBitCounts_
Definition: GctDigiToRaw.h:60
std::atomic< int > counter_
Definition: GctDigiToRaw.h:77
EventNumber_t event() const
Definition: EventID.h:40
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_forJets_
Definition: GctDigiToRaw.h:54
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_isoEm_
Definition: GctDigiToRaw.h:51
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< L1CaloEmCollection > tokenCaloEm_
Definition: GctDigiToRaw.h:63
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_tauJets_
Definition: GctDigiToRaw.h:55
edm::EDGetTokenT< L1GctHtMissCollection > tokenGctHtMiss_
Definition: GctDigiToRaw.h:61
unsigned long long EventNumber_t
edm::EDGetTokenT< L1GctEtTotalCollection > tokenGctEtTotal_
Definition: GctDigiToRaw.h:56
edm::EDGetTokenT< L1CaloRegionCollection > tokenCaloRegion_
Definition: GctDigiToRaw.h:64
edm::EDGetTokenT< L1GctJetCountsCollection > tokenGctJetCounts_
Definition: GctDigiToRaw.h:62
GctDigiToRaw(const edm::ParameterSet &)
Definition: GctDigiToRaw.cc:39
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_cenJets_
Definition: GctDigiToRaw.h:53
edm::EDGetTokenT< L1GctEtMissCollection > tokenGctEtMiss_
Definition: GctDigiToRaw.h:58
tuple d
Definition: ztail.py:151
int iEvent
Definition: GenABIO.cc:224
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
edm::EDGetTokenT< L1GctEtHadCollection > tokenGctEtHad_
Definition: GctDigiToRaw.h:57
void resize(size_t newsize)
Definition: FEDRawData.cc:28
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
def move
Definition: eostools.py:511
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
Definition: GctDigiToRaw.cc:77
edm::EDPutTokenT< FEDRawDataCollection > tokenPut_
Definition: GctDigiToRaw.h:65
const int fedId_
Definition: GctDigiToRaw.h:71
const bool packRctEm_
Definition: GctDigiToRaw.h:67
edm::EDGetTokenT< L1GctHFRingEtSumsCollection > tokenGctHFRingEtSums_
Definition: GctDigiToRaw.h:59
const bool verbose_
Definition: GctDigiToRaw.h:74
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:433
const bool packRctCalo_
Definition: GctDigiToRaw.h:68
Unpacks/packs the MC Legacy data originally produced by the GctBlockPacker class. ...
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_nonIsoEm_
Definition: GctDigiToRaw.h:52
void setPackingBxId(uint32_t bxId)
edm::EventID id() const
Definition: EventBase.h:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static std::atomic< unsigned int > counter
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
void print(FEDRawData &data) const
tuple cout
Definition: gather_cfg.py:144
T w() const
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
#define LogDebug(id)