CMS 3D CMS Logo

VMRouterCM.cc
Go to the documentation of this file.
10 
13 
14 using namespace std;
15 using namespace trklet;
16 
17 VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global)
18  : ProcessBase(name, settings, global), meTable_(settings), diskTable_(settings) {
20 
21  unsigned int region = name[9] - 'A';
23 
24  vmstubsMEPHI_.resize(1, nullptr);
25 
26  overlapbits_ = 7;
28 
29  meTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::me, region); //used for ME and outer TE barrel
30 
32  diskTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::disk, region); //outer disk used by D1, D2, and D4
33  }
34 
37 
38  nvmmebins_ = settings_.NLONGVMBINS() * ((layerdisk_ >= N_LAYER) ? 2 : 1); //number of long z/r bins in VM
39 }
40 
42  if (settings_.writetrace()) {
43  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
44  << output;
45  }
46 
47  if (output == "allinnerstubout") {
49  assert(tmp != nullptr);
50  char memtype = memory->getName().back();
51  allinnerstubs_.emplace_back(memtype, tmp);
52  return;
53  }
54 
55  if (output.substr(0, 10) == "allstubout") {
56  AllStubsMemory* tmp = dynamic_cast<AllStubsMemory*>(memory);
57  allstubs_.push_back(tmp);
58  return;
59  }
60 
61  if (output.substr(0, 9) == "vmstubout") {
62  if (memory->getName().substr(3, 2) == "TE") {
63  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
64  unsigned int iseed = output[output.size() - 1] - '0';
66 
67  int seedindex = -1;
68  for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) {
69  if (vmstubsTEPHI_[k].seednumber == iseed) {
70  seedindex = k;
71  }
72  }
73  if (seedindex == -1) {
74  seedindex = vmstubsTEPHI_.size();
75  vector<VMStubsTEMemory*> vectmp;
76  VMStubsTEPHICM atmp(iseed, vectmp);
77  vmstubsTEPHI_.push_back(atmp);
78  }
79  tmp->resize(settings_.NLONGVMBINS() * settings_.nvmte(1, iseed));
80  vmstubsTEPHI_[seedindex].vmstubmem.push_back(tmp);
81 
82  } else if (memory->getName().substr(3, 2) == "ME") {
83  VMStubsMEMemory* tmp = dynamic_cast<VMStubsMEMemory*>(memory);
84  assert(tmp != nullptr);
86  assert(vmstubsMEPHI_[0] == nullptr);
87  vmstubsMEPHI_[0] = tmp;
88  } else {
89  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " memory: " << memory->getName()
90  << " => should never get here!";
91  }
92 
93  return;
94  }
95 
96  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
97 }
98 
100  if (settings_.writetrace()) {
101  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
102  << input;
103  }
104  if (input == "stubin") {
105  InputLinkMemory* tmp1 = dynamic_cast<InputLinkMemory*>(memory);
106  assert(tmp1 != nullptr);
107  if (tmp1 != nullptr) {
108  stubinputs_.push_back(tmp1);
109  }
110  return;
111  }
112  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
113 }
114 
115 void VMRouterCM::execute(unsigned int) {
116  unsigned int allStubCounter = 0;
117 
118  //bool print = getName() == "VMR_D1PHIB" && iSector == 3;
119  //print = false;
120 
121  //Loop over the input stubs
122  for (auto& stubinput : stubinputs_) {
123  for (unsigned int i = 0; i < stubinput->nStubs(); i++) {
124  if (allStubCounter > settings_.maxStep("VMR"))
125  continue;
126  if (allStubCounter >= (1 << N_BITSMEMADDRESS))
127  continue;
128 
129  Stub* stub = stubinput->getStub(i);
130 
131  //Note - below information is not part of the stub, but rather from which input memory
132  //we are reading
133  bool negdisk = (stub->disk().value() < 0);
134 
135  //use &127 to make sure we fit into the number of bits -
136  //though we should have protected against overflows above
137  FPGAWord allStubIndex(allStubCounter & ((1 << N_BITSMEMADDRESS) - 1), N_BITSMEMADDRESS, true, __LINE__, __FILE__);
138 
139  //TODO - should not be needed - but need to migrate some other pieces of code before removing
140  stub->setAllStubIndex(allStubCounter);
141  //TODO - should not be needed - but need to migrate some other pieces of code before removing
142  stub->l1tstub()->setAllStubIndex(allStubCounter);
143 
144  allStubCounter++;
145 
146  for (auto& allstub : allstubs_) {
147  allstub->addStub(stub);
148  if (settings_.debugTracklet()) {
149  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub->getName();
150  }
151  }
152 
153  FPGAWord iphi = stub->phicorr();
154  unsigned int iphipos = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + N_PHIBITS), N_PHIBITS);
155 
156  unsigned int phicutmax = 4;
157  unsigned int phicutmin = 4;
158 
159  if (layerdisk_ != 0) {
160  phicutmax = 6;
161  phicutmin = 2;
162  }
163 
164  //Fill inner allstubs memories - in HLS this is the same write to multiple memories
165  for (auto& allstub : allinnerstubs_) {
166  char memtype = allstub.first;
167  if (memtype == 'R' && iphipos < phicutmax)
168  continue;
169  if (memtype == 'L' && iphipos >= phicutmin)
170  continue;
171  if (memtype == 'A' && iphipos < 4)
172  continue;
173  if (memtype == 'B' && iphipos >= 4)
174  continue;
175  if (memtype == 'E' && iphipos >= 4)
176  continue;
177  if (memtype == 'F' && iphipos < 4)
178  continue;
179  if (memtype == 'C' && iphipos >= 4)
180  continue;
181  if (memtype == 'D' && iphipos < 4)
182  continue;
183 
184  int absz = std::abs(stub->z().value());
186  continue;
189  continue;
191  stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr())
192  continue;
193  if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->r().value() < 2 * int(N_DSS_MOD))
194  continue;
195  if (layerdisk_ == LayerDisk::L1) {
196  if (memtype == 'M' || memtype == 'R' || memtype == 'L') {
197  if (absz < VMROUTERCUTZL1 / settings_.kz(layerdisk_))
198  continue;
199  } else {
201  continue;
202  }
203  }
204 
205  if (settings_.debugTracklet()) {
206  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub.second->getName();
207  }
208 
209  allstub.second->addStub(stub);
210  }
211 
212  //Fill all the ME VM memories
213  unsigned int ivm =
216 
217  //Calculate the z and r position for the vmstub
218 
219  //Take the top nbitszfinebintable_ bits of the z coordinate
220  int indexz = (stub->z().value() >> (stub->z().nbits() - nbitszfinebintable_)) & ((1 << nbitszfinebintable_) - 1);
221  int indexr = -1;
222  if (layerdisk_ > (N_LAYER - 1)) {
223  if (negdisk) {
224  indexz = ((1 << nbitszfinebintable_) - 1) - indexz;
225  }
226  indexr = stub->r().value();
227  if (stub->isPSmodule()) {
228  indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_);
229  }
230  } else {
231  //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values.
232  indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1);
233  }
234 
235  assert(indexz >= 0);
236  assert(indexr >= 0);
237  assert(indexz < (1 << nbitszfinebintable_));
238  assert(indexr < (1 << nbitsrfinebintable_));
239 
240  int melut = meTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
241 
242  assert(melut >= 0);
243 
244  int vmbin = melut >> NFINERZBITS;
245  if (negdisk)
246  vmbin += (1 << NFINERZBITS);
247  int rzfine = melut & ((1 << NFINERZBITS) - 1);
248 
249  // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility)
250  int nbendbits = stub->bend().nbits();
251  if (layerdisk_ >= N_LAYER)
252  nbendbits = settings_.nbendbitsmedisk();
253 
254  VMStubME vmstub(
255  stub,
257  FPGAWord(rzfine, NFINERZBITS, true, __LINE__, __FILE__),
258  FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__),
259  allStubIndex);
260 
261  assert(vmstubsMEPHI_[0] != nullptr);
262 
263  vmstubsMEPHI_[0]->addStub(vmstub, ivm * nvmmebins_ + vmbin);
264 
265  //Fill the TE VM memories
266  if (layerdisk_ >= N_LAYER && (!stub->isPSmodule()))
267  continue;
268 
269  for (auto& ivmstubTEPHI : vmstubsTEPHI_) {
270  unsigned int iseed = ivmstubTEPHI.seednumber;
271  unsigned int lutwidth = settings_.lutwidthtab(1, iseed);
272 
273  int lutval = -999;
274 
275  if (layerdisk_ < N_LAYER) {
276  lutval = melut;
277  } else {
278  lutval = diskTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
279  if (lutval == 0) {
280  continue;
281  }
282  }
283 
284  assert(lutval >= 0);
285 
286  FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__);
287 
288  if (binlookup.value() < 0)
289  continue;
290 
291  unsigned int ivmte =
294 
295  int bin = binlookup.value() / 8;
296  unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner...
297  binlookup.set(tmp, 3, true, __LINE__, __FILE__);
298 
300 
301  VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex);
302 
303  unsigned int nmem = ivmstubTEPHI.vmstubmem.size();
304  assert(nmem > 0);
305 
306  for (unsigned int l = 0; l < nmem; l++) {
307  if (settings_.debugTracklet()) {
308  edm::LogVerbatim("Tracklet") << getName() << " try adding stub to " << ivmstubTEPHI.vmstubmem[l]->getName()
309  << " bin=" << bin << " ivmte " << ivmte << " finephi " << finephi.value()
310  << " regions bits " << settings_.nphireg(1, iseed) << " finephibits "
311  << settings_.nfinephi(1, iseed);
312  }
313  ivmstubTEPHI.vmstubmem[l]->addVMStub(tmpstub, ivmte * settings_.NLONGVMBINS() + bin);
314  }
315  }
316  }
317  }
318 }
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:179
Log< level::Info, true > LogVerbatim
double kz() const
Definition: Settings.h:314
Divides< B, C > D2
Definition: Factorize.h:137
constexpr double VMROUTERCUTZL1L3L5
Definition: Settings.h:45
unsigned int maxStep(std::string module) const
Definition: Settings.h:116
const FPGAWord & r() const
Definition: Stub.h:60
double lutwidthtab(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:140
TrackletLUT diskTable_
Definition: VMRouterCM.h:58
std::string name_
Definition: ProcessBase.h:38
constexpr double VMROUTERCUTZL1
Definition: Settings.h:46
unsigned int nvmmebins_
Definition: VMRouterCM.h:55
const FPGAWord & z() const
Definition: Stub.h:61
std::vector< InputLinkMemory * > stubinputs_
Definition: VMRouterCM.h:61
unsigned int nbendbitsmedisk() const
Definition: Settings.h:92
Settings const & settings_
Definition: ProcessBase.h:40
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:904
bool writetrace() const
Definition: Settings.h:183
std::vector< std::pair< char, AllInnerStubsMemory * > > allinnerstubs_
Definition: VMRouterCM.h:65
const FPGAWord & bend() const
Definition: Stub.h:58
std::vector< VMStubsMEMemory * > vmstubsMEPHI_
Definition: VMRouterCM.h:68
constexpr unsigned int N_DSS_MOD
Definition: Settings.h:27
assert(be >=bs)
constexpr double VMROUTERCUTZL2
Definition: Settings.h:44
static std::string const input
Definition: EdmProvDump.cc:50
unsigned int NLONGVMBINS() const
Definition: Settings.h:341
const FPGAWord & disk() const
Definition: Stub.h:68
FPGAWord iphivmFineBins(int VMbits, int finebits) const
Definition: Stub.cc:107
void execute(unsigned int iSector)
Definition: VMRouterCM.cc:115
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:106
std::vector< VMStubsTEPHICM > vmstubsTEPHI_
Definition: VMRouterCM.h:71
unsigned int overlapbits_
Definition: VMRouterCM.h:49
void setAllStubIndex(int nstub)
Definition: Stub.cc:123
void addOutput(MemoryBase *memory, std::string output) override
Definition: VMRouterCM.cc:41
Divides< A, C > D1
Definition: Factorize.h:136
unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:95
constexpr double VMROUTERCUTRD1D3
Definition: Settings.h:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int value() const
Definition: FPGAWord.h:24
L1TStub * l1tstub()
Definition: Stub.h:77
unsigned int nextrabits_
Definition: VMRouterCM.h:50
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:103
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: ProcessBase.cc:33
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:101
constexpr unsigned int NFINERZBITS
Definition: Settings.h:33
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
bool debugTracklet() const
Definition: Settings.h:182
double kr() const
Definition: Settings.h:316
int iseed
Definition: AMPTWrapper.h:134
int nbits() const
Definition: FPGAWord.h:25
void set(int value, int nbits, bool positive=true, int line=-1, const char *file=nullptr)
Definition: FPGAWord.cc:14
bool isPSmodule() const
Definition: Stub.h:71
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:133
const FPGAWord & phicorr() const
Definition: Stub.h:63
unsigned int nvmme(unsigned int layerdisk) const
Definition: Settings.h:104
double nphireg(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:134
TrackletLUT meTable_
Definition: VMRouterCM.h:57
Definition: output.py:1
void setAllStubIndex(unsigned int index)
Definition: L1TStub.h:83
void addInput(MemoryBase *memory, std::string input) override
Definition: VMRouterCM.cc:99
unsigned int layerdisk_
Definition: VMRouterCM.h:45
tmp
align.sh
Definition: createJobs.py:716
std::vector< AllStubsMemory * > allstubs_
Definition: VMRouterCM.h:64
std::string const & getName() const
Definition: ProcessBase.h:22
constexpr unsigned int N_PHIBITS
Definition: Settings.h:36
void initVMRTable(unsigned int layerdisk, VMRTableType type, int region=-1)
Definition: TrackletLUT.cc:493
constexpr unsigned int N_BITSMEMADDRESS
Definition: Settings.h:39
constexpr unsigned int N_SEED_PROMPT
Definition: Settings.h:25
unsigned int vmrlutzbits(unsigned int layerdisk) const
Definition: Settings.h:178
constexpr int N_LAYER
Definition: Settings.h:21