CMS 3D CMS Logo

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