CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
GEMDigiToRawModule Class Reference

#include <GEMDigiToRawModule.h>

Inheritance diagram for GEMDigiToRawModule:
edm::global::EDProducer< edm::RunCache< GEMROmap > > edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 GEMDigiToRawModule (const edm::ParameterSet &pset)
 Constructor. More...
 
std::shared_ptr< GEMROmapglobalBeginRun (edm::Run const &, edm::EventSetup const &) const override
 
void globalEndRun (edm::Run const &, edm::EventSetup const &) const override
 
void produce (edm::StreamID, edm::Event &, edm::EventSetup const &) const override
 
- Public Member Functions inherited from edm::global::EDProducer< edm::RunCache< GEMROmap > >
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Attributes

edm::EDGetTokenT< GEMDigiCollectiondigi_token
 
int event_type_
 
bool useDBEMap_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

on CSCDigiToRawModule

Author
J. Lee - UoS

Definition at line 27 of file GEMDigiToRawModule.h.

Constructor & Destructor Documentation

GEMDigiToRawModule::GEMDigiToRawModule ( const edm::ParameterSet pset)

Constructor.

Definition at line 23 of file GEMDigiToRawModule.cc.

23  :
24  event_type_(pset.getParameter<int>("eventType")),
25  digi_token(consumes<GEMDigiCollection>( pset.getParameter<edm::InputTag>("gemDigi") )),
26  useDBEMap_(pset.getParameter<bool>("useDBEMap"))
27 {
28  produces<FEDRawDataCollection>();
29 }
T getParameter(std::string const &) const
edm::EDGetTokenT< GEMDigiCollection > digi_token

Member Function Documentation

void GEMDigiToRawModule::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 31 of file GEMDigiToRawModule.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::add().

