Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:00

0001 #include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/Util.h"
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 
0007 #include <set>
0008 #include <filesystem>
0009 #include <sstream>
0010 
0011 using namespace trklet;
0012 using namespace std;
0013 
0014 MemoryBase::MemoryBase(string name, Settings const& settings) : name_(name), settings_(settings) {
0015   iSector_ = 0;
0016   bx_ = 0;
0017   event_ = 0;
0018 }
0019 
0020 void MemoryBase::initLayerDisk(unsigned int pos, int& layer, int& disk) {
0021   string subname = name_.substr(pos, 2);
0022   layer = 0;
0023   disk = 0;
0024 
0025   if (subname.substr(0, 1) == "L")
0026     layer = stoi(subname.substr(1, 1));
0027   else if (subname.substr(0, 1) == "D")
0028     disk = stoi(subname.substr(1, 1));
0029   else
0030     throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " name = " << name_ << " subname = " << subname
0031                                       << " " << layer << " " << disk;
0032 }
0033 
0034 unsigned int MemoryBase::initLayerDisk(unsigned int pos) {
0035   int layer, disk;
0036   initLayerDisk(pos, layer, disk);
0037 
0038   if (disk > 0)
0039     return N_LAYER + disk - 1;
0040   return layer - 1;
0041 }
0042 
0043 void MemoryBase::initSpecialSeeding(unsigned int pos, bool& overlap, bool& extra, bool& extended) {
0044   overlap = false;
0045   extra = false;
0046   extended = false;
0047 
0048   char subname = name_[pos];
0049 
0050   static const std::set<char> overlapset = {
0051       'X', 'Y', 'W', 'Q', 'R', 'S', 'T', 'Z', 'x', 'y', 'w', 'q', 'r', 's', 't', 'z'};
0052   overlap = overlapset.find(subname) != overlapset.end();
0053 
0054   static const std::set<char> extraset = {'I', 'J', 'K', 'L'};
0055   extra = extraset.find(subname) != extraset.end();
0056 
0057   static const std::set<char> extendedset = {
0058       'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'x', 'y', 'z', 'w', 'q', 'r', 's', 't'};
0059   extended = extendedset.find(subname) != extendedset.end();
0060 }
0061 
0062 void MemoryBase::findAndReplaceAll(std::string& data, std::string toSearch, std::string replaceStr) {
0063   // Get the first occurrence
0064   size_t pos = data.find(toSearch);
0065 
0066   // Repeat till end is reached
0067   while (pos != std::string::npos) {
0068     // Replace this occurrence of Sub String
0069     data.replace(pos, toSearch.size(), replaceStr);
0070     // Get the next occurrence from the current position
0071     pos = data.find(toSearch, pos + replaceStr.size());
0072   }
0073 }
0074 
0075 void MemoryBase::openFile(bool first, std::string dirName, std::string filebase) {
0076   std::string fname = filebase + getName();
0077 
0078   findAndReplaceAll(fname, "PHIa", "PHIaa");
0079   findAndReplaceAll(fname, "PHIb", "PHIbb");
0080   findAndReplaceAll(fname, "PHIc", "PHIcc");
0081   findAndReplaceAll(fname, "PHId", "PHIdd");
0082 
0083   findAndReplaceAll(fname, "PHIx", "PHIxx");
0084   findAndReplaceAll(fname, "PHIy", "PHIyy");
0085   findAndReplaceAll(fname, "PHIz", "PHIzz");
0086   findAndReplaceAll(fname, "PHIw", "PHIww");
0087 
0088   fname += "_";
0089   if (iSector_ + 1 < 10)
0090     fname += "0";
0091   fname += std::to_string(iSector_ + 1);
0092   fname += ".dat";
0093 
0094   openfile(out_, first, dirName, dirName + fname, __FILE__, __LINE__);
0095 
0096   out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;
0097 
0098   bx_++;
0099   event_++;
0100   if (bx_ > 7)
0101     bx_ = 0;
0102 }
0103 
0104 size_t MemoryBase::find_nth(const string& haystack, size_t pos, const string& needle, size_t nth) {
0105   size_t found_pos = haystack.find(needle, pos);
0106   if (0 == nth || string::npos == found_pos)
0107     return found_pos;
0108   return find_nth(haystack, found_pos + 1, needle, nth - 1);
0109 }
0110 
0111 std::string MemoryBase::hexstr(unsigned int index) {
0112   std::ostringstream oss;
0113   oss << "0x" << std::setfill('0') << std::setw(2) << hex << index << dec;
0114   return oss.str();
0115 }