CMS 3D CMS Logo

MemoryBase.cc
Go to the documentation of this file.
3 
6 
7 #include <set>
8 #include <filesystem>
9 #include <sstream>
10 
11 using namespace trklet;
12 using namespace std;
13 
14 MemoryBase::MemoryBase(string name, Settings const& settings) : name_(name), settings_(settings) {
15  iSector_ = 0;
16  bx_ = 0;
17  event_ = 0;
18 }
19 
20 void MemoryBase::initLayerDisk(unsigned int pos, int& layer, int& disk) {
21  string subname = name_.substr(pos, 2);
22  layer = 0;
23  disk = 0;
24 
25  if (subname.substr(0, 1) == "L")
26  layer = stoi(subname.substr(1, 1));
27  else if (subname.substr(0, 1) == "D")
28  disk = stoi(subname.substr(1, 1));
29  else
30  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " name = " << name_ << " subname = " << subname
31  << " " << layer << " " << disk;
32 }
33 
34 unsigned int MemoryBase::initLayerDisk(unsigned int pos) {
35  int layer, disk;
36  initLayerDisk(pos, layer, disk);
37 
38  if (disk > 0)
39  return N_DISK + disk;
40  return layer - 1;
41 }
42 
43 void MemoryBase::initSpecialSeeding(unsigned int pos, bool& overlap, bool& extra, bool& extended) {
44  overlap = false;
45  extra = false;
46  extended = false;
47 
48  char subname = name_[pos];
49 
50  static const std::set<char> overlapset = {
51  'X', 'Y', 'W', 'Q', 'R', 'S', 'T', 'Z', 'x', 'y', 'w', 'q', 'r', 's', 't', 'z'};
52  overlap = overlapset.find(subname) != overlapset.end();
53 
54  static const std::set<char> extraset = {'I', 'J', 'K', 'L'};
55  extra = extraset.find(subname) != extraset.end();
56 
57  static const std::set<char> extendedset = {
58  'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'x', 'y', 'z', 'w', 'q', 'r', 's', 't'};
59  extended = extendedset.find(subname) != extendedset.end();
60 }
61 
63  // Get the first occurrence
64  size_t pos = data.find(toSearch);
65 
66  // Repeat till end is reached
67  while (pos != std::string::npos) {
68  // Replace this occurrence of Sub String
69  data.replace(pos, toSearch.size(), replaceStr);
70  // Get the next occurrence from the current position
71  pos = data.find(toSearch, pos + replaceStr.size());
72  }
73 }
74 
76  std::string fname = filebase + getName();
77 
78  findAndReplaceAll(fname, "PHIa", "PHIaa");
79  findAndReplaceAll(fname, "PHIb", "PHIbb");
80  findAndReplaceAll(fname, "PHIc", "PHIcc");
81  findAndReplaceAll(fname, "PHId", "PHIdd");
82 
83  findAndReplaceAll(fname, "PHIx", "PHIxx");
84  findAndReplaceAll(fname, "PHIy", "PHIyy");
85  findAndReplaceAll(fname, "PHIz", "PHIzz");
86  findAndReplaceAll(fname, "PHIw", "PHIww");
87 
88  fname += "_";
89  if (iSector_ + 1 < 10)
90  fname += "0";
92  fname += ".dat";
93 
94  openfile(out_, first, dirName, dirName + fname, __FILE__, __LINE__);
95 
96  out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;
97 
98  bx_++;
99  event_++;
100  if (bx_ > 7)
101  bx_ = 0;
102 }
103 
104 size_t MemoryBase::find_nth(const string& haystack, size_t pos, const string& needle, size_t nth) {
105  size_t found_pos = haystack.find(needle, pos);
106  if (0 == nth || string::npos == found_pos)
107  return found_pos;
108  return find_nth(haystack, found_pos + 1, needle, nth - 1);
109 }
110 
112  std::ostringstream oss;
113  oss << "0x" << std::setfill('0') << std::setw(2) << hex << index << dec;
114  return oss.str();
115 }
static size_t find_nth(const std::string &haystack, size_t pos, const std::string &needle, size_t nth)
Definition: MemoryBase.cc:104
constexpr int N_DISK
Definition: Settings.h:22
unsigned int iSector_
Definition: MemoryBase.h:47
void initSpecialSeeding(unsigned int pos, bool &overlap, bool &extra, bool &extended)
Definition: MemoryBase.cc:43
MemoryBase(std::string name, Settings const &settings)
Definition: MemoryBase.cc:14
std::string to_string(const V &value)
Definition: OMSAccess.h:71
void openFile(bool first, std::string dirName, std::string filebase)
Definition: MemoryBase.cc:75
void findAndReplaceAll(std::string &data, std::string toSearch, std::string replaceStr)
Definition: MemoryBase.cc:62
std::ofstream out_
Definition: MemoryBase.h:49
std::string const & getName() const
Definition: MemoryBase.h:19
static std::string hexstr(unsigned int index)
Definition: MemoryBase.cc:111
string fname
main script
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::string name_
Definition: MemoryBase.h:46
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: MemoryBase.cc:20
std::ofstream openfile(const std::string &dir, const std::string &fname, const char *file, int line)
Definition: Util.h:137