ndmspc  v1.2.0-0.1.rc3
Ndmspc::NUtils Class Reference

Utility class providing static helper functions for file operations, histogram manipulations, axis handling, string and vector utilities, JSON parsing, and progress display. More...

#include <NUtils.h>

Inheritance diagram for Ndmspc::NUtils:

Public Types

using RawJsonInjections = std::vector< std::pair< std::vector< std::string >, std::string > >
 

Static Public Member Functions

static bool EnableMT (Int_t numthreads=-1)
 Enable multi-threading with specified number of threads. More...
 
static bool AccessPathName (std::string path)
 Check if a path is accessible. More...
 
static bool IsFileSupported (std::string filename)
 Check if a file is supported. More...
 
static int Cp (std::string source, std::string destination, Bool_t progressbar=kTRUE)
 Copy a file from source to destination. More...
 
static bool CreateDirectory (const std::string &path)
 
static TFile * OpenFile (std::string filename, std::string mode="READ", bool createLocalDir=true)
 Open a ROOT file. More...
 
static std::string OpenRawFile (std::string filename)
 Open a raw file and return its content as string. More...
 
static bool SaveRawFile (std::string filename, std::string content)
 Save content to a raw file. More...
 
static TMacro * OpenMacro (std::string filename)
 Open a macro file. More...
 
static bool LoadJsonFile (json &cfg, std::string filename)
 Loads a JSON configuration file into the provided json object. More...
 
static std::string InjectRawJson (json &j, const RawJsonInjections &injections)
 
static void AddRawJsonInjection (json &j, const std::vector< std::string > &path, const std::string &rawJson, const std::string &injectionsKey="__raw_json_injections")
 Add one raw JSON injection entry into metadata field. More...
 
static bool CollectRawJsonInjections (const json &j, RawJsonInjections &injections, const std::string &injectionsKey="__raw_json_injections")
 Collect raw JSON injection entries from metadata field. More...
 
static std::string MergeRawJsonWithMetadata (const std::string &rawJson, const json &metadata)
 Merge raw JSON string with metadata fields. More...
 
static TH1 * ProjectTHnSparse (THnSparse *hns, const std::vector< int > &axes, Option_t *option="")
 Project a THnSparse histogram onto specified axes. More...
 
static bool SetAxisRanges (THnSparse *sparse, std::vector< std::vector< int >> ranges={}, bool withOverflow=false, bool modifyTitle=false, bool reset=true)
 Set axis ranges for THnSparse using vector of ranges. More...
 
static bool SetAxisRanges (THnSparse *sparse, std::map< int, std::vector< int >> ranges, bool withOverflow=false, bool modifyTitle=false, bool reset=true)
 Set axis ranges for THnSparse using map of ranges. More...
 
static bool GetAxisRangeInBase (TAxis *a, int rebin, int rebin_start, int bin, int &min, int &max)
 Get axis range in base for rebinned axis. More...
 
static bool GetAxisRangeInBase (TAxis *a, int min, int max, TAxis *base, int &minBase, int &maxBase)
 Get axis range in base axis. More...
 
static TAxis * CreateAxisFromLabels (const std::string &name, const std::string &title, const std::vector< std::string > &labels)
 Create a TAxis from a list of labels. More...
 
static TAxis * CreateAxisFromLabelsSet (const std::string &name, const std::string &title, const std::set< std::string > &labels)
 Create a TAxis from a set of labels. More...
 
static THnSparse * Convert (TH1 *h1, std::vector< std::string > names={}, std::vector< std::string > titles={})
 Convert TH1 to THnSparse. More...
 
static THnSparse * Convert (TH2 *h2, std::vector< std::string > names={}, std::vector< std::string > titles={})
 Convert TH2 to THnSparse. More...
 
static THnSparse * Convert (TH3 *h3, std::vector< std::string > names={}, std::vector< std::string > titles={})
 Convert TH3 to THnSparse. More...
 
static THnSparse * ReshapeSparseAxes (THnSparse *hns, std::vector< int > order, std::vector< TAxis * > newAxes={}, std::vector< int > newPoint={}, Option_t *option="E")
 Reshape axes of THnSparse. More...
 
static void GetTrueHistogramMinMax (const TH1 *h, double &min_val, double &max_val, bool include_overflow_underflow=false)
 Get minimum and maximum value of histogram bins. More...
 
static TObjArray * AxesFromDirectory (const std::vector< std::string > paths, const std::string &findPath, const std::string &fileName, const std::vector< std::string > &axesNames)
 Creates an array of axes objects from files in specified directories. More...
 
static std::vector< std::string > Tokenize (std::string_view input, const char delim)
 Tokenize a string by delimiter. More...
 
