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  assert(vmstubsMEPHI_[ivmPlus] != nullptr);
276  vmstubsMEPHI_[ivmPlus]->addStub(vmstub, vmbin);
277  if (settings_.debugTracklet()) {
278  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmPlus]->getName()
279  << " ivmPlus" << ivmPlus << " bin=" << vmbin;
280  }
281 
282  if (ivmMinus != ivmPlus) {
283  assert(vmstubsMEPHI_[ivmMinus] != nullptr);
284  vmstubsMEPHI_[ivmMinus]->addStub(vmstub, vmbin);
285  if (settings_.debugTracklet()) {
286  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmMinus]->getName()
287  << " ivmMinus" << ivmMinus << " bin=" << vmbin;
288  }
289  }
290 
291  //Fill the TE VM memories
292 
293  for (auto& ivmstubTEPHI : vmstubsTEPHI_) {
294  unsigned int iseed = ivmstubTEPHI.seednumber;
295  unsigned int inner = ivmstubTEPHI.stubposition;
296  if ((iseed == Seed::D1D2 || iseed == Seed::D3D4 || iseed == Seed::L1D1 || iseed == Seed::L2D1) &&
297  (!stub->isPSmodule()))
298  continue;
299 
300  unsigned int lutwidth = settings_.lutwidthtab(inner, iseed);
301  if (settings_.extended()) {
303  }
304 
305  int lutval = -999;
306 
307  if (inner > 0) {
308  if (layerdisk_ < N_LAYER) {
309  lutval = melut;
310  } else {
311  if (inner == 2 && iseed == Seed::L2L3D1) {
312  lutval = 0;
313  if (stub->r().value() < 10) {
314  lutval = 8 * (1 + (stub->r().value() >> 2));
315  } else {
316  if (stub->r().value() < settings_.rmindiskl3overlapvm() / settings_.kr()) {
317  lutval = -1;
318  }
319  }
320  } else {
321  lutval = diskTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
322  }
323  }
324  if (lutval == -1)
325  continue;
326  } else {
327  if (iseed < Seed::L1D1 || iseed > Seed::L2D1) {
328  lutval = innerTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
329  } else {
330  lutval = innerOverlapTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
331  }
332  if (lutval == -1)
333  continue;
334  if (settings_.extended() &&
336  int lutval2 = innerThirdTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
337  if (lutval2 != -1)
338  lutval += (lutval2 << 10);
339  }
340  }
341 
342  assert(lutval >= 0);
343 
344  FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__);
345 
346  if (binlookup.value() < 0)
347  continue;
348 
349  unsigned int ivmte =
352 
353  int bin = -1;
354  if (inner != 0) {
355  bin = binlookup.value() / 8;
356  unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner...
357  binlookup.set(tmp, 3, true, __LINE__, __FILE__);
358  }
359 
361 
362  VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex);
363 
364  unsigned int nmem = ivmstubTEPHI.vmstubmem[ivmte].size();
365 
366  assert(nmem > 0);
367 
368  for (unsigned int l = 0; l < nmem; l++) {
369  if (settings_.debugTracklet()) {
370  edm::LogVerbatim("Tracklet") << getName() << " try adding stub to "
371  << ivmstubTEPHI.vmstubmem[ivmte][l]->getName() << " inner=" << inner
372  << " bin=" << bin;
373  }
374  if (inner == 0) {
375  ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub);
376  } else {
377  ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub, bin);
378  }
379  }
380  }
381  }
382  }
383 }
size
Write out results.
void addInput(MemoryBase *memory, std::string input) override
Definition: VMRouter.cc:160
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:179
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:116
const FPGAWord & r() const
Definition: Stub.h:60
double lutwidthtab(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:140
std::string name_
Definition: ProcessBase.h:38
const FPGAWord & z() const
Definition: Stub.h:61
unsigned int nbendbitsmedisk() const
Definition: Settings.h:92
std::vector< InputLinkMemory * > stubinputtmp_
Definition: VMRouter.h:65
Settings const & settings_
Definition: ProcessBase.h:40
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:901
bool writetrace() const
Definition: Settings.h:183
const FPGAWord & bend() const
Definition: Stub.h:58
TrackletLUT innerTable_
Definition: VMRouter.h:60
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
const FPGAWord & disk() const
Definition: Stub.h:68
FPGAWord iphivmFineBins(int VMbits, int finebits) const
Definition: Stub.cc:107
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:106
void addOutput(MemoryBase *memory, std::string output) override
Definition: VMRouter.cc:59
double rmindiskl3overlapvm() const
Definition: Settings.h:320
void setAllStubIndex(int nstub)
Definition: Stub.cc:123
Divides< A, C > D1
Definition: Factorize.h:136
unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:95
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:141
uint16_t mem[nChs][nEvts]
L1TStub * l1tstub()
Definition: Stub.h:77
std::string const & getName() const
Definition: MemoryBase.h:19
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:103
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:101
int nbitsrfinebintable_
Definition: VMRouter.h:56
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
bool debugTracklet() const
Definition: Settings.h:182
unsigned int layerdisk_
Definition: VMRouter.h:48
double kr() const
Definition: Settings.h:304
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:71
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:133
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:63
bool extended() const
Definition: Settings.h:248
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 diskTable_
Definition: VMRouter.h:59
void setAllStubIndex(unsigned int index)
Definition: L1TStub.h:81
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:491
constexpr unsigned int N_BITSMEMADDRESS
Definition: Settings.h:39
unsigned int vmrlutzbits(unsigned int layerdisk) const
Definition: Settings.h:178
constexpr int N_LAYER
Definition: Settings.h:21