Skip to content

Commit

Permalink
Improve code that writes txt files for HLS (#57)
Browse files Browse the repository at this point in the history
* Improve code that writes txt files for HLS

* CMS formatting

* CMS formatting

* CMS formatting

* format corrections
  • Loading branch information
tomalin authored and skinnari committed Dec 22, 2020
1 parent 99af789 commit 559700c
Show file tree
Hide file tree
Showing 30 changed files with 418 additions and 163 deletions.
17 changes: 9 additions & 8 deletions L1Trigger/TrackFindingTMTT/src/KFbase.cc
Expand Up @@ -717,24 +717,24 @@ namespace tmtt {
}

unsigned int kalmanLay = layerMap[kfEtaReg][layerIDreduced];

// Fixes to layermap when "maybe layer" used
if (settings_->KFUseMaybeLayers()) {
switch (kfEtaReg) {
case 5: //case 5: B1 B2 (B3+B4)* D1 D2 D3+D4 D5+D6 -- B3 is combined with B4 and is flagged as "maybe layer"
case 5: //case 5: B1 B2 (B3+B4)* D1 D2 D3+D4 D5+D6 -- B3 is combined with B4 and is flagged as "maybe layer"
if (layerIDreduced == 6) {
kalmanLay = 5;
kalmanLay = 5;
}
break;
case 6: //case 6: B1* B2* D1 D2 D3 D4 D5 -- B1 and B2 are flagged as "maybe layer"
if (layerIDreduced > 2) {
kalmanLay++;
}
kalmanLay++;
}
break;
default:
break;
}
}
}

// Fixes to endcap stubs, for cases where identical GP encoded layer ID present in this sector from both barrel & endcap.

Expand Down Expand Up @@ -825,8 +825,9 @@ namespace tmtt {
}

bool ambiguous = false;
if (settings_->KFUseMaybeLayers()) ambiguous = ambiguityMap[kfEtaReg][kfLayer];

if (settings_->KFUseMaybeLayers())
ambiguous = ambiguityMap[kfEtaReg][kfLayer];

return ambiguous;
}