static std::vector< int > TokenizeInt (std::string_view input, const char delim)
 Tokenize a string into integers by delimiter. More...
 
static std::string Join (const std::vector< std::string > &values, const char delim=',')
 Join vector of strings into a single string with delimiter. More...
 
static std::string Join (const std::vector< int > &values, const char delim=',')
 Join vector of integers into a single string with delimiter. More...
 
static std::vector< std::string > Find (std::string path, std::string filename="")
 Find files in a path matching filename. More...
 
static std::vector< std::string > FindLocal (std::string path, std::string filename="")
 Find local files in a path matching filename. More...
 
static std::vector< std::string > FindEos (std::string path, std::string filename="")
 Find EOS files in a path matching filename. More...
 
static std::set< std::string > Unique (std::vector< std::string > &paths, int axis, std::string path, char token='/')
 Get unique values from vector of strings at specified axis. More...
 
static std::vector< std::string > Truncate (std::vector< std::string > values, std::string value)
 Truncate vector of strings by a value. More...
 
static std::vector< int > ArrayToVector (Int_t *v1, int size)
 Convert array to vector. More...
 
static void VectorToArray (std::vector< int > v1, Int_t *v2)
 Convert vector to array. More...
 
static std::string GetCoordsString (const std::vector< int > &coords, int index=-1, int width=0)
 Get string representation of coordinates. More...
 
static std::string GetCoordsString (const std::vector< size_t > &coords, int index=-1, int width=0)
 Get string representation of coordinates. More...
 
static std::string GetCoordsString (const std::vector< Long64_t > &coords, int index=-1, int width=0)
 Get string representation of coordinates (Long64_t). More...
 
static std::string GetCoordsString (const std::vector< std::string > &coords, int index=-1, int width=0)
 Get string representation of coordinates (string). More...
 
static void PrintPointSafe (const std::vector< int > &coords, int index=-1)
 Print coordinates safely. More...
 
static std::vector< std::vector< int > > Permutations (const std::vector< int > &v)
 Generate all permutations of a vector. More...
 
static std::string GetJsonString (json j)
 Get JSON value as string. More...
 
static int GetJsonInt (json j)
 Get JSON value as integer. More...
 
static double GetJsonDouble (json j)
 Get JSON value as double. More...
 
static json GetSystemStats ()
 Get process CPU and RSS memory statistics using ROOT's gSystem::GetProcInfo. More...
 
static json GetTFileIOStats ()
 Get TFile read/write statistics by inspecting ROOT's list of open files. More...
 
static json GetNetDevStats ()
 Get system-wide network interface totals (RX/TX bytes) in a cross-platform way. On Linux reads /proc/net/dev; on macOS uses getifaddrs() and struct if_data. More...
 
static bool GetJsonBool (json j)
 Get JSON value as boolean. More...
 
static std::vector< std::string > GetJsonStringArray (json j)
 Get JSON value as array of strings. More...
 
static std::string FormatTime (long long seconds)
 Format time in seconds to human-readable string. More...
 
static void ProgressBar (int current, int total, std::string prefix="", std::string suffix="", int barWidth=50)
 Display progress bar. More...
 
static void ProgressBar (int current, int total, std::chrono::high_resolution_clock::time_point startTime, std::string prefix="", std::string suffix="", int barWidth=50)
 Display progress bar with timing. More...
 
static TCanvas * CreateCanvas (const std::string &name, const std::string &title, int width=800, int height=600)
 Create a ROOT TCanvas with specified name, title, and dimensions. More...
 
static void SafeDeleteObjects (std::vector< TObject * > &objects)
 Safely delete a vector of ROOT objects, bypassing GarbageCollect. More...
 
static void SafeDeleteTList (TList *&lst)
 Safely delete a TList and all its contents, bypassing ROOT's GarbageCollect. More...
 
static void SafeDeleteObject (TObject *&obj)
 Safely delete a TObject, handling TList contents and TCanvas/TPad cleanup. More...
 
static THnSparse * CreateSparseFromParquetTaxi (const std::string &filename, THnSparse *hns=nullptr, Int_t nMaxRows=-1)
 Create THnSparse from Parquet Taxi file. More...
 

Private Member Functions

 NUtils ()
 Constructor.
 
virtual ~NUtils ()
 Destructor.
 

Detailed Description

Utility class providing static helper functions for file operations, histogram manipulations, axis handling, string and vector utilities, JSON parsing, and progress display.

Author
Martin Vala mvala.nosp@m.@cer.nosp@m.n.ch

Definition at line 25 of file NUtils.h.

Member Function Documentation

◆ AccessPathName()

bool Ndmspc::NUtils::AccessPathName ( std::string  path)
static

Check if a path is accessible.

Parameters
pathPath to check.
Returns
True if accessible, false otherwise.

Check if path exists

Definition at line 115 of file NUtils.cxx.

References Ndmspc::NHttpRequest::head().

◆ AddRawJsonInjection()

void Ndmspc::NUtils::AddRawJsonInjection ( json &  j,
const std::vector< std::string > &  path,
const std::string &  rawJson,
const std::string &  injectionsKey = "__raw_json_injections" 
)
static

Add one raw JSON injection entry into metadata field.

The server serializer can later collect these entries and apply InjectRawJson without each handler duplicating metadata format details.

Parameters
jJSON envelope that stores injection metadata
pathNested key path where raw JSON should be injected
rawJsonRaw JSON string to inject
injectionsKeyMetadata key used to store injection entries

Definition at line 881 of file NUtils.cxx.

◆ ArrayToVector()

std::vector< int > Ndmspc::NUtils::ArrayToVector ( Int_t *  v1,
int  size 
)
static

Convert array to vector.

Parameters
v1Input array.
sizeSize of array.
Returns
Vector of integers.

Convert array to vector

Definition at line 1551 of file NUtils.cxx.

Referenced by Ndmspc::NGnTree::Import(), Ndmspc::NStorageTree::Merge(), Ndmspc::NBinningPoint::Print(), Ndmspc::NBinning::PrintContent(), Ndmspc::NGnThreadData::Process(), Ndmspc::NGnTree::Process(), and Ndmspc::NBinningPoint::RecalculateStorageCoords().

◆ AxesFromDirectory()

TObjArray * Ndmspc::NUtils::AxesFromDirectory ( const std::vector< std::string >  paths,
const std::string &  findPath,
const std::string &  fileName,
const std::vector< std::string > &  axesNames 
)
static

Creates an array of axes objects from files in specified directories.

Searches the given directories for files matching the specified file name and headers, and constructs a TObjArray of axes objects found in those files.

Parameters
pathsA vector of directory paths to search.
findPathThe subdirectory path to look for within each directory.
fileNameThe name of the file to search for in each directory.
axesNamesA vector of axis names
Returns
A pointer to a TObjArray containing the axes objects, or nullptr if none found.

Definition at line 1396 of file NUtils.cxx.

References CreateAxisFromLabelsSet(), and Tokenize().

Referenced by Ndmspc::NGnTree::Import().

◆ CollectRawJsonInjections()

bool Ndmspc::NUtils::CollectRawJsonInjections ( const json &  j,
RawJsonInjections &  injections,
const std::string &  injectionsKey = "__raw_json_injections" 
)
static

Collect raw JSON injection entries from metadata field.

Parameters
jJSON envelope containing injection metadata
injectionsOutput vector of parsed {path, rawJson} entries
injectionsKeyMetadata key used to store injection entries
Returns
True if metadata exists and at least one valid injection was collected

Definition at line 924 of file NUtils.cxx.

◆ Convert() [1/3]

THnSparse * Ndmspc::NUtils::Convert ( TH1 *  h1,
std::vector< std::string >  names = {},
std::vector< std::string >  titles = {} 
)
static

Convert TH1 to THnSparse.

Parameters
h1Input TH1.
namesAxis names.
titlesAxis titles.
Returns
Pointer to THnSparse.

Convert TH1 to THnSparse

Definition at line 221 of file NUtils.cxx.

◆ Convert() [2/3]

THnSparse * Ndmspc::NUtils::Convert ( TH2 *  h2,
std::vector< std::string >  names = {},
std::vector< std::string >  titles = {} 
)
static

Convert TH2 to THnSparse.

Parameters
h2Input TH2.
namesAxis names.
titlesAxis titles.
Returns
Pointer to THnSparse.

Convert TH2 to THnSparse

Definition at line 286 of file NUtils.cxx.

◆ Convert() [3/3]

THnSparse * Ndmspc::NUtils::Convert ( TH3 *  h3,
std::vector< std::string >  names = {},
std::vector< std::string >  titles = {} 
)
static

Convert TH3 to THnSparse.

Parameters
h3Input TH3.
namesAxis names.
titlesAxis titles.
Returns
Pointer to THnSparse.

Convert TH3 to THnSparse

Definition at line 364 of file NUtils.cxx.

◆ Cp()

int Ndmspc::NUtils::Cp ( std::string  source,
std::string  destination,
Bool_t  progressbar = kTRUE 
)
static

Copy a file from source to destination.

Parameters
sourceSource file path.
destinationDestination file path.
Returns
Status code (0 for success).

Copy file

Definition at line 155 of file NUtils.cxx.

