Skip to content
Snippets Groups Projects
Commit 7441d2e1 authored by adrien-matta's avatar adrien-matta
Browse files

* Adding safety features to nptool-wizard

        - No check that a detector with similar name does not exist
parent 3574b6be
No related branches found
No related tags found
No related merge requests found
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<dlfcn.h>
#include<dirent.h>
#include"NPDetectorFactory.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <dlfcn.h>
#include <dirent.h>
#include "NPDetectorFactory.h"
int main(int argc , char** argv){
int return_value;
......
// C++ headers
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <set>
#include <string>
#include <ctime>
#include <stdlib.h>
#include <dlfcn.h>
#include <dirent.h>
// NPTool header
#include "NPVDetector.h"
// A function to get the list of existing detector
void GetListOfDetector(std::set<string>& LowerName){
DIR *dir;
struct dirent *ent;
string path = getenv("NPTOOL");
path += "/NPLib/Detectors";
string name;
if ((dir = opendir (path.c_str())) != NULL) {
while ((ent = readdir (dir)) != NULL) {
name= ent->d_name ;
std::transform(name.begin(), name.end(),name.begin(), ::tolower);
LowerName.insert(name);
}
closedir (dir);
}
}
//// The main program
int main(int argc , char** argv){
// check for the force flag
bool force = false;
for(unsigned int i = 0 ; i < argc ; i++ ){
string flag = argv[i];
if(flag=="-f")
force = true;
}
// List of existing detector name and close name
std::set<string> LowerName;
GetListOfDetector(LowerName);
// Find the different paths
std::string path = getenv("NPTOOL");
std::string pathNPL = path + "/NPLib/Detectors/";
......@@ -88,6 +124,17 @@ int main(int argc , char** argv){
std::cout << " This utility will create a new detector skeleton"<< std::endl;
std::cout << "\033[1;36m-> What is the detector name ? \033[0m";
std::cin >> answer;
// Cheking if the name does not already exist or is close to something else:
if(!force){
string lname = answer;
std::transform(lname.begin(), lname.end(),lname.begin(), ::tolower);
if(LowerName.find(lname)!=LowerName.end()){
cout << "\033[1;31m**** ERROR : A detector with name close to \033[1;36m" << answer << " \033[1;31malready exist. use \033[1;36m-f\033[1;31m flag to force recreation.\033[0m" << endl;
exit(1);
}
}
std::cout << "\033[1;36m-> What is your name (firstname and surname)? \033[0m";
std::cin >> author;
getline(cin, buffer);
......@@ -98,10 +145,6 @@ int main(int argc , char** argv){
std::cout << std::endl << std::endl;
// Cheking if the name does not already exist or is close to something else:
// TODO //
//////////
// Creating the detector files name
std::string DataFile_h = "T"+answer+"Data.h";
std::string DataFile_cxx = "T"+answer+"Data.cxx";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment