CMS 3D CMS Logo

VMRouter.cc
Go to the documentation of this file.
9 
12 
13 using namespace std;
14 using namespace trklet;
15 
16 VMRouter::VMRouter(string name, Settings const& settings, Globals* global)
17  : ProcessBase(name, settings, global),
18  meTable_(settings),
19  diskTable_(settings),
20  innerTable_(settings),
21  innerOverlapTable_(settings),
22  innerThirdTable_(settings) {
24 
25  vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr);
26 
27  unsigned int region = name[9] - 'A';
29 
30  overlapbits_ = 7;
32 
33  meTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::me, region); //used for ME and outer TE barrel
34 
36  diskTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::disk, region); //outer disk used by D1, D2, and D4
37  }
38 
42  }
43 
46  layerdisk_, TrackletLUT::VMRTableType::inneroverlap, region); //projection to disk from layer
47  }
48 
52  layerdisk_, TrackletLUT::VMRTableType::innerthird, region); //projection to third layer/disk
53  }
54 
57 }
58 
60  if (settings_.writetrace()) {
61  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
62  << output;
63  }
64 
65  if (output.substr(0, 10) == "allstubout") {
66  AllStubsMemory* tmp = dynamic_cast<AllStubsMemory*>(memory);
67  assert(tmp != nullptr);
68  allstubs_.push_back(tmp);
69  return;
70  }
71 
72  if (output.substr(0, 12) == "vmstuboutPHI" || output.substr(0, 14) == "vmstuboutMEPHI" ||
73  output.substr(0, 15) == "vmstuboutTEIPHI" || output.substr(0, 15) == "vmstuboutTEOPHI") {
74  char seedtype = memory->getName().substr(11, 1)[0];
75  unsigned int pos = 12;
76  int vmbin = memory->getName().substr(pos, 1)[0] - '0';
77  pos++;
78  if (pos < memory->getName().size()) {
79  if (memory->getName().substr(pos, 1)[0] != 'n') {
80  vmbin = vmbin * 10 + memory->getName().substr(pos, 1)[0] - '0';
81  pos++;
82  }
83  }
84 
85  int iseed = -1;
86  unsigned int inner = 1;
87  if (memory->getName().substr(3, 2) == "TE") {
88  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
89  assert(tmp != nullptr);
90  if (seedtype < 'I') {
92  iseed = Seed::L1L2;
94  iseed = Seed::L3L4;
96  iseed = Seed::L5L6;
98  iseed = Seed::D1D2;
100  iseed = Seed::D3D4;
103  inner = 0;
104  } else if (seedtype < 'M') {
106  iseed = Seed::L2L3;
107  if (layerdisk_ == LayerDisk::L2)
108  inner = 0;
109  } else if (seedtype <= 'Z') {
111  iseed = Seed::L1D1;
113  iseed = Seed::L2D1;
115  inner = 0;
116  } else if (seedtype < 'o' && seedtype >= 'a') {
119  if (layerdisk_ == LayerDisk::L2)
120  inner = 0;
121  } else if (seedtype > 'o' && seedtype <= 'z') {
122  if (layerdisk_ == LayerDisk::L2)
124  if (layerdisk_ == LayerDisk::D1)
126  inner = 2;
127  } else {
128  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!";
129  }
130  assert(iseed != -1);
131  int seedindex = -1;
132  for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) {
133  if (vmstubsTEPHI_[k].seednumber == (unsigned int)iseed) {
134  seedindex = k;
135  }
136  }
137  if (seedindex == -1) {
138  seedindex = vmstubsTEPHI_.size();
139  vector<VMStubsTEMemory*> avectmp;
140  vector<vector<VMStubsTEMemory*> > vectmp(settings_.nvmte(inner, iseed), avectmp);
141  VMStubsTEPHI atmp(iseed, inner, vectmp);
142  vmstubsTEPHI_.push_back(atmp);
143  }
144  vmstubsTEPHI_[seedindex].vmstubmem[(vmbin - 1) & (settings_.nvmte(inner, iseed) - 1)].push_back(tmp);
145 
146  } else if (memory->getName().substr(3, 2) == "ME") {
147  VMStubsMEMemory* tmp = dynamic_cast<VMStubsMEMemory*>(memory);
148  assert(tmp != nullptr);
149  vmstubsMEPHI_[(vmbin - 1) & (settings_.nvmme(layerdisk_) - 1)] = tmp;
150  } else {
151  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " should never get here!";
152  }
153 
154  return;
155  }
156 
157  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
158 }
159 
161  if (settings_.writetrace()) {
162  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
163  << input;
164  }
165  if (input == "stubin") {
166  InputLinkMemory* tmp1 = dynamic_cast<InputLinkMemory*>(memory);
167  assert(tmp1 != nullptr);
168  if (tmp1 != nullptr) {
169  if (layerdisk_ >= N_LAYER && tmp1->getName().find("2S_") != string::npos) {
170  stubinputdisk2stmp_.push_back(tmp1);
171  } else {
172  stubinputtmp_.push_back(tmp1);
173  }
174  }
175  //This gymnastic is done to ensure that in the disks the PS stubs are processed before
176  //the 2S stubs. This is needed by the current HLS implemenation of the VM router.
178  for (auto& mem : stubinputdisk2stmp_) {
179  stubinputs_.push_back(mem);
180  }
181  return;
182  }
183  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
184 }
185 
187  unsigned int allStubCounter = 0;
188 
189  //Loop over the input stubs
190  for (auto& stubinput : stubinputs_) {
191  for (unsigned int i = 0; i < stubinput->nStubs(); i++) {
192  if (allStubCounter >= settings_.maxStep("VMR"))
193  continue;
194  if (allStubCounter >= (1 << N_BITSMEMADDRESS))
195  continue;
196  Stub* stub = stubinput->getStub(i);
197 
198  //Note - below information is not part of the stub, but rather from which input memory we are reading
199  bool negdisk = (stub->disk().value() < 0);
200 
201  //use &127 to make sure we fit into the number of bits -
202  //though we should have protected against overflows above
203  FPGAWord allStubIndex(allStubCounter & ((1 << N_BITSMEMADDRESS) - 1), N_BITSMEMADDRESS, true, __LINE__, __FILE__);
204 
205  //TODO - should not be needed - but need to migrate some other pieces of code before removing
206  stub->setAllStubIndex(allStubCounter);
207  //TODO - should not be needed - but need to migrate some other pieces of code before removing
208  stub->l1tstub()->setAllStubIndex(allStubCounter);
209 
210  allStubCounter++;
211 
212  //Fill allstubs memories - in HLS this is the same write to multiple memories
213  for (auto& allstub : allstubs_) {
214  allstub->addStub(stub);
215  }
216 
217  //Fill all the ME VM memories
218 
219  FPGAWord iphi = stub->phicorr();
220  unsigned int ivm =
223  unsigned int extrabits = iphi.bits(iphi.nbits() - overlapbits_, nextrabits_);
224 
225  unsigned int ivmPlus = ivm;
226 
227  if (extrabits == ((1U << nextrabits_) - 1) && ivm != ((1U << settings_.nbitsvmme(layerdisk_)) - 1))
228  ivmPlus++;
229  unsigned int ivmMinus = ivm;
230  if (extrabits == 0 && ivm != 0)
231  ivmMinus--;
232 
233  //Calculate the z and r position for the vmstub
234 
235  //Take the top nbitszfinebintable_ bits of the z coordinate
236  int indexz = (((1 << (stub->z().nbits() - 1)) + stub->z().value()) >> (stub->z().nbits() - nbitszfinebintable_));
237  int indexr = -1;
238  if (layerdisk_ > (N_LAYER - 1)) {
239  if (negdisk) {
240  indexz = (1 << nbitszfinebintable_) - indexz;
241  }
242  indexr = stub->r().value();
243  if (stub->isPSmodule()) {
244  indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_);
245  }
246  } else {
247  //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values.
248  indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_));
249  }
250 
251  assert(indexz >= 0);
252  assert(indexr >= 0);
253  assert(indexz < (1 << nbitszfinebintable_));
254  assert(indexr < (1 << nbitsrfinebintable_));
255 
256  int melut = meTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
257  assert(melut >= 0);
258 
259  int vmbin = melut >> 3;
260  if (negdisk)
261  vmbin += 8;
262  int rzfine = melut & 7;
263 
264  // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility)
265  int nbendbits = stub->bend().nbits();
266  if (layerdisk_ >= N_LAYER)
267  nbendbits = settings_.nbendbitsmedisk();
268 
269  VMStubME vmstub(stub,
271  FPGAWord(rzfine, 3, true, __LINE__, __FILE__),
272  FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__),
273  allStubIndex);
274 
275  if (!(settings_.reduced()))
276  assert(vmstubsMEPHI_[ivmPlus] != nullptr);
277  if (vmstubsMEPHI_[ivmPlus] != nullptr)
278  vmstubsMEPHI_[ivmPlus]->addStub(vmstub, vmbin);
279  if (settings_.debugTracklet()) {
280  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmPlus]->getName()
281  << " ivmPlus" << ivmPlus << " bin=" << vmbin;
282  }
283 
284  if (ivmMinus != ivmPlus && vmstubsMEPHI_[ivmMinus] != nullptr) {
285  vmstubsMEPHI_[ivmMinus]->addStub(vmstub, vmbin);
286  if (settings_.debugTracklet()) {
287  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmMinus]->getName()
288  << " ivmMinus" << ivmMinus << " bin=" << vmbin;
289  }
290  }
291 
292  //Fill the TE VM memories
293 
294  for (auto& ivmstubTEPHI : vmstubsTEPHI_) {
295  unsigned int iseed = ivmstubTEPHI.seednumber;
296  unsigned int inner = ivmstubTEPHI.stubposition;
297  if ((iseed == Seed::D1D2 || iseed == Seed::D3D4 || iseed == Seed::L1D1 || iseed == Seed::L2D1) &&
298  (!stub->isPSmodule()))
299  continue;
300 
301  unsigned int lutwidth = settings_.lutwidthtab(inner, iseed);
302  if (settings_.extended()) {
304  }
305 
306  int lutval = -999;
307 
308  if (inner > 0) {
309  if (layerdisk_ < N_LAYER) {
310  lutval = melut;
311  } else {
312  if (inner == 2 && iseed == Seed::L2L3D1) {
313  lutval = 0;
314  if (stub->r().value() < 10) {
315  lutval = 8 * (1 + (stub->r().value() >> 2));
316  } else {
317  if (stub->r().value() < settings_.rmindiskl3overlapvm() / settings_.kr()) {
318  lutval = -1;
319  }
320  }
321  } else {
322  lutval = diskTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
323  }
324  }
325  if (lutval == -1)
326  continue;
327  } else {
328  if (iseed < Seed::L1D1 || iseed > Seed::L2D1) {
329  lutval = innerTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
330  } else {
331  lutval = innerOverlapTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
332  }
333  if (lutval == -1)
334  continue;
335  if (settings_.extended() &&
337  int lutval2 = innerThirdTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
338  if (lutval2 != -1)
339  lutval += (lutval2 << 10);
340  }
341  }
342 
343  assert(lutval >= 0);
344 
345  FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__);
346 
347  if (binlookup.value() < 0)
348  continue;
349 
350  unsigned int ivmte =
353 
354  int bin = -1;
355  if (inner != 0) {
356  bin = binlookup.value() / 8;
357  unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner...
358  binlookup.set(tmp, 3, true, __LINE__, __FILE__);
359  }
360 
362 
363  VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex);
364 
365  unsigned int nmem = ivmstubTEPHI.vmstubmem[ivmte].size();
366 
367  if (!(settings_.reduced()))
368  assert(nmem > 0);
369 
370  for (unsigned int l = 0; l < nmem; l++) {
371  if (settings_.debugTracklet()) {
372  edm::LogVerbatim("Tracklet") << getName() << " try adding stub to "
373  << ivmstubTEPHI.vmstubmem[ivmte][l]->getName() << " inner=" << inner
374  << " bin=" << bin;
375  }
376  if (inner == 0) {
377  ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub);
378  } else {
379  ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub, bin);
380  }
381  }
382  }
383  }
384  }
385 }
void addInput(MemoryBase *memory, std::string input) override
Definition: VMRouter.cc:160
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:191
Log< level::Info, true > LogVerbatim
Divides< B, C > D2
Definition: Factorize.h:137
TrackletLUT innerThirdTable_
Definition: VMRouter.h:62
std::vector< InputLinkMemory * > stubinputdisk2stmp_
Definition: VMRouter.h:65
unsigned int maxStep(std::string module) const
Definition: Settings.h:125
const FPGAWord & r() const
Definition: Stub.h:65
double lutwidthtab(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:149
std::string name_
Definition: ProcessBase.h:38
const FPGAWord & z() const
Definition: Stub.h:66
unsigned int nbendbitsmedisk() const
Definition: Settings.h:101
std::vector< InputLinkMemory * > stubinputtmp_
Definition: VMRouter.h:65
Settings const & settings_
Definition: ProcessBase.h:40
int lookup(unsigned int index) const
bool writetrace() const
Definition: Settings.h:195
const FPGAWord & bend() const
Definition: Stub.h:63
TrackletLUT innerTable_
Definition: VMRouter.h:60
bool reduced() const
Definition: Settings.h:272
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
const FPGAWord & disk() const
Definition: Stub.h:74
FPGAWord iphivmFineBins(int VMbits, int finebits) const
Definition: Stub.cc:109
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:115
void addOutput(MemoryBase *memory, std::string output) override
Definition: VMRouter.cc:59
double rmindiskl3overlapvm() const
Definition: Settings.h:360
void setAllStubIndex(int nstub)
Definition: Stub.cc:131
Divides< A, C > D1
Definition: Factorize.h:136
unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:104
std::vector< InputLinkMemory * > stubinputs_
Definition: VMRouter.h:65
int value() const
Definition: FPGAWord.h:24
double lutwidthtabextended(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:150
uint16_t mem[nChs][nEvts]
L1TStub * l1tstub()
Definition: Stub.h:83
std::string const & getName() const
Definition: MemoryBase.h:19
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:112
TrackletLUT meTable_
Definition: VMRouter.h:58
unsigned int overlapbits_
Definition: VMRouter.h:52
int nbitszfinebintable_
Definition: VMRouter.h:55
std::vector< VMStubsMEMemory * > vmstubsMEPHI_
Definition: VMRouter.h:71
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:110
int nbitsrfinebintable_
Definition: VMRouter.h:56
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:116
bool debugTracklet() const
Definition: Settings.h:194
unsigned int layerdisk_
Definition: VMRouter.h:48
double kr() const
Definition: Settings.h:344
int iseed
Definition: AMPTWrapper.h:134
unsigned int nextrabits_
Definition: VMRouter.h:53
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:77
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:142
TrackletLUT innerOverlapTable_
Definition: VMRouter.h:61
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
const FPGAWord & phicorr() const
Definition: Stub.h:69
bool extended() const
Definition: Settings.h:268
unsigned int nvmme(unsigned int layerdisk) const
Definition: Settings.h:113
double nphireg(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:143
TrackletLUT diskTable_
Definition: VMRouter.h:59
Definition: output.py:1
void setAllStubIndex(unsigned int index)
Definition: L1TStub.h:83
std::vector< AllStubsMemory * > allstubs_
Definition: VMRouter.h:68
tmp
align.sh
Definition: createJobs.py:716
std::vector< VMStubsTEPHI > vmstubsTEPHI_
Definition: VMRouter.h:74
std::string const & getName() const
Definition: ProcessBase.h:22
void initVMRTable(unsigned int layerdisk, VMRTableType type, int region=-1)
Definition: TrackletLUT.cc:998
constexpr unsigned int N_BITSMEMADDRESS
Definition: Settings.h:43
unsigned int vmrlutzbits(unsigned int layerdisk) const
Definition: Settings.h:190
constexpr int N_LAYER
Definition: Settings.h:25