References IsFileSupported().

◆ CreateAxisFromLabels()

TAxis * Ndmspc::NUtils::CreateAxisFromLabels ( const std::string &  name,
const std::string &  title,
const std::vector< std::string > &  labels 
)
static

Create a TAxis from a list of labels.

Parameters
nameAxis name.
titleAxis title.
labelsVector of labels.
Returns
Pointer to created TAxis.

Create label axis

Definition at line 185 of file NUtils.cxx.

Referenced by Ndmspc::NResourceMonitor::Initialize().

◆ CreateAxisFromLabelsSet()

TAxis * Ndmspc::NUtils::CreateAxisFromLabelsSet ( const std::string &  name,
const std::string &  title,
const std::set< std::string > &  labels 
)
static

Create a TAxis from a set of labels.

Parameters
nameAxis name.
titleAxis title.
labelsSet of labels.
Returns
Pointer to created TAxis.

Create label axis

Definition at line 202 of file NUtils.cxx.

Referenced by AxesFromDirectory().

◆ CreateCanvas()

TCanvas * Ndmspc::NUtils::CreateCanvas ( const std::string &  name,
const std::string &  title,
int  width = 800,
int  height = 600 
)
static

Create a ROOT TCanvas with specified name, title, and dimensions.

This utility function creates and returns a pointer to a new TCanvas object.

Parameters
nameName of the canvas.
titleTitle of the canvas.
widthWidth of the canvas in pixels (default: 800).
heightHeight of the canvas in pixels (default: 600).
Returns
Pointer to the created TCanvas object.

Create canvas

Definition at line 1748 of file NUtils.cxx.

◆ CreateDirectory()

bool Ndmspc::NUtils::CreateDirectory ( const std::string &  path)
static

Create a directory (and all parents) for local paths. Remote paths (containing "://", except "file://") are silently ignored as the remote protocol is expected to handle directory creation itself.

Definition at line 688 of file NUtils.cxx.

Referenced by OpenFile().

◆ CreateSparseFromParquetTaxi()

THnSparse * Ndmspc::NUtils::CreateSparseFromParquetTaxi ( const std::string &  filename,
THnSparse *  hns = nullptr,
Int_t  nMaxRows = -1 
)
static

Create THnSparse from Parquet Taxi file.

Parameters
filenameParquet file name.
hnsOptional input THnSparse.
nMaxRowsMaximum number of rows to read.
Returns
Pointer to created THnSparse.

Definition at line 1945 of file NUtils.cxx.

◆ EnableMT()

bool Ndmspc::NUtils::EnableMT ( Int_t  numthreads = -1)
static

Enable multi-threading with specified number of threads.

Parameters
numthreadsNumber of threads to enable (0 for default).

Enable multithreading

Definition at line 46 of file NUtils.cxx.

Referenced by Ndmspc::NGnTree::Process().

◆ Find()

std::vector< std::string > Ndmspc::NUtils::Find ( std::string  path,
std::string  filename = "" 
)
static

Find files in a path matching filename.

Parameters
pathDirectory path.
filenameFilename pattern.
Returns
Vector of found file paths.

Find files in path

Definition at line 963 of file NUtils.cxx.

References FindEos(), and FindLocal().

Referenced by Ndmspc::NGnTree::Import().

◆ FindEos()

std::vector< std::string > Ndmspc::NUtils::FindEos ( std::string  path,
std::string  filename = "" 
)
static

Find EOS files in a path matching filename.

Parameters
pathDirectory path.
filenameFilename pattern.
Returns
Vector of found EOS file paths.

Find eos files

Definition at line 1008 of file NUtils.cxx.

References OpenFile(), and Tokenize().

Referenced by Find().

◆ FindLocal()

std::vector< std::string > Ndmspc::NUtils::FindLocal ( std::string  path,
std::string  filename = "" 
)
static

Find local files in a path matching filename.

Parameters
pathDirectory path.
filenameFilename pattern.
Returns
Vector of found local file paths.

Find local files

Definition at line 986 of file NUtils.cxx.

Referenced by Find().

◆ FormatTime()

std::string Ndmspc::NUtils::FormatTime ( long long  seconds)
static

Format time in seconds to human-readable string.

Parameters
secondsTime in seconds.
Returns
Formatted time string.

Definition at line 1660 of file NUtils.cxx.

Referenced by Ndmspc::NGnTree::Process(), and ProgressBar().

◆ GetAxisRangeInBase() [1/2]

bool Ndmspc::NUtils::GetAxisRangeInBase ( TAxis *  a,
int  min,
int  max,
TAxis *  base,
int &  minBase,
int &  maxBase 
)
static

Get axis range in base axis.