Expand Down
2 changes: 1 addition & 1 deletion L1Trigger/TrackFindingTracklet/interface/MemoryBase.h
Expand Up @@ -35,7 +35,7 @@ namespace trklet {
//Used for a hack below due to MAC OS case sensitiviy problem for files
void findAndReplaceAll(std::string& data, std::string toSearch, std::string replaceStr);

void openFile(bool first, std::string filebase);
void openFile(bool first, std::string dirName, std::string filebase);

static size_t find_nth(const std::string& haystack, size_t pos, const std::string& needle, size_t nth);

Expand Down
9 changes: 6 additions & 3 deletions L1Trigger/TrackFindingTracklet/interface/Settings.h
Expand Up @@ -161,6 +161,7 @@ namespace trklet {

bool writeMem() const { return writeMem_; }
bool writeTable() const { return writeTable_; }
std::string memPath() const { return memPath_; }
std::string tablePath() const { return tablePath_; }

bool writeVerilog() const { return writeVerilog_; }
Expand Down Expand Up @@ -664,9 +665,11 @@ namespace trklet {
bool warnNoMem_{false}; //If true will print out warnings about missing projection memories
bool warnNoDer_{false}; //If true will print out warnings about missing track fit derivatives

bool writeMem_{false}; //If true will print out content of memories to files
bool writeTable_{false}; //If true will print out content of LUTs to files
std::string tablePath_{"../data/LUTs/"}; //path to writing LUTs
//--- These used to create files needed by HLS code.
bool writeMem_{false}; //If true will print out content of memories (between algo steps) to files
bool writeTable_{false}; //If true will print out content of LUTs to files
std::string memPath_{"../data/MemPrints/"}; //path for writing memories
std::string tablePath_{"../data/LUTs/"}; //path for writing LUTs

// Write various lookup tables and autogenerated code (from iMath)
bool writeVerilog_{false}; //Write out auto-generated Verilog mudules used by TCs
Expand Down
20 changes: 15 additions & 5 deletions L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc
@@ -1,9 +1,11 @@
#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h"
#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h"
#include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
#include <iomanip>
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <iomanip>
#include <filesystem>

using namespace trklet;
using namespace std;

Expand All @@ -13,17 +15,25 @@ AllProjectionsMemory::AllProjectionsMemory(string name, Settings const& settings
}

void AllProjectionsMemory::writeAP(bool first) {
const string dirTP = settings_.memPath() + "TrackletProjections/";

std::ostringstream oss;
oss << "../data/MemPrints/TrackletProjections/AllProj_" << getName() << "_" << std::setfill('0') << std::setw(2)
<< (iSector_ + 1) << ".dat";
oss << dirTP << "AllProj_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat";
auto const& fname = oss.str();

if (first) {
bx_ = 0;
event_ = 1;
out_.open(fname.c_str());

if (not std::filesystem::exists(dirTP)) {
system((string("mkdir -p ") + dirTP).c_str());
}
out_.open(fname);
if (out_.fail())
throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname;

} else
out_.open(fname.c_str(), std::ofstream::app);
out_.open(fname, std::ofstream::app);

out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;

Expand Down
3 changes: 2 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc
Expand Up @@ -10,7 +10,8 @@ AllStubsMemory::AllStubsMemory(string name, Settings const& settings, unsigned i
: MemoryBase(name, settings, iSector) {}

void AllStubsMemory::writeStubs(bool first) {
openFile(first, "../data/MemPrints/Stubs/AllStubs_");
const string dirS = settings_.memPath() + "Stubs/";
openFile(first, dirS, "AllStubs_");

for (unsigned int j = 0; j < stubs_.size(); j++) {
string stub = stubs_[j]->str();
Expand Down
21 changes: 16 additions & 5 deletions L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc
Expand Up @@ -2,10 +2,12 @@
#include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h"
#include "L1Trigger/TrackFindingTracklet/interface/Stub.h"
#include <iomanip>
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"

#include <iomanip>
#include <filesystem>

using namespace std;
using namespace trklet;

Expand All @@ -27,17 +29,26 @@ void CandidateMatchMemory::addMatch(std::pair<Tracklet*, int> tracklet, const St
}

void CandidateMatchMemory::writeCM(bool first) {
const string dirM = settings_.memPath() + "Matches/";

std::ostringstream oss;
oss << "../data/MemPrints/Matches/CandidateMatches_" << getName() << "_" << std::setfill('0') << std::setw(2)
<< (iSector_ + 1) << ".dat";
oss << dirM << "CandidateMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1)
<< ".dat";
auto const& fname = oss.str();

if (first) {
bx_ = 0;
event_ = 1;
out_.open(fname.c_str());

if (not std::filesystem::exists(dirM)) {
system((string("mkdir -p ") + dirM).c_str());
}
out_.open(fname);
if (out_.fail())
throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname;

} else
out_.open(fname.c_str(), std::ofstream::app);
out_.open(fname, std::ofstream::app);

out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;

Expand Down
21 changes: 15 additions & 6 deletions L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc
Expand Up @@ -2,6 +2,7 @@
#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h"
#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h"
#include <iomanip>
#include <filesystem>

using namespace std;
using namespace trklet;
Expand All @@ -14,17 +15,25 @@ CleanTrackMemory::CleanTrackMemory(
}

void CleanTrackMemory::writeCT(bool first) {
const string dirCT = settings_.memPath() + "CleanTrack/";

std::ostringstream oss;
oss << "../data/MemPrints/CleanTrack/CleanTrack_" << getName() << "_" << std::setfill('0') << std::setw(2)
<< (iSector_ + 1) << ".dat";
oss << dirCT << "CleanTrack_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat";
auto const& fname = oss.str();

if (first) {
bx_ = 0;
event_ = 1;
out_.open(fname.c_str());

if (not std::filesystem::exists(dirCT)) {
system((string("mkdir -p ") + dirCT).c_str());
}
out_.open(fname);
if (out_.fail())
throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname;

} else
out_.open(fname.c_str(), std::ofstream::app);
out_.open(fname, std::ofstream::app);

out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;

Expand All @@ -42,9 +51,9 @@ void CleanTrackMemory::writeCT(bool first) {
if (settings_.writeMonitorData("CT")) {
std::string fnameAll = "CleanTracksAll.dat";
if (first && getName() == "CT_L1L2" && iSector_ == 0)
out_.open(fnameAll.c_str());
out_.open(fnameAll);
else
out_.open(fnameAll.c_str(), std::ofstream::app);
out_.open(fnameAll, std::ofstream::app);

if (!tracks_.empty())
out_ << "BX= " << (bitset<3>)bx_ << " event= " << event_ << " seed= " << getName()
Expand Down
19 changes: 14 additions & 5 deletions L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc
Expand Up @@ -2,8 +2,9 @@
#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h"
#include "L1Trigger/TrackFindingTracklet/interface/Stub.h"
#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h"
#include <iomanip>
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iomanip>
#include <filesystem>

using namespace std;
using namespace trklet;
Expand Down Expand Up @@ -39,17 +40,25 @@ void FullMatchMemory::addMatch(Tracklet* tracklet, const Stub* stub) {
}

void FullMatchMemory::writeMC(bool first) {
const string dirM = settings_.memPath() + "Matches/";

std::ostringstream oss;
oss << "../data/MemPrints/Matches/FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2)
<< (iSector_ + 1) << ".dat";
oss << dirM << "FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat";
auto const& fname = oss.str();

if (first) {
bx_ = 0;
event_ = 1;
out_.open(fname.c_str());

if (not std::filesystem::exists(dirM)) {
system((string("mkdir -p ") + dirM).c_str());
}
out_.open(fname);
if (out_.fail())
throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname;

} else
out_.open(fname.c_str(), std::ofstream::app);
out_.open(fname, std::ofstream::app);

out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;

Expand Down
3 changes: 2 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc
Expand Up @@ -86,7 +86,8 @@ bool InputLinkMemory::addStub(
}

void InputLinkMemory::writeStubs(bool first) {
openFile(first, "../data/MemPrints/InputStubs/InputStubs_");
const string dirIS = settings_.memPath() + "InputStubs/";
openFile(first, dirIS, "InputStubs_");

for (unsigned int j = 0; j < stubs_.size(); j++) {
string stub = stubs_[j]->str();
Expand Down

0 comments on commit 559700c

Please sign in to comment.