CMS 3D CMS Logo

VMRouterCM.cc
Go to the documentation of this file.
9 
12 
13 using namespace std;
14 using namespace trklet;
15 
16 VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global, unsigned int iSector)
17  : ProcessBase(name, settings, global, iSector), vmrtable_(settings) {
19 
20  vmstubsMEPHI_.resize(1, nullptr);
21 
22  overlapbits_ = 7;
24 
26 
29 
30  nvmmebins_ = settings_.NLONGVMBINS() * ((layerdisk_ >= 6) ? 2 : 1); //number of long z/r bins in VM
31 }
32 
34  if (settings_.writetrace()) {
35  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
36  << output;
37  }
38 
39  if (output.substr(0, 10) == "allstubout") {
40  AllStubsMemory* tmp = dynamic_cast<AllStubsMemory*>(memory);
41  assert(tmp != nullptr);
42  char memtype = 0;
43  if (output.size() > 10) {
44  memtype = output[11];
45  }
46  allstubs_.emplace_back(memtype, tmp);
47  return;
48  }
49 
50  if (output.substr(0, 9) == "vmstubout") {
51  unsigned int pos = 12;
52  int vmbin = memory->getName().substr(pos, 1)[0] - '0';
53  pos++;
54  if (pos < memory->getName().size()) {
55  if (memory->getName().substr(pos, 1)[0] != 'n') {
56  vmbin = vmbin * 10 + memory->getName().substr(pos, 1)[0] - '0';
57  pos++;
58  }
59  }
60  if (memory->getName().substr(3, 2) == "TE") {
61  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
62  int iseed = output[output.size() - 1] - '0';
63  assert(iseed >= 0);
64  assert(iseed < 8);
65 
66  int seedindex = -1;
67  for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) {
68  if (vmstubsTEPHI_[k].seednumber == (unsigned int)iseed) {
69  seedindex = k;
70  }
71  }
72  if (seedindex == -1) {
73  seedindex = vmstubsTEPHI_.size();
74  vector<VMStubsTEMemory*> vectmp;
75  VMStubsTEPHICM atmp(iseed, vectmp);
76  vmstubsTEPHI_.push_back(atmp);
77  }
78  tmp->resize(settings_.NLONGVMBINS() * settings_.nvmte(1, iseed));
79  vmstubsTEPHI_[seedindex].vmstubmem.push_back(tmp);
80 
81  } else if (memory->getName().substr(3, 2) == "ME") {
82  VMStubsMEMemory* tmp = dynamic_cast<VMStubsMEMemory*>(memory);
83  assert(tmp != nullptr);
85  assert(vmstubsMEPHI_[0] == nullptr);
86  vmstubsMEPHI_[0] = tmp;
87  } else {
88  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " memory: " << memory->getName()
89  << " => should never get here!";
90  }
91 
92  return;
93  }
94 
95  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
96 }
97 
99  if (settings_.writetrace()) {
100  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
101  << input;
102  }
103  if (input == "stubin") {
104  InputLinkMemory* tmp1 = dynamic_cast<InputLinkMemory*>(memory);
105  assert(tmp1 != nullptr);
106  if (tmp1 != nullptr) {
107  stubinputs_.push_back(tmp1);
108  }
109  return;
110  }
111  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
112 }
113 
115  unsigned int allStubCounter = 0;
116 
117  //Loop over the input stubs
118  for (auto& stubinput : stubinputs_) {
119  for (unsigned int i = 0; i < stubinput->nStubs(); i++) {
120  if (allStubCounter > settings_.maxStep("VMR"))
121  continue;
122  if (allStubCounter > 127)
123  continue;
124 
125  Stub* stub = stubinput->getStub(i);
126 
127  //Note - below information is not part of the stub, but rather from which input memory
128  //we are reading
129  bool negdisk = (stub->disk().value() < 0);
130 
131  //use &127 to make sure we fit into the number of bits -
132  //though we should have protected against overflows above
133  FPGAWord allStubIndex(allStubCounter & 127, 7, true, __LINE__, __FILE__);
134 
135  //TODO - should not be needed - but need to migrate some other pieces of code before removing
136  stub->setAllStubIndex(allStubCounter);
137  //TODO - should not be needed - but need to migrate some other pieces of code before removing
138  stub->l1tstub()->setAllStubIndex(allStubCounter);
139 
140  allStubCounter++;
141 
142  FPGAWord iphi = stub->phicorr();
143  unsigned int iphipos = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + 3), 3);
144 
145  //Fill allstubs memories - in HLS this is the same write to multiple memories
146  for (auto& allstub : allstubs_) {
147  char memtype = allstub.first;
148  if ((memtype == 'R' && iphipos < 5) || (memtype == 'L' && iphipos >= 3) || (memtype == 'A' && iphipos < 4) ||
149  (memtype == 'B' && iphipos >= 4) || (memtype == 'E' && iphipos >= 4) || (memtype == 'F' && iphipos < 4) ||
150  (memtype == 'C' && iphipos >= 4) || (memtype == 'D' && iphipos < 4))
151  continue;
152  allstub.second->addStub(stub);
153  }
154 
155  //Fill all the ME VM memories
156  unsigned int ivm =
159  unsigned int extrabits = iphi.bits(iphi.nbits() - overlapbits_, nextrabits_);
160 
161  unsigned int ivmPlus = ivm;
162 
163  if (extrabits == ((1U << nextrabits_) - 1) && ivm != ((1U << settings_.nbitsvmme(layerdisk_)) - 1))
164  ivmPlus++;
165  unsigned int ivmMinus = ivm;
166  if (extrabits == 0 && ivm != 0)
167  ivmMinus--;
168 
169  //Calculate the z and r position for the vmstub
170 
171  //Take the top nbitszfinebintable_ bits of the z coordinate
172  int indexz = (((1 << (stub->z().nbits() - 1)) + stub->z().value()) >> (stub->z().nbits() - nbitszfinebintable_));
173  int indexr = -1;
174  if (layerdisk_ > (N_LAYER - 1)) {
175  if (negdisk) {
176  indexz = (1 << nbitszfinebintable_) - indexz;
177  }
178  indexr = stub->r().value();
179  if (stub->isPSmodule()) {
180  indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_);
181  }
182  } else {
183  //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values.
184  indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_));
185  }
186 
187  assert(indexz >= 0);
188  assert(indexr >= 0);
189  assert(indexz < (1 << nbitszfinebintable_));
190  assert(indexr < (1 << nbitsrfinebintable_));
191 
192  int melut = vmrtable_.lookup(indexz, indexr);
193 
194  assert(melut >= 0);
195 
196  int vmbin = melut >> NFINERZBITS;
197  if (negdisk)
198  vmbin += (1 << NFINERZBITS);
199  int rzfine = melut & ((1 << NFINERZBITS) - 1);
200 
201  // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility)
202  int nbendbits = stub->bend().nbits();
203  if (layerdisk_ >= N_LAYER)
204  nbendbits = settings_.nbendbitsmedisk();
205 
206  VMStubME vmstub(
207  stub,
209  FPGAWord(rzfine, NFINERZBITS, true, __LINE__, __FILE__),
210  FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__),
211  allStubIndex);
212 
213  assert(vmstubsMEPHI_[0] != nullptr);
214  vmstubsMEPHI_[0]->addStub(vmstub, ivmPlus * nvmmebins_ + vmbin);
215 
216  if (ivmMinus != ivmPlus) {
217  vmstubsMEPHI_[0]->addStub(vmstub, ivmMinus * nvmmebins_ + vmbin);
218  }
219 
220  //Fill the TE VM memories
221  if (layerdisk_ >= 6 && (!stub->isPSmodule()))
222  continue;
223 
224  for (auto& ivmstubTEPHI : vmstubsTEPHI_) {
225  unsigned int iseed = ivmstubTEPHI.seednumber;
226  unsigned int lutwidth = settings_.lutwidthtab(1, iseed);
227 
228  int lutval = -999;
229 
230  if (layerdisk_ < N_LAYER) {
231  lutval = melut;
232  } else {
233  lutval = vmrtable_.lookupdisk(indexz, indexr);
234  }
235  if (lutval == -1)
236  continue;
237 
238  assert(lutval >= 0);
239 
240  FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__);
241 
242  if (binlookup.value() < 0)
243  continue;
244 
245  unsigned int ivmte =
248 
249  int bin = binlookup.value() / 8;
250  unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner...
251  binlookup.set(tmp, 3, true, __LINE__, __FILE__);
252 
254 
255  VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex);
256 
257  unsigned int nmem = ivmstubTEPHI.vmstubmem.size();
258  assert(nmem > 0);
259 
260  for (unsigned int l = 0; l < nmem; l++) {
261  if (settings_.debugTracklet()) {
262  edm::LogVerbatim("Tracklet") << getName() << " try adding stub to " << ivmstubTEPHI.vmstubmem[l]->getName()
263  << " bin=" << bin << " ivmte " << ivmte << " finephi " << finephi.value()
264  << " regions bits " << settings_.nphireg(1, iseed) << " finephibits "
265  << settings_.nfinephi(1, iseed);
266  }
267  ivmstubTEPHI.vmstubmem[l]->addVMStub(tmpstub, ivmte * settings_.NLONGVMBINS() + bin);
268  }
269  }
270  }
271  }
272 }
Settings.h
trklet::VMRouterCM::allstubs_
std::vector< std::pair< char, AllStubsMemory * > > allstubs_
Definition: VMRouterCM.h:62
trklet::AllStubsMemory
Definition: AllStubsMemory.h:16
mps_fire.i
i
Definition: mps_fire.py:428
trklet::Settings::writetrace
bool writetrace() const
Definition: Settings.h:162
trklet::VMRouterCM::vmstubsMEPHI_
std::vector< VMStubsMEMemory * > vmstubsMEPHI_
Definition: VMRouterCM.h:65
trklet::VMStubsMEMemory
Definition: VMStubsMEMemory.h:16
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
trklet::VMRouterTable::init
void init(unsigned int layerdisk, std::string const &name)
Definition: VMRouterTable.cc:17
trklet::VMStubTE
Definition: VMStubTE.h:15
trklet::VMRouterTable::lookupdisk
int lookupdisk(int zbin, int rbin)
Definition: VMRouterTable.cc:304
AllStubsMemory.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
trklet::Stub::bend
const FPGAWord & bend() const
Definition: Stub.h:47
memory
Definition: HGCRecHitSoA.h:20
pos
Definition: PixelAliasList.h:18
trklet::Settings::vmrlutrbits
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:158
trklet::Settings
Definition: Settings.h:31
trklet::Settings::nbitsallstubs
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:93
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
trklet::Settings::lutwidthtab
double lutwidthtab(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:129
trklet::ProcessBase::settings_
Settings const & settings_
Definition: ProcessBase.h:44
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
trklet::VMRouterCM::addInput
void addInput(MemoryBase *memory, std::string input) override
Definition: VMRouterCM.cc:98
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
trklet::VMRouterCM::overlapbits_
unsigned int overlapbits_
Definition: VMRouterCM.h:48
trklet::VMRouterTable::lookup
int lookup(int zbin, int rbin)
Definition: VMRouterTable.cc:298
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::Stub
Definition: Stub.h:16
trklet::Settings::nbitsvmme
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:90
trklet::N_LAYER
constexpr int N_LAYER
Definition: Settings.h:19
trklet::VMRouterCM::nbitszfinebintable_
int nbitszfinebintable_
Definition: VMRouterCM.h:51
trklet::VMRouterCM::nvmmebins_
unsigned int nvmmebins_
Definition: VMRouterCM.h:54
dqmdumpme.k
k
Definition: dqmdumpme.py:60
trklet::FPGAWord
Definition: FPGAWord.h:9
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
trklet::ProcessBase::initLayerDisk
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: ProcessBase.cc:45
trklet::VMRouterCM::vmrtable_
VMRouterTable vmrtable_
Definition: VMRouterCM.h:56
VMStubsMEMemory.h
trklet::MemoryBase
Definition: MemoryBase.h:13
trklet::Settings::nfinephi
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:122
iseed
int iseed
Definition: AMPTWrapper.h:134
trklet::VMRouterCM::vmstubsTEPHI_
std::vector< VMStubsTEPHICM > vmstubsTEPHI_
Definition: VMRouterCM.h:68
trklet::Settings::NLONGVMBINS
unsigned int NLONGVMBINS() const
Definition: Settings.h:295
trklet::VMRouterCM::execute
void execute()
Definition: VMRouterCM.cc:114
trklet::VMRouterCM::nbitsrfinebintable_
int nbitsrfinebintable_
Definition: VMRouterCM.h:52
trklet::Settings::nvmme
unsigned int nvmme(unsigned int layerdisk) const
Definition: Settings.h:91
trklet::VMStubsTEPHICM
Definition: VMRouterCM.h:23
Globals.h
trklet::Settings::nphireg
double nphireg(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:123
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
VMStubsTEMemory.h
VMRouterCM.h
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
trklet::VMRouterCM::nextrabits_
unsigned int nextrabits_
Definition: VMRouterCM.h:49
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
trklet::Settings::nbitsvmte
unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:82
trklet::VMRouterCM::layerdisk_
unsigned int layerdisk_
Definition: VMRouterCM.h:44
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::NFINERZBITS
constexpr unsigned int NFINERZBITS
Definition: Settings.h:27
trklet::Stub::l1tstub
L1TStub * l1tstub()
Definition: Stub.h:69
trklet::Settings::vmrlutzbits
unsigned int vmrlutzbits(unsigned int layerdisk) const
Definition: Settings.h:157
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
trklet::ProcessBase::getName
std::string const & getName() const
Definition: ProcessBase.h:22
trklet::VMRouterCM::addOutput
void addOutput(MemoryBase *memory, std::string output) override
Definition: VMRouterCM.cc:33
trklet::Settings::nvmte
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:88
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:161
Exception.h
trklet::Stub::isPSmodule
bool isPSmodule() const
Definition: Stub.h:63
trklet::Settings::maxStep
unsigned int maxStep(std::string module) const
Definition: Settings.h:103
trklet::L1TStub::setAllStubIndex
void setAllStubIndex(unsigned int index)
Definition: L1TStub.h:80
trklet::VMStubME
Definition: VMStubME.h:15
trklet::VMRouterCM::stubinputs_
std::vector< InputLinkMemory * > stubinputs_
Definition: VMRouterCM.h:59
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
trklet::Settings::nbendbitsmedisk
unsigned int nbendbitsmedisk() const
Definition: Settings.h:79