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, unsigned int iSector)
17  : ProcessBase(name, settings, global, iSector), vmrtable_(settings) {
19 
20  vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr);
21 
22  overlapbits_ = 7;
24 
26 
29 }
30 
32  if (settings_.writetrace()) {
33  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
34  << output;
35  }
36 
37  if (output.substr(0, 10) == "allstubout") {
38  AllStubsMemory* tmp = dynamic_cast<AllStubsMemory*>(memory);
39  assert(tmp != nullptr);
40  allstubs_.push_back(tmp);
41  return;
42  }
43 
44  if (output.substr(0, 12) == "vmstuboutPHI") {
45  char seedtype = memory->getName().substr(11, 1)[0];
46  unsigned int pos = 12;
47  int vmbin = memory->getName().substr(pos, 1)[0] - '0';
48  pos++;
49  if (pos < memory->getName().size()) {
50  if (memory->getName().substr(pos, 1)[0] != 'n') {
51  vmbin = vmbin * 10 + memory->getName().substr(pos, 1)[0] - '0';
52  pos++;
53  }
54  }
55 
56  int iseed = -1;
57  unsigned int inner = 1;
58  if (memory->getName().substr(3, 2) == "TE") {
59  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
60  assert(tmp != nullptr);
61  if (seedtype < 'I') {
62  if (layerdisk_ == 0 || layerdisk_ == 1)
63  iseed = 0;
64  if (layerdisk_ == 2 || layerdisk_ == 3)
65  iseed = 2;
66  if (layerdisk_ == 4 || layerdisk_ == 5)
67  iseed = 3;
68  if (layerdisk_ == 6 || layerdisk_ == 7)
69  iseed = 4;
70  if (layerdisk_ == 8 || layerdisk_ == 9)
71  iseed = 5;
72  if (layerdisk_ == 0 || layerdisk_ == 2 || layerdisk_ == 4 || layerdisk_ == 6 || layerdisk_ == 8)
73  inner = 0;
74  } else if (seedtype < 'M') {
75  if (layerdisk_ == 1 || layerdisk_ == 2)
76  iseed = 1;
77  if (layerdisk_ == 1)
78  inner = 0;
79  } else if (seedtype <= 'Z') {
80  if (layerdisk_ == 0 || layerdisk_ == 6)
81  iseed = 6;
82  if (layerdisk_ == 1 || layerdisk_ == 6)
83  iseed = 7;
84  if (layerdisk_ == 0 || layerdisk_ == 1)
85  inner = 0;
86  } else if (seedtype < 'o' && seedtype >= 'a') {
87  if (layerdisk_ == 1 || layerdisk_ == 2)
88  iseed = 10;
89  if (layerdisk_ == 1)
90  inner = 0;
91  } else if (seedtype > 'o' && seedtype <= 'z') {
92  if (layerdisk_ == 1)
93  iseed = 11;
94  if (layerdisk_ == 6)
95  iseed = 10;
96  inner = 2;
97  } else {
98  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!";
99  }
100  assert(iseed != -1);
101  int seedindex = -1;
102  for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) {
103  if (vmstubsTEPHI_[k].seednumber == (unsigned int)iseed) {
104  seedindex = k;
105  }
106  }
107  if (seedindex == -1) {
108  seedindex = vmstubsTEPHI_.size();
109  vector<VMStubsTEMemory*> avectmp;
110  vector<vector<VMStubsTEMemory*> > vectmp(settings_.nvmte(inner, iseed), avectmp);
111  VMStubsTEPHI atmp(iseed, inner, vectmp);
112  vmstubsTEPHI_.push_back(atmp);
113  }
114  vmstubsTEPHI_[seedindex].vmstubmem[(vmbin - 1) & (settings_.nvmte(inner, iseed) - 1)].push_back(tmp);
115 
116  } else if (memory->getName().substr(3, 2) == "ME") {
117  VMStubsMEMemory* tmp = dynamic_cast<VMStubsMEMemory*>(memory);
118  assert(tmp != nullptr);
119  vmstubsMEPHI_[(vmbin - 1) & (settings_.nvmme(layerdisk_) - 1)] = tmp;
120  } else {
121  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " should never get here!";
122  }
123 
124  return;
125  }
126 
127  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
128 }
129 
131  if (settings_.writetrace()) {
132  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
133  << input;
134  }
135  if (input == "stubin") {
136  InputLinkMemory* tmp1 = dynamic_cast<InputLinkMemory*>(memory);
137  assert(tmp1 != nullptr);
138  if (tmp1 != nullptr) {
139  stubinputs_.push_back(tmp1);
140  }
141  return;
142  }
143  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
144 }
145 
147  unsigned int allStubCounter = 0;
148 
149  //Loop over the input stubs
150  for (auto& stubinput : stubinputs_) {
151  for (unsigned int i = 0; i < stubinput->nStubs(); i++) {
152  if (allStubCounter > settings_.maxStep("VMR"))
153  continue;
154  if (allStubCounter > 127)
155  continue;
156  Stub* stub = stubinput->getStub(i);
157 
158  //Note - below information is not part of the stub, but rather from which input memory we are reading
159  bool negdisk = (stub->disk().value() < 0);
160 
161  //use &127 to make sure we fit into the number of bits -
162  //though we should have protected against overflows above
163  FPGAWord allStubIndex(allStubCounter & 127, 7, true, __LINE__, __FILE__);
164 
165  //TODO - should not be needed - but need to migrate some other pieces of code before removing
166  stub->setAllStubIndex(allStubCounter);
167  //TODO - should not be needed - but need to migrate some other pieces of code before removing
168  stub->l1tstub()->setAllStubIndex(allStubCounter);
169 
170  allStubCounter++;
171 
172  //Fill allstubs memories - in HLS this is the same write to multiple memories
173  for (auto& allstub : allstubs_) {
174  allstub->addStub(stub);
175  }
176 
177  //Fill all the ME VM memories
178 
179  FPGAWord iphi = stub->phicorr();
180  unsigned int ivm =
183  unsigned int extrabits = iphi.bits(iphi.nbits() - overlapbits_, nextrabits_);
184 
185  unsigned int ivmPlus = ivm;
186 
187  if (extrabits == ((1U << nextrabits_) - 1) && ivm != ((1U << settings_.nbitsvmme(layerdisk_)) - 1))
188  ivmPlus++;
189  unsigned int ivmMinus = ivm;
190  if (extrabits == 0 && ivm != 0)
191  ivmMinus--;
192 
193  //Calculate the z and r position for the vmstub
194 
195  //Take the top nbitszfinebintable_ bits of the z coordinate
196  int indexz = (((1 << (stub->z().nbits() - 1)) + stub->z().value()) >> (stub->z().nbits() - nbitszfinebintable_));
197  int indexr = -1;
198  if (layerdisk_ > (N_LAYER - 1)) {
199  if (negdisk) {
200  indexz = (1 << nbitszfinebintable_) - indexz;
201  }
202  indexr = stub->r().value();
203  if (stub->isPSmodule()) {
204  indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_);
205  }
206  } else {
207  //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values.
208  indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_));
209  }
210 
211  assert(indexz >= 0);
212  assert(indexr >= 0);
213  assert(indexz < (1 << nbitszfinebintable_));
214  assert(indexr < (1 << nbitsrfinebintable_));
215 
216  int melut = vmrtable_.lookup(indexz, indexr);
217 
218  assert(melut >= 0);
219 
220  int vmbin = melut >> 3;
221  if (negdisk)
222  vmbin += 8;
223  int rzfine = melut & 7;
224 
225  // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility)
226  int nbendbits = stub->bend().nbits();
227  if (layerdisk_ >= N_LAYER)
228  nbendbits = settings_.nbendbitsmedisk();
229 
230  VMStubME vmstub(
231  stub,
234  FPGAWord(rzfine, 3, true, __LINE__, __FILE__),
235  FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__),
236  allStubIndex);
237 
238  assert(vmstubsMEPHI_[ivmPlus] != nullptr);
239  vmstubsMEPHI_[ivmPlus]->addStub(vmstub, vmbin);
240 
241  if (ivmMinus != ivmPlus) {
242  assert(vmstubsMEPHI_[ivmMinus] != nullptr);
243  vmstubsMEPHI_[ivmMinus]->addStub(vmstub, vmbin);
244  }
245 
246  //Fill the TE VM memories
247 
248  for (auto& ivmstubTEPHI : vmstubsTEPHI_) {
249  unsigned int iseed = ivmstubTEPHI.seednumber;
250  unsigned int inner = ivmstubTEPHI.stubposition;
251  if ((iseed == 4 || iseed == 5 || iseed == 6 || iseed == 7) && (!stub->isPSmodule()))
252  continue;
253 
254  unsigned int lutwidth = settings_.lutwidthtab(inner, iseed);
255  if (settings_.extended()) {
257  }
258 
259  int lutval = -999;
260 
261  if (inner > 0) {
262  if (layerdisk_ < N_LAYER) {
263  lutval = melut;
264  } else {
265  if (inner == 2 && iseed == 10) {
266  lutval = 0;
267  if (stub->r().value() < 10) {
268  lutval = 8 * (1 + (stub->r().value() >> 2));
269  } else {
270  if (stub->r().value() < settings_.rmindiskl3overlapvm() / settings_.kr()) {
271  lutval = -1;
272  }
273  }
274  } else {
275  lutval = vmrtable_.lookupdisk(indexz, indexr);
276  }
277  }
278  if (lutval == -1)
279  continue;
280  } else {
281  if (iseed < 6 || iseed > 7) {
282  lutval = vmrtable_.lookupinner(indexz, indexr);
283  } else {
284  lutval = vmrtable_.lookupinneroverlap(indexz, indexr);
285  }
286  if (lutval == -1)
287  continue;
288  if (settings_.extended() && (iseed == 2 || iseed == 3 || iseed == 10 || iseed == 4)) {
289  int lutval2 = vmrtable_.lookupinnerThird(indexz, indexr);
290  if (lutval2 == -1)
291  continue;
292  lutval += (lutval2 << 10);
293  }
294  }
295 
296  assert(lutval >= 0);
297 
298  FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__);
299 
300  if (binlookup.value() < 0)
301  continue;
302 
303  unsigned int ivmte =
306 
307  int bin = -1;
308  if (inner != 0) {
309  bin = binlookup.value() / 8;
310  unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner...
311  binlookup.set(tmp, 3, true, __LINE__, __FILE__);
312  }
313 
315 
316  VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex);
317 
318  unsigned int nmem = ivmstubTEPHI.vmstubmem[ivmte].size();
319 
320  assert(nmem > 0);
321 
322  for (unsigned int l = 0; l < nmem; l++) {
323  if (settings_.debugTracklet()) {
324  edm::LogVerbatim("Tracklet") << getName() << " try adding stub to "
325  << ivmstubTEPHI.vmstubmem[ivmte][l]->getName() << " inner=" << inner
326  << " bin=" << bin;
327  }
328  if (inner == 0) {
329  ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub);
330  } else {
331  ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub, bin);
332  }
333  }
334  }
335  }
336  }
337 }
Settings.h
trklet::VMRouter::nextrabits_
unsigned int nextrabits_
Definition: VMRouter.h:53
trklet::AllStubsMemory
Definition: AllStubsMemory.h:16
mps_fire.i
i
Definition: mps_fire.py:355
trklet::Settings::writetrace
bool writetrace() const
Definition: Settings.h:147
trklet::VMStubsMEMemory
Definition: VMStubsMEMemory.h:16
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
trklet::VMStubTE
Definition: VMStubTE.h:15
trklet::VMRouterTable::lookupdisk
int lookupdisk(int zbin, int rbin)
Definition: VMRouterTable.cc:266
AllStubsMemory.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
trklet::Stub::bend
const FPGAWord & bend() const
Definition: Stub.h:47
pos
Definition: PixelAliasList.h:18
trklet::Settings::vmrlutrbits
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:143
trklet::Settings
Definition: Settings.h:26
trklet::Settings::nbitsallstubs
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:83
trklet::VMStubsTEMemory
Definition: VMStubsTEMemory.h:16
cms::cuda::assert
assert(be >=bs)
trklet::FPGAWord::set
void set(int value, int nbits, bool positive=true, int line=-1, const char *file=nullptr)
Definition: FPGAWord.cc:14
VMRouter.h
trklet::VMRouter::vmrtable_
VMRouterTable vmrtable_
Definition: VMRouter.h:58
trklet::Settings::lutwidthtab
double lutwidthtab(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:114
trklet::ProcessBase::settings_
Settings const & settings_
Definition: ProcessBase.h:44
trklet::VMRouterTable::lookupinneroverlap
int lookupinneroverlap(int zbin, int rbin)
Definition: VMRouterTable.cc:278
trklet::FPGAWord::nbits
int nbits() const
Definition: FPGAWord.h:25
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
trklet::Globals
Definition: Globals.h:32
InputLinkMemory.h
trklet::Stub::r
const FPGAWord & r() const
Definition: Stub.h:49
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
trklet::VMRouterTable::lookup
int lookup(int zbin, int rbin)
Definition: VMRouterTable.cc:260
trklet::InputLinkMemory
Definition: InputLinkMemory.h:18
trklet::Stub::disk
const FPGAWord & disk() const
Definition: Stub.h:57
trklet::Stub::iphivmFineBins
FPGAWord iphivmFineBins(int VMbits, int finebits) const
Definition: Stub.cc:172
trklet::Stub::z
const FPGAWord & z() const
Definition: Stub.h:50
trklet::Settings::lutwidthtabextended
double lutwidthtabextended(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:115
trklet::VMRouter::overlapbits_
unsigned int overlapbits_
Definition: VMRouter.h:52
trklet::Stub
Definition: Stub.h:16
SurfaceOrientation::inner
Definition: Surface.h:19
trklet::Settings::nbitsvmme
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:80
trklet::N_LAYER
constexpr int N_LAYER
Definition: Settings.h:19
trklet::VMRouterTable::lookupinnerThird
int lookupinnerThird(int zbin, int rbin)
Definition: VMRouterTable.cc:284
trklet::VMRouter::vmstubsTEPHI_
std::vector< VMStubsTEPHI > vmstubsTEPHI_
Definition: VMRouter.h:70
trklet::VMRouter::layerdisk_
unsigned int layerdisk_
Definition: VMRouter.h:48
trklet::VMRouter::execute
void execute()
Definition: VMRouter.cc:146
dqmdumpme.k
k
Definition: dqmdumpme.py:60
trklet::VMRouter::allstubs_
std::vector< AllStubsMemory * > allstubs_
Definition: VMRouter.h:64
trklet::VMRouter::nbitsrfinebintable_
int nbitsrfinebintable_
Definition: VMRouter.h:56
trklet::FPGAWord
Definition: FPGAWord.h:9
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
trklet::VMRouterTable::lookupinner
int lookupinner(int zbin, int rbin)
Definition: VMRouterTable.cc:272
trklet::ProcessBase::initLayerDisk
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: ProcessBase.cc:45
trklet::Settings::kr
double kr() const
Definition: Settings.h:250
VMStubsMEMemory.h
trklet::VMRouter::stubinputs_
std::vector< InputLinkMemory * > stubinputs_
Definition: VMRouter.h:61
trklet::MemoryBase
Definition: MemoryBase.h:13
iseed
int iseed
Definition: AMPTWrapper.h:134
trklet::Settings::extended
bool extended() const
Definition: Settings.h:207
trklet::Settings::nvmme
unsigned int nvmme(unsigned int layerdisk) const
Definition: Settings.h:81
trklet::Settings::rmindiskl3overlapvm
double rmindiskl3overlapvm() const
Definition: Settings.h:265
Globals.h
edm::LogVerbatim
Definition: MessageLogger.h:297
trklet::Settings::nphireg
double nphireg(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:113
trklet
Definition: AllProjectionsMemory.h:9
trklet::Stub::setAllStubIndex
void setAllStubIndex(int nstub)
Definition: Stub.cc:188
trklet::FPGAWord::value
int value() const
Definition: FPGAWord.h:24
trklet::VMRouter::nbitszfinebintable_
int nbitszfinebintable_
Definition: VMRouter.h:55
VMStubsTEMemory.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
trklet::Settings::nbitsvmte
unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:77
trklet::VMRouterTable::init
void init(unsigned int layerdisk)
Definition: VMRouterTable.cc:16
std
Definition: JetResolutionObject.h:76
VMStubTE.h
trklet::Stub::phicorr
const FPGAWord & phicorr() const
Definition: Stub.h:52
trklet::ProcessBase
Definition: ProcessBase.h:12
trklet::Stub::l1tstub
L1TStub * l1tstub()
Definition: Stub.h:69
trklet::Settings::vmrlutzbits
unsigned int vmrlutzbits(unsigned int layerdisk) const
Definition: Settings.h:142
Exception
Definition: hltDiff.cc:246
trklet::VMRouter::addInput
void addInput(MemoryBase *memory, std::string input) override
Definition: VMRouter.cc:130
trklet::ProcessBase::getName
std::string const & getName() const
Definition: ProcessBase.h:22
trklet::Settings::nvmte
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:78
trklet::ProcessBase::name_
std::string name_
Definition: ProcessBase.h:38
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
trklet::Settings::debugTracklet
bool debugTracklet() const
Definition: Settings.h:146
Exception.h
trklet::VMRouter::vmstubsMEPHI_
std::vector< VMStubsMEMemory * > vmstubsMEPHI_
Definition: VMRouter.h:67
trklet::Stub::isPSmodule
bool isPSmodule() const
Definition: Stub.h:63
trklet::Settings::maxStep
unsigned int maxStep(std::string module) const
Definition: Settings.h:93
trklet::Settings::nfinephi
double nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:112
trklet::L1TStub::setAllStubIndex
void setAllStubIndex(unsigned int index)
Definition: L1TStub.h:80
trklet::VMStubME
Definition: VMStubME.h:15
trklet::VMStubsTEPHI
Definition: VMRouter.h:23
trklet::VMRouter::addOutput
void addOutput(MemoryBase *memory, std::string output) override
Definition: VMRouter.cc:31
memory
Definition: vlib.h:178
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
trklet::Settings::nbendbitsmedisk
unsigned int nbendbitsmedisk() const
Definition: Settings.h:74