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 {
47  LogDebug("GCT") << "GctDigiToRaw will pack FED Id " << fedId_;
48 
49  //register the products
50  tokenPut_ = produces<FEDRawDataCollection>();
51  const edm::InputTag rctInputTag = iConfig.getParameter<edm::InputTag>("rctInputLabel");
52  const edm::InputTag gctInputTag = iConfig.getParameter<edm::InputTag>("gctInputLabel");
53  const std::string& gctInputLabelStr = gctInputTag.label();
54  tokenL1GctEmCand_isoEm_ = consumes<L1GctEmCandCollection>(edm::InputTag(gctInputLabelStr, "isoEm"));
55  tokenL1GctEmCand_nonIsoEm_ = consumes<L1GctEmCandCollection>(edm::InputTag(gctInputLabelStr, "nonIsoEm"));
56  tokenGctJetCand_cenJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "cenJets"));
57  tokenGctJetCand_forJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "forJets"));
58  tokenGctJetCand_tauJets_ = consumes<L1GctJetCandCollection>(edm::InputTag(gctInputLabelStr, "tauJets"));
59  tokenGctEtTotal_ = consumes<L1GctEtTotalCollection>(gctInputTag);
60  tokenGctEtHad_ = consumes<L1GctEtHadCollection>(gctInputTag);
61  tokenGctEtMiss_ = consumes<L1GctEtMissCollection>(gctInputTag);
62  tokenGctHFRingEtSums_ = consumes<L1GctHFRingEtSumsCollection>(gctInputTag);
63  tokenGctHFBitCounts_ = consumes<L1GctHFBitCountsCollection>(gctInputTag);
64  tokenGctHtMiss_ = consumes<L1GctHtMissCollection>(gctInputTag);
65  tokenGctJetCounts_ = consumes<L1GctJetCountsCollection>(gctInputTag);
66  if(packRctEm_) {
67  tokenCaloEm_ = consumes<L1CaloEmCollection>(rctInputTag);
68  }
69  if(packRctCalo_) {
70  tokenCaloRegion_ = consumes<L1CaloRegionCollection>(rctInputTag);
71  }
72 }
73 
74 
75 //
76 // member functions
77 //
78 
79 // ------------ method called to produce the data ------------
80 void
82 {
83  using namespace edm;
84 
85  auto counter = counter_++; // To "simulate" bunch crossings for now...
86  unsigned int bx = counter % 3564; // What's the proper way of doing this?
87  EventNumber_t eventNumber = iEvent.id().event();
88 
89  // digi to block converter
90  // Supply bx and EvID to the packer so it can make internal capture block headers.
91  GctFormatTranslateMCLegacy formatTranslator;
92  formatTranslator.setPackingBxId(bx);
93  formatTranslator.setPackingEventId(eventNumber);
94 
95  // get GCT digis
97  iEvent.getByToken(tokenL1GctEmCand_isoEm_, isoEm);
99  iEvent.getByToken(tokenL1GctEmCand_nonIsoEm_, nonIsoEm);
101  iEvent.getByToken(tokenGctJetCand_cenJets_, cenJets);
103  iEvent.getByToken(tokenGctJetCand_forJets_, forJets);
105  iEvent.getByToken(tokenGctJetCand_tauJets_, tauJets);
107  iEvent.getByToken(tokenGctEtTotal_, etTotal);
109  iEvent.getByToken(tokenGctEtHad_, etHad);
111  iEvent.getByToken(tokenGctEtMiss_, etMiss);
113  iEvent.getByToken(tokenGctHFRingEtSums_, hfRingSums);
115  iEvent.getByToken(tokenGctHFBitCounts_, hfBitCounts);
117  iEvent.getByToken(tokenGctHtMiss_, htMiss);
119  iEvent.getByToken(tokenGctJetCounts_, jetCounts);
120 
121  // get RCT EM Cand digi
122  bool packRctEmThisEvent = packRctEm_;
124  if(packRctEmThisEvent)
125  {
126  iEvent.getByToken(tokenCaloEm_, rctEm);
127  if(rctEm.failedToGet())
128  {
129  packRctEmThisEvent = false;
130  LogDebug("GCT") << "RCT EM Candidate packing requested, but failed to get them from event!";
131  }
132  }
133 
134  // get RCT Calo region digi
135  bool packRctCaloThisEvent = packRctCalo_;
137  if(packRctCaloThisEvent)
138  {
139  iEvent.getByToken(tokenCaloRegion_, rctCalo);
140  if(rctCalo.failedToGet())
141  {
142  packRctCaloThisEvent = false;
143  LogDebug("GCT") << "RCT Calo Region packing requested, but failed to get them from event!";
144  }
145  }
146 
147  // create the raw data collection
148  FEDRawDataCollection rawColl;
149 
150  // get the GCT buffer
151  FEDRawData& fedRawData=rawColl.FEDData(fedId_);
152 
153  // set the size & make pointers to the header, beginning of payload, and footer.
154  unsigned int rawSize = 88; // MUST BE MULTIPLE OF 8! (slink packets are 64 bit, but using 8-bit data struct).
155  if(packRctEmThisEvent) { rawSize += 232; } // Space for RCT EM Cands.
156  if(packRctCaloThisEvent) { rawSize += 800; } // Space for RCT Calo Regions (plus a 32-bit word of padding to make divisible by 8)
157  fedRawData.resize(rawSize);
158  unsigned char * pHeader = fedRawData.data();
159  unsigned char * pPayload = pHeader + 16; // 16 = 8 for slink header + 8 for Greg's versioning header.
160  unsigned char * pFooter = pHeader + rawSize - 8;
161 
162  // Write CDF header (exactly as told by Marco Zanetti)
163  FEDHeader fedHeader(pHeader);
164  fedHeader.set(pHeader, 1, eventNumber, bx, fedId_); // what should the bx_ID be?
165 
166  // Pack GCT jet output digis
167  formatTranslator.writeGctOutJetBlock(pPayload,
168  cenJets.product(),
169  forJets.product(),
170  tauJets.product(),
171  hfRingSums.product(),
172  hfBitCounts.product(),
173  htMiss.product());
174 
175  pPayload += 36; //advance payload pointer
176 
177  // Pack GCT EM and energy sums digis.
178  formatTranslator.writeGctOutEmAndEnergyBlock(pPayload,
179  isoEm.product(),
180  nonIsoEm.product(),
181  etTotal.product(),
182  etHad.product(),
183  etMiss.product());
184 
185  pPayload += 28; //advance payload pointer
186 
187  // Pack RCT EM Cands
188  if(packRctEmThisEvent)
189  {
190  formatTranslator.writeRctEmCandBlocks(pPayload, rctEm.product());
191  pPayload+=232; //advance payload pointer
192  }
193 
194  // Pack RCT Calo Regions
195  if(packRctCaloThisEvent)
196  {
197  formatTranslator.writeAllRctCaloRegionBlock(pPayload, rctCalo.product());
198  }
199 
200  // Write CDF footer (exactly as told by Marco Zanetti)
201  FEDTrailer fedTrailer(pFooter);
202  fedTrailer.set(pFooter, rawSize/8, evf::compute_crc(pHeader, rawSize), 0, 0);
203 
204  // Debug output.
205  if (verbose_) { print(fedRawData); }
206 
207  // Put the collection in the event.
208  iEvent.emplace(tokenPut_,std::move(rawColl));
209 }
210 
211 
213 
214  const unsigned char * d = data.data();
215 
216  for (unsigned int i=0; i<data.size(); i=i+4) {
217  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);
218  cout << std::hex << std::setw(4) << i/4 << " " << std::setw(8) << w << endl;
219  }
220 
221 }
222 
223 
226 
#define LogDebug(id)
edm::EDGetTokenT< L1GctHFBitCountsCollection > tokenGctHFBitCounts_
Definition: GctDigiToRaw.h:62
void setPackingEventId(uint32_t eventId)
std::atomic< int > counter_
Definition: GctDigiToRaw.h:79
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:56
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:517
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_isoEm_
Definition: GctDigiToRaw.h:53
edm::EDGetTokenT< L1CaloEmCollection > tokenCaloEm_
Definition: GctDigiToRaw.h:65
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_tauJets_
Definition: GctDigiToRaw.h:57
edm::EDGetTokenT< L1GctHtMissCollection > tokenGctHtMiss_
Definition: GctDigiToRaw.h:63
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:58
edm::EDGetTokenT< L1CaloRegionCollection > tokenCaloRegion_
Definition: GctDigiToRaw.h:66
edm::EDGetTokenT< L1GctJetCountsCollection > tokenGctJetCounts_
Definition: GctDigiToRaw.h:64
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:55
edm::EDGetTokenT< L1GctEtMissCollection > tokenGctEtMiss_
Definition: GctDigiToRaw.h:60
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
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:60
edm::EDGetTokenT< L1GctEtHadCollection > tokenGctEtHad_
Definition: GctDigiToRaw.h:59
void resize(size_t newsize)
Definition: FEDRawData.cc:32
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
edm::EDPutTokenT< FEDRawDataCollection > tokenPut_
Definition: GctDigiToRaw.h:67
const int fedId_
Definition: GctDigiToRaw.h:73
const bool packRctEm_
Definition: GctDigiToRaw.h:69
bool failedToGet() const
Definition: HandleBase.h:78
edm::EDGetTokenT< L1GctHFRingEtSumsCollection > tokenGctHFRingEtSums_
Definition: GctDigiToRaw.h:61
const bool verbose_
Definition: GctDigiToRaw.h:76
T const * product() const
Definition: Handle.h:74
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:413
const bool packRctCalo_
Definition: GctDigiToRaw.h:70
Unpacks/packs the MC Legacy data originally produced by the GctBlockPacker class. ...
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_nonIsoEm_
Definition: GctDigiToRaw.h:54
void setPackingBxId(uint32_t bxId)
edm::EventID id() const
Definition: EventBase.h:59
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
void print(FEDRawData &data) 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:47
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
Definition: GctDigiToRaw.cc:81
def move(src, dest)
Definition: eostools.py:511