CMS 3D CMS Logo

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