CMS 3D CMS Logo

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 
39 
41  packRctEm_(iConfig.getUntrackedParameter<bool>("packRctEm", true)),
42  packRctCalo_(iConfig.getUntrackedParameter<bool>("packRctCalo", true)),
43  fedId_(iConfig.getParameter<int>("gctFedId")),
44  verbose_(iConfig.getUntrackedParameter<bool>("verbose",false)),
45  counter_(0),
46  formatTranslator_()
47 {
48  LogDebug("GCT") << "GctDigiToRaw will pack FED Id " << fedId_;
49 
50  //register the products
51  produces<FEDRawDataCollection>();
52  const edm::InputTag rctInputTag = iConfig.getParameter<edm::InputTag>("rctInputLabel");
53  const edm::InputTag gctInputTag = iConfig.getParameter<edm::InputTag>("gctInputLabel");
54  const std::string& gctInputLabelStr = gctInputTag.label();
55  tokenL1GctEmCand_isoEm_ = consumes<L1GctEmCandCollection>(edm::InputTag(gctInputLabelStr, "isoEm"));
56  tokenL1GctEmCand_nonIsoEm_ = consumes<L1GctEmCandCollection>(edm::InputTag(gctInputLabelStr, "nonIsoEm"));
57  tokenGctJetCand_cenJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "cenJets"));
58  tokenGctJetCand_forJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "forJets"));
59  tokenGctJetCand_tauJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "tauJets"));
60  tokenGctEtTotal_ = consumes<L1GctEtTotalCollection>(gctInputTag);
61  tokenGctEtHad_ = consumes<L1GctEtHadCollection>(gctInputTag);
62  tokenGctEtMiss_ = consumes<L1GctEtMissCollection>(gctInputTag);
63  tokenGctHFRingEtSums_ = consumes<L1GctHFRingEtSumsCollection>(gctInputTag);
64  tokenGctHFBitCounts_ = consumes<L1GctHFBitCountsCollection>(gctInputTag);
65  tokenGctHtMiss_ = consumes<L1GctHtMissCollection>(gctInputTag);
66  tokenGctJetCounts_ = consumes<L1GctJetCountsCollection>(gctInputTag);
67  if(packRctEm_) {
68  tokenCaloEm_ = consumes<L1CaloEmCollection>(rctInputTag);
69  }
70  if(packRctCalo_) {
71  tokenCaloRegion_ = consumes<L1CaloRegionCollection>(rctInputTag);
72  }
73 }
74 
75 
77 {
78  // do anything here that needs to be done at destruction time
79  // (e.g. close files, deallocate resources etc.)
80 }
81 
82 
83 //
84 // member functions
85 //
86 
87 // ------------ method called to produce the data ------------
88 void
90 {
91  using namespace edm;
92 
93  counter_++; // To "simulate" bunch crossings for now...
94  unsigned int bx = counter_ % 3564; // What's the proper way of doing this?
95  EventNumber_t eventNumber = iEvent.id().event();
96 
97  // Supply bx and EvID to the packer so it can make internal capture block headers.
100 
101  // get GCT digis
103  iEvent.getByToken(tokenL1GctEmCand_isoEm_, isoEm);
105  iEvent.getByToken(tokenL1GctEmCand_nonIsoEm_, nonIsoEm);
107  iEvent.getByToken(tokenGctJetCand_cenJets_, cenJets);
109  iEvent.getByToken(tokenGctJetCand_forJets_, forJets);
111  iEvent.getByToken(tokenGctJetCand_tauJets_, tauJets);
113  iEvent.getByToken(tokenGctEtTotal_, etTotal);
115  iEvent.getByToken(tokenGctEtHad_, etHad);
117  iEvent.getByToken(tokenGctEtMiss_, etMiss);
119  iEvent.getByToken(tokenGctHFRingEtSums_, hfRingSums);
121  iEvent.getByToken(tokenGctHFBitCounts_, hfBitCounts);
123  iEvent.getByToken(tokenGctHtMiss_, htMiss);
125  iEvent.getByToken(tokenGctJetCounts_, jetCounts);
126 
127  // get RCT EM Cand digi
128  bool packRctEmThisEvent = packRctEm_;
130  if(packRctEmThisEvent)
131  {
132  iEvent.getByToken(tokenCaloEm_, rctEm);
133  if(rctEm.failedToGet())
134  {
135  packRctEmThisEvent = false;
136  LogDebug("GCT") << "RCT EM Candidate packing requested, but failed to get them from event!";
137  }
138  }
139 
140  // get RCT Calo region digi
141  bool packRctCaloThisEvent = packRctCalo_;
143  if(packRctCaloThisEvent)
144  {
145  iEvent.getByToken(tokenCaloRegion_, rctCalo);
146  if(rctCalo.failedToGet())
147  {
148  packRctCaloThisEvent = false;
149  LogDebug("GCT") << "RCT Calo Region packing requested, but failed to get them from event!";
150  }
151  }
152 
153  // create the raw data collection
154  std::unique_ptr<FEDRawDataCollection> rawColl(new FEDRawDataCollection());
155 
156  // get the GCT buffer
157  FEDRawData& fedRawData=rawColl->FEDData(fedId_);
158 
159  // set the size & make pointers to the header, beginning of payload, and footer.
160  unsigned int rawSize = 88; // MUST BE MULTIPLE OF 8! (slink packets are 64 bit, but using 8-bit data struct).
161  if(packRctEmThisEvent) { rawSize += 232; } // Space for RCT EM Cands.
162  if(packRctCaloThisEvent) { rawSize += 800; } // Space for RCT Calo Regions (plus a 32-bit word of padding to make divisible by 8)
163  fedRawData.resize(rawSize);
164  unsigned char * pHeader = fedRawData.data();
165  unsigned char * pPayload = pHeader + 16; // 16 = 8 for slink header + 8 for Greg's versioning header.
166  unsigned char * pFooter = pHeader + rawSize - 8;
167 
168  // Write CDF header (exactly as told by Marco Zanetti)
169  FEDHeader fedHeader(pHeader);
170  fedHeader.set(pHeader, 1, eventNumber, bx, fedId_); // what should the bx_ID be?
171 
172  // Pack GCT jet output digis
174  cenJets.product(),
175  forJets.product(),
176  tauJets.product(),
177  hfRingSums.product(),
178  hfBitCounts.product(),
179  htMiss.product());
180 
181  pPayload += 36; //advance payload pointer
182 
183  // Pack GCT EM and energy sums digis.
185  isoEm.product(),
186  nonIsoEm.product(),
187  etTotal.product(),
188  etHad.product(),
189  etMiss.product());
190 
191  pPayload += 28; //advance payload pointer
192 
193  // Pack RCT EM Cands
194  if(packRctEmThisEvent)
195  {
197  pPayload+=232; //advance payload pointer
198  }
199 
200  // Pack RCT Calo Regions
201  if(packRctCaloThisEvent)
202  {
204  }
205 
206  // Write CDF footer (exactly as told by Marco Zanetti)
207  FEDTrailer fedTrailer(pFooter);
208  fedTrailer.set(pFooter, rawSize/8, evf::compute_crc(pHeader, rawSize), 0, 0);
209 
210  // Debug output.
211  if (verbose_) { print(fedRawData); }
212 
213  // Put the collection in the event.
214  iEvent.put(std::move(rawColl));
215 }
216 
217 
219 
220  const unsigned char * d = data.data();
221 
222  for (unsigned int i=0; i<data.size(); i=i+4) {
223  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);
224  cout << std::hex << std::setw(4) << i/4 << " " << std::setw(8) << w << endl;
225  }
226 
227 }
228 
229 
230 // ------------ method called once each job just before starting event loop ------------
231 void
233 {
234 }
235 
236 // ------------ method called once each job just after ending the event loop ------------
237 void
239 }
240 
243 
#define LogDebug(id)
edm::EDGetTokenT< L1GctHFBitCountsCollection > tokenGctHFBitCounts_
Definition: GctDigiToRaw.h:65
void setPackingEventId(uint32_t eventId)
void writeGctOutEmAndEnergyBlock(unsigned char *d, const L1GctEmCandCollection *iso, const L1GctEmCandCollection *nonIso, const L1GctEtTotalCollection *etTotal, const L1GctEtHadCollection *etHad, const L1GctEtMissCollection *etMiss)
Writes GCT output EM and energy sums block into an unsigned char array, starting at the position poin...
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_forJets_
Definition: GctDigiToRaw.h:59
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
void writeAllRctCaloRegionBlock(unsigned char *d, const L1CaloRegionCollection *rctCalo)
Writes the giant hack that is the RCT Calo Regions block.
const double w
Definition: UKUtility.cc:23
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
bool packRctCalo_
Definition: GctDigiToRaw.h:73
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_isoEm_
Definition: GctDigiToRaw.h:56
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< L1CaloEmCollection > tokenCaloEm_
Definition: GctDigiToRaw.h:68
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_tauJets_
Definition: GctDigiToRaw.h:60
edm::EDGetTokenT< L1GctHtMissCollection > tokenGctHtMiss_
Definition: GctDigiToRaw.h:66
void writeRctEmCandBlocks(unsigned char *d, const L1CaloEmCollection *rctEm)
Writes the 4 RCT EM Candidate blocks.
unsigned long long EventNumber_t
edm::EDGetTokenT< L1GctEtTotalCollection > tokenGctEtTotal_
Definition: GctDigiToRaw.h:61
edm::EDGetTokenT< L1CaloRegionCollection > tokenCaloRegion_
Definition: GctDigiToRaw.h:69
edm::EDGetTokenT< L1GctJetCountsCollection > tokenGctJetCounts_
Definition: GctDigiToRaw.h:67
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:42
void writeGctOutJetBlock(unsigned char *d, const L1GctJetCandCollection *cenJets, const L1GctJetCandCollection *forJets, const L1GctJetCandCollection *tauJets, const L1GctHFRingEtSumsCollection *hfRingSums, const L1GctHFBitCountsCollection *hfBitCounts, const L1GctHtMissCollection *htMiss)
Writes GCT output jet cands and counts into an unsigned char array, starting at the position pointed ...
GctDigiToRaw(const edm::ParameterSet &)
Definition: GctDigiToRaw.cc:40
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_cenJets_
Definition: GctDigiToRaw.h:58
edm::EDGetTokenT< L1GctEtMissCollection > tokenGctEtMiss_
Definition: GctDigiToRaw.h:63
~GctDigiToRaw() override
Definition: GctDigiToRaw.cc:76
void print(FEDRawData &data)
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< L1GctEtHadCollection > tokenGctEtHad_
Definition: GctDigiToRaw.h:62
void resize(size_t newsize)
Definition: FEDRawData.cc:32
static void set(unsigned char *header, int evt_ty, int lvl1_ID, int bx_ID, int source_ID, int version=0, bool H=false)
Set all fields in the header.
Definition: FEDHeader.cc:40
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:67
void beginJob() override
void endJob() override
bool failedToGet() const
Definition: HandleBase.h:78
edm::EDGetTokenT< L1GctHFRingEtSumsCollection > tokenGctHFRingEtSums_
Definition: GctDigiToRaw.h:64
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_nonIsoEm_
Definition: GctDigiToRaw.h:57
void setPackingBxId(uint32_t bxId)
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
GctFormatTranslateMCLegacy formatTranslator_
Definition: GctDigiToRaw.h:85
void produce(edm::Event &, const edm::EventSetup &) override
Definition: GctDigiToRaw.cc:89
def move(src, dest)
Definition: eostools.py:510