Parameters
aAxis pointer.
minMinimum bin.
maxMaximum bin.
baseBase axis pointer.
minBaseOutput minimum base bin.
maxBaseOutput maximum base bin.
Returns
True if successful.

Gets axis range in base

Definition at line 1373 of file NUtils.cxx.

References GetAxisRangeInBase().

◆ GetAxisRangeInBase() [2/2]

bool Ndmspc::NUtils::GetAxisRangeInBase ( TAxis *  a,
int  rebin,
int  rebin_start,
int  bin,
int &  min,
int &  max 
)
static

Get axis range in base for rebinned axis.

Parameters
aAxis pointer.
rebinRebin factor.
rebin_startStart bin for rebinning.
binBin index.
minOutput minimum bin.
maxOutput maximum bin.
Returns
True if successful.

Returns axis range in base in min and max variables

Definition at line 1338 of file NUtils.cxx.

Referenced by GetAxisRangeInBase(), and Ndmspc::NGnNavigator::Reshape().

◆ GetCoordsString() [1/4]

◆ GetCoordsString() [2/4]

std::string Ndmspc::NUtils::GetCoordsString ( const std::vector< Long64_t > &  coords,
int  index = -1,
int  width = 0 
)
static

Get string representation of coordinates (Long64_t).

Parameters
coordsVector of coordinates.
indexIndex to highlight (-1 for none).
widthWidth for formatting.
Returns
String representation.

Get coordinates string

Definition at line 1574 of file NUtils.cxx.

◆ GetCoordsString() [3/4]

std::string Ndmspc::NUtils::GetCoordsString ( const std::vector< size_t > &  coords,
int  index = -1,
int  width = 0 
)
static

Get string representation of coordinates.

Parameters
coordsVector of coordinates.
indexIndex to highlight (-1 for none).
widthWidth for formatting.
Returns
String representation.

Get coordinates string

Definition at line 1602 of file NUtils.cxx.

◆ GetCoordsString() [4/4]

std::string Ndmspc::NUtils::GetCoordsString ( const std::vector< std::string > &  coords,
int  index = -1,
int  width = 0 
)
static

Get string representation of coordinates (string).

Parameters
coordsVector of coordinates.
indexIndex to highlight (-1 for none).
widthWidth for formatting.
Returns
String representation.

Get coordinates string

Definition at line 1616 of file NUtils.cxx.

◆ GetJsonBool()

bool Ndmspc::NUtils::GetJsonBool ( json  j)
static

Get JSON value as boolean.

Parameters
jInput JSON.
Returns
Boolean value.

Returns json bool if it is valid

Definition at line 1513 of file NUtils.cxx.

◆ GetJsonDouble()

double Ndmspc::NUtils::GetJsonDouble ( json  j)
static

Get JSON value as double.

Parameters
jInput JSON.
Returns
Double value.

Returns json double if it is valid

Definition at line 1490 of file NUtils.cxx.

◆ GetJsonInt()

int Ndmspc::NUtils::GetJsonInt ( json  j)
static

Get JSON value as integer.

Parameters
jInput JSON.
Returns
Integer value.

Returns json int if it is valid

Definition at line 1467 of file NUtils.cxx.

◆ GetJsonString()

std::string Ndmspc::NUtils::GetJsonString ( json  j)
static

Get JSON value as string.

Parameters
jInput JSON.
Returns
String value.

Returns json string if it is valid

Definition at line 1442 of file NUtils.cxx.

Referenced by GetJsonStringArray().

◆ GetJsonStringArray()

std::vector< std::string > Ndmspc::NUtils::GetJsonStringArray ( json  j)
static

Get JSON value as array of strings.

Parameters
jInput JSON.
Returns
Vector of strings.

Returns json string array if it is valid

Definition at line 1536 of file NUtils.cxx.

References GetJsonString().

◆ GetNetDevStats()

json Ndmspc::NUtils::GetNetDevStats ( )
static

Get system-wide network interface totals (RX/TX bytes) in a cross-platform way. On Linux reads /proc/net/dev; on macOS uses getifaddrs() and struct if_data.

Returns
json object containing per-interface and aggregated rx/tx bytes

Definition at line 2130 of file NUtils.cxx.

◆ GetSystemStats()

json Ndmspc::NUtils::GetSystemStats ( )
static

Get process CPU and RSS memory statistics using ROOT's gSystem::GetProcInfo.

Returns
json object containing cpu and rss information

Definition at line 2055 of file NUtils.cxx.

◆ GetTFileIOStats()

json Ndmspc::NUtils::GetTFileIOStats ( )
static

Get TFile read/write statistics by inspecting ROOT's list of open files.

