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 
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::StreamID
Definition: StreamID.h:30
counter
Definition: counter.py:1
L1CaloEmCand.h
GctDigiToRaw::tokenGctHtMiss_
edm::EDGetTokenT< L1GctHtMissCollection > tokenGctHtMiss_
Definition: GctDigiToRaw.h:61
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
GctDigiToRaw::tokenCaloRegion_
edm::EDGetTokenT< L1CaloRegionCollection > tokenCaloRegion_
Definition: GctDigiToRaw.h:64
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
edm::Handle::product
T const * product() const
Definition: Handle.h:70
GctDigiToRaw::tokenPut_
edm::EDPutTokenT< FEDRawDataCollection > tokenPut_
Definition: GctDigiToRaw.h:65
L1GctCollections.h
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
GctDigiToRaw::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const final
Definition: GctDigiToRaw.cc:77
GctFormatTranslateBase::setPackingEventId
void setPackingEventId(uint32_t eventId)
Definition: GctFormatTranslateBase.h:41
edm
HLT enums.
Definition: AlignableModifier.h:19
GctDigiToRaw::packRctEm_
const bool packRctEm_
Definition: GctDigiToRaw.h:67
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GctDigiToRaw::GctDigiToRaw
GctDigiToRaw(const edm::ParameterSet &)
Definition: GctDigiToRaw.cc:39
GctDigiToRaw::tokenGctHFRingEtSums_
edm::EDGetTokenT< L1GctHFRingEtSumsCollection > tokenGctHFRingEtSums_
Definition: GctDigiToRaw.h:59
GctFormatTranslateMCLegacy::writeGctOutJetBlock
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 ...
Definition: GctFormatTranslateMCLegacy.cc:220
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
GctDigiToRaw::print
void print(FEDRawData &data) const
Definition: GctDigiToRaw.cc:202
GctDigiToRaw
Definition: GctDigiToRaw.h:40
GctDigiToRaw::verbose_
const bool verbose_
Definition: GctDigiToRaw.h:74
GctFormatTranslateBase::setPackingBxId
void setPackingBxId(uint32_t bxId)
Definition: GctFormatTranslateBase.h:38
edm::Handle
Definition: AssociativeIterator.h:50
l1GctValidation_cfi.rctInputTag
rctInputTag
Definition: l1GctValidation_cfi.py:4
GctFormatTranslateMCLegacy
Unpacks/packs the MC Legacy data originally produced by the GctBlockPacker class.
Definition: GctFormatTranslateMCLegacy.h:20
FEDRawData
Definition: FEDRawData.h:19
GctFormatTranslateMCLegacy::writeRctEmCandBlocks
void writeRctEmCandBlocks(unsigned char *d, const L1CaloEmCollection *rctEm)
Writes the 4 RCT EM Candidate blocks.
Definition: GctFormatTranslateMCLegacy.cc:312
MakerMacros.h
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
w
const double w
Definition: UKUtility.cc:23
GctFormatTranslateMCLegacy::writeGctOutEmAndEnergyBlock
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...
Definition: GctFormatTranslateMCLegacy.cc:134
EventID.h
GctDigiToRaw::fedId_
const int fedId_
Definition: GctDigiToRaw.h:71
GctDigiToRaw::tokenGctJetCounts_
edm::EDGetTokenT< L1GctJetCountsCollection > tokenGctJetCounts_
Definition: GctDigiToRaw.h:62
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
GctDigiToRaw::packRctCalo_
const bool packRctCalo_
Definition: GctDigiToRaw.h:68
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
evf::compute_crc
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
Definition: CRC16.h:46
l1GctValidation_cfi.gctInputTag
gctInputTag
Definition: l1GctValidation_cfi.py:5
L1CaloRegionDetId.h
funct::true
true
Definition: Factorize.h:173
GctDigiToRaw::tokenGctHFBitCounts_
edm::EDGetTokenT< L1GctHFBitCountsCollection > tokenGctHFBitCounts_
Definition: GctDigiToRaw.h:60
edm::HandleBase::failedToGet
bool failedToGet() const
Definition: HandleBase.h:72
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
FEDTrailer
Definition: FEDTrailer.h:14
GctDigiToRaw::counter_
std::atomic< int > counter_
Definition: GctDigiToRaw.h:77
ModuleDef.h
createfilelist.int
int
Definition: createfilelist.py:10
L1CaloCollections.h
iEvent
int iEvent
Definition: GenABIO.cc:224
GctDigiToRaw::tokenGctJetCand_tauJets_
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_tauJets_
Definition: GctDigiToRaw.h:55
FEDRawDataCollection.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
GctDigiToRaw::tokenL1GctEmCand_isoEm_
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_isoEm_
Definition: GctDigiToRaw.h:51
edm::EventSetup
Definition: EventSetup.h:58
FEDTrailer::set
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
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GctDigiToRaw::tokenCaloEm_
edm::EDGetTokenT< L1CaloEmCollection > tokenCaloEm_
Definition: GctDigiToRaw.h:63
GctFormatTranslateMCLegacy::writeAllRctCaloRegionBlock
void writeAllRctCaloRegionBlock(unsigned char *d, const L1CaloRegionCollection *rctCalo)
Writes the giant hack that is the RCT Calo Regions block.
Definition: GctFormatTranslateMCLegacy.cc:397
eostools.move
def move(src, dest)
Definition: eostools.py:511
GctDigiToRaw::tokenGctEtTotal_
edm::EDGetTokenT< L1GctEtTotalCollection > tokenGctEtTotal_
Definition: GctDigiToRaw.h:56
GctDigiToRaw.h
GctDigiToRaw::tokenGctEtMiss_
edm::EDGetTokenT< L1GctEtMissCollection > tokenGctEtMiss_
Definition: GctDigiToRaw.h:58
FEDHeader::set
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
GctDigiToRaw::tokenGctJetCand_forJets_
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_forJets_
Definition: GctDigiToRaw.h:54
GctDigiToRaw::tokenGctJetCand_cenJets_
edm::EDGetTokenT< L1GctJetCandCollection > tokenGctJetCand_cenJets_
Definition: GctDigiToRaw.h:53
ztail.d
d
Definition: ztail.py:151
GctDigiToRaw::tokenL1GctEmCand_nonIsoEm_
edm::EDGetTokenT< L1GctEmCandCollection > tokenL1GctEmCand_nonIsoEm_
Definition: GctDigiToRaw.h:52
FEDHeader
Definition: FEDHeader.h:14
GctDigiToRaw::tokenGctEtHad_
edm::EDGetTokenT< L1GctEtHadCollection > tokenGctEtHad_
Definition: GctDigiToRaw.h:57
edm::Event
Definition: Event.h:73
FEDHeader.h
edm::InputTag
Definition: InputTag.h:15
L1CaloRegion.h
CRC16.h
FEDTrailer.h