diff --git a/CMakeLists.txt b/CMakeLists.txt index 02f95fbb9..0f3667807 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,11 +16,20 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif () if (CMAKE_SYSTEM_NAME MATCHES "Darwin") - SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-fsanitize=address") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") else () - SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-lstdc++fs") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs") endif (CMAKE_SYSTEM_NAME MATCHES "Darwin") +if ( CMAKE_BUILD_TYPE MATCHES "Release" ) + message( STATUS "Enabling warnings as errors" ) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-cast-function-type -Wno-unused-function -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor") +endif ( CMAKE_BUILD_TYPE MATCHES "Release" ) + +if ( CMAKE_BUILD_TYPE MATCHES "Debug" ) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +endif ( CMAKE_BUILD_TYPE MATCHES "Debug" ) + # https://github.com/rest-for-physics/framework/issues/162 & https://github.com/rest-for-physics/framework/issues/236 if (${CMAKE_VERSION} VERSION_LESS "3.23") cmake_policy(SET CMP0082 OLD) diff --git a/cmake/MacroRootDict.cmake b/cmake/MacroRootDict.cmake index 80be7677c..c57fd1b15 100644 --- a/cmake/MacroRootDict.cmake +++ b/cmake/MacroRootDict.cmake @@ -236,11 +236,23 @@ MACRO(COMPILEDIR libname) foreach (exclude ${excludes}) if ("${exclude}" STREQUAL "${class}") set(SKIP "TRUE") - # message( STATUS "Skipping ${class}" ) + # message( STATUS "Skipping ${class}" ) endif () endforeach (exclude) endif () + #### We will remove those classes that do not inherit from TObject from dictionary generation + set(NOTDICT "FALSE") + #### Probably all those classes should be on the same directory (framework/tools) + set( nodicts "TRestReflector;TRestSystemOfUnits;TRestStringHelper;TRestPhysics;TRestDataBase;TRestTools;TRestThread" ) + foreach (nodict ${nodicts}) + if ("${nodict}" STREQUAL "${class}") + set(NOTDICT "TRUE") + message( STATUS "Skipping dictionary generation for ${class}" ) + endif () + endforeach (nodict) + ###################################### + if (${SKIP} STREQUAL "FALSE") set(ROOT_DICT_INCLUDE_DIRS ${local_include_dirs} ${external_include_dirs}) file(GLOB_RECURSE header ${class}.h) @@ -248,10 +260,10 @@ MACRO(COMPILEDIR libname) message(WARNING "header file: " ${class}.h " does not exist for source file: " ${file} ". If you really want to build it, add it to \"addon_src\" variable before calling COMPILEDIR()") else () set(ROOT_DICT_INPUT_HEADERS ${header} ${ROOT_DICT_OUTPUT_DIR}/${class}_LinkDef.h) - if (${SCHEMA_EVOLUTION} MATCHES "ON") + if (${SCHEMA_EVOLUTION} MATCHES "ON" AND ${NOTDICT} STREQUAL "FALSE" ) GEN_ROOT_DICT_LINKDEF_HEADER(${class} ${header}) GEN_ROOT_DICT_SOURCES(CINT_${class}.cxx ${ROOT_DICT_OUTPUT_DIR}/${class}_LinkDef.h) - else () + elseif( ${NOTDICT} STREQUAL "FALSE") GEN_ROOT_DICT_SOURCES(CINT_${class}.cxx) endif () diff --git a/cmake/thisREST.cmake b/cmake/thisREST.cmake index 50249fd3b..eb35d8512 100644 --- a/cmake/thisREST.cmake +++ b/cmake/thisREST.cmake @@ -163,7 +163,7 @@ foreach (mac ${rest_macros}) install(CODE " file( APPEND \${CMAKE_INSTALL_PREFIX}/thisREST.csh -alias ${mac} \\\"restManager ${m}\\\" +\"alias ${mac} \\\"restManager ${m}\\\" \" ) " diff --git a/source/bin/restManager.cxx b/source/bin/restManager.cxx index d33500b71..c22282ba3 100644 --- a/source/bin/restManager.cxx +++ b/source/bin/restManager.cxx @@ -23,9 +23,11 @@ int fork_n_execute(string command) { if (pid == 0) { /* This is the child process */ - system(command.c_str()); // execute the command + int z = system(command.c_str()); // execute the command + if (z != 0) printf("Problem executing command : %s", command.c_str()); // we call exit() when system() returns to complete child process exit(EXIT_SUCCESS); + } else if (pid < 0) { /* The fork failed */ printf("Failed to fork(): %s ", command.c_str()); @@ -126,7 +128,7 @@ int main(int argc, char* argv[]) { argVApp[1] = batch; { // handle special arguments like "--batch" - for (int i = 1; i < args.size(); i++) { + for (unsigned int i = 1; i < args.size(); i++) { if (args[i] == "--batch") { RESTcout << "you are in batch mode, all graphical displays off" << RESTendl; REST_Display_CompatibilityMode = true; @@ -160,7 +162,7 @@ int main(int argc, char* argv[]) { // read arguments if (args.size() >= 2) { if (args[1][0] == '-') { // usage1 - for (int i = 1; i < args.size(); i++) { + for (unsigned int i = 1; i < args.size(); i++) { char* c = &args[i][0]; if (*c == '-') { c++; @@ -215,7 +217,6 @@ int main(int argc, char* argv[]) { RESTcout << "Launching TRestManager..." << RESTendl; RESTcout << RESTendl; - int pid = 0; if (doFork && input_files.size() > maxForksAllowed) { RESTError << "Fork list is larger than " << maxForksAllowed << " files. Please, use a glob pattern producing a shorter list" << RESTendl; @@ -252,7 +253,7 @@ int main(int argc, char* argv[]) { } else // usage2 { vector argumentlist; - for (int i = 2; i < args.size(); i++) { + for (unsigned int i = 2; i < args.size(); i++) { argumentlist.push_back(args[i]); } string type = (args[1]); diff --git a/source/bin/restRoot.cxx b/source/bin/restRoot.cxx index f3778ccb1..dd60ff993 100644 --- a/source/bin/restRoot.cxx +++ b/source/bin/restRoot.cxx @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) { map metanames; for (int n = 0; n < numberOfMetadataStructures; n++) { string metaName = runTmp->GetMetadataStructureNames()[n]; - if (metaName.find("Historic") != -1) { + if (metaName.find("Historic") != string::npos) { continue; } diff --git a/source/framework/analysis/inc/TRestDataQualityRules.h b/source/framework/analysis/inc/TRestDataQualityRules.h index f52f55795..d9245cc62 100644 --- a/source/framework/analysis/inc/TRestDataQualityRules.h +++ b/source/framework/analysis/inc/TRestDataQualityRules.h @@ -69,28 +69,25 @@ class TRestDataQualityRules : public TObject { std::vector GetBits() { return fBits; } - TString GetType(Int_t n) { + TString GetType(unsigned int n) { if (fTypes.size() <= n) return ""; else return fTypes[n]; } - TString GetValue(Int_t n) { + TString GetValue(unsigned int n) { if (fValues.size() <= n) return ""; else return fValues[n]; } - TVector2 GetRange(Int_t n) { - if (fRanges.size() <= n) - return TVector2(0, 0); - else - return fRanges[n]; + TVector2 GetRange(unsigned int n) { + return (n < fRanges.size()) ? fRanges[n] : TVector2(0,0); } - Int_t GetBit(Int_t n) { + Int_t GetBit(unsigned int n) { if (fBits.size() <= n) return -1; else diff --git a/source/framework/analysis/src/TRestDataQualityProcess.cxx b/source/framework/analysis/src/TRestDataQualityProcess.cxx index f8deac075..111b53566 100644 --- a/source/framework/analysis/src/TRestDataQualityProcess.cxx +++ b/source/framework/analysis/src/TRestDataQualityProcess.cxx @@ -135,7 +135,7 @@ TRestEvent* TRestDataQualityProcess::ProcessEvent(TRestEvent* inputEvent) { /// void TRestDataQualityProcess::EndProcess() { /// We loop to each quality number definition - for (int n = 0; n < fQualityNumber.size(); n++) { + for (unsigned int n = 0; n < fQualityNumber.size(); n++) { /// We loop to each rule from the quality definition for (int r = 0; r < fRules[n].GetNumberOfRules(); r++) { // We implement metadata-based quality numbers @@ -233,7 +233,7 @@ void TRestDataQualityProcess::InitFromConfigFile() { void TRestDataQualityProcess::PrintMetadata() { BeginPrintProcess(); - for (int n = 0; n < fQualityNumber.size(); n++) { + for (unsigned int n = 0; n < fQualityNumber.size(); n++) { RESTMetadata << " " << RESTendl; RESTMetadata << "xxxxxxxxxxxxxxxxxxxxxx" << RESTendl; RESTMetadata << " tag : " << fQualityTag[n] << ". Quality number : " << fQualityNumber[n] << RESTendl; diff --git a/source/framework/analysis/src/TRestEventSelectionProcess.cxx b/source/framework/analysis/src/TRestEventSelectionProcess.cxx index 55ba2b3c2..6b168819c 100644 --- a/source/framework/analysis/src/TRestEventSelectionProcess.cxx +++ b/source/framework/analysis/src/TRestEventSelectionProcess.cxx @@ -101,7 +101,7 @@ void TRestEventSelectionProcess::Initialize() { /// /// void TRestEventSelectionProcess::InitProcess() { - if (fFileWithIDs.substr(fFileWithIDs.length() - 4) == ".txt") { + if (TRestTools::GetFileNameExtension(fFileWithIDs) == "txt") { string line; ifstream File(fFileWithIDs); @@ -111,9 +111,7 @@ void TRestEventSelectionProcess::InitProcess() { } File.close(); } - } - - else if (fFileWithIDs.substr(fFileWithIDs.length() - 4) == "root") { + } else if (TRestTools::GetFileNameExtension(fFileWithIDs) == "root") { TRestRun* run = new TRestRun(fFileWithIDs); fList = run->GetEventIdsWithConditions(fConditions); delete run; @@ -126,7 +124,7 @@ void TRestEventSelectionProcess::InitProcess() { TRestEvent* TRestEventSelectionProcess::ProcessEvent(TRestEvent* inputEvent) { fEvent = inputEvent; - for (int i = 0; i < fList.size(); i++) { + for (unsigned int i = 0; i < fList.size(); i++) { if (fList[i] == fEvent->GetID()) { return fEvent; } diff --git a/source/framework/analysis/src/TRestMySQLToAnalysisProcess.cxx b/source/framework/analysis/src/TRestMySQLToAnalysisProcess.cxx index b74459751..66cd10985 100644 --- a/source/framework/analysis/src/TRestMySQLToAnalysisProcess.cxx +++ b/source/framework/analysis/src/TRestMySQLToAnalysisProcess.cxx @@ -256,7 +256,7 @@ void TRestMySQLToAnalysisProcess::PrintMetadata() { RESTMetadata << "List of variables added to the analysis tree" << RESTendl; RESTMetadata << " ------------------------------------------ " << RESTendl; - for (int n = 0; n < fAnaTreeVariables.size(); n++) { + for (unsigned int n = 0; n < fAnaTreeVariables.size(); n++) { RESTMetadata << " + SQL field : " << fSQLVariables[n] << RESTendl; RESTMetadata << " - Tree name : " << fAnaTreeVariables[n] << RESTendl; RESTMetadata << " - Min value : " << fMinValues[n] << RESTendl; @@ -408,7 +408,7 @@ void TRestMySQLToAnalysisProcess::FillDBArrays() { /// string TRestMySQLToAnalysisProcess::BuildQueryString() { string sqlQuery = "SELECT timestamp"; - for (int n = 0; n < fSQLVariables.size(); n++) { + for (unsigned int n = 0; n < fSQLVariables.size(); n++) { sqlQuery += ","; sqlQuery += fSQLVariables[n]; } @@ -431,7 +431,7 @@ Double_t TRestMySQLToAnalysisProcess::GetDBValueAtTimestamp(Int_t index, Double_ Int_t bin = (Int_t)((timestamp - fStartTimestamp) / fSampling); if (bin < 0) return fDBdata.front()[index]; - if (bin + 1 >= fDBdata.size()) return fDBdata.back()[index]; + if ((unsigned int)(bin + 1) >= fDBdata.size()) return fDBdata.back()[index]; double y2 = fDBdata[bin + 1][index]; double y1 = fDBdata[bin][index]; diff --git a/source/framework/analysis/src/TRestRealTimeDrawingProcess.cxx b/source/framework/analysis/src/TRestRealTimeDrawingProcess.cxx index bae00a4e3..9f9775a26 100644 --- a/source/framework/analysis/src/TRestRealTimeDrawingProcess.cxx +++ b/source/framework/analysis/src/TRestRealTimeDrawingProcess.cxx @@ -226,11 +226,11 @@ void TRestRealTimeDrawingProcess::EndProcess() { void TRestRealTimeDrawingProcess::DrawOnce() { Long64_t totalentries = GetFullAnalysisTree()->GetEntries(); - for (int i = 0; i < fPlots.size(); i++) { + for (unsigned int i = 0; i < fPlots.size(); i++) { fPlots[i]->SetTreeEntryRange(totalentries - fLastDrawnEntry, fLastDrawnEntry); fPlots[i]->PlotCombinedCanvas(); } - for (int i = 0; i < fProcessesToDraw.size(); i++) { + for (unsigned int i = 0; i < fProcessesToDraw.size(); i++) { GetFriendLive(fProcessesToDraw[i])->Draw(); } } @@ -254,9 +254,9 @@ void TRestRealTimeDrawingProcess::DrawWithNotification() { int _runNumber = run->GetRunNumber(); delete run; if (_runNumber == runNumber) { - for (int i = 0; i < fPlots.size(); i++) { - fPlots[i]->SetFile(message); - fPlots[i]->PlotCombinedCanvas(); + for (auto& plot: fPlots) { + plot->SetFile(message); + plot->PlotCombinedCanvas(); } } else { // if the runnumber does not match, we put this message back to pool diff --git a/source/framework/core/inc/TRestRun.h b/source/framework/core/inc/TRestRun.h index 41c03c977..44d565af5 100644 --- a/source/framework/core/inc/TRestRun.h +++ b/source/framework/core/inc/TRestRun.h @@ -131,7 +131,7 @@ class TRestRun : public TRestMetadata { inline TString GetExperimentName() const { return fExperimentName; } inline std::vector GetInputFileNames() const { return fInputFileNames; } - inline std::string GetInputFileName(int i) const { + inline std::string GetInputFileName(unsigned int i) const { return i < fInputFileNames.size() ? (std::string)fInputFileNames[i] : ""; } inline std::string GetInputFileNamePattern() const { return fInputFileName.Data(); } diff --git a/source/framework/core/inc/TRestTask.h b/source/framework/core/inc/TRestTask.h index 2fd188dcb..9e2c23339 100644 --- a/source/framework/core/inc/TRestTask.h +++ b/source/framework/core/inc/TRestTask.h @@ -28,7 +28,7 @@ class TRestTask : public TRestMetadata { protected: TRestTask(TString TaskString, REST_TASKMODE mode = TASK_MACRO); - int fNRequiredArgument; + unsigned int fNRequiredArgument; REST_TASKMODE fMode; std::string fInvokeObject = ""; std::string fInvokeMethod = ""; diff --git a/source/framework/core/inc/TRestThread.h b/source/framework/core/inc/TRestThread.h index 21fb8f6a3..addfbbce2 100644 --- a/source/framework/core/inc/TRestThread.h +++ b/source/framework/core/inc/TRestThread.h @@ -74,8 +74,6 @@ class TRestThread { // Constructor & Destructor TRestThread() { Initialize(); } ~TRestThread(){}; - - ClassDef(TRestThread, 1); }; #endif diff --git a/source/framework/core/src/TRestAnalysisPlot.cxx b/source/framework/core/src/TRestAnalysisPlot.cxx index 1457b7cd9..93b20cf0f 100644 --- a/source/framework/core/src/TRestAnalysisPlot.cxx +++ b/source/framework/core/src/TRestAnalysisPlot.cxx @@ -49,7 +49,6 @@ TRestAnalysisPlot::~TRestAnalysisPlot() { } void TRestAnalysisPlot::InitFromConfigFile() { - size_t position = 0; if (fHostmgr->GetRunInfo() != nullptr) { fRun = fHostmgr->GetRunInfo(); } @@ -87,7 +86,6 @@ void TRestAnalysisPlot::InitFromConfigFile() { #pragma region ReadLabels RESTDebug << "TRestAnalysisPlot: Reading canvas settings" << RESTendl; - position = 0; TiXmlElement* formatDefinition = GetElement("labels"); if (formatDefinition != nullptr) { if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) { @@ -128,7 +126,6 @@ void TRestAnalysisPlot::InitFromConfigFile() { #pragma endregion #pragma region ReadLegend - position = 0; TiXmlElement* legendDefinition = GetElement("legendPosition"); if (legendDefinition != nullptr) { if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) { @@ -159,7 +156,6 @@ void TRestAnalysisPlot::InitFromConfigFile() { #pragma endregion #pragma region ReadCanvas - position = 0; TiXmlElement* canvasdef = fElement->FirstChildElement("canvas"); if (canvasdef == nullptr) { canvasdef = fElement; @@ -336,9 +332,9 @@ void TRestAnalysisPlot::InitFromConfigFile() { } } - for (int n = 0; n < fPanels.size(); n++) { + for (unsigned int n = 0; n < fPanels.size(); n++) { RESTExtreme << "Panel " << n << " with font size : " << fPanels[n].font_size << RESTendl; - for (int m = 0; m < fPanels[n].posX.size(); m++) { + for (unsigned int m = 0; m < fPanels[n].posX.size(); m++) { RESTExtreme << "Label : " << fPanels[n].label[m] << RESTendl; RESTExtreme << "Pos X : " << fPanels[n].posX[m] << RESTendl; RESTExtreme << "Pos Y : " << fPanels[n].posY[m] << RESTendl; @@ -353,7 +349,7 @@ TRestAnalysisPlot::HistoInfoSet TRestAnalysisPlot::SetupHistogramFromConfigFile( hist.name = RemoveWhiteSpaces(GetParameter("name", histele, plot.name)); hist.drawOption = GetParameter("option", histele, "colz"); - for (int n = 0; n < fPlotNamesCheck.size(); n++) + for (unsigned int n = 0; n < fPlotNamesCheck.size(); n++) if (hist.name == fPlotNamesCheck[n]) { RESTError << "Repeated plot/histo names were found! Please, use different names for different plots!" @@ -401,7 +397,7 @@ TRestAnalysisPlot::HistoInfoSet TRestAnalysisPlot::SetupHistogramFromConfigFile( // 2. construct plot name for the hist string rangestr = ""; - for (int i = 0; i < bins.size(); i++) { + for (unsigned int i = 0; i < bins.size(); i++) { string binsStr = ToString(bins[i]); if (bins[i] == -1) binsStr = " "; @@ -590,7 +586,7 @@ TRestRun* TRestAnalysisPlot::GetRunInfo(TString fileName) { } bool TRestAnalysisPlot::IsDynamicRange(TString rangeString) { - return (string(rangeString)).find(", ") != -1; + return (string(rangeString)).find(", ") != string::npos; } Int_t TRestAnalysisPlot::GetColorIDFromString(string in) { @@ -668,7 +664,7 @@ void TRestAnalysisPlot::PlotCombinedCanvas() { runLength /= 3600.; for (unsigned int n = 0; n < fPanels.size(); n++) { - TPad* targetPad = (TPad*)fCombinedCanvas->cd(n + 1); + fCombinedCanvas->cd(n + 1); for (unsigned int m = 0; m < fPanels[n].posX.size(); m++) { string label = fPanels[n].label[m]; @@ -885,7 +881,7 @@ void TRestAnalysisPlot::PlotCombinedCanvas() { // draw to the pad targetPad = (TPad*)fCombinedCanvas->cd(n + 1 + fPanels.size()); Double_t maxValue_Pad = 0; - int maxID = 0; + unsigned int maxID = 0; for (unsigned int i = 0; i < plot.histos.size(); i++) { // need to draw the max histogram first, in order to prevent peak hidden problem if (plot.histos[i].ptr == nullptr) continue; diff --git a/source/framework/core/src/TRestAnalysisTree.cxx b/source/framework/core/src/TRestAnalysisTree.cxx index b52cd0ac7..5e32ed219 100644 --- a/source/framework/core/src/TRestAnalysisTree.cxx +++ b/source/framework/core/src/TRestAnalysisTree.cxx @@ -183,7 +183,7 @@ Int_t TRestAnalysisTree::GetMatchedObservableID(const string& obsName) { int matchedCount = 0; int minPos = 0; int min = 1e5; - for (int i = 0; i < diffs.size(); i++) { + for (unsigned int i = 0; i < diffs.size(); i++) { if (min > diffs[i]) { min = diffs[i]; minPos = i; @@ -432,7 +432,7 @@ void TRestAnalysisTree::InitObservables() { void TRestAnalysisTree::MakeObservableIdMap() { if (fObservableIdMap.size() != fObservableNames.size()) { fObservableIdMap.clear(); - for (int i = 0; i < fObservableNames.size(); i++) { + for (unsigned int i = 0; i < fObservableNames.size(); i++) { fObservableIdMap[(string)fObservableNames[i]] = i; } if (fObservableIdMap.size() != fObservableNames.size()) { @@ -448,7 +448,7 @@ void TRestAnalysisTree::ReadLeafValueToObservable(TLeaf* lf, RESTValue& obs) { // this means we need to determine the observable type first string type; string leafdef(lf->GetBranch()->GetTitle()); - if (leafdef.find("[") == -1) { + if (leafdef.find("[") == string::npos) { // there is no [] mark in the leaf. The leaf is a single values switch (leafdef[leafdef.size() - 1]) { case 'C': @@ -622,7 +622,6 @@ RESTValue TRestAnalysisTree::AddObservable(const TString& observableName, const return -1; } - Double_t x = 0; if (GetObservableID((string)observableName) == -1) { RESTValue ptr = REST_Reflection::Assembly((string)observableType); ptr.name = observableName; @@ -790,7 +789,7 @@ void TRestAnalysisTree::SetObservable(Int_t id, RESTValue obs) { AddObservable(obs.name, obs.type); id = GetObservableID(obs.name); } - } else if (id == fObservables.size()) { + } else if (id == (int)fObservables.size()) { // this means we want to add observable directly AddObservable(obs.name, obs.type); id = GetObservableID(obs.name); @@ -876,7 +875,7 @@ Bool_t TRestAnalysisTree::EvaluateCut(const string& cut) { if (cut.find("&&") != string::npos) return EvaluateCuts(cut); string operation, observable; - Double_t value; + Double_t value = -1; for (const auto& validOperator : validOperators) { if (cut.find(validOperator) != string::npos) { operation = validOperator; @@ -913,7 +912,6 @@ vector TRestAnalysisTree::GetCutObservables(const string& cut_str) { vector obsNames; for (auto& cut : cuts) { string operation, observable; - Double_t value; for (const auto& validOperator : validOperators) { if (cut.find(validOperator) != string::npos) { obsNames.push_back((string)cut.substr(0, cut.find(validOperator))); @@ -1025,10 +1023,10 @@ Double_t TRestAnalysisTree::GetObservableMinimum(const TString& obsName, Double_ /// \brief It returns a vector with strings containing all the observables that exist in /// the analysis tree. /// + std::vector TRestAnalysisTree::GetObservableNames() { std::vector names; - // Int_t nEntries = GetEntries(); auto branches = GetListOfBranches(); for (int i = 0; i < branches->GetEntries(); i++) { names.push_back((string)branches->At(i)->GetName()); diff --git a/source/framework/core/src/TRestBrowser.cxx b/source/framework/core/src/TRestBrowser.cxx index 1d1aa867b..5d4508874 100644 --- a/source/framework/core/src/TRestBrowser.cxx +++ b/source/framework/core/src/TRestBrowser.cxx @@ -333,7 +333,7 @@ Bool_t TRestBrowser::OpenFile(const TString& filename) { fInputFileName = filename; fRestRun->OpenInputFile(fInputFileName); - TFile* f = fRestRun->GetInputFile(); + fRestRun->GetInputFile()->cd(); TTree* t = fRestRun->GetEventTree(); TGeoManager* geometry = gGeoManager; @@ -343,7 +343,7 @@ Bool_t TRestBrowser::OpenFile(const TString& filename) { TObjArray* branches = t->GetListOfBranches(); for (int i = 0; i <= branches->GetLast(); i++) { auto branch = (TBranch*)branches->At(i); - if (((string)branch->GetName()).find("EventBranch") != -1) { + if (((string)branch->GetName()).find("EventBranch") != string::npos) { string eventType = Replace((string)branch->GetName(), "Branch", ""); fEventTypeComboBox->AddEntry(eventType.c_str(), fEventTypeComboBox->GetNumberOfEntries()); // we make the entry of input event being selected diff --git a/source/framework/core/src/TRestDataSet.cxx b/source/framework/core/src/TRestDataSet.cxx index c51234c4c..3c0cc7ae5 100644 --- a/source/framework/core/src/TRestDataSet.cxx +++ b/source/framework/core/src/TRestDataSet.cxx @@ -375,7 +375,7 @@ std::vector TRestDataSet::FileSelection() { if (properties.strategy == "min") if (properties.value == 0 || properties.value > value) properties.value = value; - if (properties.strategy == "unique") + if (properties.strategy == "unique") { if (properties.value == 0) properties.value = value; else if (properties.value != value) { @@ -385,6 +385,7 @@ std::vector TRestDataSet::FileSelection() { RESTWarning << "Pre-registered value : " << properties.value << " New value : " << value << RESTendl; } + } if (properties.strategy == "last") properties.value = value; } @@ -636,8 +637,8 @@ void TRestDataSet::Export(const std::string& filename) { fprintf(f, "###\n"); fprintf(f, "### Data starts here\n"); - for (int n = 0; n < fTree->GetEntries(); n++) { - for (int m = 0; m < GetNumberOfBranches(); m++) { + for (unsigned int n = 0; n < fTree->GetEntries(); n++) { + for (unsigned int m = 0; m < GetNumberOfBranches(); m++) { std::string bName = fTree->GetListOfBranches()->At(m)->GetName(); if (m > 0) fprintf(f, "\t"); if (dataTypes[m] == "Double_t") diff --git a/source/framework/core/src/TRestEventProcess.cxx b/source/framework/core/src/TRestEventProcess.cxx index e6b47ef8d..feac4ef01 100644 --- a/source/framework/core/src/TRestEventProcess.cxx +++ b/source/framework/core/src/TRestEventProcess.cxx @@ -138,7 +138,7 @@ vector TRestEventProcess::ReadObservables() { } // now we get a list of all observal names, we add them into fAnalysisTree and fObservableInfo - for (int i = 0; i < obsNames.size(); i++) { + for (unsigned int i = 0; i < obsNames.size(); i++) { string obsName = this->GetName() + (string) "_" + obsNames[i]; fAnalysisTree->AddObservable(obsName, obsTypes[i], obsDesc[i]); int id = fAnalysisTree->GetObservableID(obsName); @@ -296,7 +296,7 @@ TRestEventProcess* TRestEventProcess::GetFriendLive(const string& nameOrType) { /// process `TRestRawSignalAnalysisProcess` from thread 2, and a friend process /// `TRestRawToSignalProcess` from thread 1. TRestEventProcess* TRestEventProcess::GetParallel(int i) { - if (i >= 0 && i < fParallelProcesses.size()) { + if (i >= 0 && i < (int)fParallelProcesses.size()) { return fParallelProcesses[i]; } return nullptr; diff --git a/source/framework/core/src/TRestGDMLParser.cxx b/source/framework/core/src/TRestGDMLParser.cxx index caa47faef..e50764303 100644 --- a/source/framework/core/src/TRestGDMLParser.cxx +++ b/source/framework/core/src/TRestGDMLParser.cxx @@ -32,9 +32,9 @@ void TRestGDMLParser::Load(const string& filename) { fFileString = str; t.close(); - int pp = fFileString.find("##VERSION", 0); + size_t pp = fFileString.find("##VERSION", 0); if (pp != string::npos) { - int pp2 = fFileString.find("##", pp + 4); + size_t pp2 = fFileString.find("##", pp + 4); if (pp2 != string::npos) fGdmlVersion = fFileString.substr(pp + 9, pp2 - pp - 9); fGdmlVersion = ReplaceMathematicalExpressions(ReplaceConstants(ReplaceVariables(fGdmlVersion))); } @@ -136,9 +136,9 @@ void TRestGDMLParser::ReplaceEntity() { str = ReplaceConstants(ReplaceVariables(str)); fEntityVersionMap[entityName] = ""; - int pp = str.find("##VERSION", 0); + size_t pp = str.find("##VERSION", 0); if (pp != string::npos) { - int pp2 = str.find("##", pp + 4); + size_t pp2 = str.find("##", pp + 4); if (pp2 != string::npos) { fEntityVersionMap[entityName] = str.substr(pp + 9, pp2 - pp - 9); } diff --git a/source/framework/core/src/TRestHits.cxx b/source/framework/core/src/TRestHits.cxx index 86111226a..e2d0dc9e4 100644 --- a/source/framework/core/src/TRestHits.cxx +++ b/source/framework/core/src/TRestHits.cxx @@ -99,7 +99,7 @@ TRestHits::~TRestHits() = default; /// \brief It will return true only if all the hits inside are of type XY. /// Bool_t TRestHits::areXY() const { - for (int i = 0; i < GetNumberOfHits(); i++) { + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != XY) { // all hits should fit this condition to be considered XY return false; @@ -114,7 +114,7 @@ Bool_t TRestHits::areXY() const { /// \brief It will return true only if all the hits inside are of type XZ. /// Bool_t TRestHits::areXZ() const { - for (int i = 0; i < GetNumberOfHits(); i++) { + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != XZ) { // all hits should fit this condition to be considered XY return false; @@ -129,7 +129,7 @@ Bool_t TRestHits::areXZ() const { /// \brief It will return true only if all the hits inside are of type YZ. /// Bool_t TRestHits::areYZ() const { - for (int i = 0; i < GetNumberOfHits(); i++) { + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != YZ) { // all hits should fit this condition to be considered XY return false; @@ -144,7 +144,7 @@ Bool_t TRestHits::areYZ() const { /// \brief It will return true only if all the hits inside are of type XYZ. /// Bool_t TRestHits::areXYZ() const { - for (int i = 0; i < GetNumberOfHits(); i++) { + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { if (fType[i] != XYZ) { // all hits should fit this condition to be considered XY return false; @@ -169,7 +169,7 @@ Bool_t TRestHits::isNaN(Int_t n) const { /// Double_t TRestHits::GetEnergyIntegral() const { Double_t sum = 0; - for (int i = 0; i < GetNumberOfHits(); i++) sum += GetEnergy(i); + for (unsigned int i = 0; i < GetNumberOfHits(); i++) sum += GetEnergy(i); return sum; } @@ -207,7 +207,7 @@ Double_t TRestHits::GetEnergyInPrism(const TVector3& x0, const TVector3& x1, Dou Double_t theta) const { Double_t energy = 0.; - for (int n = 0; n < GetNumberOfHits(); n++) + for (unsigned int n = 0; n < GetNumberOfHits(); n++) if (isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) energy += this->GetEnergy(n); return energy; @@ -222,7 +222,7 @@ Int_t TRestHits::GetNumberOfHitsInsidePrism(const TVector3& x0, const TVector3& Double_t sizeY, Double_t theta) const { Int_t hits = 0; - for (int n = 0; n < GetNumberOfHits(); n++) + for (unsigned int n = 0; n < GetNumberOfHits(); n++) if (isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)) hits++; return hits; @@ -266,7 +266,7 @@ Double_t TRestHits::GetEnergyInCylinder(Int_t i, Int_t j, Double_t radius) const /// Double_t TRestHits::GetEnergyInCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const { Double_t energy = 0.; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (isHitNInsideCylinder(n, x0, x1, radius)) energy += this->GetEnergy(n); } @@ -288,7 +288,7 @@ Int_t TRestHits::GetNumberOfHitsInsideCylinder(Int_t i, Int_t j, Double_t radius Int_t TRestHits::GetNumberOfHitsInsideCylinder(const TVector3& x0, const TVector3& x1, Double_t radius) const { Int_t hits = 0; - for (int n = 0; n < GetNumberOfHits(); n++) + for (unsigned int n = 0; n < GetNumberOfHits(); n++) if (isHitNInsideCylinder(n, x0, x1, radius)) hits++; return hits; @@ -308,7 +308,7 @@ Double_t TRestHits::GetEnergyInSphere(const TVector3& pos0, Double_t radius) con /// Double_t TRestHits::GetEnergyInSphere(Double_t x0, Double_t y0, Double_t z0, Double_t radius) const { Double_t sum = 0; - for (int i = 0; i < GetNumberOfHits(); i++) { + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { Double_t x = this->GetPosition(i).X(); Double_t y = this->GetPosition(i).Y(); Double_t z = this->GetPosition(i).Z(); @@ -451,7 +451,7 @@ void TRestHits::Rotate(Int_t n, Double_t alpha, const TVector3& vAxis, const TVe /// Double_t TRestHits::GetMaximumHitEnergy() const { Double_t energy = 0; - for (int i = 0; i < GetNumberOfHits(); i++) + for (unsigned int i = 0; i < GetNumberOfHits(); i++) if (GetEnergy(i) > energy) energy = GetEnergy(i); return energy; } @@ -461,7 +461,7 @@ Double_t TRestHits::GetMaximumHitEnergy() const { /// Double_t TRestHits::GetMinimumHitEnergy() const { Double_t energy = GetMaximumHitEnergy(); - for (int i = 0; i < GetNumberOfHits(); i++) + for (unsigned int i = 0; i < GetNumberOfHits(); i++) if (GetEnergy(i) < energy) energy = GetEnergy(i); return energy; } @@ -509,7 +509,7 @@ void TRestHits::SwapHits(Int_t i, Int_t j) { /// \brief It returns true if the hits are ordered in increasing energies. /// Bool_t TRestHits::isSortedByEnergy() const { - for (int i = 0; i < GetNumberOfHits() - 1; i++) + for (unsigned int i = 0; i < GetNumberOfHits() - 1; i++) if (GetEnergy(i + 1) > GetEnergy(i)) return false; return true; @@ -556,7 +556,7 @@ TVector3 TRestHits::GetVector(int i, int j) const { return GetPosition(i) - GetP Int_t TRestHits::GetNumberOfHitsX() const { Int_t nHitsX = 0; - for (int n = 0; n < GetNumberOfHits(); n++) + for (unsigned int n = 0; n < GetNumberOfHits(); n++) if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0)) nHitsX++; return nHitsX; @@ -568,7 +568,7 @@ Int_t TRestHits::GetNumberOfHitsX() const { Int_t TRestHits::GetNumberOfHitsY() const { Int_t nHitsY = 0; - for (int n = 0; n < GetNumberOfHits(); n++) + for (unsigned int n = 0; n < GetNumberOfHits(); n++) if ((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0)) nHitsY++; return nHitsY; @@ -579,7 +579,7 @@ Int_t TRestHits::GetNumberOfHitsY() const { /// Double_t TRestHits::GetEnergyX() const { Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0)) { totalEnergy += fEnergy[n]; } @@ -593,7 +593,7 @@ Double_t TRestHits::GetEnergyX() const { /// Double_t TRestHits::GetEnergyY() const { Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0)) { totalEnergy += fEnergy[n]; } @@ -609,7 +609,7 @@ Double_t TRestHits::GetEnergyY() const { Double_t TRestHits::GetMeanPositionX() const { Double_t meanX = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0)) { meanX += fX[n] * fEnergy[n]; totalEnergy += fEnergy[n]; @@ -629,7 +629,7 @@ Double_t TRestHits::GetMeanPositionX() const { Double_t TRestHits::GetMeanPositionY() const { Double_t meanY = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0)) { meanY += fY[n] * fEnergy[n]; totalEnergy += fEnergy[n]; @@ -649,7 +649,7 @@ Double_t TRestHits::GetMeanPositionY() const { Double_t TRestHits::GetMeanPositionZ() const { Double_t meanZ = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (!IsNaN(fZ[n])) { meanZ += fZ[n] * fEnergy[n]; totalEnergy += fEnergy[n]; @@ -680,7 +680,7 @@ Double_t TRestHits::GetSigmaXY2() const { Double_t totalEnergy = this->GetTotalEnergy(); Double_t meanX = this->GetMeanPositionX(); Double_t meanY = this->GetMeanPositionY(); - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0)) sigmaXY2 += fEnergy[n] * (meanY - fY[n]) * (meanY - fY[n]); if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0)) @@ -698,7 +698,7 @@ Double_t TRestHits::GetSigmaX() const { Double_t totalEnergy = this->GetTotalEnergy(); Double_t meanX = this->GetMeanPositionX(); - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0)) sigmaX2 += fEnergy[n] * (meanX - fX[n]) * (meanX - fX[n]); } @@ -716,7 +716,7 @@ Double_t TRestHits::GetSigmaY() const { Double_t totalEnergy = this->GetTotalEnergy(); Double_t meanY = this->GetMeanPositionY(); - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0)) sigmaY2 += fEnergy[n] * (meanY - fY[n]) * (meanY - fY[n]); } @@ -730,7 +730,7 @@ Double_t TRestHits::GetSigmaY() const { /// void TRestHits::WriteHitsToTextFile(TString filename) { FILE* fff = fopen(filename.Data(), "w"); - for (int i = 0; i < GetNumberOfHits(); i++) { + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { if ((fType.size() == 0 ? !IsNaN(fX[i]) : fType[i] % X == 0)) fprintf(fff, "%d\t%e\t%s\t%e\t%e\n", i, fX[i], "NaN", fZ[i], fEnergy[i]); if ((fType.size() == 0 ? !IsNaN(fY[i]) : fType[i] % Y == 0)) @@ -784,7 +784,7 @@ Double_t TRestHits::GetGaussSigmaX() { Int_t k = nAdd / 2; Double_t xMin = std::numeric_limits::max(); Double_t xMax = std::numeric_limits::lowest(); - for (int n = 0; n < GetNumberOfHits(); k++, n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); k++, n++) { x[k] = fX[n]; y[k] = fEnergy[n]; ex[k] = 0; @@ -856,7 +856,7 @@ Double_t TRestHits::GetGaussSigmaY() { Int_t k = nAdd / 2; Double_t xMin = std::numeric_limits::max(); Double_t xMax = std::numeric_limits::lowest(); - for (int n = 0; n < GetNumberOfHits(); k++, n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); k++, n++) { x[k] = fY[n]; y[k] = fEnergy[n]; ex[k] = 0; @@ -927,7 +927,7 @@ Double_t TRestHits::GetGaussSigmaZ() { Int_t k = nAdd / 2; Double_t xMin = std::numeric_limits::max(); Double_t xMax = std::numeric_limits::lowest(); - for (int n = 0; n < GetNumberOfHits(); k++, n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); k++, n++) { x[k] = fZ[n]; y[k] = fEnergy[n]; ex[k] = 0; @@ -989,7 +989,7 @@ Double_t TRestHits::GetSkewXY() const { Double_t sigmaXY = TMath::Sqrt(this->GetSigmaXY2()); Double_t meanX = this->GetMeanPositionX(); Double_t meanY = this->GetMeanPositionY(); - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0)) skewXY += fEnergy[n] * (meanY - fY[n]) * (meanY - fY[n]) * (meanY - fY[n]); if ((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0)) @@ -1006,7 +1006,7 @@ Double_t TRestHits::GetSigmaZ2() const { Double_t totalEnergy = this->GetTotalEnergy(); Double_t meanZ = this->GetMeanPositionZ(); - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (!IsNaN(fZ[n])) sigmaZ2 += fEnergy[n] * (meanZ - fZ[n]) * (meanZ - fZ[n]); } return sigmaZ2 /= totalEnergy; @@ -1021,7 +1021,7 @@ Double_t TRestHits::GetSkewZ() const { Double_t sigmaZ = TMath::Sqrt(this->GetSigmaZ2()); Double_t meanZ = this->GetMeanPositionZ(); - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (!IsNaN(fZ[n])) skewZ += fEnergy[n] * (meanZ - fZ[n]) * (meanZ - fZ[n]) * (meanZ - fZ[n]); } return skewZ /= (totalEnergy * sigmaZ * sigmaZ * sigmaZ); @@ -1036,7 +1036,7 @@ Double_t TRestHits::GetMeanPositionXInPrism(const TVector3& x0, const TVector3& Double_t sizeY, Double_t theta) const { Double_t meanX = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0) && (isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)))) { meanX += fX[n] * fEnergy[n]; @@ -1058,7 +1058,7 @@ Double_t TRestHits::GetMeanPositionYInPrism(const TVector3& x0, const TVector3& Double_t sizeY, Double_t theta) const { Double_t meanY = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0) && (isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)))) { meanY += fY[n] * fEnergy[n]; @@ -1080,7 +1080,7 @@ Double_t TRestHits::GetMeanPositionZInPrism(const TVector3& x0, const TVector3& Double_t sizeY, Double_t theta) const { Double_t meanZ = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((!IsNaN(fZ[n]) && (isHitNInsidePrism(n, x0, x1, sizeX, sizeY, theta)))) { meanZ += fZ[n] * fEnergy[n]; totalEnergy += fEnergy[n]; @@ -1113,7 +1113,7 @@ Double_t TRestHits::GetMeanPositionXInCylinder(const TVector3& x0, const TVector Double_t radius) const { Double_t meanX = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (((fType.size() == 0 ? !IsNaN(fX[n]) : fType[n] % X == 0) && (isHitNInsideCylinder(n, x0, x1, radius)))) { meanX += fX[n] * fEnergy[n]; @@ -1134,7 +1134,7 @@ Double_t TRestHits::GetMeanPositionYInCylinder(const TVector3& x0, const TVector Double_t radius) const { Double_t meanY = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if (((fType.size() == 0 ? !IsNaN(fY[n]) : fType[n] % Y == 0) && (isHitNInsideCylinder(n, x0, x1, radius)))) { meanY += fY[n] * fEnergy[n]; @@ -1155,7 +1155,7 @@ Double_t TRestHits::GetMeanPositionZInCylinder(const TVector3& x0, const TVector Double_t radius) const { Double_t meanZ = 0; Double_t totalEnergy = 0; - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { if ((!IsNaN(fZ[n]) && (isHitNInsideCylinder(n, x0, x1, radius)))) { meanZ += fZ[n] * fEnergy[n]; totalEnergy += fEnergy[n]; @@ -1183,7 +1183,7 @@ TVector3 TRestHits::GetMeanPositionInCylinder(const TVector3& x0, const TVector3 /// Double_t TRestHits::GetHitsPathLength(Int_t n, Int_t m) const { if (n < 0) n = 0; - if (m > GetNumberOfHits() - 1) m = GetNumberOfHits() - 1; + if (m > (int)GetNumberOfHits() - 1) m = GetNumberOfHits() - 1; Double_t distance = 0; for (int i = n; i < m; i++) distance += TMath::Sqrt(GetDistance2(i, i + 1)); @@ -1196,7 +1196,7 @@ Double_t TRestHits::GetHitsPathLength(Int_t n, Int_t m) const { /// Double_t TRestHits::GetTotalDistance() const { Double_t distance = 0; - for (int i = 0; i < GetNumberOfHits() - 1; i++) distance += TMath::Sqrt(GetDistance2(i, i + 1)); + for (unsigned int i = 0; i < GetNumberOfHits() - 1; i++) distance += TMath::Sqrt(GetDistance2(i, i + 1)); return distance; } @@ -1221,7 +1221,7 @@ Double_t TRestHits::GetDistance2(int n, int m) const { /// Double_t TRestHits::GetDistanceToNode(Int_t n) const { Double_t distance = 0; - if (n > GetNumberOfHits() - 1) n = GetNumberOfHits() - 1; + if (n > (int)GetNumberOfHits() - 1) n = GetNumberOfHits() - 1; for (int hit = 0; hit < n; hit++) distance += GetVector(hit + 1, hit).Mag(); @@ -1250,7 +1250,7 @@ Int_t TRestHits::GetClosestHit(const TVector3& position) const { Int_t closestHit = 0; Double_t minDistance = 1.e30; - for (int nHit = 0; nHit < GetNumberOfHits(); nHit++) { + for (unsigned int nHit = 0; nHit < GetNumberOfHits(); nHit++) { TVector3 vector = position - GetPosition(nHit); Double_t distance = vector.Mag2(); @@ -1356,8 +1356,8 @@ Double_t TRestHits::GetHitsTwistWeighted(Int_t n, Int_t m) const { /// Double_t TRestHits::GetMaximumHitDistance() const { Double_t maxDistance = 0; - for (int n = 0; n < this->GetNumberOfHits(); n++) - for (int m = n + 1; m < this->GetNumberOfHits(); m++) { + for (unsigned int n = 0; n < this->GetNumberOfHits(); n++) + for (unsigned int m = n + 1; m < this->GetNumberOfHits(); m++) { Double_t d = this->GetDistance(n, m); if (d > maxDistance) maxDistance = d; } @@ -1370,8 +1370,8 @@ Double_t TRestHits::GetMaximumHitDistance() const { /// Double_t TRestHits::GetMaximumHitDistance2() const { Double_t maxDistance = 0; - for (int n = 0; n < this->GetNumberOfHits(); n++) - for (int m = n + 1; m < this->GetNumberOfHits(); m++) { + for (unsigned int n = 0; n < this->GetNumberOfHits(); n++) + for (unsigned int m = n + 1; m < this->GetNumberOfHits(); m++) { Double_t d = this->GetDistance2(n, m); if (d > maxDistance) maxDistance = d; } @@ -1386,7 +1386,7 @@ void TRestHits::PrintHits(Int_t nHits) const { Int_t N = nHits; if (N == -1) N = GetNumberOfHits(); - if (N > GetNumberOfHits()) N = GetNumberOfHits(); + if (N > (int)GetNumberOfHits()) N = GetNumberOfHits(); for (int n = 0; n < N; n++) { cout << "Hit " << n << " X: " << GetX(n) << " Y: " << GetY(n) << " Z: " << GetZ(n) diff --git a/source/framework/core/src/TRestManager.cxx b/source/framework/core/src/TRestManager.cxx index c6cb8e16d..604f0371e 100644 --- a/source/framework/core/src/TRestManager.cxx +++ b/source/framework/core/src/TRestManager.cxx @@ -170,7 +170,7 @@ void TRestManager::InitFromTask(string taskName, vector arguments) { /// \brief Get the application metadata class, according to the type /// TRestMetadata* TRestManager::GetMetadataClass(string type) { - for (int i = 0; i < fMetaObjects.size(); i++) { + for (unsigned int i = 0; i < fMetaObjects.size(); i++) { if ((string)fMetaObjects[i]->ClassName() == type) { return fMetaObjects[i]; } @@ -182,7 +182,7 @@ TRestMetadata* TRestManager::GetMetadataClass(string type) { /// \brief Get the application metadata class, according to the name /// TRestMetadata* TRestManager::GetMetadata(string name) { - for (int i = 0; i < fMetaObjects.size(); i++) { + for (unsigned int i = 0; i < fMetaObjects.size(); i++) { if (fMetaObjects[i]->GetName() == name) { return fMetaObjects[i]; } diff --git a/source/framework/core/src/TRestMesh.cxx b/source/framework/core/src/TRestMesh.cxx index 49681cce0..5ee2b74ba 100644 --- a/source/framework/core/src/TRestMesh.cxx +++ b/source/framework/core/src/TRestMesh.cxx @@ -317,7 +317,7 @@ Int_t TRestMesh::GetNodeZ(TVector3 v, Bool_t relative) { /// void TRestMesh::SetNodesFromHits(TRestHits* hits) { double nan = numeric_limits::quiet_NaN(); - for (int hit = 0; hit < hits->GetNumberOfHits(); hit++) { + for (unsigned int hit = 0; hit < hits->GetNumberOfHits(); hit++) { if (hits->GetEnergy(hit) <= 0) continue; REST_HitType type = hits->GetType(hit); this->AddNode(type == YZ ? nan : hits->GetX(hit), type == XZ ? nan : hits->GetY(hit), hits->GetZ(hit), @@ -336,7 +336,7 @@ void TRestMesh::SetNodesFromSphericalHits(TRestHits* hits) { if (!fIsSpherical) cout << "TRestMesh::SetNodesFromSphericalHits is only to be used with a spherical mesh!" << endl; - for (int hit = 0; hit < hits->GetNumberOfHits(); hit++) { + for (unsigned int hit = 0; hit < hits->GetNumberOfHits(); hit++) { if (hits->GetEnergy(hit) <= 0) continue; this->AddSphericalNode(hits->GetX(hit), hits->GetY(hit), hits->GetZ(hit), hits->GetEnergy(hit)); } @@ -771,10 +771,6 @@ std::vector TRestMesh::GetTrackBoundaries(TVector3 pos, TVector3 dir, } if (boundaries.size() == 2) { - TVector3 center = 0.5 * (boundaries[0] + boundaries[1]); - Double_t product_1 = (boundaries[0] - center) * dir; - Double_t product_2 = (boundaries[1] - center) * dir; - if (particle) { // d1 and d2 is the signed distance to the volume boundaries Double_t d1 = (boundaries[0] - pos) * dir; diff --git a/source/framework/core/src/TRestMessenger.cxx b/source/framework/core/src/TRestMessenger.cxx index 7c7ba76c7..24c87a77d 100644 --- a/source/framework/core/src/TRestMessenger.cxx +++ b/source/framework/core/src/TRestMessenger.cxx @@ -130,12 +130,14 @@ void TRestMessenger::InitFromConfigFile() { string token = GetParameter("token", "116027"); string source = GetParameter("messageSource", "OUTPUTFILE"); key_t key = StringToInteger(token); - int flag; - if (fMode == MessagePool_Host) { - flag = SHMFLAG_CREATEUNIQUE; - } else { - flag = SHMFLAG_OPEN; - } + /* +int flag = 0; +if (fMode == MessagePool_Host) { + flag = SHMFLAG_CREATEUNIQUE; +} else { + flag = SHMFLAG_OPEN; +} + */ bool created = false; int shmid = shmget(key, sizeof(messagepool_t), SHMFLAG_OPEN); diff --git a/source/framework/core/src/TRestMetadata.cxx b/source/framework/core/src/TRestMetadata.cxx index dde0d8d2a..61a91ae7b 100644 --- a/source/framework/core/src/TRestMetadata.cxx +++ b/source/framework/core/src/TRestMetadata.cxx @@ -769,7 +769,7 @@ TRestMetadata* TRestMetadata::InstantiateChildMetadata(std::string pattern, std: std::string xmlChild = paraele->Value(); if (xmlChild.find("TRest") == 0) { if (pattern.empty() || xmlChild.find(pattern) != string::npos) { - if (name.empty() || !name.empty() && name == (string)paraele->Attribute("name")) { + if (name.empty() || (!name.empty() && name == (string)paraele->Attribute("name"))) { TClass* c = TClass::GetClass(xmlChild.c_str()); if (c) // this means we have the metadata class was found { @@ -940,7 +940,7 @@ void TRestMetadata::ReadElement(TiXmlElement* e, bool recursive) { // these sections will be executed individually by the corresponding TRestXXX class while (contentelement != nullptr) { TiXmlElement* nxt = contentelement->NextSiblingElement(); - if (recursive || ((string)contentelement->Value()).find("TRest") == -1) { + if (recursive || ((string)contentelement->Value()).find("TRest") == string::npos) { RESTDebug << "into child element \"" << contentelement->Value() << "\" of \"" << e->Value() << "\"" << RESTendl; ReadElement(contentelement, recursive); @@ -985,7 +985,7 @@ void TRestMetadata::ExpandIfSections(TiXmlElement* e) { const char* evaluate = e->Attribute("evaluate"); const char* condition = e->Attribute("condition"); - if (condition == nullptr || string(condition).find_first_of("=!<>") == -1) { + if (condition == nullptr || string(condition).find_first_of("=!<>") == string::npos) { RESTWarning << "Invalid \"IF\" structure!" << RESTendl; return; } @@ -1111,7 +1111,7 @@ void TRestMetadata::ReplaceForLoopVars(TiXmlElement* e, map forL if (strcmp(name, "name") != 0) { string outputBuffer = val; - if (outputBuffer.find("[") != (int)string::npos || outputBuffer.find("]") != (int)string::npos) { + if (outputBuffer.find("[") != string::npos || outputBuffer.find("]") != string::npos) { RESTError << "TRestMetadata::ReplaceForLoopVars. Old for-loop construction identified" << RESTendl; RESTError << "Please, replace [] variable nomenclature by ${}." << RESTendl; @@ -1935,20 +1935,17 @@ string TRestMetadata::GetKEYStructure(std::string keyName, size_t& fromPosition, return result; } string TRestMetadata::GetKEYStructure(std::string keyName, size_t& fromPosition, TiXmlElement* ele) { - size_t position = fromPosition; - RESTDebug << "Finding " << fromPosition << "th appearance of KEY Structure \"" << keyName << "\"..." << RESTendl; TiXmlElement* childele = ele->FirstChildElement(keyName); - for (int i = 0; childele != nullptr && i < fromPosition; i++) { + for (unsigned int i = 0; childele != nullptr && i < fromPosition; i++) { childele = childele->NextSiblingElement(keyName); } if (childele != nullptr) { string result = ElementToString(childele); fromPosition = fromPosition + 1; RESTDebug << "Found Key : " << result << RESTendl; - // RESTDebug << "New position : " << fromPosition << RESTendl; return result; } @@ -2119,9 +2116,6 @@ string TRestMetadata::ReplaceConstants(const string buffer) { RESTDebug << "Entering ... TRestMetadata::ReplaceConstants (" << buffer << ")" << RESTendl; string outputBuffer = buffer; - int startPosition = 0; - int endPosition = 0; - // replace bare constant name. ignore sub strings. // e.g. variable "nCh" with value "3" cannot replace the string "nChannels+1" for (auto iter : fConstants) { @@ -2297,7 +2291,7 @@ Int_t TRestMetadata::GetVersionCode() { return TRestTools::ConvertVersionCode((s /// fSectionName std::string TRestMetadata::GetSectionName() { auto a = fSectionName.find('\n', 0); - if (a != -1) return fSectionName.substr(0, a); + if (a != string::npos) return fSectionName.substr(0, a); return fSectionName; } @@ -2557,7 +2551,7 @@ void TRestMetadata::ReadOneParameter(string name, string value) { vector availableparameters; vector datamembers = thisactual.GetListOfDataMembers(); - for (int i = 0; i < datamembers.size(); i++) { + for (unsigned int i = 0; i < datamembers.size(); i++) { string parameter = DataMemberNameToParameterName(datamembers[i]); if (parameter != "") { if (parameter == "name" || parameter == "title" || parameter == "verboseLevel" || diff --git a/source/framework/core/src/TRestMetadataPlot.cxx b/source/framework/core/src/TRestMetadataPlot.cxx index c66657a19..b5da2b2d0 100644 --- a/source/framework/core/src/TRestMetadataPlot.cxx +++ b/source/framework/core/src/TRestMetadataPlot.cxx @@ -298,14 +298,12 @@ void TRestMetadataPlot::Initialize() { /// \brief Initialization of TRestMetadataPlot members through a RML file /// void TRestMetadataPlot::InitFromConfigFile() { - size_t position = 0; if (fHostmgr->GetRunInfo() != nullptr) { fRun = fHostmgr->GetRunInfo(); } #pragma region ReadLabels RESTDebug << "TRestMetadataPlot: Reading canvas settings" << RESTendl; - position = 0; TiXmlElement* formatDefinition = GetElement("labels"); if (formatDefinition != nullptr) { if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) { @@ -346,7 +344,6 @@ void TRestMetadataPlot::InitFromConfigFile() { #pragma endregion #pragma region ReadLegend - position = 0; TiXmlElement* legendDefinition = GetElement("legendPosition"); if (legendDefinition != nullptr) { if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) { @@ -380,7 +377,6 @@ void TRestMetadataPlot::InitFromConfigFile() { #pragma endregion #pragma region ReadCanvas - position = 0; TiXmlElement* canvasDefinition = GetElement("canvas"); if (canvasDefinition != nullptr) { fCanvasSize = StringTo2DVector(GetFieldValue("size", canvasDefinition)); @@ -491,9 +487,9 @@ void TRestMetadataPlot::InitFromConfigFile() { } } - for (int n = 0; n < fPanels.size(); n++) { + for (unsigned int n = 0; n < fPanels.size(); n++) { RESTExtreme << "Panel " << n << " with font size : " << fPanels[n].font_size << RESTendl; - for (int m = 0; m < fPanels[n].posX.size(); m++) { + for (unsigned int m = 0; m < fPanels[n].posX.size(); m++) { RESTExtreme << "Label : " << fPanels[n].label[m] << RESTendl; RESTExtreme << "Pos X : " << fPanels[n].posX[m] << RESTendl; RESTExtreme << "Pos Y : " << fPanels[n].posY[m] << RESTendl; @@ -514,7 +510,7 @@ TRestMetadataPlot::Graph_Info_Set TRestMetadataPlot::SetupGraphFromConfigFile(Ti graph.drawOption = RemoveWhiteSpaces(GetParameter("option", graphele, "")); graph.metadataRule = RemoveWhiteSpaces(GetParameter("metadataRule", graphele, "")); - for (int n = 0; n < fPlotNamesCheck.size(); n++) + for (unsigned int n = 0; n < fPlotNamesCheck.size(); n++) if (graph.name == fPlotNamesCheck[n]) { RESTError << "Repeated plot/graph names were found! Please, use different names for different plots!" @@ -566,7 +562,7 @@ void TRestMetadataPlot::AddFileFromExternalRun() { } else if (fRun->GetInputFileNames().size() != 0) { // if we have only TRestRun, we ask for its input file list auto names = fRun->GetInputFileNames(); - for (int i = 0; i < names.size(); i++) { + for (unsigned int i = 0; i < names.size(); i++) { this->AddFile(names[i]); } return; @@ -682,7 +678,7 @@ void TRestMetadataPlot::GenerateCanvas() { panelRun->SetHistoricMetadataSaving(false); panelRun->OpenInputFile(fRunInputFileName[0]); for (unsigned int n = 0; n < fPanels.size(); n++) { - TPad* targetPad = (TPad*)fCombinedCanvas->cd(n + 1); + fCombinedCanvas->cd(n + 1); for (unsigned int m = 0; m < fPanels[n].posX.size(); m++) { string label = fPanels[n].label[m]; @@ -817,7 +813,7 @@ void TRestMetadataPlot::GenerateCanvas() { RESTWarning << "X: " << xData[0] << " Y: " << yData[0] << RESTendl; } - for (int nn = 0; nn < xData.size(); nn++) + for (unsigned int nn = 0; nn < xData.size(); nn++) RESTDebug << "X: " << xData[nn] << " Y: " << yData[nn] << RESTendl; // adjust the graph diff --git a/source/framework/core/src/TRestProcessRunner.cxx b/source/framework/core/src/TRestProcessRunner.cxx index 0432cda9f..e3d237e3c 100644 --- a/source/framework/core/src/TRestProcessRunner.cxx +++ b/source/framework/core/src/TRestProcessRunner.cxx @@ -677,7 +677,8 @@ void TRestProcessRunner::PauseMenu() { fThreads[i]->StartThread(); } RESTInfo << "Re-directing output to " << file << RESTendl; - freopen(file.c_str(), "w", stdout); + FILE* f = freopen(file.c_str(), "w", stdout); + if (f == nullptr) RESTWarning << "Couldnt redirect output for file: " << file << RESTendl; REST_Display_CompatibilityMode = true; } // father process @@ -960,8 +961,9 @@ void TRestProcessRunner::ConfigOutputFile() { void TRestProcessRunner::WriteMetadata() { fOutputDataFile->cd(); fRunInfo->SetNFilesSplit(fNFilesSplit); - fRunInfo->Write(0, TObject::kOverwrite); - this->Write(0, TObject::kWriteDelete); + fRunInfo->Write(nullptr, TObject::kOverwrite); + this->Write(nullptr, TObject::kWriteDelete); + if (fRunInfo->GetFileProcess() != nullptr) { // std::cout << "Run. Process-0. " << fRunInfo->GetFileProcess()->GetName() << std::endl; fRunInfo->GetFileProcess()->Write(nullptr, kOverwrite); diff --git a/source/framework/core/src/TRestRun.cxx b/source/framework/core/src/TRestRun.cxx index f5b28d3bf..16af1639e 100644 --- a/source/framework/core/src/TRestRun.cxx +++ b/source/framework/core/src/TRestRun.cxx @@ -258,7 +258,8 @@ void TRestRun::InitFromConfigFile() { fOutputFileName = (TString)TRestTools::RemoveMultipleSlash((string)fOutputFileName); if (!TRestTools::fileExists(outputdir)) { - system((TString) "mkdir -p " + outputdir); + int z = system((TString) "mkdir -p " + outputdir); + if (z != 0) RESTError << "Problem creating directory : " << outputdir << RESTendl; } if (!TRestTools::isPathWritable(outputdir)) { RESTWarning << "TRestRun: Output path '" << outputdir << "' does not exist or it is not writable." @@ -303,7 +304,7 @@ void TRestRun::InitFromConfigFile() { OpenInputFile(0); RESTDebug << "TRestRun::EndOfInit. InputFile pattern: \"" << fInputFileName << "\"" << RESTendl; RESTInfo << "which matches :" << RESTendl; - for (int i = 0; i < fInputFileNames.size(); i++) { + for (unsigned int i = 0; i < fInputFileNames.size(); i++) { RESTInfo << fInputFileNames[i] << RESTendl; } RESTEssential << "(" << fInputFileNames.size() << " added files)" << RESTendl; @@ -313,7 +314,7 @@ void TRestRun::InitFromConfigFile() { /// \brief Open the i th file in the file list /// void TRestRun::OpenInputFile(int i) { - if (fInputFileNames.size() > i) { + if (fInputFileNames.size() > (unsigned int)i) { TString Filename = fInputFileNames[i]; RESTInfo << "opening... " << Filename << RESTendl; OpenInputFile((string)Filename); @@ -561,7 +562,7 @@ void TRestRun::ReadInputFileTrees() { TKey* key; while ((key = (TKey*)nextkey())) { // cout << key->GetName() << endl; - if (((string)key->GetName()).find("EventTree") != -1) { + if (((string)key->GetName()).find("EventTree") != string::npos) { _eventTree = (TTree*)fInputFile->Get(key->GetName()); string eventname = Replace(key->GetName(), "Tree", "", 0); TBranch* br = _eventTree->GetBranch("eventBranch"); @@ -715,7 +716,7 @@ void TRestRun::ReadFileInfo(const string& filename) { } pos = -1; - for (int i = 0; i < formatsectionlist.size() && i < formatprefixlist.size() - 1; i++) { + for (unsigned int i = 0; i < formatsectionlist.size() && i < formatprefixlist.size() - 1; i++) { if (i != 0 && formatprefixlist[i] == "") { RESTWarning << "file format reference contains error!" << RESTendl; return; @@ -992,12 +993,12 @@ TFile* TRestRun::MergeToOutputFile(vector filenames, string outputfilena RESTDebug << "TRestRun::FormOutputFile. Starting to add files" << RESTendl; - for (int i = 0; i < filenames.size(); i++) { + for (unsigned int i = 0; i < filenames.size(); i++) { m->AddFile(filenames[i].c_str(), false); } if (m->Merge()) { - for (int i = 0; i < filenames.size(); i++) { + for (unsigned int i = 0; i < filenames.size(); i++) { remove(filenames[i].c_str()); } } else { @@ -1167,8 +1168,8 @@ void TRestRun::CloseFile() { fEventTree = nullptr; } - for (int i = 0; i < fMetadata.size(); i++) { - for (int j = 0; j < fInputMetadata.size(); j++) { + for (unsigned int i = 0; i < fMetadata.size(); i++) { + for (unsigned int j = 0; j < fInputMetadata.size(); j++) { if (fMetadata[i] == fInputMetadata[j]) { delete fMetadata[i]; fMetadata.erase(fMetadata.begin() + i); @@ -1397,6 +1398,9 @@ TRestEvent* TRestRun::GetEventWithID(Int_t eventID, Int_t subEventID, const TStr std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int startingIndex, int maxNumber) { + int max = maxNumber; + if (max < 0) max = GetEntries(); + std::vector eventIds; // parsing cuts std::vector observables; @@ -1407,9 +1411,9 @@ std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int vector cutsVector = Split(cuts, "&&", false, true); - for (int i = 0; i < cutsVector.size(); i++) { + for (unsigned int i = 0; i < cutsVector.size(); i++) { string cut = cutsVector[i]; - for (int j = 0; j < validOperators.size(); j++) { + for (unsigned int j = 0; j < validOperators.size(); j++) { if (cut.find(validOperators[j]) != string::npos) { operators.push_back(validOperators[j]); observables.push_back((string)cut.substr(0, cut.find(validOperators[j]))); @@ -1431,7 +1435,7 @@ std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int branchNames.insert((string)branches->At(i)->GetName()); } // verify all observables in cuts are branch names - for (int i = 0; i < observables.size(); i++) { + for (unsigned int i = 0; i < observables.size(); i++) { // verify operators if (std::find(validOperators.begin(), validOperators.end(), operators[i]) == validOperators.end()) { // invalid operation @@ -1454,7 +1458,7 @@ std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int } // read only the necessary branches fAnalysisTree->SetBranchStatus("*", false); - for (int i = 0; i < observables.size(); i++) { + for (unsigned int i = 0; i < observables.size(); i++) { fAnalysisTree->SetBranchStatus(observables[i].c_str(), true); } // comparison code @@ -1465,7 +1469,7 @@ std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int i = (iNoOffset + startingIndex) % nEntries; fAnalysisTree->GetEntry(i); comparisonResult = true; - for (int j = 0; j < observables.size(); j++) { + for (unsigned int j = 0; j < observables.size(); j++) { valueToCompareFrom = fAnalysisTree->GetDblObservableValue(observables[j].c_str()); if (operators[j] == "=" || operators[j] == "==") { comparisonResult = comparisonResult && (valueToCompareFrom == values[j]); @@ -1479,8 +1483,9 @@ std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int comparisonResult = comparisonResult && (valueToCompareFrom >= values[j]); } } + if (comparisonResult) { - if (eventIds.size() < maxNumber) { + if ((int)eventIds.size() < max) { eventIds.push_back(i); } else { break; @@ -1493,9 +1498,12 @@ std::vector TRestRun::GetEventEntriesWithConditions(const string& cuts, int } std::vector TRestRun::GetEventIdsWithConditions(const string& cuts, int startingIndex, int maxNumber) { - auto indices = GetEventEntriesWithConditions(cuts, startingIndex, maxNumber); + int max = maxNumber; + if (max < 0) max = GetEntries(); + + auto indices = GetEventEntriesWithConditions(cuts, startingIndex, max); std::vector ids; - for (int i = 0; i < indices.size(); i++) { + for (unsigned int i = 0; i < indices.size(); i++) { GetEntry(indices[i]); ids.push_back(fAnalysisTree->GetEventID()); } @@ -1572,7 +1580,7 @@ TRestMetadata* TRestRun::GetMetadataClass(const TString& type, TFile* file) { } } } else { - for (int i = 0; i < fMetadata.size(); i++) + for (unsigned int i = 0; i < fMetadata.size(); i++) if (fMetadata[i]->InheritsFrom(type)) return fMetadata[i]; if (fInputFile != nullptr && this->GetVersionCode() >= TRestTools::ConvertVersionCode("2.2.1")) { @@ -1633,7 +1641,7 @@ std::vector TRestRun::GetMetadataStructureTitles() { /// \return The string with data members replaced /// string TRestRun::ReplaceMetadataMembers(const string& instr, Int_t precision) { - if (instr.find("[", 0) == (int)string::npos) return instr; + if (instr.find("[", 0) == string::npos) return instr; string outstring = instr; int startPosition = 0; @@ -1691,7 +1699,7 @@ string TRestRun::ReplaceMetadataMember(const string& instr, Int_t precision) { if (results.size() == 1) results = Split(instr, "->", false, true); if (results.size() == 2) { - Int_t index = 0; + size_t index = 0; int pos1 = results[1].find("[", 0); int pos2 = results[1].find("]", pos1); if (pos1 > 0 && pos2 > 0) { @@ -1755,7 +1763,7 @@ Bool_t TRestRun::EvaluateMetadataMember(const string& instr) { string expOp = ""; std::vector results; - for (int n = 0; n < oper.size(); n++) { + for (unsigned int n = 0; n < oper.size(); n++) { size_t pos = 0; if (instr.find("->") != string::npos) pos = instr.find("->") + 2; @@ -1884,13 +1892,13 @@ void TRestRun::PrintEndDate() { /// void TRestRun::PrintErrors() { Int_t nErrors = 0; - for (int n = 0; n < fMetadata.size(); n++) + for (unsigned int n = 0; n < fMetadata.size(); n++) if (fMetadata[n]->GetError()) nErrors++; if (nErrors) { cout << endl; RESTError << "Found a total of " << nErrors << " metadata errors" << RESTendl; - for (int n = 0; n < fMetadata.size(); n++) + for (unsigned int n = 0; n < fMetadata.size(); n++) if (fMetadata[n]->GetError()) { cout << endl; RESTError << "Class: " << fMetadata[n]->ClassName() << " Name: " << fMetadata[n]->GetName() @@ -1910,13 +1918,13 @@ void TRestRun::PrintErrors() { /// void TRestRun::PrintWarnings() { Int_t nWarnings = 0; - for (int n = 0; n < fMetadata.size(); n++) + for (unsigned int n = 0; n < fMetadata.size(); n++) if (fMetadata[n]->GetWarning()) nWarnings++; if (nWarnings) { cout << endl; RESTWarning << "Found a total of " << nWarnings << " metadata warnings" << RESTendl; - for (int n = 0; n < fMetadata.size(); n++) + for (unsigned int n = 0; n < fMetadata.size(); n++) if (fMetadata[n]->GetWarning()) { cout << endl; RESTWarning << "Class: " << fMetadata[n]->ClassName() << " Name: " << fMetadata[n]->GetName() diff --git a/source/framework/core/src/TRestSystemOfUnits.cxx b/source/framework/core/src/TRestSystemOfUnits.cxx index 7e1fa273e..a0fbc3e6a 100644 --- a/source/framework/core/src/TRestSystemOfUnits.cxx +++ b/source/framework/core/src/TRestSystemOfUnits.cxx @@ -264,13 +264,13 @@ TRestSystemOfUnits::TRestSystemOfUnits(string unitsStr) { } fScaleCombined = 1; - for (int pos = 0; pos >= 0 && pos < unitsStr.size();) { + for (size_t pos = 0; pos >= 0 && pos < unitsStr.size();) { if (isalpha(unitsStr[pos])) { - int pos1 = pos; + size_t pos1 = pos; while (pos < unitsStr.size() && isalpha(unitsStr[pos])) { pos++; } - int pos2 = pos; + size_t pos2 = pos; string singleunit = unitsStr.substr(pos1, pos2 - pos1); if (IsBasicUnit(singleunit)) { @@ -340,7 +340,7 @@ double TRestSystemOfUnits::GetUnitScale(string singleUnit) { string TRestSystemOfUnits::ToStandardDefinition() { string result = ""; - for (int i = 0; i < fComponents.size(); i++) { + for (unsigned int i = 0; i < fComponents.size(); i++) { if (fComponentOrder[i] < 0) { result += "/"; } else if (i > 0) { diff --git a/source/framework/core/src/TRestTask.cxx b/source/framework/core/src/TRestTask.cxx index 9bd2a42f6..9a6fa2b46 100644 --- a/source/framework/core/src/TRestTask.cxx +++ b/source/framework/core/src/TRestTask.cxx @@ -166,17 +166,16 @@ void TRestTask::RunTask(TRestManager* mgr) { } else { if (fMode == TASK_MACRO) { // call gInterpreter to run a command - for (int i = 0; i < fArgumentValues.size(); i++) { + for (unsigned int i = 0; i < fArgumentValues.size(); i++) { if (fArgumentValues[i] == "NOT SET") { RESTError << "TRestTask : argument " << i << " not set! Task will not run!" << RESTendl; } } fConstructedCommand = fInvokeMethod + "("; - for (int i = 0; i < fArgumentValues.size(); i++) { + for (unsigned int i = 0; i < fArgumentValues.size(); i++) { if (fArgumentTypes[i] == 1) { - fConstructedCommand += - "\"" + Replace(fArgumentValues[i], "\\", "\\\\", 0) + "\""; + fConstructedCommand += "\"" + Replace(fArgumentValues[i], "\\", "\\\\", 0) + "\""; } else { fConstructedCommand += fArgumentValues[i]; } @@ -224,7 +223,8 @@ void TRestTask::RunTask(TRestManager* mgr) { } } } else if (fMode == TASK_SHELLCMD) { - system(fConstructedCommand.c_str()); + int z = system(fConstructedCommand.c_str()); + if (z != 0) RESTError << "Problem launching : " << fConstructedCommand << RESTendl; } } } @@ -237,16 +237,16 @@ void TRestTask::PrintArgumentHelp() { if (fMode == 0) { RESTError << fInvokeMethod << "() Gets invalided input!" << RESTendl; cout << "You should give the following arguments (* is mandatory input):" << endl; - int n = fArgumentNames.size(); - for (int i = 0; i < n; i++) { + unsigned int n = fArgumentNames.size(); + for (unsigned int i = 0; i < n; i++) { cout << (i < fNRequiredArgument ? "*" : "") << fArgumentNames[i] << endl; } } else if (fMode == 1) { } else if (fMode == 2) { RESTError << "Macro class \"" << this->ClassName() << "\" gets invalided input!" << RESTendl; RESTError << "You should give the following arguments ( * : necessary input):" << RESTendl; - int n = any(this).GetNumberOfDataMembers(); - for (int i = 1; i < n; i++) { + unsigned int n = any(this).GetNumberOfDataMembers(); + for (unsigned int i = 1; i < n; i++) { if (i < fNRequiredArgument + 1) RESTError << "*"; RESTError << any(this).GetDataMember(i).name << RESTendl; } @@ -310,7 +310,7 @@ TRestTask* TRestTask::GetTaskFromMacro(TString taskName) { TRestTask* TRestTask::GetTaskFromCommand(TString cmd) { REST_TASKMODE mode = TASK_CPPCMD; - if (((string)cmd).find("->") == -1) mode = TASK_SHELLCMD; + if (((string)cmd).find("->") == string::npos) mode = TASK_SHELLCMD; auto tsk = new TRestTask(cmd, mode); if (tsk->GetMode() == TASK_ERROR) { diff --git a/source/framework/core/src/TRestThread.cxx b/source/framework/core/src/TRestThread.cxx index 786535e54..2df77ba5b 100644 --- a/source/framework/core/src/TRestThread.cxx +++ b/source/framework/core/src/TRestThread.cxx @@ -32,8 +32,6 @@ using namespace std; using namespace chrono; #endif -ClassImp(TRestThread); - /////////////////////////////////////////////// /// \brief Set variables by default during initialization. /// @@ -102,7 +100,7 @@ Int_t TRestThread::ValidateChain(TRestEvent* input) { } // verify that the output event type is good to be the input event of the next process - for (int i = 0; i < processes.size() - 1; i++) { + for (unsigned int i = 0; i < processes.size() - 1; i++) { string outEventType = processes[i]->GetOutputEvent().type; string nextinEventType = processes[i + 1]->GetInputEvent().type; if (outEventType != nextinEventType && outEventType != "TRestEvent" && @@ -326,7 +324,7 @@ void TRestThread::PrepareToProcess(bool* outputConfig) { if (branchesToAdd.size() == 0) branchesToAdd.push_back(pair(BranchName, evt)); else - for (int j = 0; j < branchesToAdd.size(); j++) { + for (unsigned int j = 0; j < branchesToAdd.size(); j++) { if (branchesToAdd[j].first == BranchName) branchesToAdd[j].second = evt; else if (j == branchesToAdd.size() - 1) @@ -341,7 +339,7 @@ void TRestThread::PrepareToProcess(bool* outputConfig) { if (branchesToAdd.size() == 0) branchesToAdd.push_back(pair(BranchName, evt)); else - for (int j = 0; j < branchesToAdd.size(); j++) { + for (unsigned int j = 0; j < branchesToAdd.size(); j++) { if (branchesToAdd[j].first == BranchName) branchesToAdd[j].second = evt; else if (j == branchesToAdd.size() - 1) @@ -359,7 +357,7 @@ void TRestThread::PrepareToProcess(bool* outputConfig) { if (branchesToAdd.size() == 0) branchesToAdd.push_back(pair(BranchName, evt)); else - for (int j = 0; j < branchesToAdd.size(); j++) { + for (unsigned int j = 0; j < branchesToAdd.size(); j++) { if (branchesToAdd[j].first == BranchName) branchesToAdd[j].second = evt; else if (j == branchesToAdd.size() - 1) diff --git a/source/framework/core/src/TRestVolumeHits.cxx b/source/framework/core/src/TRestVolumeHits.cxx index 99722cdf2..4ef3bc5b8 100644 --- a/source/framework/core/src/TRestVolumeHits.cxx +++ b/source/framework/core/src/TRestVolumeHits.cxx @@ -134,8 +134,8 @@ void TRestVolumeHits::RemoveHit(int n) { void TRestVolumeHits::SortByEnergy() { while (!isSortedByEnergy()) { - for (int i = 0; i < GetNumberOfHits(); i++) { - for (int j = i + 1; j < GetNumberOfHits(); j++) { + for (unsigned int i = 0; i < GetNumberOfHits(); i++) { + for (unsigned int j = i + 1; j < GetNumberOfHits(); j++) { if (GetEnergy(i) < GetEnergy(j)) SwapHits(i, j); } } @@ -155,7 +155,7 @@ TVector3 TRestVolumeHits::GetSigma(int n) const { } void TRestVolumeHits::PrintHits() const { - for (int n = 0; n < GetNumberOfHits(); n++) { + for (unsigned int n = 0; n < GetNumberOfHits(); n++) { cout << "Hit " << n << " X: " << GetX(n) << " Y: " << GetY(n) << " Z: " << GetZ(n) << " sX: " << GetSigmaX(n) << " sY: " << GetSigmaY(n) << " sZ: " << GetSigmaZ(n) << " Energy: " << GetEnergy(n) << endl; @@ -174,7 +174,7 @@ void TRestVolumeHits::kMeansClustering(TRestVolumeHits* hits, TRestVolumeHits& v for (int it = 0; it < maxIt; it++) { for (int n = 0; n < nodes; n++) volHits[n].RemoveHits(); - for (int i = 0; i < hits->GetNumberOfHits(); i++) { + for (unsigned int i = 0; i < hits->GetNumberOfHits(); i++) { double minDist = 1E9; int clIndex = -1; for (int n = 0; n < nodes; n++) { diff --git a/source/framework/core/src/startup.cpp b/source/framework/core/src/startup.cpp index 5d2846afd..259956073 100644 --- a/source/framework/core/src/startup.cpp +++ b/source/framework/core/src/startup.cpp @@ -75,13 +75,13 @@ struct __REST_CONST_INIT { COLOR_RESET = info[0].Attributes; #endif // WIN32 - char* _REST_PATH = getenv("REST_PATH"); - char* _REST_USER = getenv("USER"); - char* _REST_USERHOME = getenv("HOME"); + char* _REST_PATH = getenv("REST_PATH"); + char* _REST_USER = getenv("USER"); + char* _REST_USERHOME = getenv("HOME"); - //char* _REST_PATH = 0; - //char* _REST_USER = 0; - //char* _REST_USERHOME = 0; + // char* _REST_PATH = 0; + // char* _REST_USER = 0; + // char* _REST_USERHOME = 0; #ifdef WIN32 if (_REST_PATH == nullptr) { @@ -260,7 +260,7 @@ template string VectorToString(vector vec) { stringstream ss; ss << "{"; - for (int i = 0; i < vec.size(); i++) { + for (unsigned int i = 0; i < vec.size(); i++) { ss << Converter::thisptr->ToStringFunc(vec.at(i)); if (i < vec.size() - 1) { ss << ","; diff --git a/source/framework/external/tinyxml/tinyxmlparser.cpp b/source/framework/external/tinyxml/tinyxmlparser.cpp index ec80cea9e..adcfe9cc7 100644 --- a/source/framework/external/tinyxml/tinyxmlparser.cpp +++ b/source/framework/external/tinyxml/tinyxmlparser.cpp @@ -41,11 +41,7 @@ distribution. // is less flexible than it appears. Changing the entries // or order will break putstring. TiXmlBase::Entity TiXmlBase::entity[TiXmlBase::NUM_ENTITY] = { - {"&", 5, '&'}, - {"<", 4, '<'}, - {">", 4, '>'}, - {""", 6, '\"'}, - {"'", 6, '\''}}; + {"&", 5, '&'}, {"<", 4, '<'}, {">", 4, '>'}, {""", 6, '\"'}, {"'", 6, '\''}}; // Bunch of unicode info at: // http://www.unicode.org/faq/utf_bom.html @@ -62,322 +58,298 @@ const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; const int TiXmlBase::utf8ByteTable[256] = { - // 0 1 2 3 4 5 6 7 8 9 a b c d - //e + // 0 1 2 3 4 5 6 7 8 9 a b c + // d + // e // f - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 - 1, 1, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte - 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 - 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte - 4, 4, 4, 4, 4, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte + 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid }; -void TiXmlBase::ConvertUTF32ToUTF8(unsigned long input, char* output, - int* length) { - const unsigned long BYTE_MASK = 0xBF; - const unsigned long BYTE_MARK = 0x80; - const unsigned long FIRST_BYTE_MARK[7] = {0x00, 0x00, 0xC0, 0xE0, - 0xF0, 0xF8, 0xFC}; - - if (input < 0x80) - *length = 1; - else if (input < 0x800) - *length = 2; - else if (input < 0x10000) - *length = 3; - else if (input < 0x200000) - *length = 4; - else { - *length = 0; - return; - } // This code won't covert this correctly anyway. - - output += *length; - - // Scary scary fall throughs. - switch (*length) { - case 4: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 3: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 2: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 1: - --output; - *output = (char)(input | FIRST_BYTE_MARK[*length]); - } +void TiXmlBase::ConvertUTF32ToUTF8(unsigned long input, char* output, int* length) { + const unsigned long BYTE_MASK = 0xBF; + const unsigned long BYTE_MARK = 0x80; + const unsigned long FIRST_BYTE_MARK[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; + + if (input < 0x80) + *length = 1; + else if (input < 0x800) + *length = 2; + else if (input < 0x10000) + *length = 3; + else if (input < 0x200000) + *length = 4; + else { + *length = 0; + return; + } // This code won't covert this correctly anyway. + + output += *length; + + // Scary scary fall throughs. + switch (*length) { + case 4: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 3: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 2: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 1: + --output; + *output = (char)(input | FIRST_BYTE_MARK[*length]); + } } -/*static*/ int TiXmlBase::IsAlpha(unsigned char anyByte, - TiXmlEncoding /*encoding*/) { - // This will only work for low-ascii, everything else is assumed to be a valid - // letter. I'm not sure this is the best approach, but it is quite tricky - // trying to figure out alhabetical vs. not across encoding. So take a very - // conservative approach. - - // if ( encoding == TIXML_ENCODING_UTF8 ) - // { - if (anyByte < 127) - return isalpha(anyByte); - else - return 1; // What else to do? The unicode set is huge...get the english - // ones right. - // } - // else - // { - // return isalpha( anyByte ); - // } +/*static*/ int TiXmlBase::IsAlpha(unsigned char anyByte, TiXmlEncoding /*encoding*/) { + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky + // trying to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + + // if ( encoding == TIXML_ENCODING_UTF8 ) + // { + if (anyByte < 127) + return isalpha(anyByte); + else + return 1; // What else to do? The unicode set is huge...get the english + // ones right. + // } + // else + // { + // return isalpha( anyByte ); + // } } -/*static*/ int TiXmlBase::IsAlphaNum(unsigned char anyByte, - TiXmlEncoding /*encoding*/) { - // This will only work for low-ascii, everything else is assumed to be a valid - // letter. I'm not sure this is the best approach, but it is quite tricky - // trying to figure out alhabetical vs. not across encoding. So take a very - // conservative approach. - - // if ( encoding == TIXML_ENCODING_UTF8 ) - // { - if (anyByte < 127) - return isalnum(anyByte); - else - return 1; // What else to do? The unicode set is huge...get the english - // ones right. - // } - // else - // { - // return isalnum( anyByte ); - // } +/*static*/ int TiXmlBase::IsAlphaNum(unsigned char anyByte, TiXmlEncoding /*encoding*/) { + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky + // trying to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + + // if ( encoding == TIXML_ENCODING_UTF8 ) + // { + if (anyByte < 127) + return isalnum(anyByte); + else + return 1; // What else to do? The unicode set is huge...get the english + // ones right. + // } + // else + // { + // return isalnum( anyByte ); + // } } class TiXmlParsingData { - friend class TiXmlDocument; + friend class TiXmlDocument; - public: - void Stamp(const char* now, TiXmlEncoding encoding); + public: + void Stamp(const char* now, TiXmlEncoding encoding); - const TiXmlCursor& Cursor() const { return cursor; } + const TiXmlCursor& Cursor() const { return cursor; } - private: - // Only used by the document! - TiXmlParsingData(const char* start, int _tabsize, int row, int col) { - assert(start); - stamp = start; - tabsize = _tabsize; - cursor.row = row; - cursor.col = col; - } + private: + // Only used by the document! + TiXmlParsingData(const char* start, int _tabsize, int row, int col) { + assert(start); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } - TiXmlCursor cursor; - const char* stamp; - int tabsize; + TiXmlCursor cursor; + const char* stamp; + int tabsize; }; void TiXmlParsingData::Stamp(const char* now, TiXmlEncoding encoding) { - assert(now); - - // Do nothing if the tabsize is 0. - if (tabsize < 1) { - return; - } - - // Get the current row, column. - int row = cursor.row; - int col = cursor.col; - const char* p = stamp; - assert(p); - - while (p < now) { - // Treat p as unsigned, so we have a happy compiler. - const unsigned char* pU = (const unsigned char*)p; - - // Code contributed by Fletcher Dunn: (modified by lee) - switch (*pU) { - case 0: - // We *should* never get here, but in case we do, don't - // advance past the terminating null character, ever - return; - - case '\r': - // bump down to the next line - ++row; - col = 0; - // Eat the character - ++p; - - // Check for \r\n sequence, and treat this as a single character - if (*p == '\n') { - ++p; - } - break; - - case '\n': - // bump down to the next line - ++row; - col = 0; - - // Eat the character - ++p; - - // Check for \n\r sequence, and treat this as a single - // character. (Yes, this bizarre thing does occur still - // on some arcane platforms...) - if (*p == '\r') { - ++p; - } - break; - - case '\t': - // Eat the character - ++p; + assert(now); - // Skip to next tab stop - col = (col / tabsize + 1) * tabsize; - break; - - case TIXML_UTF_LEAD_0: - if (encoding == TIXML_ENCODING_UTF8) { - if (*(p + 1) && *(p + 2)) { - // In these cases, don't advance the column. These are - // 0-width spaces. - if (*(pU + 1) == TIXML_UTF_LEAD_1 && *(pU + 2) == TIXML_UTF_LEAD_2) - p += 3; - else if (*(pU + 1) == 0xbfU && *(pU + 2) == 0xbeU) - p += 3; - else if (*(pU + 1) == 0xbfU && *(pU + 2) == 0xbfU) - p += 3; - else { - p += 3; - ++col; - } // A normal character. - } - } else { - ++p; - ++col; - } - break; + // Do nothing if the tabsize is 0. + if (tabsize < 1) { + return; + } - default: - if (encoding == TIXML_ENCODING_UTF8) { - // Eat the 1 to 4 byte utf8 character. - int step = TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; - if (step == 0) - step = 1; // Error case from bad encoding, but handle gracefully. - p += step; - - // Just advance one column, of course. - ++col; - } else { - ++p; - ++col; + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const char* p = stamp; + assert(p); + + while (p < now) { + // Treat p as unsigned, so we have a happy compiler. + const unsigned char* pU = (const unsigned char*)p; + + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*pU) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + case TIXML_UTF_LEAD_0: + if (encoding == TIXML_ENCODING_UTF8) { + if (*(p + 1) && *(p + 2)) { + // In these cases, don't advance the column. These are + // 0-width spaces. + if (*(pU + 1) == TIXML_UTF_LEAD_1 && *(pU + 2) == TIXML_UTF_LEAD_2) + p += 3; + else if (*(pU + 1) == 0xbfU && *(pU + 2) == 0xbeU) + p += 3; + else if (*(pU + 1) == 0xbfU && *(pU + 2) == 0xbfU) + p += 3; + else { + p += 3; + ++col; + } // A normal character. + } + } else { + ++p; + ++col; + } + break; + + default: + if (encoding == TIXML_ENCODING_UTF8) { + // Eat the 1 to 4 byte utf8 character. + int step = TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; + if (step == 0) step = 1; // Error case from bad encoding, but handle gracefully. + p += step; + + // Just advance one column, of course. + ++col; + } else { + ++p; + ++col; + } + break; } - break; } - } - cursor.row = row; - cursor.col = col; - assert(cursor.row >= -1); - assert(cursor.col >= -1); - stamp = p; - assert(stamp); + cursor.row = row; + cursor.col = col; + assert(cursor.row >= -1); + assert(cursor.col >= -1); + stamp = p; + assert(stamp); } const char* TiXmlBase::SkipWhiteSpace(const char* p, TiXmlEncoding encoding) { - if (!p || !*p) { - return 0; - } - if (encoding == TIXML_ENCODING_UTF8) { - while (*p) { - const unsigned char* pU = (const unsigned char*)p; - - // Skip the stupid Microsoft UTF-8 Byte order marks - if (*(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) == TIXML_UTF_LEAD_1 && - *(pU + 2) == TIXML_UTF_LEAD_2) { - p += 3; - continue; - } else if (*(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) == 0xbfU && - *(pU + 2) == 0xbeU) { - p += 3; - continue; - } else if (*(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) == 0xbfU && - *(pU + 2) == 0xbfU) { - p += 3; - continue; - } - - if (IsWhiteSpace(*p)) // Still using old rules for white space. - ++p; - else - break; + if (!p || !*p) { + return 0; + } + if (encoding == TIXML_ENCODING_UTF8) { + while (*p) { + const unsigned char* pU = (const unsigned char*)p; + + // Skip the stupid Microsoft UTF-8 Byte order marks + if (*(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) == TIXML_UTF_LEAD_1 && + *(pU + 2) == TIXML_UTF_LEAD_2) { + p += 3; + continue; + } else if (*(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) == 0xbfU && *(pU + 2) == 0xbeU) { + p += 3; + continue; + } else if (*(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) == 0xbfU && *(pU + 2) == 0xbfU) { + p += 3; + continue; + } + + if (IsWhiteSpace(*p)) // Still using old rules for white space. + ++p; + else + break; + } + } else { + while (*p && IsWhiteSpace(*p)) ++p; } - } else { - while (*p && IsWhiteSpace(*p)) ++p; - } - return p; + return p; } #ifdef TIXML_USE_STL -/*static*/ bool TiXmlBase::StreamWhiteSpace(std::istream* in, - TIXML_STRING* tag) { - for (;;) { - if (!in->good()) return false; +/*static*/ bool TiXmlBase::StreamWhiteSpace(std::istream* in, TIXML_STRING* tag) { + for (;;) { + if (!in->good()) return false; - int c = in->peek(); - // At this scope, we can't get to a document. So fail silently. - if (!IsWhiteSpace(c) || c <= 0) return true; + int c = in->peek(); + // At this scope, we can't get to a document. So fail silently. + if (!IsWhiteSpace(c) || c <= 0) return true; - *tag += (char)in->get(); - } + *tag += (char)in->get(); + } } -/*static*/ bool TiXmlBase::StreamTo(std::istream* in, int character, - TIXML_STRING* tag) { - // assert( character > 0 && character < 128 ); // else it won't work in - // utf-8 - while (in->good()) { - int c = in->peek(); - if (c == character) return true; - if (c <= 0) // Silent failure: can't get document at this scope - return false; - - in->get(); - *tag += (char)c; - } - return false; +/*static*/ bool TiXmlBase::StreamTo(std::istream* in, int character, TIXML_STRING* tag) { + // assert( character > 0 && character < 128 ); // else it won't work in + // utf-8 + while (in->good()) { + int c = in->peek(); + if (c == character) return true; + if (c <= 0) // Silent failure: can't get document at this scope + return false; + + in->get(); + *tag += (char)c; + } + return false; } #endif @@ -385,1118 +357,1066 @@ const char* TiXmlBase::SkipWhiteSpace(const char* p, TiXmlEncoding encoding) { // overhead down. The "assign" optimization removes over 10% of the execution // time. // -const char* TiXmlBase::ReadName(const char* p, TIXML_STRING* name, - TiXmlEncoding encoding) { - // Oddly, not supported on some comilers, - // name->clear(); - // So use this: - *name = ""; - assert(p); - - // Names start with letters or underscores. - // Of course, in unicode, tinyxml has no idea what a letter *is*. The - // algorithm is generous. - // - // After that, they can be letters, underscores, numbers, - // hyphens, or colons. (Colons are valid ony for namespaces, - // but tinyxml can't tell namespaces from names.) - if (p && *p && (IsAlpha((unsigned char)*p, encoding) || *p == '_')) { - const char* start = p; - while (p && *p && - (IsAlphaNum((unsigned char)*p, encoding) || *p == '_' || *p == '-' || - *p == '.' || *p == ':')) { - //(*name) += *p; // expensive - ++p; - } - if (p - start > 0) { - name->assign(start, p - start); +const char* TiXmlBase::ReadName(const char* p, TIXML_STRING* name, TiXmlEncoding encoding) { + // Oddly, not supported on some comilers, + // name->clear(); + // So use this: + *name = ""; + assert(p); + + // Names start with letters or underscores. + // Of course, in unicode, tinyxml has no idea what a letter *is*. The + // algorithm is generous. + // + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if (p && *p && (IsAlpha((unsigned char)*p, encoding) || *p == '_')) { + const char* start = p; + while ( + p && *p && + (IsAlphaNum((unsigned char)*p, encoding) || *p == '_' || *p == '-' || *p == '.' || *p == ':')) { + //(*name) += *p; // expensive + ++p; + } + if (p - start > 0) { + name->assign(start, p - start); + } + return p; } - return p; - } - return 0; + return 0; } -const char* TiXmlBase::GetEntity(const char* p, char* value, int* length, - TiXmlEncoding encoding) { - // Presume an entity, and pull it out. - TIXML_STRING ent; - int i; - *length = 0; - - if (*(p + 1) && *(p + 1) == '#' && *(p + 2)) { - unsigned long ucs = 0; - ptrdiff_t delta = 0; - unsigned mult = 1; - - if (*(p + 2) == 'x') { - // Hexadecimal. - if (!*(p + 3)) return 0; - - const char* q = p + 3; - q = strchr(q, ';'); - - if (!q || !*q) return 0; - - delta = q - p; - --q; - - while (*q != 'x') { - if (*q >= '0' && *q <= '9') - ucs += mult * (*q - '0'); - else if (*q >= 'a' && *q <= 'f') - ucs += mult * (*q - 'a' + 10); - else if (*q >= 'A' && *q <= 'F') - ucs += mult * (*q - 'A' + 10); - else - return 0; - mult *= 16; - --q; - } - } else { - // Decimal. - if (!*(p + 2)) return 0; +const char* TiXmlBase::GetEntity(const char* p, char* value, int* length, TiXmlEncoding encoding) { + // Presume an entity, and pull it out. + TIXML_STRING ent; + int i; + *length = 0; + + if (*(p + 1) && *(p + 1) == '#' && *(p + 2)) { + unsigned long ucs = 0; + ptrdiff_t delta = 0; + unsigned mult = 1; + + if (*(p + 2) == 'x') { + // Hexadecimal. + if (!*(p + 3)) return 0; + + const char* q = p + 3; + q = strchr(q, ';'); + + if (!q || !*q) return 0; + + delta = q - p; + --q; + + while (*q != 'x') { + if (*q >= '0' && *q <= '9') + ucs += mult * (*q - '0'); + else if (*q >= 'a' && *q <= 'f') + ucs += mult * (*q - 'a' + 10); + else if (*q >= 'A' && *q <= 'F') + ucs += mult * (*q - 'A' + 10); + else + return 0; + mult *= 16; + --q; + } + } else { + // Decimal. + if (!*(p + 2)) return 0; - const char* q = p + 2; - q = strchr(q, ';'); + const char* q = p + 2; + q = strchr(q, ';'); - if (!q || !*q) return 0; + if (!q || !*q) return 0; - delta = q - p; - --q; + delta = q - p; + --q; - while (*q != '#') { - if (*q >= '0' && *q <= '9') - ucs += mult * (*q - '0'); - else - return 0; - mult *= 10; - --q; - } - } - if (encoding == TIXML_ENCODING_UTF8) { - // convert the UCS to UTF-8 - ConvertUTF32ToUTF8(ucs, value, length); - } else { - *value = (char)ucs; - *length = 1; + while (*q != '#') { + if (*q >= '0' && *q <= '9') + ucs += mult * (*q - '0'); + else + return 0; + mult *= 10; + --q; + } + } + if (encoding == TIXML_ENCODING_UTF8) { + // convert the UCS to UTF-8 + ConvertUTF32ToUTF8(ucs, value, length); + } else { + *value = (char)ucs; + *length = 1; + } + return p + delta + 1; } - return p + delta + 1; - } - - // Now try to match it. - for (i = 0; i < NUM_ENTITY; ++i) { - if (strncmp(entity[i].str, p, entity[i].strLength) == 0) { - assert(strlen(entity[i].str) == entity[i].strLength); - *value = entity[i].chr; - *length = 1; - return (p + entity[i].strLength); + + // Now try to match it. + for (i = 0; i < NUM_ENTITY; ++i) { + if (strncmp(entity[i].str, p, entity[i].strLength) == 0) { + assert(strlen(entity[i].str) == entity[i].strLength); + *value = entity[i].chr; + *length = 1; + return (p + entity[i].strLength); + } } - } - - // So it wasn't an entity, its unrecognized, or something like that. - *value = *p; // Don't put back the last one, since we return it! - //*length = 1; // Leave unrecognized entities - this doesn't really - // work. - // Just writes strange XML. - return p + 1; + + // So it wasn't an entity, its unrecognized, or something like that. + *value = *p; // Don't put back the last one, since we return it! + //*length = 1; // Leave unrecognized entities - this doesn't really + // work. + // Just writes strange XML. + return p + 1; } -bool TiXmlBase::StringEqual(const char* p, const char* tag, bool ignoreCase, - TiXmlEncoding encoding) { - assert(p); - assert(tag); - if (!p || !*p) { - assert(0); - return false; - } +bool TiXmlBase::StringEqual(const char* p, const char* tag, bool ignoreCase, TiXmlEncoding encoding) { + assert(p); + assert(tag); + if (!p || !*p) { + assert(0); + return false; + } - const char* q = p; + const char* q = p; - if (ignoreCase) { - while (*q && *tag && ToLower(*q, encoding) == ToLower(*tag, encoding)) { - ++q; - ++tag; - } + if (ignoreCase) { + while (*q && *tag && ToLower(*q, encoding) == ToLower(*tag, encoding)) { + ++q; + ++tag; + } - if (*tag == 0) return true; - } else { - while (*q && *tag && *q == *tag) { - ++q; - ++tag; - } + if (*tag == 0) return true; + } else { + while (*q && *tag && *q == *tag) { + ++q; + ++tag; + } - if (*tag == 0) // Have we found the end of the tag, and everything equal? - return true; - } - return false; + if (*tag == 0) // Have we found the end of the tag, and everything equal? + return true; + } + return false; } -const char* TiXmlBase::ReadText(const char* p, TIXML_STRING* text, - bool trimWhiteSpace, const char* endTag, +const char* TiXmlBase::ReadText(const char* p, TIXML_STRING* text, bool trimWhiteSpace, const char* endTag, bool caseInsensitive, TiXmlEncoding encoding) { - *text = ""; - if (!trimWhiteSpace // certain tags always keep whitespace - || !condenseWhiteSpace) // if true, whitespace is always kept - { - // Keep all the white space. - while (p && *p && !StringEqual(p, endTag, caseInsensitive, encoding)) { - int len; - char cArr[4] = {0, 0, 0, 0}; - p = GetChar(p, cArr, &len, encoding); - text->append(cArr, len); - } - } else { - bool whitespace = false; + *text = ""; + if (!trimWhiteSpace // certain tags always keep whitespace + || !condenseWhiteSpace) // if true, whitespace is always kept + { + // Keep all the white space. + while (p && *p && !StringEqual(p, endTag, caseInsensitive, encoding)) { + int len; + char cArr[4] = {0, 0, 0, 0}; + p = GetChar(p, cArr, &len, encoding); + text->append(cArr, len); + } + } else { + bool whitespace = false; - // Remove leading white space: - p = SkipWhiteSpace(p, encoding); - while (p && *p && !StringEqual(p, endTag, caseInsensitive, encoding)) { - if (*p == '\r' || *p == '\n') { - whitespace = true; - ++p; - } else if (IsWhiteSpace(*p)) { - whitespace = true; - ++p; - } else { - // If we've found whitespace, add it before the - // new character. Any whitespace just becomes a space. - if (whitespace) { - (*text) += ' '; - whitespace = false; + // Remove leading white space: + p = SkipWhiteSpace(p, encoding); + while (p && *p && !StringEqual(p, endTag, caseInsensitive, encoding)) { + if (*p == '\r' || *p == '\n') { + whitespace = true; + ++p; + } else if (IsWhiteSpace(*p)) { + whitespace = true; + ++p; + } else { + // If we've found whitespace, add it before the + // new character. Any whitespace just becomes a space. + if (whitespace) { + (*text) += ' '; + whitespace = false; + } + int len; + char cArr[4] = {0, 0, 0, 0}; + p = GetChar(p, cArr, &len, encoding); + if (len == 1) + (*text) += cArr[0]; // more efficient + else + text->append(cArr, len); + } } - int len; - char cArr[4] = {0, 0, 0, 0}; - p = GetChar(p, cArr, &len, encoding); - if (len == 1) - (*text) += cArr[0]; // more efficient - else - text->append(cArr, len); - } } - } - if (p && *p) p += strlen(endTag); - return (p && *p) ? p : 0; + if (p && *p) p += strlen(endTag); + return (p && *p) ? p : 0; } #ifdef TIXML_USE_STL void TiXmlDocument::StreamIn(std::istream* in, TIXML_STRING* tag) { - // The basic issue with a document is that we don't know what we're - // streaming. Read something presumed to be a tag (and hope), then - // identify it, and call the appropriate stream method on the tag. - // - // This "pre-streaming" will never read the closing ">" so the - // sub-tag can orient itself. - - if (!StreamTo(in, '<', tag)) { - SetError(TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); - return; - } - - while (in->good()) { - int tagIndex = (int)tag->length(); - while (in->good() && in->peek() != '>') { - int c = in->get(); - if (c <= 0) { - SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN); - break; - } - (*tag) += (char)c; + // The basic issue with a document is that we don't know what we're + // streaming. Read something presumed to be a tag (and hope), then + // identify it, and call the appropriate stream method on the tag. + // + // This "pre-streaming" will never read the closing ">" so the + // sub-tag can orient itself. + + if (!StreamTo(in, '<', tag)) { + SetError(TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); + return; } - if (in->good()) { - // We now have something we presume to be a node of - // some sort. Identify it, and call the node to - // continue streaming. - TiXmlNode* node = - Identify(tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING); - - if (node) { - node->StreamIn(in, tag); - bool isElement = node->ToElement() != 0; - delete node; - node = 0; - - // If this is the root element, we're done. Parsing will be - // done by the >> operator. - if (isElement) { - return; + while (in->good()) { + int tagIndex = (int)tag->length(); + while (in->good() && in->peek() != '>') { + int c = in->get(); + if (c <= 0) { + SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN); + break; + } + (*tag) += (char)c; + } + + if (in->good()) { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + TiXmlNode* node = Identify(tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING); + + if (node) { + node->StreamIn(in, tag); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if (isElement) { + return; + } + } else { + SetError(TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN); + return; + } } - } else { - SetError(TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN); - return; - } } - } - // We should have returned sooner. - SetError(TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN); + // We should have returned sooner. + SetError(TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN); } #endif -const char* TiXmlDocument::Parse(const char* p, TiXmlParsingData* prevData, - TiXmlEncoding encoding) { - ClearError(); +const char* TiXmlDocument::Parse(const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding) { + ClearError(); - // Parse away, at the document level. Since a document - // contains nothing but other tags, most of what happens - // here is skipping white space. - if (!p || !*p) { - SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); - return 0; - } - - // Note that, for a document, this needs to come - // before the while space skip, so that parsing - // starts from the pointer we are given. - location.Clear(); - if (prevData) { - location.row = prevData->cursor.row; - location.col = prevData->cursor.col; - } else { - location.row = 0; - location.col = 0; - } - TiXmlParsingData data(p, TabSize(), location.row, location.col); - location = data.Cursor(); - - if (encoding == TIXML_ENCODING_UNKNOWN) { - // Check for the Microsoft UTF-8 lead bytes. - const unsigned char* pU = (const unsigned char*)p; - if (*(pU + 0) && *(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) && - *(pU + 1) == TIXML_UTF_LEAD_1 && *(pU + 2) && - *(pU + 2) == TIXML_UTF_LEAD_2) { - encoding = TIXML_ENCODING_UTF8; - useMicrosoftBOM = true; - } - } - - p = SkipWhiteSpace(p, encoding); - if (!p) { - SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); - return 0; - } - - while (p && *p) { - TiXmlNode* node = Identify(p, encoding); - if (node) { - if (lastChild && lastChild->ToElement() && node->ToElement()) { - node->Parse(p, &data, encoding); - SetError(TIXML_ERROR_MULTI_ROOTSECTION, p, &data, encoding); + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if (!p || !*p) { + SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); return 0; - } + } - p = node->Parse(p, &data, encoding); - LinkEndChild(node); + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if (prevData) { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; } else { - break; + location.row = 0; + location.col = 0; } - - // Did we get encoding info? - if (encoding == TIXML_ENCODING_UNKNOWN && node->ToDeclaration()) { - TiXmlDeclaration* dec = node->ToDeclaration(); - const char* enc = dec->Encoding(); - assert(enc); - - if (*enc == 0) - encoding = TIXML_ENCODING_UTF8; - else if (StringEqual(enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN)) - encoding = TIXML_ENCODING_UTF8; - else if (StringEqual(enc, "UTF8", true, TIXML_ENCODING_UNKNOWN)) - encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice - else - encoding = TIXML_ENCODING_LEGACY; + TiXmlParsingData data(p, TabSize(), location.row, location.col); + location = data.Cursor(); + + if (encoding == TIXML_ENCODING_UNKNOWN) { + // Check for the Microsoft UTF-8 lead bytes. + const unsigned char* pU = (const unsigned char*)p; + if (*(pU + 0) && *(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) && *(pU + 1) == TIXML_UTF_LEAD_1 && + *(pU + 2) && *(pU + 2) == TIXML_UTF_LEAD_2) { + encoding = TIXML_ENCODING_UTF8; + useMicrosoftBOM = true; + } } p = SkipWhiteSpace(p, encoding); - } + if (!p) { + SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); + return 0; + } - // Was this empty? - if (!firstChild) { - SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding); - return 0; - } + while (p && *p) { + TiXmlNode* node = Identify(p, encoding); + if (node) { + if (lastChild && lastChild->ToElement() && node->ToElement()) { + node->Parse(p, &data, encoding); + SetError(TIXML_ERROR_MULTI_ROOTSECTION, p, &data, encoding); + return 0; + } + + p = node->Parse(p, &data, encoding); + LinkEndChild(node); + } else { + break; + } - // All is well. - return p; -} + // Did we get encoding info? + if (encoding == TIXML_ENCODING_UNKNOWN && node->ToDeclaration()) { + TiXmlDeclaration* dec = node->ToDeclaration(); + const char* enc = dec->Encoding(); + assert(enc); + + if (*enc == 0) + encoding = TIXML_ENCODING_UTF8; + else if (StringEqual(enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN)) + encoding = TIXML_ENCODING_UTF8; + else if (StringEqual(enc, "UTF8", true, TIXML_ENCODING_UNKNOWN)) + encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice + else + encoding = TIXML_ENCODING_LEGACY; + } -inline TIXML_STRING NotifyPosition(const char* p, TiXmlCursor c) { - char _message[30]; - sprintf(_message, "row %i, column %i", c.row + 1, c.col + 1); - TIXML_STRING message = TIXML_STRING(_message); - TIXML_STRING line; - TIXML_STRING pointer; - - int length = 40; - int n = 0; - int m = 0; - if (p) { - const char* pp = p; - while (*pp != 0 && *pp != '\n') { - --pp; - ++n; - } - ++pp; - --n; - if (n == -1) { - return message; - } - message += ":"; - line += TIXML_STRING(pp, n <= length ? n : length - 5); - if (n > length) { - line += " ... "; + p = SkipWhiteSpace(p, encoding); } - pointer = line; - for (int i = 0; i < pointer.size(); i++) { - if (iswprint(pointer[i])) pointer[i] = ' '; + // Was this empty? + if (!firstChild) { + SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding); + return 0; } - pointer += '^'; - pp = p; - while (*pp != 0 && *pp != '\n' && m <= length) { - ++pp; - ++m; - } - line += TIXML_STRING(p, m <= length ? m : length - 5); - if (m > length) { - line += "..."; + // All is well. + return p; +} + +inline TIXML_STRING NotifyPosition(const char* p, TiXmlCursor c) { + char _message[40]; + sprintf(_message, "row %i, column %i", c.row + 1, c.col + 1); + TIXML_STRING message = TIXML_STRING(_message); + TIXML_STRING line; + TIXML_STRING pointer; + + int length = 40; + int n = 0; + int m = 0; + if (p) { + const char* pp = p; + while (*pp != 0 && *pp != '\n') { + --pp; + ++n; + } + ++pp; + --n; + if (n == -1) { + return message; + } + message += ":"; + line += TIXML_STRING(pp, n <= length ? n : length - 5); + if (n > length) { + line += " ... "; + } + + pointer = line; + for (unsigned int i = 0; i < pointer.size(); i++) { + if (iswprint(pointer[i])) pointer[i] = ' '; + } + pointer += '^'; + + pp = p; + while (*pp != 0 && *pp != '\n' && m <= length) { + ++pp; + ++m; + } + line += TIXML_STRING(p, m <= length ? m : length - 5); + if (m > length) { + line += "..."; + } } - } - return message + '\n' + line + '\n' + pointer; + return message + '\n' + line + '\n' + pointer; } -void TiXmlDocument::SetError(int err, const char* pError, - TiXmlParsingData* data, TiXmlEncoding encoding) { - // The first error in a chain is more accurate - don't set again! - if (error) return; - - assert(err > 0 && err < TIXML_ERROR_STRING_COUNT); - error = true; - errorId = err; - errorDesc = errorString[errorId]; - - errorLocation.Clear(); - if (pError && data) { - data->Stamp(pError, encoding); - errorLocation = data->Cursor(); - errorDesc += "\nIn " + TIXML_STRING(this->value) + ": "; - errorDesc += NotifyPosition(pError, errorLocation); - } +void TiXmlDocument::SetError(int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding) { + // The first error in a chain is more accurate - don't set again! + if (error) return; + + assert(err > 0 && err < TIXML_ERROR_STRING_COUNT); + error = true; + errorId = err; + errorDesc = errorString[errorId]; + + errorLocation.Clear(); + if (pError && data) { + data->Stamp(pError, encoding); + errorLocation = data->Cursor(); + errorDesc += "\nIn " + TIXML_STRING(this->value) + ": "; + errorDesc += NotifyPosition(pError, errorLocation); + } } TiXmlNode* TiXmlNode::Identify(const char* p, TiXmlEncoding encoding) { - TiXmlNode* returnNode = 0; + TiXmlNode* returnNode = 0; - p = SkipWhiteSpace(p, encoding); - if (!p || !*p || *p != '<') { - return 0; - } + p = SkipWhiteSpace(p, encoding); + if (!p || !*p || *p != '<') { + return 0; + } - p = SkipWhiteSpace(p, encoding); + p = SkipWhiteSpace(p, encoding); - if (!p || !*p) { - return 0; - } + if (!p || !*p) { + return 0; + } - // What is this thing? - // - Elements start with a letter or underscore, but xml is reserved. - // - Comments: "; + if (data) { + data->Stamp(p, encoding); + location = data->Cursor(); + } + const char* startTag = ""; - if (!StringEqual(p, startTag, false, encoding)) { - if (document) - document->SetError(TIXML_ERROR_PARSING_COMMENT, p, data, encoding); - return 0; - } - p += strlen(startTag); - - // [ 1475201 ] TinyXML parses entities in comments - // Oops - ReadText doesn't work, because we don't want to parse the entities. - // p = ReadText( p, &value, false, endTag, false, encoding ); - // - // from the XML spec: - /* - [Definition: Comments may appear anywhere in a document outside other markup; - in addition, they may appear within the document type declaration at places - allowed by the grammar. They are not part of the document's character data; - an XML processor MAY, but need not, make it possible for an application to - retrieve the text of comments. For compatibility, the string "--" - (double-hyphen) MUST NOT occur within comments.] Parameter entity references - MUST NOT be recognized within comments. - - An example of a comment: - - - */ - - value = ""; - // Keep all the white space. - while (p && *p && !StringEqual(p, endTag, false, encoding)) { - value.append(p, 1); - ++p; - } - if (p && *p) p += strlen(endTag); + if (!StringEqual(p, startTag, false, encoding)) { + if (document) document->SetError(TIXML_ERROR_PARSING_COMMENT, p, data, encoding); + return 0; + } + p += strlen(startTag); - return p; -} + // [ 1475201 ] TinyXML parses entities in comments + // Oops - ReadText doesn't work, because we don't want to parse the entities. + // p = ReadText( p, &value, false, endTag, false, encoding ); + // + // from the XML spec: + /* + [Definition: Comments may appear anywhere in a document outside other markup; + in addition, they may appear within the document type declaration at places + allowed by the grammar. They are not part of the document's character data; + an XML processor MAY, but need not, make it possible for an application to + retrieve the text of comments. For compatibility, the string "--" + (double-hyphen) MUST NOT occur within comments.] Parameter entity references + MUST NOT be recognized within comments. + + An example of a comment: + + + */ -const char* TiXmlAttribute::Parse(const char* p, TiXmlParsingData* data, - TiXmlEncoding encoding) { - p = SkipWhiteSpace(p, encoding); - if (!p || !*p) return 0; - - if (data) { - data->Stamp(p, encoding); - location = data->Cursor(); - } - // Read the name, the '=' and the value. - const char* pErr = p; - p = ReadName(p, &name, encoding); - if (!p || !*p) { - if (document) - document->SetError(TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding); - return 0; - } - p = SkipWhiteSpace(p, encoding); - if (!p || !*p || *p != '=') { - if (document) - document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding); - return 0; - } + value = ""; + // Keep all the white space. + while (p && *p && !StringEqual(p, endTag, false, encoding)) { + value.append(p, 1); + ++p; + } + if (p && *p) p += strlen(endTag); - ++p; // skip '=' - p = SkipWhiteSpace(p, encoding); - if (!p || !*p) { - if (document) - document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding); - return 0; - } + return p; +} - const char* end; - const char SINGLE_QUOTE = '\''; - const char DOUBLE_QUOTE = '\"'; +const char* TiXmlAttribute::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) { + p = SkipWhiteSpace(p, encoding); + if (!p || !*p) return 0; - if (*p == SINGLE_QUOTE) { - ++p; - end = "\'"; // single quote in string - p = ReadText(p, &value, false, end, false, encoding); - } else if (*p == DOUBLE_QUOTE) { - ++p; - end = "\""; // double quote in string - p = ReadText(p, &value, false, end, false, encoding); - } else { - // All attribute values should be in single or double quotes. - // But this is such a common error that the parser will try - // its best, even without them. - value = ""; - while (p && *p // existence - && !IsWhiteSpace(*p) // whitespace - && *p != '/' && *p != '>') // tag end - { - if (*p == SINGLE_QUOTE || *p == DOUBLE_QUOTE) { - // [ 1451649 ] Attribute values with trailing quotes not handled - // correctly We did not have an opening quote but seem to have a closing - // one. Give up and throw an error. - if (document) - document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding); + if (data) { + data->Stamp(p, encoding); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const char* pErr = p; + p = ReadName(p, &name, encoding); + if (!p || !*p) { + if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding); + return 0; + } + p = SkipWhiteSpace(p, encoding); + if (!p || !*p || *p != '=') { + if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace(p, encoding); + if (!p || !*p) { + if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding); return 0; - } - value += *p; - ++p; } - } - return p; + + const char* end; + const char SINGLE_QUOTE = '\''; + const char DOUBLE_QUOTE = '\"'; + + if (*p == SINGLE_QUOTE) { + ++p; + end = "\'"; // single quote in string + p = ReadText(p, &value, false, end, false, encoding); + } else if (*p == DOUBLE_QUOTE) { + ++p; + end = "\""; // double quote in string + p = ReadText(p, &value, false, end, false, encoding); + } else { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = ""; + while (p && *p // existence + && !IsWhiteSpace(*p) // whitespace + && *p != '/' && *p != '>') // tag end + { + if (*p == SINGLE_QUOTE || *p == DOUBLE_QUOTE) { + // [ 1451649 ] Attribute values with trailing quotes not handled + // correctly We did not have an opening quote but seem to have a closing + // one. Give up and throw an error. + if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding); + return 0; + } + value += *p; + ++p; + } + } + return p; } #ifdef TIXML_USE_STL void TiXmlText::StreamIn(std::istream* in, TIXML_STRING* tag) { - while (in->good()) { - int c = in->peek(); - if (!cdata && (c == '<')) { - return; - } - if (c <= 0) { - TiXmlDocument* document = GetDocument(); - if (document) - document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, - TIXML_ENCODING_UNKNOWN); - return; - } + while (in->good()) { + int c = in->peek(); + if (!cdata && (c == '<')) { + return; + } + if (c <= 0) { + TiXmlDocument* document = GetDocument(); + if (document) document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN); + return; + } - (*tag) += (char)c; - in->get(); // "commits" the peek made above + (*tag) += (char)c; + in->get(); // "commits" the peek made above - if (cdata && c == '>' && tag->size() >= 3) { - size_t len = tag->size(); - if ((*tag)[len - 2] == ']' && (*tag)[len - 3] == ']') { - // terminator of cdata. - return; - } + if (cdata && c == '>' && tag->size() >= 3) { + size_t len = tag->size(); + if ((*tag)[len - 2] == ']' && (*tag)[len - 3] == ']') { + // terminator of cdata. + return; + } + } } - } } #endif -const char* TiXmlText::Parse(const char* p, TiXmlParsingData* data, - TiXmlEncoding encoding) { - value = ""; - TiXmlDocument* document = GetDocument(); +const char* TiXmlText::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding) { + value = ""; + TiXmlDocument* document = GetDocument(); - if (data) { - data->Stamp(p, encoding); - location = data->Cursor(); - } + if (data) { + data->Stamp(p, encoding); + location = data->Cursor(); + } - const char* const startTag = ""; + const char* const startTag = ""; - if (cdata || StringEqual(p, startTag, false, encoding)) { - cdata = true; + if (cdata || StringEqual(p, startTag, false, encoding)) { + cdata = true; - if (!StringEqual(p, startTag, false, encoding)) { - if (document) - document->SetError(TIXML_ERROR_PARSING_CDATA, p, data, encoding); - return 0; - } - p += strlen(startTag); + if (!StringEqual(p, startTag, false, encoding)) { + if (document) document->SetError(TIXML_ERROR_PARSING_CDATA, p, data, encoding); + return 0; + } + p += strlen(startTag); - // Keep all the white space, ignore the encoding, etc. - while (p && *p && !StringEqual(p, endTag, false, encoding)) { - value += *p; - ++p; - } + // Keep all the white space, ignore the encoding, etc. + while (p && *p && !StringEqual(p, endTag, false, encoding)) { + value += *p; + ++p; + } - TIXML_STRING dummy; - p = ReadText(p, &dummy, false, endTag, false, encoding); - return p; - } else { - bool ignoreWhite = true; + TIXML_STRING dummy; + p = ReadText(p, &dummy, false, endTag, false, encoding); + return p; + } else { + bool ignoreWhite = true; - const char* end = "<"; - p = ReadText(p, &value, ignoreWhite, end, false, encoding); - if (p && *p) return p - 1; // don't truncate the '<' - return 0; - } + const char* end = "<"; + p = ReadText(p, &value, ignoreWhite, end, false, encoding); + if (p && *p) return p - 1; // don't truncate the '<' + return 0; + } } #ifdef TIXML_USE_STL void TiXmlDeclaration::StreamIn(std::istream* in, TIXML_STRING* tag) { - while (in->good()) { - int c = in->get(); - if (c <= 0) { - TiXmlDocument* document = GetDocument(); - if (document) - document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, - TIXML_ENCODING_UNKNOWN); - return; - } - (*tag) += (char)c; + while (in->good()) { + int c = in->get(); + if (c <= 0) { + TiXmlDocument* document = GetDocument(); + if (document) document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN); + return; + } + (*tag) += (char)c; - if (c == '>') { - // All is well. - return; + if (c == '>') { + // All is well. + return; + } } - } } #endif -const char* TiXmlDeclaration::Parse(const char* p, TiXmlParsingData* data, - TiXmlEncoding _encoding) { - p = SkipWhiteSpace(p, _encoding); - // Find the beginning, find the end, and look for - // the stuff in-between. - TiXmlDocument* document = GetDocument(); - if (!p || !*p || !StringEqual(p, "SetError(TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding); - return 0; - } - if (data) { - data->Stamp(p, _encoding); - location = data->Cursor(); - } - p += 5; - - version = ""; - encoding = ""; - standalone = ""; - - while (p && *p) { - if (*p == '>') { - ++p; - return p; +const char* TiXmlDeclaration::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding) { + p = SkipWhiteSpace(p, _encoding); + // Find the beginning, find the end, and look for + // the stuff in-between. + TiXmlDocument* document = GetDocument(); + if (!p || !*p || !StringEqual(p, "SetError(TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding); + return 0; } + if (data) { + data->Stamp(p, _encoding); + location = data->Cursor(); + } + p += 5; - p = SkipWhiteSpace(p, _encoding); - if (StringEqual(p, "version", true, _encoding)) { - TiXmlAttribute attrib; - p = attrib.Parse(p, data, _encoding); - version = attrib.Value(); - } else if (StringEqual(p, "encoding", true, _encoding)) { - TiXmlAttribute attrib; - p = attrib.Parse(p, data, _encoding); - encoding = attrib.Value(); - } else if (StringEqual(p, "standalone", true, _encoding)) { - TiXmlAttribute attrib; - p = attrib.Parse(p, data, _encoding); - standalone = attrib.Value(); - } else { - // Read over whatever it is. - while (p && *p && *p != '>' && !IsWhiteSpace(*p)) ++p; + version = ""; + encoding = ""; + standalone = ""; + + while (p && *p) { + if (*p == '>') { + ++p; + return p; + } + + p = SkipWhiteSpace(p, _encoding); + if (StringEqual(p, "version", true, _encoding)) { + TiXmlAttribute attrib; + p = attrib.Parse(p, data, _encoding); + version = attrib.Value(); + } else if (StringEqual(p, "encoding", true, _encoding)) { + TiXmlAttribute attrib; + p = attrib.Parse(p, data, _encoding); + encoding = attrib.Value(); + } else if (StringEqual(p, "standalone", true, _encoding)) { + TiXmlAttribute attrib; + p = attrib.Parse(p, data, _encoding); + standalone = attrib.Value(); + } else { + // Read over whatever it is. + while (p && *p && *p != '>' && !IsWhiteSpace(*p)) ++p; + } } - } - return 0; + return 0; } bool TiXmlText::Blank() const { - for (unsigned i = 0; i < value.length(); i++) - if (!IsWhiteSpace(value[i])) return false; - return true; + for (unsigned i = 0; i < value.length(); i++) + if (!IsWhiteSpace(value[i])) return false; + return true; } diff --git a/source/framework/masks/inc/TRestCombinedMask.h b/source/framework/masks/inc/TRestCombinedMask.h index 54ac9084d..2b906b88e 100644 --- a/source/framework/masks/inc/TRestCombinedMask.h +++ b/source/framework/masks/inc/TRestCombinedMask.h @@ -35,7 +35,7 @@ class TRestCombinedMask : public TRestPatternMask { void AddMask(TRestPatternMask* mask) { fMasks.push_back(mask); } - TRestPatternMask* const& GetMask(int index) const { + TRestPatternMask* const& GetMask(unsigned int index) const { if (index < fMasks.size()) { return fMasks[index]; } diff --git a/source/framework/masks/inc/TRestRingsMask.h b/source/framework/masks/inc/TRestRingsMask.h index 0c022bbd5..bc21527a9 100644 --- a/source/framework/masks/inc/TRestRingsMask.h +++ b/source/framework/masks/inc/TRestRingsMask.h @@ -69,7 +69,7 @@ class TRestRingsMask : public TRestPatternMask { return; } - for (int n = 0; n < innerR.size(); n++) { + for (unsigned int n = 0; n < innerR.size(); n++) { std::pair p(innerR[n], outterR[n]); fRingsRadii.push_back(p); } diff --git a/source/framework/masks/src/TRestPatternMask.cxx b/source/framework/masks/src/TRestPatternMask.cxx index c834fd19f..bac331286 100644 --- a/source/framework/masks/src/TRestPatternMask.cxx +++ b/source/framework/masks/src/TRestPatternMask.cxx @@ -204,7 +204,7 @@ TCanvas* TRestPatternMask::DrawMonteCarlo(Int_t nSamples) { TGraph* gr = new TGraph(); gr->SetName(grname.c_str()); - for (int n = 0; n < x.second.size(); n++) { + for (unsigned int n = 0; n < x.second.size(); n++) { gr->SetPoint(gr->GetN(), x.second[n].X(), x.second[n].Y()); } diff --git a/source/framework/masks/src/TRestRingsMask.cxx b/source/framework/masks/src/TRestRingsMask.cxx index 7e3899690..66513d8d3 100644 --- a/source/framework/masks/src/TRestRingsMask.cxx +++ b/source/framework/masks/src/TRestRingsMask.cxx @@ -224,7 +224,7 @@ void TRestRingsMask::PrintMaskMembers() { if (fRingsRadii.size() > 0) { if (fNRings > 0) RESTMetadata << "-----" << RESTendl; RESTMetadata << "Inner radii : ("; - for (int n = 0; n < fRingsRadii.size(); n++) { + for (unsigned int n = 0; n < fRingsRadii.size(); n++) { if (n > 0) RESTMetadata << ", "; RESTMetadata << fRingsRadii[n].first; } @@ -232,7 +232,7 @@ void TRestRingsMask::PrintMaskMembers() { } if (fRingsRadii.size() > 0) { RESTMetadata << "Outter radii : ("; - for (int n = 0; n < fRingsRadii.size(); n++) { + for (unsigned int n = 0; n < fRingsRadii.size(); n++) { if (n > 0) RESTMetadata << ", "; RESTMetadata << fRingsRadii[n].second; } @@ -245,6 +245,6 @@ void TRestRingsMask::PrintMaskMembers() { /// excluding common metadata headers. /// void TRestRingsMask::PrintRings() { - for (int n = 0; n < fRingsRadii.size(); n++) + for (unsigned int n = 0; n < fRingsRadii.size(); n++) std::cout << n << " - " << fRingsRadii[n].first << " - " << fRingsRadii[n].second << std::endl; } diff --git a/source/framework/masks/src/TRestSpiderMask.cxx b/source/framework/masks/src/TRestSpiderMask.cxx index e735d18b6..1c9721880 100644 --- a/source/framework/masks/src/TRestSpiderMask.cxx +++ b/source/framework/masks/src/TRestSpiderMask.cxx @@ -246,38 +246,38 @@ void TRestSpiderMask::GenerateSpider() { RESTDebug << "Printing positive spider angles" << RESTendl; RESTDebug << "-------------------------------" << RESTendl; - for (int n = 0; n < fPositiveRanges.size(); n++) { + for (unsigned int n = 0; n < fPositiveRanges.size(); n++) { RESTDebug << "n : " << n << " from : " << 180 * fPositiveRanges[n].first / TMath::Pi() << " to " << 180 * fPositiveRanges[n].second / TMath::Pi() << RESTendl; } RESTDebug << "Printing negative spider angles" << RESTendl; RESTDebug << "-------------------------------" << RESTendl; - for (int n = 0; n < fNegativeRanges.size(); n++) { + for (unsigned int n = 0; n < fNegativeRanges.size(); n++) { RESTDebug << "n : " << n << " from : " << 180 * fNegativeRanges[n].first / TMath::Pi() << " to " << 180 * fNegativeRanges[n].second / TMath::Pi() << RESTendl; } - for (int n = 0; n < fNegativeRanges.size(); n++) { + for (unsigned int n = 0; n < fNegativeRanges.size(); n++) { fNegativeRanges[n].first = TMath::Cos(fNegativeRanges[n].first); fNegativeRanges[n].second = TMath::Cos(fNegativeRanges[n].second); } - for (int n = 0; n < fPositiveRanges.size(); n++) { + for (unsigned int n = 0; n < fPositiveRanges.size(); n++) { fPositiveRanges[n].first = TMath::Cos(fPositiveRanges[n].first); fPositiveRanges[n].second = TMath::Cos(fPositiveRanges[n].second); } RESTDebug << "Printing positive spider angles" << RESTendl; RESTDebug << "-------------------------------" << RESTendl; - for (int n = 0; n < fPositiveRanges.size(); n++) { + for (unsigned int n = 0; n < fPositiveRanges.size(); n++) { RESTDebug << "n : " << n << " from : " << fPositiveRanges[n].first << " to " << fPositiveRanges[n].second << RESTendl; } RESTDebug << "Printing negative spider cosines" << RESTendl; RESTDebug << "--------------------------------" << RESTendl; - for (int n = 0; n < fNegativeRanges.size(); n++) { + for (unsigned int n = 0; n < fNegativeRanges.size(); n++) { RESTDebug << "n : " << n << " from : " << fNegativeRanges[n].first << " to " << fNegativeRanges[n].second << RESTendl; } @@ -317,20 +317,20 @@ void TRestSpiderMask::PrintMaskMembers() { if (fPositiveRanges.size() > 0) { RESTMetadata << "-------------------------------" << RESTendl; - for (int n = 0; n < fPositiveRanges.size(); n++) { + for (unsigned int n = 0; n < fPositiveRanges.size(); n++) { RESTDebug << "n : " << n << " from : " << 180 * fPositiveRanges[n].first / TMath::Pi() << " to " << 180 * fPositiveRanges[n].second / TMath::Pi() << RESTendl; } RESTMetadata << "Positive ranges : {"; - for (int n = 0; n < fPositiveRanges.size(); n++) { + for (unsigned int n = 0; n < fPositiveRanges.size(); n++) { if (n > 0) RESTMetadata << ", "; RESTMetadata << "(" << fPositiveRanges[n].first << ", " << fPositiveRanges[n].second << ")"; } RESTMetadata << "}" << RESTendl; RESTMetadata << "Negative ranges : {"; - for (int n = 0; n < fNegativeRanges.size(); n++) { + for (unsigned int n = 0; n < fNegativeRanges.size(); n++) { if (n > 0) RESTMetadata << ", "; RESTMetadata << "(" << fNegativeRanges[n].first << ", " << fNegativeRanges[n].second << ")"; } diff --git a/source/framework/tools/inc/TRestStringHelper.h b/source/framework/tools/inc/TRestStringHelper.h index 655cc72c6..c49b97225 100644 --- a/source/framework/tools/inc/TRestStringHelper.h +++ b/source/framework/tools/inc/TRestStringHelper.h @@ -67,7 +67,7 @@ std::string ToString(T source, int length = -1, char fill = ' ') { std::string s = ss1.str(); if (length < 0) { return s; - } else if (s.size() < length) { + } else if (s.size() < (unsigned int)length) { return s + std::string(length - s.size(), fill); } else { return s.substr(0, length); diff --git a/source/framework/tools/inc/TRestTools.h b/source/framework/tools/inc/TRestTools.h index 78fe8b04e..6b7a16c89 100644 --- a/source/framework/tools/inc/TRestTools.h +++ b/source/framework/tools/inc/TRestTools.h @@ -93,7 +93,7 @@ class TRestTools { static T GetIntegralFromTable(const std::vector>& data); template - static std::vector GetColumnFromTable(const std::vector>& data, int column); + static std::vector GetColumnFromTable(const std::vector>& data, unsigned int column); template static int PrintTable(std::vector> data, Int_t start = 0, Int_t end = 0); @@ -129,9 +129,6 @@ class TRestTools { static std::string POSTRequest(const std::string& url, const std::map& keys); static void ChangeDirectory(const std::string& toDirectory); - - /// Rest tools class - ClassDef(TRestTools, 1); }; namespace REST_InitTools { diff --git a/source/framework/tools/src/TRestDataBase.cxx b/source/framework/tools/src/TRestDataBase.cxx index 3cc1eb8b1..10a033a83 100644 --- a/source/framework/tools/src/TRestDataBase.cxx +++ b/source/framework/tools/src/TRestDataBase.cxx @@ -212,7 +212,7 @@ DBEntry TRestDataBase::query_data(DBEntry _info) { _info.version == "") return DBEntry(); - for (int i = 0; i < fDataEntries.size(); i++) { + for (unsigned int i = 0; i < fDataEntries.size(); i++) { DBEntry info = fDataEntries[i]; bool runmatch = (_info.runNr == 0 || info.runNr == 0 || info.runNr == _info.type); diff --git a/source/framework/tools/src/TRestPhysics.cxx b/source/framework/tools/src/TRestPhysics.cxx index fef959418..5b6dc3098 100644 --- a/source/framework/tools/src/TRestPhysics.cxx +++ b/source/framework/tools/src/TRestPhysics.cxx @@ -291,7 +291,7 @@ Double_t GetConeVectorIntersection(const TVector3& pos, const TVector3& dir, con // The projections along the cone axis. If positive then the solution // gives the cone intersection with the side defined by `axis` - Double_t h1 = t1 * dir.Dot(axis) + axis.Dot(deltaV); + // Double_t h1 = t1 * dir.Dot(axis) + axis.Dot(deltaV); Double_t h2 = t2 * dir.Dot(axis) + axis.Dot(deltaV); // We use it to select the root we are interested in diff --git a/source/framework/tools/src/TRestReflector.cxx b/source/framework/tools/src/TRestReflector.cxx index b21db9c2c..fc34484d0 100644 --- a/source/framework/tools/src/TRestReflector.cxx +++ b/source/framework/tools/src/TRestReflector.cxx @@ -201,7 +201,11 @@ int TRestReflector::InitDictionary() { << endl; return -1; } - system(Form("mkdir -p %s/AddonDict", REST_USER_PATH.c_str())); + int z = system(Form("mkdir -p %s/AddonDict", REST_USER_PATH.c_str())); + if (z != 0) { + cout << "mkdir failed to create directory" << endl; + return -1; + } string linkdeffilename = REST_USER_PATH + (string) "/AddonDict/LinkDef.h"; ofstream ofs(linkdeffilename); diff --git a/source/framework/tools/src/TRestStringHelper.cxx b/source/framework/tools/src/TRestStringHelper.cxx index 7de043a4d..4bfeca413 100644 --- a/source/framework/tools/src/TRestStringHelper.cxx +++ b/source/framework/tools/src/TRestStringHelper.cxx @@ -40,14 +40,14 @@ Int_t REST_StringHelper::isAExpression(const string& in) { } if (!symbol) { - int pos = in.find_first_of("+-*/e^%"); + size_t pos = in.find_first_of("+-*/e^%"); if (pos > 0 && pos < in.size() - 1) { symbol = true; } } if (!symbol) { - int pos = in.find_first_of("%"); + size_t pos = in.find_first_of("%"); if (pos == in.size() - 1) { symbol = true; } @@ -132,7 +132,7 @@ string REST_StringHelper::ReplaceMathematicalExpressions(string buffer, Int_t pr erased = true; } - for (int i = 0; i < Expressions.size(); i++) { + for (size_t i = 0; i < Expressions.size(); i++) { if (!isAExpression(Expressions[i])) { result += Expressions[i] + ","; continue; @@ -304,7 +304,7 @@ ULong64_t REST_StringHelper::ToHash(string str) { ULong64_t basis = 0xCBF29CE484222325ull; ULong64_t ret{basis}; - for (int i = 0; i < str.size(); i++) { + for (unsigned int i = 0; i < str.size(); i++) { ret ^= str[i]; ret *= prime; } @@ -506,27 +506,17 @@ string REST_StringHelper::ToDateTimeString(time_t time) { hour = tm_->tm_hour; minute = tm_->tm_min; second = tm_->tm_sec; - char yearStr[5], monthStr[3], dayStr[3], hourStr[3], minuteStr[3], secondStr[3]; - sprintf(yearStr, "%d", year); - sprintf(monthStr, "%d", month); - sprintf(dayStr, "%d", day); - sprintf(hourStr, "%d", hour); - sprintf(minuteStr, "%d", minute); - if (minuteStr[1] == '\0') { - minuteStr[2] = '\0'; - minuteStr[1] = minuteStr[0]; - minuteStr[0] = '0'; - } - sprintf(secondStr, "%d", second); - if (secondStr[1] == '\0') { - secondStr[2] = '\0'; - secondStr[1] = secondStr[0]; - secondStr[0] = '0'; - } - char s[20]; - sprintf(s, "%s-%s-%s %s:%s:%s", yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr); - string str(s); - return str; + + string yearStr = IntegerToString(year); + std::string monthStr = IntegerToString(month, "%02d"); + std::string dayStr = IntegerToString(day, "%02d"); + std::string hourStr = IntegerToString(hour, "%02d"); + std::string minuteStr = IntegerToString(minute, "%02d"); + std::string secondStr = IntegerToString(second, "%02d"); + + std::string date = + yearStr + "/" + monthStr + "/" + dayStr + " " + hourStr + ":" + minuteStr + ":" + secondStr; + return date; } /////////////////////////////////////////////// @@ -843,14 +833,14 @@ TF1* REST_StringHelper::CreateTF1FromString(string func, double init, double end int a = 0; vector optPos(n); vector options(n); // Vector of strings of any size. - for (int i = 0; i < n; i++) { + for (unsigned int i = 0; i < n; i++) { optPos[i] = func.find("[", a); options[i] = func.substr(func.find("[", a) + 1, func.find("]", func.find("[", a)) - func.find("[", a) - 1); a = func.find("[", a) + 1; } // Removing options from function string - for (int i = 0; i < n; i++) { + for (unsigned int i = 0; i < n; i++) { tf1.replace(optPos[n - 1 - i] + 1, (func.find("]", optPos[n - 1 - i]) - optPos[n - 1 - i] - 1), string(1, func[optPos[n - 1 - i] + 1])); } @@ -860,7 +850,7 @@ TF1* REST_StringHelper::CreateTF1FromString(string func, double init, double end TF1* f = new TF1("f", tf1c, init, end); // Initial conditions - for (int i = 0; i < n; i++) { + for (unsigned int i = 0; i < n; i++) { if (options[i].find("=") != string::npos) { string op = options[i].substr(options[i].find_last_of("=") + 1, options[i].find("(") - options[i].find_last_of("=") - 1); @@ -875,7 +865,7 @@ TF1* REST_StringHelper::CreateTF1FromString(string func, double init, double end } // Fixed values - for (int i = 0; i < n; i++) { + for (unsigned int i = 0; i < n; i++) { if (count(options[i].begin(), options[i].end(), '=') == 2) { string op = options[i].substr(options[i].find_last_of("=") + 1, options[i].find("(") - options[i].find_last_of("=") - 1); @@ -887,7 +877,7 @@ TF1* REST_StringHelper::CreateTF1FromString(string func, double init, double end } // Ranges - for (int i = 0; i < n; i++) { + for (unsigned int i = 0; i < n; i++) { if (options[i].find("(") != string::npos) { string op = options[i].substr(options[i].find("(") + 1, options[i].find(")") - options[i].find("(") - 1); diff --git a/source/framework/tools/src/TRestStringOutput.cxx b/source/framework/tools/src/TRestStringOutput.cxx index a8e932605..dcfbba946 100644 --- a/source/framework/tools/src/TRestStringOutput.cxx +++ b/source/framework/tools/src/TRestStringOutput.cxx @@ -264,7 +264,7 @@ string TRestStringOutput::FormattingPrintString(string input) { } string& border = formatstring; - for (unsigned int i = 0; i < Lfmt && i < length; i++) { + for (int i = 0; i < Lfmt && i < length; i++) { output[i] = border[i]; output[length - i - 1] = mirrorchar(border[i]); } diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 3fe4617cf..646d791e3 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -73,8 +73,6 @@ using namespace std; -ClassImp(TRestTools); - /////////////////////////////////////////////// /// \brief Returns all the options in an option string /// @@ -162,7 +160,7 @@ int TRestTools::PrintTable(std::vector> data, Int_t start, Int_t Int_t size = data.size(); if (end > 0 && size > end) size = end; for (int n = start; n < size; n++) { - for (int m = 0; m < data[n].size(); m++) cout << data[n][m] << "\t"; + for (unsigned int m = 0; m < data[n].size(); m++) cout << data[n][m] << "\t"; cout << endl; } return 0; @@ -185,8 +183,8 @@ int TRestTools::ExportASCIITable(std::string fname, std::vector>& return 1; } - for (int n = 0; n < data.size(); n++) - for (int m = 0; m < data[n].size(); m++) { + for (unsigned int n = 0; n < data.size(); n++) + for (unsigned int m = 0; m < data[n].size(); m++) { file << data[n][m]; if (m + 1 < data[n].size()) file << "\t"; if (m + 1 == data[n].size()) file << "\n"; @@ -214,8 +212,8 @@ int TRestTools::ExportBinaryTable(std::string fname, std::vector> return 1; } - for (int n = 0; n < data.size(); n++) - for (int m = 0; m < data[n].size(); m++) { + for (unsigned int n = 0; n < data.size(); n++) + for (unsigned int m = 0; m < data[n].size(); m++) { file.write((char*)&data[n][m], sizeof(T)); } file.close(); @@ -343,8 +341,8 @@ void TRestTools::TransposeTable(std::vector>& data) { std::vector> trans_vec(data[0].size(), std::vector()); - for (int i = 0; i < data.size(); i++) - for (int j = 0; j < data[i].size(); j++) trans_vec[j].push_back(data[i][j]); + for (unsigned int i = 0; i < data.size(); i++) + for (unsigned int j = 0; j < data[i].size(); j++) trans_vec[j].push_back(data[i][j]); data = trans_vec; } @@ -365,16 +363,16 @@ template void TRestTools::TransposeTable(std::vector>& template T TRestTools::GetMaxValueFromTable(const std::vector>& data, Int_t column) { if (data.size() == 0) return 0; - if (column != -1 && data[0].size() <= column) return 0; + if (column > -1 && data[0].size() <= (unsigned int)column) return 0; T maxValue = data[0][0]; if (column == -1) { - for (int n = 0; n < data.size(); n++) - for (int c = 0; c < data[n].size(); c++) + for (unsigned int n = 0; n < data.size(); n++) + for (unsigned int c = 0; c < data[n].size(); c++) if (maxValue < data[n][c]) maxValue = data[n][c]; } else { maxValue = data[0][column]; - for (int n = 0; n < data.size(); n++) + for (unsigned int n = 0; n < data.size(); n++) if (maxValue < data[n][column]) maxValue = data[n][column]; } @@ -400,16 +398,16 @@ template Double_t TRestTools::GetMaxValueFromTable(const std::vector T TRestTools::GetMinValueFromTable(const std::vector>& data, Int_t column) { if (data.empty()) return 0; - if (column != -1 && data[0].size() <= column) return 0; + if (column != -1 && data[0].size() <= (unsigned int)column) return 0; T minValue = data[0][0]; if (column == -1) { - for (int n = 0; n < data.size(); n++) - for (int c = 0; c < data[n].size(); c++) + for (unsigned int n = 0; n < data.size(); n++) + for (unsigned int c = 0; c < data[n].size(); c++) if (minValue > data[n][c]) minValue = data[n][c]; } else { minValue = data[0][column]; - for (int n = 0; n < data.size(); n++) + for (unsigned int n = 0; n < data.size(); n++) if (minValue > data[n][column]) minValue = data[n][column]; } @@ -436,9 +434,9 @@ template Double_t TRestTools::GetMinValueFromTable(const std::vector T TRestTools::GetLowestIncreaseFromTable(std::vector> data, Int_t column) { - if (data.size() == 0 || data[0].size() <= column) return 0; + if (data.size() == 0 || data[0].size() <= (unsigned int)column) return 0; T lowestIncrease = abs(data[0][column] - data[1][column]); - for (int n = 1; n < data.size(); n++) { + for (unsigned int n = 1; n < data.size(); n++) { T value = abs(data[n - 1][column] - data[n][column]); if (lowestIncrease == 0) lowestIncrease = value; if (value > 0 && value < lowestIncrease) lowestIncrease = value; @@ -468,8 +466,8 @@ template T TRestTools::GetIntegralFromTable(const std::vector>& data) { if (data.size() == 0) return 0; T sum = 0; - for (int n = 0; n < data.size(); n++) { - for (int m = 0; m < data[n].size(); m++) sum += data[n][m]; + for (unsigned int n = 0; n < data.size(); n++) { + for (unsigned int m = 0; m < data[n].size(); m++) sum += data[n][m]; } return sum; } @@ -487,23 +485,23 @@ template Double_t TRestTools::GetIntegralFromTable(const std::vector -std::vector TRestTools::GetColumnFromTable(const std::vector>& data, int column) { +std::vector TRestTools::GetColumnFromTable(const std::vector>& data, unsigned int column) { std::vector columnData; if (data.size() == 0 || data[0].size() <= column) return columnData; - for (int n = 0; n < data.size(); n++) columnData.push_back(data[n][column]); + for (unsigned int n = 0; n < data.size(); n++) columnData.push_back(data[n][column]); return columnData; } template std::vector TRestTools::GetColumnFromTable(const std::vector>& data, - int column); + unsigned int column); template std::vector TRestTools::GetColumnFromTable( - const std::vector>& data, int column); + const std::vector>& data, unsigned int column); template std::vector TRestTools::GetColumnFromTable( - const std::vector>& data, int column); + const std::vector>& data, unsigned int column); /////////////////////////////////////////////// /// \brief Reads an ASCII file containing a table with values @@ -552,11 +550,11 @@ int TRestTools::ReadASCIITable(string fName, std::vector>& } // Filling the double values table (TODO error handling in case ToDouble conversion fails) - for (int n = 0; n < values.size(); n++) { + for (unsigned int n = 0; n < values.size(); n++) { std::vector dblTmp; dblTmp.clear(); - for (int m = 0; m < values[n].size(); m++) dblTmp.push_back(StringToDouble(values[n][m])); + for (unsigned int m = 0; m < values[n].size(); m++) dblTmp.push_back(StringToDouble(values[n][m])); data.push_back(dblTmp); } @@ -611,11 +609,11 @@ int TRestTools::ReadASCIITable(string fName, std::vector>& } // Filling the float values table (TODO error handling in case ToFloat conversion fails) - for (int n = 0; n < values.size(); n++) { + for (unsigned int n = 0; n < values.size(); n++) { std::vector dblTmp; dblTmp.clear(); - for (int m = 0; m < values[n].size(); m++) dblTmp.push_back(StringToFloat(values[n][m])); + for (unsigned int m = 0; m < values[n].size(); m++) dblTmp.push_back(StringToFloat(values[n][m])); data.push_back(dblTmp); } @@ -707,7 +705,7 @@ bool TRestTools::isPathWritable(const string& path) { /// \brief Check if the path is absolute path or not /// bool TRestTools::isAbsolutePath(const string& path) { - if (path[0] == '/' || path[0] == '~' || path.find(':') != -1) { + if (path[0] == '/' || path[0] == '~' || path.find(':') != string::npos) { return true; } return false; @@ -781,7 +779,7 @@ string TRestTools::GetPureFileName(const string& path) { return filesystem::path /// string TRestTools::ToAbsoluteName(const string& filename) { filesystem::path path; - for (const auto directory : filesystem::path(filename)) { + for (const auto& directory : filesystem::path(filename)) { if (path.empty() && directory == "~") { // path starts with ~ const auto envVariableHome = getenv("HOME"); @@ -844,7 +842,7 @@ string TRestTools::SearchFileInPath(vector paths, string filename) { if (fileExists(filename)) { return filename; } else { - for (int i = 0; i < paths.size(); i++) { + for (unsigned int i = 0; i < paths.size(); i++) { string path = paths[i]; if (path[path.size() - 1] != '/') { path = path + "/"; @@ -856,7 +854,7 @@ string TRestTools::SearchFileInPath(vector paths, string filename) { // search also in subdirectory, but only 5 times of recursion vector pathsExpanded = GetSubdirectories(paths[i], 5); - for (int j = 0; j < pathsExpanded.size(); j++) + for (unsigned int j = 0; j < pathsExpanded.size(); j++) if (fileExists(pathsExpanded[j] + "/" + filename)) return pathsExpanded[j] + "/" + filename; } } @@ -915,7 +913,7 @@ vector TRestTools::GetFilesMatchingPattern(string pattern) { string a = Execute("find " + item); auto b = Split(a, "\n"); - for (int i = 0; i < b.size(); i++) { + for (unsigned int i = 0; i < b.size(); i++) { outputFileNames.push_back(b[i]); } #endif @@ -1070,7 +1068,10 @@ int TRestTools::DownloadRemoteFile(string remoteFile, string localFile) { if ((string)url.GetProtocol() == "https" || (string)url.GetProtocol() == "http") { string path = TRestTools::SeparatePathAndName(localFiletmp).first; if (!TRestTools::fileExists(path)) { - system(("mkdir -p " + path).c_str()); + if (!filesystem::create_directories(path)){ + std::cerr << "mkdir failed to create directory: " << path << std::endl; + return -1; + } } string cmd = "wget --no-check-certificate " + EscapeSpecialLetters(remoteFile) + " -O " +