Returns
json object containing per-file and aggregated IO statistics

Definition at line 2074 of file NUtils.cxx.

◆ GetTrueHistogramMinMax()

void Ndmspc::NUtils::GetTrueHistogramMinMax ( const TH1 *  h,
double &  min_val,
double &  max_val,
bool  include_overflow_underflow = false 
)
static

Get minimum and maximum value of histogram bins.

Parameters
hInput histogram.
min_valOutput minimum value.
max_valOutput maximum value.
include_overflow_underflowInclude overflow/underflow bins.

Retrieve the true min and max values of a histogram, ignoring underflow and overflow bins

Definition at line 621 of file NUtils.cxx.

Referenced by Ndmspc::NGnNavigator::ExportToJson().

◆ InjectRawJson()

std::string Ndmspc::NUtils::InjectRawJson ( json &  j,
const RawJsonInjections &  injections 
)
static

Injects multiple raw JSON strings into a json object at the specified nested key paths. Each entry in the injections vector is a pair of:

  • keys: nested key path (e.g. {"data", "detector", "list"})
  • rawJson: raw JSON string to inject at that path

This avoids re-parsing raw JSON strings, preserving the exact output of TBufferJSON.

Parameters
jsonThe json object to inject into
injectionsVector of {keys, rawJson} pairs
Returns
The final JSON string with all raw JSONs injected
Exceptions
std::invalid_argumentif any keys array is empty
std::runtime_errorif any placeholder is not found after dump

Definition at line 839 of file NUtils.cxx.

◆ IsFileSupported()

bool Ndmspc::NUtils::IsFileSupported ( std::string  filename)
static

Check if a file is supported.

Parameters
filenameName of the file.
Returns
True if supported, false otherwise.

Check if file is supported

Definition at line 97 of file NUtils.cxx.

Referenced by Cp().

◆ Join() [1/2]

std::string Ndmspc::NUtils::Join ( const std::vector< int > &  values,
const char  delim = ',' 
)
static

Join vector of integers into a single string with delimiter.

Parameters
valuesVector of integers.
delimDelimiter character.
Returns
Joined string.

Join helper function

Definition at line 1124 of file NUtils.cxx.

◆ Join() [2/2]

std::string Ndmspc::NUtils::Join ( const std::vector< std::string > &  values,
const char  delim = ',' 
)
static

Join vector of strings into a single string with delimiter.

Parameters
valuesVector of strings.
delimDelimiter character.
Returns
Joined string.

Join helper function

Definition at line 1111 of file NUtils.cxx.

Referenced by Ndmspc::NGnNavigator::DrawSpectra(), Ndmspc::NGnThreadData::Init(), and Ndmspc::NGnTree::Projection().

◆ LoadJsonFile()

bool Ndmspc::NUtils::LoadJsonFile ( json &  cfg,
std::string  filename 
)
static

Loads a JSON configuration file into the provided json object.

Parameters
cfgReference to a json object where the file contents will be loaded.
filenamePath to the JSON file to load.
Returns
true if the file was loaded and parsed successfully, false otherwise.

Load JSON file

Definition at line 814 of file NUtils.cxx.

References OpenRawFile().

◆ MergeRawJsonWithMetadata()

std::string Ndmspc::NUtils::MergeRawJsonWithMetadata ( const std::string &  rawJson,
const json &  metadata 
)
static

Merge raw JSON string with metadata fields.

Parses the raw JSON string and merges in metadata fields. Metadata fields at the top level are added/merged directly; nested paths are not supported.

Parameters
rawJsonRaw JSON string to merge into
metadataJSON object with fields to merge
Returns
Merged JSON string

Merge raw JSON string with metadata fields

Definition at line 941 of file NUtils.cxx.

◆ OpenFile()

TFile * Ndmspc::NUtils::OpenFile ( std::string  filename,
std::string  mode = "READ",
bool  createLocalDir = true 
)
static

Open a ROOT file.

Parameters
filenameFile name.
modeFile open mode ("READ", "UPDATE", etc.).
createLocalDirCreate local directory if needed.
Returns
Pointer to opened TFile.

Open root file and create directory when needed in local case

Definition at line 719 of file NUtils.cxx.

References CreateDirectory().

Referenced by FindEos(), Ndmspc::NStorageTree::InitTree(), OpenRawFile(), and SaveRawFile().

◆ OpenMacro()

TMacro * Ndmspc::NUtils::OpenMacro ( std::string  filename)
static

Open a macro file.

Parameters
filenameMacro file name.
Returns
Pointer to TMacro object.

Open macro - supports local files and http/https URLs

Definition at line 781 of file NUtils.cxx.

References Ndmspc::NHttpRequest::get(), and OpenRawFile().

