Commit 72151027 authored by Vratislav Chudoba's avatar Vratislav Chudoba

Makefile cleaned.

Warnings in ConfigDictionary class resolved.
parent 88726b84
*~
# Ignore compiled files
*.o
*.out
*.d
*.so
#Ignore files automatically build by ROOT
*.pcm
*Dict.cpp
# Ignore log files
*.log
# Ignore build directories
build/
# Ignore data and calibration files
*.root
*.cal
#Ignore VS code stuff
.vscode/
# config.ini
\ No newline at end of file
......@@ -161,46 +161,61 @@ void ConfigDictionary::FromString(std::string params){
}
//_____________________________________________________________________________
std::string ConfigDictionary::GetString(std::string key)throw(std::string){
std::string ConfigDictionary::GetString(std::string key){
//Extracts string from given key
//(if it exist, otherwise raises exception)
//This works also for long strings with white spaces in it!
if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetString",
"Couldn't find the key: %s!",key.c_str());
throw(key);
// throw(key);
throw std::runtime_error("Couldn't find the key: " + key);
}
return configMap[key];
}
//_____________________________________________________________________________
int ConfigDictionary::GetInt(std::string key)throw(std::string){
//Extracts integer from given key
//(if it exist, otherwise raises exception)
return Get<int>(key);
int ConfigDictionary::GetInt(std::string key) {
// Extracts integer from given key
// (if it exists, otherwise raises exception)
try {
return Get<int>(key);
} catch (const std::string& message) {
// Catch the exception thrown by Get<int> and re-throw it as std::runtime_error
throw std::runtime_error(message);
}
}
//_____________________________________________________________________________
double ConfigDictionary::GetDouble(std::string key)throw(std::string){
double ConfigDictionary::GetDouble(std::string key){
//Extracts double precision floating number from given key
//(if it exist, otherwise raises exception)
return Get<double>(key);
try
{
return Get<double>(key);
} catch (const std::string& message) {
// Catch the exception thrown by Get<int> and re-throw it as std::runtime_error
throw std::runtime_error(message);
}
}
//_____________________________________________________________________________
bool ConfigDictionary::GetBool(std::string key)throw(std::string){
bool ConfigDictionary::GetBool(std::string key){
//Extracts boolean from given key
//(if it exist, otherwise raises exception)
//Differs from template to make it more readable.
// Check if the key exists in the config map
if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetBool",
"Couldn't find the key: %s!",key.c_str());
throw(key);
throw std::runtime_error("Couldn't find the key: " + key);
}
//Convert string to bool:
if (configMap[key].compare("true") == 0)
return true;
else return false;
else
return false;
}
//_____________________________________________________________________________
......
......@@ -33,10 +33,10 @@ public:
//These throw errors if couldn't find key:
//Most of methods below are just using templates to
//make them usable in Cint.
std::string GetString(std::string)throw(std::string);
int GetInt(std::string)throw(std::string);
double GetDouble(std::string)throw(std::string);
bool GetBool(std::string)throw(std::string);
std::string GetString(std::string);
int GetInt(std::string);
double GetDouble(std::string);
bool GetBool(std::string);
//These will always set 'something' into map:
void SetString(std::string,std::string);
......@@ -50,7 +50,7 @@ public:
//_________________________________________________________________________
template <class T>
T Get(std::string key) throw (std::string) {
T Get(std::string key) {
//This method will get object of any class
//that was - presumably - stored before in string format in CD.
//Object needs to have proper >> operator.
......@@ -62,11 +62,20 @@ public:
Error( "ConfigDictionary::Get",
"Couldn't find the key: %s!",
key.c_str());
throw(key);
throw std::runtime_error("Couldn't find the key: " + key);
}
// Use std::istringstream to convert the string to the desired type
std::istringstream inStream(configMap[key]);
T item;
// Extract the value from the stringstream
inStream >> item;
// Check if extraction failed
if (inStream.fail()) {
// Throw std::runtime_error with an informative message
throw std::runtime_error("Failed to extract value for key: " + key);
}
// Return the extracted item
return item;
}
......@@ -83,29 +92,39 @@ public:
//_________________________________________________________________________
template <class T>
int GetArray(std::string key,std::vector<T> & output)throw(std::string){
int GetArray(std::string key,std::vector<T> & output){
//Preconditions: T must have >> operator
//Effect: searches for key in map and pushes values stored in it into output vector
//Returns: number of elements pushed into vector
int retNumber = 0;
int retNumber = 0; // Counter for the number of elements pushed into the vector
// Check if the key exists in the config map
if (configMap.find(key) == configMap.end()){
Error( "ConfigDictionary::GetInt",
"Couldn't find the key: %s!",key.c_str());
throw(key);
throw std::runtime_error("Couldn't find the key: " + key);
}
// Create a string stream from the value associated with the key
std::istringstream arrayString(configMap[key]);
// Temporary string to hold each item from the string stream
std::string itemString;
//Dangerous - maybe? - exceptions for ss not handled...
while (arrayString){
std::getline(arrayString,itemString,ARRAY_DELIM);
std::stringstream itemStream(itemString);
if (itemString.length() > 0){
T item;
itemStream>>item;
output.push_back(item);
retNumber++;
// Loop to extract each item from the string stream
while (std::getline(arrayString,itemString,ARRAY_DELIM)){
std::stringstream itemStream(itemString); // Create a string stream from the item string
if (!itemString.empty()) { // Check if the item string is not empty
T item; // Temporary variable to hold the converted item
itemStream >> item; // Extract the item from the string stream
output.push_back(item); // Push the item into the output vector
retNumber++; // Increment the counter
}
}
// Return the number of elements pushed into the vector
return retNumber;
}
......
......@@ -51,23 +51,22 @@ clean_htmldoc:
clean:
-$(RM) $(UTILITIESOBJS) $(UTILITIESCPP_DEPS)
-$(RM) $(UTILITIES)/UtilitiesDict.* libUtilities.so
-$(RM) $(UTILITIES)/UtilitiesDict.* libUtilities.so $(UTILITIES)/*.pcm
-@echo ' '
-$(RM) $(ACULDATAOBJS) $(ACULDATACPP_DEPS)
-$(RM) $(ACULDATA)/AculDataDict.* *.pcm $(ACULDATA)/*.pcm
-$(RM) libAculData.so
-@echo ' '
-$(RM) $(ACULCALIBOBJS) $(ACULCALIBCPP_DEPS)
-$(RM) $(ACULCALIB)/AculCalibDict.* libAculCalib.so
-$(RM) $(ACULCALIB)/AculCalibDict.* libAculCalib.so $(ACULCALIB)/*.pcm
-@echo ' '
-$(RM) $(TELOSSOBJS) $(TELOSSCPP_DEPS)
-$(RM) $(TELOSS)/TELossDict.* *.pcm $(TELOSS)/*.pcm
-$(RM) $(TELOSS)/TELossDict.* *.pcm $(TELOSS)/*.pcm $(TELOSS)/*.pcm
-$(RM) libTELoss.so
-@echo ' '
-$(RM) htmldoc
-@echo ' '
# <<<<<<< HEAD
# Those *Dictionary* files below need special treating:
$(UTILITIES)/UtilitiesDict.cpp:
-@echo 'Pre-building UtilitiesDict.cpp and UtilitiesDict.h files'
......@@ -98,28 +97,6 @@ $(TELOSS)/TELossDict.cpp:
-ln -s $(TELOSS)/TELossDict_rdict.pcm .
-@echo ' '
# =======
# Those *Cint* files below need special treating:
# $(UTILITIES)/UtilitiesDict.cpp:
# -@echo 'Pre-building UtilitiesDict.cpp and UtilitiesDict.h files'
# -rootcint -f $(UTILITIES)/UtilitiesDict.cpp -c -p $(UTILITIES_HEADERS)
# -@echo ' '
# $(ACULDATA)/AculDataCint.cpp:
# -@echo 'Pre-building AculDataCint.cpp and AculDataCint.h files'
# -rootcint -f $(ACULDATA)/AculDataCint.cpp -c -p $(ACULDATA_HEADERS)
# -@echo ' '
# $(ACULCALIB)/AculCalibDict.cpp:
# -@echo 'Pre-building AculCalibDict.cpp and AculCalibDict.h files'
# -rootcint -f $(ACULCALIB)/AculCalibDict.cpp -c -p $(ACULCALIB_HEADERS)
# -@echo ' '
# $(TELOSS)/TELossCint.cpp:
# -@echo 'Pre-building TELossCint.cpp and TELossCint.h files'
# -rootcint -f $(TELOSS)/TELossCint.cpp -c -p $(TELOSS)/TELoss.h $(TELOSS)/linkdef.h
# >>>>>>> newArch
#*.so files
libUtilities.so: $(UTILITIESOBJS)
@echo 'Building target: $@'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment