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  unsigned int pos = 12;
63  int vmbin = memory->getName().substr(pos, 1)[0] - '0';
64  pos++;
65  if (pos < memory->getName().size()) {
66  if (memory->getName().substr(pos, 1)[0] != 'n') {
67  vmbin = vmbin * 10 + memory->getName().substr(pos, 1)[0] - '0';
68  pos++;
69  }
70  }
71  if (memory->getName().substr(3, 2) == "TE") {
72  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
73  unsigned int iseed = output[output.size() - 1] - '0';
75 
76  int seedindex = -1;
77  for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) {
78  if (vmstubsTEPHI_[k].seednumber == iseed) {
79  seedindex = k;
80  }
81  }
82  if (seedindex == -1) {
83  seedindex = vmstubsTEPHI_.size();
84  vector<VMStubsTEMemory*> vectmp;
85  VMStubsTEPHICM atmp(iseed, vectmp);
86  vmstubsTEPHI_.push_back(atmp);
87  }
88  tmp->resize(settings_.NLONGVMBINS() * settings_.nvmte(1, iseed));
89  vmstubsTEPHI_[seedindex].vmstubmem.push_back(tmp);
90 
91  } else if (memory->getName().substr(3, 2) == "ME") {
92  VMStubsMEMemory* tmp = dynamic_cast<VMStubsMEMemory*>(memory);
93  assert(tmp != nullptr);
95  assert(vmstubsMEPHI_[0] == nullptr);
96  vmstubsMEPHI_[0] = tmp;
97  } else {
98  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " memory: " << memory->getName()
99  << " => should never get here!";
100  }
101 
102  return;
103  }
104 
105  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
106 }
107 
109  if (settings_.writetrace()) {
110  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
111  << input;
112  }
113  if (input == "stubin") {
114  InputLinkMemory* tmp1 = dynamic_cast<InputLinkMemory*>(memory);
115  assert(tmp1 != nullptr);
116  if (tmp1 != nullptr) {
117  stubinputs_.push_back(tmp1);
118  }
119  return;
120  }
121  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
122 }
123 
125  unsigned int allStubCounter = 0;
126 
127  //Loop over the input stubs
128  for (auto& stubinput : stubinputs_) {
129  for (unsigned int i = 0; i < stubinput->nStubs(); i++) {
130  if (allStubCounter > settings_.maxStep("VMR"))
131  continue;
132  if (allStubCounter >= (1 << N_BITSMEMADDRESS))
133  continue;
134 
135  Stub* stub = stubinput->getStub(i);
136 
137  //Note - below information is not part of the stub, but rather from which input memory
138  //we are reading
139  bool negdisk = (stub->disk().value() < 0);
140 
141  //use &127 to make sure we fit into the number of bits -
142  //though we should have protected against overflows above
143  FPGAWord allStubIndex(allStubCounter & ((1 << N_BITSMEMADDRESS) - 1), N_BITSMEMADDRESS, true, __LINE__, __FILE__);
144 
145  //TODO - should not be needed - but need to migrate some other pieces of code before removing
146  stub->setAllStubIndex(allStubCounter);
147  //TODO - should not be needed - but need to migrate some other pieces of code before removing
148  stub->l1tstub()->setAllStubIndex(allStubCounter);
149 
150  allStubCounter++;
151 
152  for (auto& allstub : allstubs_) {
153  allstub->addStub(stub);
154  if (settings_.debugTracklet()) {
155  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub->getName();
156  }
157  }
158 
159  FPGAWord iphi = stub->phicorr();
160  unsigned int iphipos = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + N_PHIBITS), N_PHIBITS);
161 
162  unsigned int phicutmax = 4;
163  unsigned int phicutmin = 4;
164 
165  if (layerdisk_ != 0) {
166  phicutmax = 6;
167  phicutmin = 2;
168  }
169 
170  //Fill inner allstubs memories - in HLS this is the same write to multiple memories
171  for (auto& allstub : allinnerstubs_) {
172  char memtype = allstub.first;
173  if (memtype == 'R' && iphipos < phicutmax)
174  continue;
175  if (memtype == 'L' && iphipos >= phicutmin)
176  continue;
177  if (memtype == 'A' && iphipos < 4)
178  continue;
179  if (memtype == 'B' && iphipos >= 4)
180  continue;
181  if (memtype == 'E' && iphipos >= 4)
182  continue;
183  if (memtype == 'F' && iphipos < 4)
184  continue;
185  if (memtype == 'C' && iphipos >= 4)
186  continue;
187  if (memtype == 'D' && iphipos < 4)
188  continue;
189 
190  int absz = std::abs(stub->z().value());
192  continue;
195  continue;
197  stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr())
198  continue;
199  if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->r().value() < 2 * int(N_DSS_MOD))
200  continue;
201  if (layerdisk_ == LayerDisk::L1) {
202  if (memtype == 'M' || memtype == 'R' || memtype == 'L') {
203  if (absz < VMROUTERCUTZL1 / settings_.kz(layerdisk_))
204  continue;
205  } else {
207  continue;
208  }
209  }
210 
211  if (settings_.debugTracklet()) {
212  edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub.second->getName();
213  }
214 
215  allstub.second->addStub(stub);
216  }
217 
218  //Fill all the ME VM memories
219  unsigned int ivm =
222 
223  //Calculate the z and r position for the vmstub
224 
225  //Take the top nbitszfinebintable_ bits of the z coordinate
226  int indexz = (stub->z().value() >> (stub->z().nbits() - nbitszfinebintable_)) & ((1 << nbitszfinebintable_) - 1);
227  int indexr = -1;
228  if (layerdisk_ > (N_LAYER - 1)) {
229  if (negdisk) {
230  indexz = ((1 << nbitszfinebintable_) - 1) - indexz;
231  }
232  indexr = stub->r().value();
233  if (stub->isPSmodule()) {
234  indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_);
235  }
236  } else {
237  //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values.
238  indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1);
239  }
240 
241  assert(indexz >= 0);
242  assert(indexr >= 0);
243  assert(indexz < (1 << nbitszfinebintable_));
244  assert(indexr < (1 << nbitsrfinebintable_));
245 
246  int melut = meTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
247 
248  assert(melut >= 0);
249 
250  int vmbin = melut >> NFINERZBITS;
251  if (negdisk)
252  vmbin += (1 << NFINERZBITS);
253  int rzfine = melut & ((1 << NFINERZBITS) - 1);
254 
255  // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility)
256  int nbendbits = stub->bend().nbits();
257  if (layerdisk_ >= N_LAYER)
258  nbendbits = settings_.nbendbitsmedisk();
259 
260  VMStubME vmstub(
261  stub,
263  FPGAWord(rzfine, NFINERZBITS, true, __LINE__, __FILE__),
264  FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__),
265  allStubIndex);
266 
267  assert(vmstubsMEPHI_[0] != nullptr);
268 
269  vmstubsMEPHI_[0]->addStub(vmstub, ivm * nvmmebins_ + vmbin);
270 
271  //Fill the TE VM memories
272  if (layerdisk_ >= N_LAYER && (!stub->isPSmodule()))
273  continue;
274 
275  for (auto& ivmstubTEPHI : vmstubsTEPHI_) {
276  unsigned int iseed = ivmstubTEPHI.seednumber;
277  unsigned int lutwidth = settings_.lutwidthtab(1, iseed);
278 
279  int lutval = -999;
280 
281  if (layerdisk_ < N_LAYER) {
282  lutval = melut;
283  } else {
284  lutval = diskTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
285  if (lutval == 0) {
286  continue;
287  }
288  }
289 
290  assert(lutval >= 0);
291 
292  FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__);
293 
294  if (binlookup.value() < 0)
295  continue;
296 
297  unsigned int ivmte =
300 
301  int bin = binlookup.value() / 8;
302  unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner...
303  binlookup.set(tmp, 3, true, __LINE__, __FILE__);
304 
306 
307  VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex);
308 
309  unsigned int nmem = ivmstubTEPHI.vmstubmem.size();
310  assert(nmem > 0);
311 
312  for (unsigned int l = 0; l < nmem; l++) {
313  if (settings_.debugTracklet()) {
314  edm::LogVerbatim("Tracklet") << getName() << " try adding stub to " << ivmstubTEPHI.vmstubmem[l]->getName()
315  << " bin=" << bin << " ivmte " << ivmte << " finephi " << finephi.value()
316  << " regions bits " << settings_.nphireg(1, iseed) << " finephibits "
317  << settings_.nfinephi(1, iseed);
318  }
319  ivmstubTEPHI.vmstubmem[l]->addVMStub(tmpstub, ivmte * settings_.NLONGVMBINS() + bin);
320  }
321  }
322  }
323  }
324 }
size
Write out results.
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:179
Log< level::Info, true > LogVerbatim
double kz() const
Definition: Settings.h:302
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:900
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:47
unsigned int NLONGVMBINS() const
Definition: Settings.h:329
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
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:304
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
void setAllStubIndex(unsigned int index)
Definition: L1TStub.h:81
void addInput(MemoryBase *memory, std::string input) override
Definition: VMRouterCM.cc:108
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:490
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