CMS 3D CMS Logo

DTCLinkMemory.cc
Go to the documentation of this file.
4 
6 
7 #include <iomanip>
8 #include <cmath>
9 #include <sstream>
10 #include <cctype>
11 
13 
14 using namespace trklet;
15 using namespace std;
16 
17 DTCLinkMemory::DTCLinkMemory(string name, Settings const& settings, double, double) : MemoryBase(name, settings) {}
18 
19 void DTCLinkMemory::addStub(const L1TStub& al1stub, const Stub& stub) {
20  //Make new objects owned by the dtclink memory and save in list of stubs
21  if (stubs_.size() < settings_.maxStep("IR")) {
22  Stub* stubptr = new Stub(stub);
23  stubptr->setl1tstub(new L1TStub(al1stub));
24 
25  stubs_.emplace_back(stubptr);
26  }
27 }
28 
29 void DTCLinkMemory::writeStubs(bool first, unsigned int iSector) {
30  iSector_ = iSector;
31 
32  const string dirIS = settings_.memPath() + "InputStubs/";
33  openFile(first, dirIS, "Link_");
34 
35  for (unsigned int j = 0; j < stubs_.size(); j++) {
36  string dtcname = stubs_[j]->l1tstub()->DTClink();
37  int layerdisk = stubs_[j]->l1tstub()->layerdisk();
38 
39  //If the string starts with 'neg' skip the first three character
40  int start = dtcname.substr(0, 3) == "neg" ? 3 : 0;
41 
42  //For the dtcbase name remove the leading 'neg' if in the name and the trailing '_A' or '_B'
43  string dtcbase = dtcname.substr(start, dtcname.size() - 2 - start);
44 
45  const vector<int>& layers = settings_.dtcLayers(dtcbase);
46 
47  int lcode = -1;
48  for (unsigned int index = 0; index < layers.size(); index++) {
49  if (layerdisk == layers[index]) {
50  lcode = index;
51  }
52  }
53  assert(lcode != -1);
54 
55  FPGAWord ldcode(lcode, 2, true);
56 
57  string stub = stubs_[j]->str() + "|" + ldcode.str() + "|1";
58  out_ << std::setfill('0') << std::setw(2);
59  out_ << hex << j << dec;
60  out_ << " " << stub << " " << trklet::hexFormat(stub) << endl;
61  }
62  out_.close();
63 }
64 
66  for (auto& stub : stubs_) {
67  delete stub->l1tstub();
68  delete stub;
69  }
70  stubs_.clear();
71 }
Definition: start.py:1
const std::vector< int > & dtcLayers(const std::string &dtcName) const
Definition: Settings.h:420
unsigned int maxStep(std::string module) const
Definition: Settings.h:116
unsigned int iSector_
Definition: MemoryBase.h:44
std::vector< Stub * > stubs_
Definition: DTCLinkMemory.h:34
void openFile(bool first, std::string dirName, std::string filebase)
Definition: MemoryBase.cc:74
void writeStubs(bool first, unsigned int iSector)
assert(be >=bs)
std::string hexFormat(const std::string &binary)
Definition: Util.h:19
std::string memPath() const
Definition: Settings.h:192
Settings const & settings_
Definition: MemoryBase.h:50
std::ofstream out_
Definition: MemoryBase.h:46
void addStub(const L1TStub &al1stub, const Stub &stub)
void clean() override
DTCLinkMemory(std::string name, Settings const &settings, double, double)
void setl1tstub(L1TStub *l1tstub)
Definition: Stub.h:79
std::string str() const
Definition: FPGAWord.cc:54