Skip to content

Commit

Permalink
Ian fix system calls (#66)
Browse files Browse the repository at this point in the history
* Check error return from system calls

* tweak
  • Loading branch information
tomalin authored Jan 12, 2021
1 parent fd1f230 commit 0fa71fe
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 23 deletions.
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ void AllProjectionsMemory::writeAP(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirTP)) {
system((string("mkdir -p ") + dirTP).c_str());
int fail = system((string("mkdir -p ") + dirTP).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP;
}
out_.open(fname);
if (out_.fail())
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void CandidateMatchMemory::writeCM(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirM)) {
system((string("mkdir -p ") + dirM).c_str());
int fail = system((string("mkdir -p ") + dirM).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirM;
}
out_.open(fname);
if (out_.fail())
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ void CleanTrackMemory::writeCT(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirCT)) {
system((string("mkdir -p ") + dirCT).c_str());
int fail = system((string("mkdir -p ") + dirCT).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirCT;
}
out_.open(fname);
if (out_.fail())
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ void FullMatchMemory::writeMC(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirM)) {
system((string("mkdir -p ") + dirM).c_str());
int fail = system((string("mkdir -p ") + dirM).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirM;
}
out_.open(fname);
if (out_.fail())
Expand Down
10 changes: 8 additions & 2 deletions L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals*

if (iSector_ == 0 && layerdisk_ < N_LAYER && settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

const string filephicut = settings_.tablePath() + getName() + "_phicut.tab";
Expand Down Expand Up @@ -94,7 +97,10 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals*

if (iSector_ == 0 && layerdisk_ >= N_LAYER && settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

const string filePSphicut = settings_.tablePath() + getName() + "_PSphicut.tab";
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/MatchEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global,

if (settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

char layer = '0' + layer_;
Expand Down
10 changes: 8 additions & 2 deletions L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g

if (iSector_ == 0 && layer_ > 0 && settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

const string filephicut = settings_.tablePath() + getName() + "_phicut.tab";
Expand Down Expand Up @@ -114,7 +117,10 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g

if (settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

char layer = '0' + layer_;
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/MemoryBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ void MemoryBase::findAndReplaceAll(std::string& data, std::string toSearch, std:

void MemoryBase::openFile(bool first, std::string dirName, std::string filebase) {
if (not std::filesystem::exists(dirName)) {
system((string("mkdir -p ") + dirName).c_str());
int fail = system((string("mkdir -p ") + dirName).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirName;
}

std::string fname = dirName + filebase;
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ void StubPairsMemory::writeSP(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirSP)) {
system((string("mkdir -p ") + dirSP).c_str());
int fail = system((string("mkdir -p ") + dirSP).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirSP;
}
out_.open(fname);
if (out_.fail())
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ void StubTripletsMemory::writeST(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirSP)) {
system((string("mkdir -p ") + dirSP).c_str());
int fail = system((string("mkdir -p ") + dirSP).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirSP;
}
out_.open(fname);
if (out_.fail())
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ void TrackDerTable::fillTable() {

if (settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

const string fnameL = settings_.tablePath() + "FitDerTableNew_LayerMem.tab";
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void TrackFitMemory::writeTF(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirFT)) {
system((string("mkdir -p ") + dirFT).c_str());
int fail = system((string("mkdir -p ") + dirFT).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirFT;
}
out_.open(fname);
if (out_.fail())
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ void TrackletEngine::setVMPhiBin() {

void TrackletEngine::writeTETable() {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

const string fnameI = settings_.tablePath() + getName() + "_stubptinnercut.tab";
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ void TrackletEventProcessor::event(SLHCEvent& ev) {
fname += "_A.dat";

if (not std::filesystem::exists(dirIS)) {
system((string("mkdir -p ") + dirIS).c_str());
int fail = system((string("mkdir -p ") + dirIS).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirIS;
}

ofstream* out = new ofstream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ void TrackletParametersMemory::writeTPAR(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirTP)) {
system((string("mkdir -p ") + dirTP).c_str());
int fail = system((string("mkdir -p ") + dirTP).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP;
}
out_.open(fname);
if (out_.fail())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ void TrackletProjectionsMemory::clean() { tracklets_.clear(); }
void TrackletProjectionsMemory::writeTPROJ(bool first) {
const string dirTP = settings_.memPath() + "TrackletProjections/";
if (not std::filesystem::exists(dirTP)) {
system((string("mkdir -p ") + dirTP).c_str());
int fail = system((string("mkdir -p ") + dirTP).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP;
}

std::ostringstream oss;
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ void VMProjectionsMemory::writeVMPROJ(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirVM)) {
system((string("mkdir -p ") + dirVM).c_str());
int fail = system((string("mkdir -p ") + dirVM).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirVM;
}
out_.open(fname);
if (out_.fail())
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ void VMRouterPhiCorrTable::init(int layer, int bendbits, int rbits) {

if (settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

writeVMTable(settings_.tablePath() + "VMPhiCorrL" + std::to_string(layer_) + ".tab", false);
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ void VMRouterTable::init(unsigned int layerdisk, std::string const& name) {

if (settings_.writeTable()) {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

// write finebin tables
Expand Down
4 changes: 3 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ void VMStubsMEMemory::writeStubs(bool first) {
event_ = 1;

if (not std::filesystem::exists(dirVM)) {
system((string("mkdir -p ") + dirVM).c_str());
int fail = system((string("mkdir -p ") + dirVM).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirVM;
}
out_.open(fname);
if (out_.fail())
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ void VMStubsTEMemory::setbendtable(std::vector<bool> vmbendtable) {

void VMStubsTEMemory::writeVMBendTable() {
if (not std::filesystem::exists(settings_.tablePath())) {
system((string("mkdir -p ") + settings_.tablePath()).c_str());
int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
if (fail)
throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
<< settings_.tablePath();
}

const string fname = settings_.tablePath() + getName() + "_vmbendcut.tab";
Expand Down

0 comments on commit 0fa71fe

Please sign in to comment.