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 *.root
*.cal *.cal
#Ignore VS code stuff
.vscode/
# config.ini
\ No newline at end of file
...@@ -161,46 +161,61 @@ void ConfigDictionary::FromString(std::string params){ ...@@ -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 //Extracts string from given key
//(if it exist, otherwise raises exception) //(if it exist, otherwise raises exception)
//This works also for long strings with white spaces in it! //This works also for long strings with white spaces in it!
if (configMap.find(key) == configMap.end()){ if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetString", Error("ConfigDictionary::GetString",
"Couldn't find the key: %s!",key.c_str()); "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]; return configMap[key];
} }
//_____________________________________________________________________________ //_____________________________________________________________________________
int ConfigDictionary::GetInt(std::string key)throw(std::string){ int ConfigDictionary::GetInt(std::string key) {
//Extracts integer from given key // Extracts integer from given key
//(if it exist, otherwise raises exception) // (if it exists, otherwise raises exception)
try {
return Get<int>(key); 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 //Extracts double precision floating number from given key
//(if it exist, otherwise raises exception) //(if it exist, otherwise raises exception)
try
{
return Get<double>(key); 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 //Extracts boolean from given key
//(if it exist, otherwise raises exception) //(if it exist, otherwise raises exception)
//Differs from template to make it more readable. //Differs from template to make it more readable.
// Check if the key exists in the config map
if (configMap.find(key) == configMap.end()){ if (configMap.find(key) == configMap.end()){
Error("ConfigDictionary::GetBool", Error("ConfigDictionary::GetBool",
"Couldn't find the key: %s!",key.c_str()); "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: //Convert string to bool:
if (configMap[key].compare("true") == 0) if (configMap[key].compare("true") == 0)
return true; return true;
else return false; else
return false;
} }
//_____________________________________________________________________________ //_____________________________________________________________________________
......
...@@ -33,10 +33,10 @@ public: ...@@ -33,10 +33,10 @@ public:
//These throw errors if couldn't find key: //These throw errors if couldn't find key:
//Most of methods below are just using templates to //Most of methods below are just using templates to
//make them usable in Cint. //make them usable in Cint.
std::string GetString(std::string)throw(std::string); std::string GetString(std::string);
int GetInt(std::string)throw(std::string); int GetInt(std::string);
double GetDouble(std::string)throw(std::string); double GetDouble(std::string);
bool GetBool(std::string)throw(std::string); bool GetBool(std::string);
//These will always set 'something' into map: //These will always set 'something' into map:
void SetString(std::string,std::string); void SetString(std::string,std::string);
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
//_________________________________________________________________________ //_________________________________________________________________________
template <class T> template <class T>
T Get(std::string key) throw (std::string) { T Get(std::string key) {
//This method will get object of any class //This method will get object of any class
//that was - presumably - stored before in string format in CD. //that was - presumably - stored before in string format in CD.
//Object needs to have proper >> operator. //Object needs to have proper >> operator.
...@@ -62,11 +62,20 @@ public: ...@@ -62,11 +62,20 @@ public:
Error( "ConfigDictionary::Get", Error( "ConfigDictionary::Get",
"Couldn't find the key: %s!", "Couldn't find the key: %s!",
key.c_str()); 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]); std::istringstream inStream(configMap[key]);
T item; T item;
// Extract the value from the stringstream
inStream >> item; 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; return item;
} }
...@@ -83,29 +92,39 @@ public: ...@@ -83,29 +92,39 @@ public:
//_________________________________________________________________________ //_________________________________________________________________________
template <class T> 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 //Preconditions: T must have >> operator
//Effect: searches for key in map and pushes values stored in it into output vector //Effect: searches for key in map and pushes values stored in it into output vector
//Returns: number of elements pushed into 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()){ if (configMap.find(key) == configMap.end()){
Error( "ConfigDictionary::GetInt", Error( "ConfigDictionary::GetInt",
"Couldn't find the key: %s!",key.c_str()); "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]); std::istringstream arrayString(configMap[key]);
// Temporary string to hold each item from the string stream
std::string itemString; std::string itemString;
//Dangerous - maybe? - exceptions for ss not handled... //Dangerous - maybe? - exceptions for ss not handled...
while (arrayString){ // Loop to extract each item from the string stream
std::getline(arrayString,itemString,ARRAY_DELIM); while (std::getline(arrayString,itemString,ARRAY_DELIM)){
std::stringstream itemStream(itemString); std::stringstream itemStream(itemString); // Create a string stream from the item string
if (itemString.length() > 0){ if (!itemString.empty()) { // Check if the item string is not empty
T item; T item; // Temporary variable to hold the converted item
itemStream>>item; itemStream >> item; // Extract the item from the string stream
output.push_back(item); output.push_back(item); // Push the item into the output vector
retNumber++; retNumber++; // Increment the counter
} }
} }
// Return the number of elements pushed into the vector
return retNumber; return retNumber;
} }
......
...@@ -51,23 +51,22 @@ clean_htmldoc: ...@@ -51,23 +51,22 @@ clean_htmldoc:
clean: clean:
-$(RM) $(UTILITIESOBJS) $(UTILITIESCPP_DEPS) -$(RM) $(UTILITIESOBJS) $(UTILITIESCPP_DEPS)
-$(RM) $(UTILITIES)/UtilitiesDict.* libUtilities.so -$(RM) $(UTILITIES)/UtilitiesDict.* libUtilities.so $(UTILITIES)/*.pcm
-@echo ' ' -@echo ' '
-$(RM) $(ACULDATAOBJS) $(ACULDATACPP_DEPS) -$(RM) $(ACULDATAOBJS) $(ACULDATACPP_DEPS)
-$(RM) $(ACULDATA)/AculDataDict.* *.pcm $(ACULDATA)/*.pcm -$(RM) $(ACULDATA)/AculDataDict.* *.pcm $(ACULDATA)/*.pcm
-$(RM) libAculData.so -$(RM) libAculData.so
-@echo ' ' -@echo ' '
-$(RM) $(ACULCALIBOBJS) $(ACULCALIBCPP_DEPS) -$(RM) $(ACULCALIBOBJS) $(ACULCALIBCPP_DEPS)
-$(RM) $(ACULCALIB)/AculCalibDict.* libAculCalib.so -$(RM) $(ACULCALIB)/AculCalibDict.* libAculCalib.so $(ACULCALIB)/*.pcm
-@echo ' ' -@echo ' '
-$(RM) $(TELOSSOBJS) $(TELOSSCPP_DEPS) -$(RM) $(TELOSSOBJS) $(TELOSSCPP_DEPS)
-$(RM) $(TELOSS)/TELossDict.* *.pcm $(TELOSS)/*.pcm -$(RM) $(TELOSS)/TELossDict.* *.pcm $(TELOSS)/*.pcm $(TELOSS)/*.pcm
-$(RM) libTELoss.so -$(RM) libTELoss.so
-@echo ' ' -@echo ' '
-$(RM) htmldoc -$(RM) htmldoc
-@echo ' ' -@echo ' '
# <<<<<<< HEAD
# Those *Dictionary* files below need special treating: # Those *Dictionary* files below need special treating:
$(UTILITIES)/UtilitiesDict.cpp: $(UTILITIES)/UtilitiesDict.cpp:
-@echo 'Pre-building UtilitiesDict.cpp and UtilitiesDict.h files' -@echo 'Pre-building UtilitiesDict.cpp and UtilitiesDict.h files'
...@@ -98,28 +97,6 @@ $(TELOSS)/TELossDict.cpp: ...@@ -98,28 +97,6 @@ $(TELOSS)/TELossDict.cpp:
-ln -s $(TELOSS)/TELossDict_rdict.pcm . -ln -s $(TELOSS)/TELossDict_rdict.pcm .
-@echo ' ' -@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 #*.so files
libUtilities.so: $(UTILITIESOBJS) libUtilities.so: $(UTILITIESOBJS)
@echo 'Building target: $@' @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