Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:33

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