◆ OpenRawFile()

std::string Ndmspc::NUtils::OpenRawFile ( std::string  filename)
static

Open a raw file and return its content as string.

Parameters
filenameFile name.
Returns
File content.

Opens raw file

Definition at line 735 of file NUtils.cxx.

References OpenFile().

Referenced by LoadJsonFile(), and OpenMacro().

◆ Permutations()

std::vector< std::vector< int > > Ndmspc::NUtils::Permutations ( const std::vector< int > &  v)
static

Generate all permutations of a vector.

Parameters
vInput vector.
Returns
Vector of permutations.

Return all permutations of a vector

Definition at line 1639 of file NUtils.cxx.

References GetCoordsString().

Referenced by Ndmspc::NGnNavigator::DrawSpectra().

◆ PrintPointSafe()

void Ndmspc::NUtils::PrintPointSafe ( const std::vector< int > &  coords,
int  index = -1 
)
static

Print coordinates safely.

Parameters
coordsVector of coordinates.
indexIndex to highlight (-1 for none).

Print point safe

Definition at line 1630 of file NUtils.cxx.

References GetCoordsString().

◆ ProgressBar() [1/2]

void Ndmspc::NUtils::ProgressBar ( int  current,
int  total,
std::chrono::high_resolution_clock::time_point  startTime,
std::string  prefix = "",
std::string  suffix = "",
int  barWidth = 50 
)
static

Display progress bar with timing.

Parameters
currentCurrent progress.
totalTotal value.
startTimeStart time point.
barWidthWidth of the bar.
prefixPrefix string.
suffixSuffix string.

Print progress bar

Definition at line 1704 of file NUtils.cxx.

References FormatTime(), and Ndmspc::NLogger::GetLoggerMutex().

◆ ProgressBar() [2/2]

void Ndmspc::NUtils::ProgressBar ( int  current,
int  total,
std::string  prefix = "",
std::string  suffix = "",
int  barWidth = 50 
)
static

Display progress bar.

Parameters
currentCurrent progress.
totalTotal value.
barWidthWidth of the bar.
prefixPrefix string.
suffixSuffix string.

Print progress bar

Definition at line 1673 of file NUtils.cxx.

References Ndmspc::NLogger::GetLoggerMutex().

Referenced by Ndmspc::NGnTree::Process().

◆ ProjectTHnSparse()

TH1 * Ndmspc::NUtils::ProjectTHnSparse ( THnSparse *  hns,
const std::vector< int > &  axes,
Option_t *  option = "" 
)
static

Project a THnSparse histogram onto specified axes.

Parameters
hnsInput THnSparse.
axesAxes to project.
optionProjection options.
Returns
Pointer to projected TH1.

Project THnSparse onto TH1

Definition at line 1167 of file NUtils.cxx.

Referenced by Ndmspc::NGnNavigator::DrawSpectra(), and Ndmspc::NGnTree::Projection().

◆ ReshapeSparseAxes()

THnSparse * Ndmspc::NUtils::ReshapeSparseAxes ( THnSparse *  hns,
std::vector< int >  order,
std::vector< TAxis * >  newAxes = {},
std::vector< int >  newPoint = {},
Option_t *  option = "E" 
)
static

Reshape axes of THnSparse.

Parameters
hnsInput THnSparse.
orderNew axis order.
newAxesNew axes (optional).
newPointNew point (optional).
optionOption string.
Returns
Pointer to reshaped THnSparse.

Reshape sparse axes

loop over all axes

Definition at line 452 of file NUtils.cxx.

Referenced by Ndmspc::NResourceMonitor::Initialize().

◆ SafeDeleteObject()

void Ndmspc::NUtils::SafeDeleteObject ( TObject *&  obj)
static

Safely delete a TObject, handling TList contents and TCanvas/TPad cleanup.

If the object is a TList, delegates to SafeDeleteTList. Otherwise deletes directly.

Parameters
objPointer reference to the object. Set to nullptr after deletion.

Definition at line 2040 of file NUtils.cxx.

References SafeDeleteTList().

◆ SafeDeleteObjects()

void Ndmspc::NUtils::SafeDeleteObjects ( std::vector< TObject * > &  objects)
static

Safely delete a vector of ROOT objects, bypassing GarbageCollect.

Extracts and empties pad primitive lists (to prevent GarbageCollect during canvas/pad destruction), then deletes all objects directly.

Parameters
objectsVector of object pointers. Cleared after deletion.

Definition at line 1953 of file NUtils.cxx.

Referenced by Ndmspc::NGnThreadData::FlushDeferredDeletes(), and SafeDeleteTList().

◆ SafeDeleteTList()