32 {
34  desc.add<edm::InputTag>("gemDigi", edm::InputTag("simMuonGEMDigis"));
35  desc.add<int>("eventType", 0);
36  desc.add<bool>("useDBEMap", false);
37  descriptions.add("gemPackerDefault", desc);
38 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::shared_ptr< GEMROmap > GEMDigiToRawModule::globalBeginRun ( edm::Run const &  ,
edm::EventSetup const &  iSetup 
) const
override

Definition at line 40 of file GEMDigiToRawModule.cc.

References edm::EventSetup::get(), edm::ESHandle< T >::product(), and useDBEMap_.

41 {
42  auto gemORmap = std::make_shared<GEMROmap>();
43  if (useDBEMap_){
44  edm::ESHandle<GEMELMap> gemEMapRcd;
45  iSetup.get<GEMELMapRcd>().get(gemEMapRcd);
46  auto gemEMap = std::make_unique<GEMELMap>(*(gemEMapRcd.product()));
47  gemEMap->convert(*gemORmap);
48  gemEMap.reset();
49  }
50  else {
51  // no EMap in DB, using dummy
52  auto gemEMap = std::make_unique<GEMELMap>();
53  gemEMap->convertDummy(*gemORmap);
54  gemEMap.reset();
55  }
56  return gemORmap;
57 }
T const * product() const
Definition: ESHandle.h:86
void GEMDigiToRawModule::globalEndRun ( edm::Run const &  ,
edm::EventSetup const &   
) const
inlineoverride

Definition at line 35 of file GEMDigiToRawModule.h.

References fillDescriptions().

35 {};
void GEMDigiToRawModule::produce ( edm::StreamID  iID,
edm::Event iEvent,
edm::EventSetup const &   
) const
overridevirtual

<1010:4 Control bits, shoud be 1010

<Bunch Crossing number, 12 bits

<1100:4, Control bits, shoud be 1100

<Event Counter, 8 bits

<Control Flags: 4 bits, Hamming Error/AFULL/SEUlogic/SUEI2C

<1110:4 Control bits, shoud be 1110

<Calculated chip position

<Shows if block is good (control bits, chip ID and CRC checks)

<channels from 1to64

<channels from 65to128

<Check Sum value, 16 bits

<Check Sum value recalculated, 16 bits

Implements edm::global::EDProducerBase.

Definition at line 59 of file GEMDigiToRawModule.cc.

References GEMELMap::amcBX_, GEMROmap::eCoord::amcId, edm::EventBase::bunchCrossing(), GEMDigi::bx(), officialStyle::chan, GEMROmap::channelNum::chNum, FEDRawData::data(), digi_token, RecoEcal_EventContent_cff::ec, edm::EventID::event(), event_type_, nanoDQM_cfi::Flag, GEMROmap::eCoord::gebId, GEMROmap::dCoord::gemDetId, edm::Event::getByToken(), edm::Event::getRun(), mps_fire::i, edm::EventBase::id(), edm::Run::index(), GEMROmap::dCoord::iPhi, LogDebug, GEMELMap::maxChan_, GEMELMap::maxVFatGE11_, GEMELMap::maxVFatGE21_, FEDNumbering::MINGEMFEDID, eostools::move(), GetRecoTauVFromDQM_MC_cff::next, edm::Event::put(), FEDRawData::resize(), GEMDetId::station(), GEMROmap::stripNum::stNum, GEMDigi::strip(), GEMROmap::eCoord::vfatId, GEMROmap::dCoord::vfatType, and w.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

60 {
61  auto fedRawDataCol = std::make_unique<FEDRawDataCollection>();
62 
63  // Take digis from the event
65  iEvent.getByToken( digi_token, gemDigis );
66 
67  auto gemROMap = runCache(iEvent.getRun().index());
68 
69  std::vector<std::unique_ptr<AMC13Event>> amc13Events;
70  // currently only one FEDRaw
71  amc13Events.reserve(1);
72  {
73  auto amc13Event = std::make_unique<AMC13Event>();
74 
75  uint16_t amcId = 0, gebId = 0;
76  std::unique_ptr<AMCdata> amcData;
77  std::unique_ptr<GEBdata> gebData;
78 
79  const std::map<GEMROmap::eCoord,GEMROmap::dCoord> *roMapED = gemROMap->getRoMap();
80  for (auto ro=roMapED->begin(); ro!=roMapED->end(); ++ro){
81  GEMROmap::eCoord ec = ro->first;
82  GEMROmap::dCoord dc = ro->second;
83 
84  if (amcId != ec.amcId || !amcData){
85  amcId = ec.amcId;
86  amcData = std::make_unique<AMCdata>();
87  amcData->setBID(amcId);
88  amcData->setBX(GEMELMap::amcBX_);
89  }
90 
91  if (gebId != ec.gebId || !gebData){
92  gebId = ec.gebId;
93  gebData = std::make_unique<GEBdata>();
94  gebData->setInputID(gebId);
95  }
96 
97  uint16_t vfatId = ec.vfatId;
98  GEMDetId gemId = dc.gemDetId;
99 
100  for (uint16_t bc = 0; bc < 2*GEMELMap::amcBX_; ++bc){
101  bool hasDigi = false;
102 
103  uint8_t b1010 =0xA;
104  uint16_t BC =bc;
105  uint8_t b1100 =0xC;
106  uint8_t EC =0;
107  uint8_t Flag =0;
108  uint8_t b1110 =0xE;
109  int SlotNumber =0;
110  bool isBlockGood=false;
111  uint64_t lsData =0;
112  uint64_t msData =0;
113  uint16_t crc =0;
114  uint16_t crc_calc =0;
115 
116  GEMDigiCollection::Range range = gemDigis->get(gemId);
117  for (GEMDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
118 
119  const GEMDigi & digi = (*digiIt);
120  if (digi.bx() != bc-GEMELMap::amcBX_) continue;
121 
122  int maxVFat = GEMELMap::maxVFatGE11_;
123  if (gemId.station() == 2) maxVFat = GEMELMap::maxVFatGE21_;
124 
125  int localStrip = digi.strip() - ((dc.iPhi-1)%maxVFat)*GEMELMap::maxChan_;
126  // skip strips not in current vFat
127  if (localStrip < 1 || localStrip > GEMELMap::maxChan_) continue;
128 
129  hasDigi = true;
130 
131  GEMROmap::stripNum stMap = {dc.vfatType, localStrip};
132  GEMROmap::channelNum chMap = gemROMap->hitPosition(stMap);
133 
134  int chan = chMap.chNum;
135  uint64_t oneBit = 0x1;
136  if (chan < 64) lsData = lsData | (oneBit << chan);
137  else msData = msData | (oneBit << (chan-64));
138 
139  LogDebug("GEMDigiToRawModule") <<" vfatId "<<ec.vfatId
140  <<" gemDetId "<< gemId
141  <<" chan "<< chMap.chNum
142  <<" strip "<< stMap.stNum
143  <<" bx "<< digi.bx();
144 
145  }
146 
147  if (!hasDigi) continue;
148  // only make vfat with hits
149  auto vfatData = std::make_unique<VFATdata>(b1010, BC, b1100, EC, Flag, b1110, vfatId, lsData, msData,
150  crc, crc_calc, SlotNumber, isBlockGood);
151  gebData->addVFAT(*vfatData);
152  }
153 
154  bool saveGeb = false;
155  bool saveAMC = false;
156  auto nx = std::next(ro);
157  // last vfat, save
158  if (nx == roMapED->end()){
159  saveGeb = true;
160  saveAMC = true;
161  }
162  else {
163  // check if next vfat is in new geb or amc
164  GEMROmap::eCoord ecNext = nx->first;
165  if (ecNext.gebId != gebId) saveGeb = true;
166  if (ecNext.amcId != amcId) saveAMC = true;
167  }
168 
169  if (!gebData->vFATs()->empty() && saveGeb){
170  gebData->setVwh(gebData->vFATs()->size()*3);
171  amcData->addGEB(*gebData);
172  }
173  if (!amcData->gebs()->empty() && saveAMC){
174  amcData->setGDcount(amcData->gebs()->size());
175  amc13Event->addAMCpayload(*amcData);
176  }
177  }
178 
179  // CDFHeader
180  uint8_t cb5 = 0x5;// control bit, should be 0x5 bits 60-63
181  uint8_t Evt_ty = event_type_;
182  uint32_t LV1_id = iEvent.id().event();
183  uint16_t BX_id = iEvent.bunchCrossing();
184  uint16_t Source_id = FEDNumbering::MINGEMFEDID;
185  amc13Event->setCDFHeader(cb5, Evt_ty, LV1_id, BX_id, Source_id);
186 
187  // AMC13header
188  uint8_t CalTyp = 1;
189  uint8_t nAMC = amc13Event->getAMCpayloads()->size(); // currently only one AMC13Event
190  uint32_t OrN = 2;
191  uint8_t cb0 = 0b0000;// control bit, should be 0b0000
192  amc13Event->setAMC13header(CalTyp, nAMC, OrN, cb0);
193 
194  for (unsigned short i = 0; i < amc13Event->nAMC(); ++i){
195  uint32_t AMC_size = 0;
196  uint8_t Blk_No = 0;
197  uint8_t AMC_No = 0;
198  uint16_t BoardID = 0;
199  amc13Event->addAMCheader(AMC_size, Blk_No, AMC_No, BoardID);
200  }
201 
202  //AMC13 trailer
203  uint32_t CRC_amc13 = 0;
204  uint8_t Blk_NoT = 0;
205  uint8_t LV1_idT = 0;
206  uint16_t BX_idT = BX_id;
207  amc13Event->setAMC13trailer(CRC_amc13, Blk_NoT, LV1_idT, BX_idT);
208  //CDF trailer
209  uint8_t cbA = 0xA; // control bit, should be 0xA bits 60-63
210  uint32_t EvtLength = 0;
211  uint16_t CRC_cdf = 0;
212  amc13Event->setCDFTrailer(cbA, EvtLength, CRC_cdf);
213  amc13Events.emplace_back(std::move(amc13Event));
214  }// finished making amc13Event data
215 
216  // read out amc13Events into fedRawData
217  for (const auto & amc13e : amc13Events){
218  std::vector<uint64_t> words;
219  words.emplace_back(amc13e->getCDFHeader());
220  words.emplace_back(amc13e->getAMC13header());
221 
222  for (const auto & w: *amc13e->getAMCheaders())
223  words.emplace_back(w);
224 
225  for (const auto & amc : *amc13e->getAMCpayloads()){
226  words.emplace_back(amc.getAMCheader1());
227  words.emplace_back(amc.getAMCheader2());
228  words.emplace_back(amc.getGEMeventHeader());
229 
230  for (const auto & geb: *amc.gebs()){
231  words.emplace_back(geb.getChamberHeader());
232 
233  for (const auto & vfat: *geb.vFATs()){
234  words.emplace_back(vfat.get_fw());
235  words.emplace_back(vfat.get_sw());
236  words.emplace_back(vfat.get_tw());
237  }
238 
239  words.emplace_back(geb.getChamberTrailer());
240  }
241 
242  words.emplace_back(amc.getGEMeventTrailer());
243  words.emplace_back(amc.getAMCTrailer());
244  }
245 
246  words.emplace_back(amc13e->getAMC13trailer());
247  words.emplace_back(amc13e->getCDFTrailer());
248 
249  FEDRawData & fedRawData = fedRawDataCol->FEDData(amc13e->source_id());
250 
251  int dataSize = (words.size()) * sizeof(uint64_t);
252  fedRawData.resize(dataSize);
253 
254  uint64_t * w = reinterpret_cast<uint64_t* >(fedRawData.data());
255  for (const auto & word: words) *(w++) = word;
256 
257  LogDebug("GEMDigiToRawModule") <<" words " << words.size();
258  }
259 
260  iEvent.put(std::move(fedRawDataCol));
261 }
#define LogDebug(id)
EventNumber_t event() const
Definition: EventID.h:41
edm::EDGetTokenT< GEMDigiCollection > digi_token
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
const double w
Definition: UKUtility.cc:23
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
int bunchCrossing() const
Definition: EventBase.h:66
Run const & getRun() const
Definition: Event.cc:114
static const int maxVFatGE21_
Definition: GEMELMap.h:60
uint16_t gebId
Definition: GEMROmap.h:11
static const int maxChan_
Definition: GEMELMap.h:61
void resize(size_t newsize)
Definition: FEDRawData.cc:32
GEMDetId gemDetId
Definition: GEMROmap.h:30
int station() const
Station id : the station is the pair of chambers at same disk.
Definition: GEMDetId.h:64
RunIndex index() const
Definition: Run.cc:24
static const int amcBX_
Definition: GEMELMap.h:62
int bx() const
Definition: GEMDigi.h:27
unsigned long long uint64_t
Definition: Time.h:15
static const int maxVFatGE11_
Definition: GEMELMap.h:59
uint16_t vfatId
Definition: GEMROmap.h:12
std::vector< GEMDigi >::const_iterator const_iterator
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
edm::EventID id() const
Definition: EventBase.h:60
uint16_t amcId
Definition: GEMROmap.h:10
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
std::pair< const_iterator, const_iterator > Range
int strip() const
Definition: GEMDigi.h:26
Definition: AMCSpec.h:8
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

edm::EDGetTokenT<GEMDigiCollection> GEMDigiToRawModule::digi_token
private

Definition at line 43 of file GEMDigiToRawModule.h.

Referenced by produce().

int GEMDigiToRawModule::event_type_
private

Definition at line 42 of file GEMDigiToRawModule.h.

Referenced by produce().

bool GEMDigiToRawModule::useDBEMap_
private

Definition at line 44 of file GEMDigiToRawModule.h.

Referenced by globalBeginRun().