Skip to content

Commit

Permalink
Merge pull request #493 from rest-for-physics/jgalan_minor_fixes
Browse files Browse the repository at this point in the history
Minor updates
  • Loading branch information
jgalan authored Nov 23, 2023
2 parents d9f958c + 533d7a1 commit b676b50
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmake/thisREST.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export PYTHONPATH=${PYTHON_BINDINGS_INSTALL_DIR}:\\\$PYTHONPATH
alias restRoot=\\\"restRoot -l\\\"
alias restRootMacros=\\\"restRoot -l --m\\\"
alias restListMacros=\\\"restManager ListMacros\\\"
if [ \\\$(rest-config --flags | grep \\\"REST_WELCOME=ON\\\") ]; then
rest-config --welcome
Expand Down
45 changes: 38 additions & 7 deletions macros/REST_CheckRunFileList.C → macros/REST_CheckValidRuns.C
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
#include <filesystem>
#include <iostream>
#include <vector>

#include "TGeoManager.h"
#include "TRestTask.h"
#include "TSystem.h"
using namespace std;
namespace fs = std::filesystem;

#ifndef RESTTask_CheckRunFileList
#define RESTTask_CheckRunFileList
#ifndef RESTTask_CheckValidRuns
#define RESTTask_CheckValidRuns

//*******************************************************************************************************
//***
//*** Your HELP is needed to verify, validate and document this macro
//*** This macro might need update/revision.
//*** Description: This macro will identify run files that were not properly closed.
//***
//*** --------------
//*** The first and mandatory argument must provide a full data and pattern to filter the files that
//*** will be checked. E.g. to add all the Hits files from run number 123 the first argument would be
//*** pattern = "/path/to/data/Run00123*Hits*root".
//***
//*** IMPORTANT: The pattern must be given using double quotes ""
//***
//*** --------------
//*** Usage: restManager CheckValidRuns "/full/path/file_*pattern*.root" [purge]
//*** --------------
//***
//*** An optional parameter `purge` can be made true. In that case, this macro will not just provide
//*** a list of the files not properly closed but it will also remove them!
//***
//*** The following command will remove the non-valid runs
//*** --------------
//*** Usage: restManager CheckValidRuns "/full/path/file_*pattern*.root" 1
//*** --------------
//***
//*** CAUTION: Be aware that any non-REST file in the list will be removed if you use purge=1
//***
//*******************************************************************************************************
Int_t REST_CheckRunFileList(TString namePattern, Int_t N = 100000) {
Int_t REST_CheckValidRuns(TString namePattern, Bool_t purge = false) {
TGeoManager::SetVerboseLevel(0);

vector<TString> filesNotWellClosed;
vector<std::string> filesNotWellClosed;

TRestStringOutput RESTLog;

Expand Down Expand Up @@ -70,7 +92,16 @@ Int_t REST_CheckRunFileList(TString namePattern, Int_t N = 100000) {
RESTLog << "---------------------" << RESTendl;
RESTLog << "Files not well closed" << RESTendl;
RESTLog << "---------------------" << RESTendl;
for (int i = 0; i < filesNotWellClosed.size(); i++) RESTLog << filesNotWellClosed[i] << RESTendl;
for (int i = 0; i < filesNotWellClosed.size(); i++) {
RESTLog << filesNotWellClosed[i] << RESTendl;
if (purge) fs::remove(filesNotWellClosed[i]);
}

if (purge) {
RESTLog << "---------------------------" << RESTendl;
RESTLog << "The files have been removed" << RESTendl;
RESTLog << "---------------------------" << RESTendl;
}
}

RESTLog << "------------------------------" << RESTendl;
Expand Down
6 changes: 4 additions & 2 deletions macros/REST_GenerateDataSets.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
//***
//*******************************************************************************************************

Int_t REST_GenerateDataSets(const std::string& inputRML, const std::string& datasets) {
Int_t REST_GenerateDataSets(const std::string& inputRML, const std::string& datasets,
std::string outPath = "") {
std::vector<std::string> sets = REST_StringHelper::Split(datasets, ",");

for (const auto& set : sets) {
std::cout << "Set : " << set << std::endl;
TRestDataSet d(inputRML.c_str(), set.c_str());
d.GenerateDataSet();
d.Export("Dataset_" + set + ".root");
if (!outPath.empty() && outPath.back() != '/') outPath += '/';
d.Export(outPath + "Dataset_" + set + ".root");
}
return 0;
}
Expand Down
10 changes: 9 additions & 1 deletion source/framework/core/src/TRestSystemOfUnits.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,16 @@ TRestSystemOfUnits::TRestSystemOfUnits(string unitsStr) {

} else {
if (pos == unitsStr.size() - 1) {
RESTWarning << "last character inside \"" << unitsStr << "\" \"" << unitsStr[pos]
RESTWarning << "Last character inside \"" << unitsStr << "\" \"" << unitsStr[pos]
<< "\" unrecognized in unit definition!" << RESTendl;

std::string lastChar = unitsStr.substr(pos, 1);

if (isANumber(lastChar)) {
std::string tmpStr = unitsStr;
tmpStr.insert(pos, "^");
RESTWarning << "Perhaps you meant: " << tmpStr << RESTendl;
}
}

pos++;
Expand Down

0 comments on commit b676b50

Please sign in to comment.