void Ndmspc::NUtils::SafeDeleteTList ( TList *&  lst)
static

Safely delete a TList and all its contents, bypassing ROOT's GarbageCollect.

Extracts objects into a vector, destroys the TList shell, then delegates to SafeDeleteObjects.

Parameters
lstPointer reference to the TList. Set to nullptr after deletion.

Definition at line 2018 of file NUtils.cxx.

References SafeDeleteObjects().

Referenced by Ndmspc::NTreeBranch::GetEntry(), and SafeDeleteObject().

◆ SaveRawFile()

bool Ndmspc::NUtils::SaveRawFile ( std::string  filename,
std::string  content 
)
static

Save content to a raw file.

Parameters
filenameFile name.
contentContent to save.
Returns
True if successful.

Save raw file

Definition at line 765 of file NUtils.cxx.

References OpenFile().

Referenced by Ndmspc::NGnNavigator::Export().

◆ SetAxisRanges() [1/2]

bool Ndmspc::NUtils::SetAxisRanges ( THnSparse *  sparse,
std::map< int, std::vector< int >>  ranges,
bool  withOverflow = false,
bool  modifyTitle = false,
bool  reset = true 
)
static

Set axis ranges for THnSparse using map of ranges.

Parameters
sparseInput THnSparse.
rangesMap of axis ranges.
withOverflowInclude overflow bins.
modifyTitleModify histogram title.
resetReset axis ranges before setting new ones.
Returns
True if successful.

Set axis ranges

Reset all axis ranges

Definition at line 1278 of file NUtils.cxx.

◆ SetAxisRanges() [2/2]

bool Ndmspc::NUtils::SetAxisRanges ( THnSparse *  sparse,
std::vector< std::vector< int >>  ranges = {},
bool  withOverflow = false,
bool  modifyTitle = false,
bool  reset = true 
)
static

Set axis ranges for THnSparse using vector of ranges.

Parameters
sparseInput THnSparse.
rangesVector of axis ranges.
withOverflowInclude overflow bins.
modifyTitleModify histogram title.
resetReset axis ranges before setting new ones.
Returns
True if successful.

Set axis ranges

Reset all axis ranges

Definition at line 1220 of file NUtils.cxx.

Referenced by Ndmspc::NGnNavigator::DrawSpectra(), Ndmspc::NStorageTree::Fill(), Ndmspc::NGnNavigator::GetChild(), Ndmspc::NGnTree::NGnTree(), Ndmspc::NGnTree::Play(), Ndmspc::NGnTree::Projection(), and Ndmspc::NGnNavigator::Reshape().

◆ Tokenize()

std::vector< std::string > Ndmspc::NUtils::Tokenize ( std::string_view  input,
const char  delim 
)
static

Tokenize a string by delimiter.

Parameters
inputInput string.
delimDelimiter character.
Returns
Vector of tokens.

Tokenize helper function

Definition at line 1073 of file NUtils.cxx.

Referenced by AxesFromDirectory(), FindEos(), Ndmspc::NGnTree::Open(), TokenizeInt(), and Unique().

◆ TokenizeInt()

std::vector< int > Ndmspc::NUtils::TokenizeInt ( std::string_view  input,
const char  delim 
)
static

Tokenize a string into integers by delimiter.

Parameters
inputInput string.
delimDelimiter character.
Returns
Vector of integers.

Tokenize helper function

Definition at line 1095 of file NUtils.cxx.

References Tokenize().

◆ Truncate()

std::vector< std::string > Ndmspc::NUtils::Truncate ( std::vector< std::string >  values,
std::string  value 
)
static

Truncate vector of strings by a value.

Parameters
valuesVector of strings.
valueValue to truncate by.
Returns
Truncated vector.

Truncate helper function

Definition at line 1138 of file NUtils.cxx.

Referenced by Unique().

◆ Unique()

std::set< std::string > Ndmspc::NUtils::Unique ( std::vector< std::string > &  paths,
int  axis,
std::string  path,
char  token = '/' 
)
static

Get unique values from vector of strings at specified axis.

Parameters
pathsVector of paths.
axisAxis index.
pathPath string.
tokenToken character.
Returns
Set of unique strings.

Unique helper function

Definition at line 1152 of file NUtils.cxx.

References Tokenize(), and Truncate().

◆ VectorToArray()

void Ndmspc::NUtils::VectorToArray ( std::vector< int >  v1,
Int_t *  v2 
)
static

Convert vector to array.

Parameters
v1Input vector.
v2Output array.

Convert vector to array

Definition at line 1564 of file NUtils.cxx.

Referenced by Ndmspc::NBinning::AddBinning().


The documentation for this class was generated from the following files: