-
Notifications
You must be signed in to change notification settings - Fork 17
CHG: MAssembly hardening and unit tests #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop/em
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,35 +29,23 @@ | |||||
| // Standard libs: | ||||||
| #include <iostream> | ||||||
| #include <sstream> | ||||||
| #include <vector> | ||||||
| #include <csignal> | ||||||
| using namespace std; | ||||||
|
|
||||||
| // ROOT libs: | ||||||
| #include "TROOT.h" | ||||||
| #include "TCanvas.h" | ||||||
| #include "TView.h" | ||||||
| #include "TGMsgBox.h" | ||||||
| #include "TH2.h" | ||||||
| #include "TCanvas.h" | ||||||
| #include "TApplication.h" | ||||||
| #include "TRandom.h" | ||||||
|
|
||||||
| // MEGAlib libs: | ||||||
| #include "MGlobal.h" | ||||||
| #include "MAssert.h" | ||||||
| #include "MStreams.h" | ||||||
| #include "MString.h" | ||||||
| #include "MTimer.h" | ||||||
| #include "MFile.h" | ||||||
|
|
||||||
| // Nuclearizer libs: | ||||||
| #include "MFretalonRegistry.h" | ||||||
| #include "MReadOutDataTAC.h" | ||||||
| #include "MReadOutDataEnergy.h" | ||||||
| #include "MReadOutAssembly.h" | ||||||
| #include "MModule.h" | ||||||
| #include "MGUIExpoCombinedViewer.h" | ||||||
| #include "MModuleTransmitterRealta.h" | ||||||
| #include "MModuleLoaderSimulationsCosima.h" | ||||||
| #include "MModuleLoaderMeasurementsROA.h" | ||||||
|
|
@@ -96,13 +84,13 @@ ClassImp(MAssembly) | |||||
| MAssembly::MAssembly() | ||||||
| { | ||||||
| // standard constructor | ||||||
|
|
||||||
| m_Interrupt = false; | ||||||
|
|
||||||
| m_UseGui = true; | ||||||
|
|
||||||
| m_HasCommandLineError = false; | ||||||
|
|
||||||
| g_Verbosity = c_Error; | ||||||
| //! Register new read out data: | ||||||
|
|
||||||
| // Register new read-out data: | ||||||
| MReadOutDataTAC TAC; | ||||||
| MFretalonRegistry::Instance().Register(TAC); | ||||||
|
|
||||||
|
|
@@ -111,16 +99,16 @@ MAssembly::MAssembly() | |||||
|
|
||||||
| // Create the supervisor | ||||||
| m_Supervisor = MSupervisor::GetSupervisor(); | ||||||
|
|
||||||
| // Fixed seed to reproduce DEE results | ||||||
| gRandom->SetSeed(20170912); | ||||||
|
|
||||||
| MString Cfg = "~/.nuclearizer.cfg"; | ||||||
| MFile::ExpandFileName(Cfg); | ||||||
| m_Supervisor->SetConfigurationFileName(Cfg); | ||||||
|
|
||||||
| m_Supervisor->UseMultiThreading(true); | ||||||
|
|
||||||
| m_Supervisor->AddAvailableModule(new MModuleLoaderSimulationsCosima()); | ||||||
| m_Supervisor->AddAvailableModule(new MModuleLoaderMeasurementsROA()); | ||||||
| m_Supervisor->AddAvailableModule(new MModuleLoaderMeasurementsHDF()); | ||||||
|
|
@@ -135,7 +123,7 @@ MAssembly::MAssembly() | |||||
| m_Supervisor->AddAvailableModule(new MModuleStripPairingMultiRoundChiSquare()); | ||||||
| m_Supervisor->AddAvailableModule(new MModuleStripPairingChiSquare()); | ||||||
| m_Supervisor->AddAvailableModule(new MModuleDepthCalibration()); | ||||||
|
|
||||||
| m_Supervisor->AddAvailableModule(new MModuleEventSaver()); | ||||||
| m_Supervisor->AddAvailableModule(new MModuleSaverMeasurementsL0()); | ||||||
| m_Supervisor->AddAvailableModule(new MModuleSaverMeasurementsFITS()); | ||||||
|
|
@@ -152,7 +140,7 @@ MAssembly::MAssembly() | |||||
| m_Supervisor->AddAvailableModule(new MModuleDiagnosticsEnergyPerStrip()); | ||||||
|
|
||||||
| m_Supervisor->Load(); | ||||||
|
|
||||||
| m_Supervisor->SetUIProgramName("Nuclearizer"); | ||||||
| m_Supervisor->SetUIPicturePath("$(NUCLEARIZER)/resource/icons/Nuclearizer.xpm"); | ||||||
| m_Supervisor->SetUISubTitle("The detector calibrator of the COmpton Spectrometer and Imager, COSI"); | ||||||
|
|
@@ -180,9 +168,9 @@ bool MAssembly::ParseCommandLine(int argc, char** argv) | |||||
| Usage<<endl; | ||||||
| Usage<<" Usage: Nuclearizer <options>"<<endl; | ||||||
| Usage<<endl; | ||||||
| Usage<<" -c --configuration <filename>.xml.cfg:"<<endl; | ||||||
| Usage<<" -c --configuration <filename>.cfg:"<<endl; | ||||||
| Usage<<" Use this file as configuration file."<<endl; | ||||||
| Usage<<" If no configuration file is give ~/.nuclearizer.xml.cfg is used"<<endl; | ||||||
| Usage<<" If no configuration file is given ~/.nuclearizer.cfg is used"<<endl; | ||||||
| Usage<<" -C --change-configuration <pattern>:"<<endl; | ||||||
| Usage<<" Replace any value in the configuration file (-C can be used multiple times)"<<endl; | ||||||
| Usage<<" E.g. to change the roa file, one would set pattern to:"<<endl; | ||||||
|
|
@@ -197,77 +185,120 @@ bool MAssembly::ParseCommandLine(int argc, char** argv) | |||||
| Usage<<" Perform a test run to see if nuclearizer can be started up correctly."<<endl; | ||||||
| Usage<<" -v --verbosity:"<<endl; | ||||||
| Usage<<" Verbosity: 0: Quiet, 1: Errors, 2: Warnings, 3: Info"<<endl; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe for clarity (there's many colons here):
Suggested change
? |
||||||
| Usage<<" -h --help:"<<endl; | ||||||
| Usage<<" You know the answer..."<<endl; | ||||||
| Usage<<" -h --help -? ?:"<<endl; | ||||||
| Usage<<" Print these command line options"<<endl; | ||||||
| Usage<<" Help gets preference over all other options"<<endl; | ||||||
| Usage<<endl; | ||||||
|
|
||||||
|
|
||||||
| // Each call starts without an error, otherwise an error of an earlier call would stick | ||||||
| m_HasCommandLineError = false; | ||||||
|
|
||||||
| // Store some options temporarily: | ||||||
| MString Option; | ||||||
|
|
||||||
| // Check for help | ||||||
| for (int i = 1; i < argc; i++) { | ||||||
| Option = argv[i]; | ||||||
| if (Option == "-h" || Option == "--help" || Option == "?" || Option == "-?") { | ||||||
| if (Option == "--help" || Option == "-h" || Option == "-?" || Option == "?") { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of interest: why was the order of the |
||||||
| cout<<Usage.str()<<endl; | ||||||
| return false; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // First check if all options are ok: | ||||||
| for (int i = 1; i < argc; i++) { | ||||||
| Option = argv[i]; | ||||||
|
|
||||||
| // Single argument | ||||||
| if (Option == "-c" || Option == "--configuration" || | ||||||
| Option == "-g" || Option == "--geometry" || | ||||||
| Option == "-m" || Option == "--multithreading") { | ||||||
| if (!((argc > i+1) && argv[i+1][0] != '-')){ | ||||||
| cout<<"Error: Option "<<argv[i][1]<<" needs a second argument!"<<endl; | ||||||
| if (Option == "--configuration" || Option == "-c" || | ||||||
| Option == "--change-configuration" || Option == "-C" || | ||||||
| Option == "--geometry" || Option == "-g" || | ||||||
| Option == "--multithreading" || Option == "-m" || | ||||||
| Option == "--verbosity" || Option == "-v") { | ||||||
| if (argc <= i + 1 || argv[i + 1][0] == '-') { | ||||||
| cout<<"ERROR: Command-line parser: Option "<<Option<<" needs a second argument!"<<endl; | ||||||
| cout<<Usage.str()<<endl; | ||||||
| m_HasCommandLineError = true; | ||||||
| return false; | ||||||
| } | ||||||
| } | ||||||
| // No argument | ||||||
| else if (Option == "--auto" || Option == "-a" || | ||||||
| Option == "--test" || Option == "-t") { | ||||||
| // Nothing to check | ||||||
| } | ||||||
| // Anything else which looks like an option is unknown - the arguments of the | ||||||
| // above options never start with a "-", thus they cannot end up here | ||||||
| else if (Option.BeginsWith("-") == true) { | ||||||
| cout<<"WARNING: Command-line parser: Unknown option: "<<Option<<endl; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Now parse all low level options | ||||||
| for (int i = 1; i < argc; i++) { | ||||||
| Option = argv[i]; | ||||||
| if (Option == "--configuration" || Option == "-c") { | ||||||
| m_Supervisor->Load(argv[++i]); | ||||||
| cout<<"Command-line parser: Use configuration file "<<argv[i]<<endl; | ||||||
| // If the configuration file cannot be read, we continue with an empty one | ||||||
| if (m_Supervisor->Load(argv[++i]) == false) { | ||||||
| cout<<"WARNING: Command-line parser: Unable to load configuration file "<<argv[i]<<endl; | ||||||
| } else { | ||||||
| cout<<"Command-line parser: Use configuration file "<<argv[i]<<endl; | ||||||
| } | ||||||
| } else if (Option == "--verbosity" || Option == "-v") { | ||||||
| g_Verbosity = atoi(argv[++i]); | ||||||
| const MString Value = argv[++i]; | ||||||
| if (Value.Is<int>() == false) { | ||||||
| cout<<"ERROR: Command-line parser: Option "<<Option<<" needs an integer argument, not \""<<Value<<"\"!"<<endl; | ||||||
| cout<<Usage.str()<<endl; | ||||||
| m_HasCommandLineError = true; | ||||||
| return false; | ||||||
| } | ||||||
| int Verbosity = Value.ToInt(); | ||||||
| if (Verbosity < c_Quiet || Verbosity > c_Info) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've seen in megalib that there is also |
||||||
| cout<<"ERROR: Command-line parser: Option "<<Option<<" needs an argument between "<<c_Quiet<<" and "<<c_Info<<", not \""<<Value<<"\"!"<<endl; | ||||||
| cout<<Usage.str()<<endl; | ||||||
| m_HasCommandLineError = true; | ||||||
| return false; | ||||||
| } | ||||||
| g_Verbosity = Verbosity; | ||||||
| cout<<"Command-line parser: Verbosity "<<g_Verbosity<<endl; | ||||||
| } else if (Option == "--multithreading" || Option == "-m") { | ||||||
| m_Supervisor->UseMultiThreading((atoi(argv[++i]) != 0 ? true : false)); | ||||||
| cout<<"Command-line parser: Using multithreading: "<<(atoi(argv[i]) != 0 ? "yes" : "no")<<endl; | ||||||
| const MString Value = argv[++i]; | ||||||
| if (Value.Is<int>() == false) { | ||||||
| cout<<"ERROR: Command-line parser: Option "<<Option<<" needs an integer argument, not \""<<Value<<"\"!"<<endl; | ||||||
| cout<<Usage.str()<<endl; | ||||||
| m_HasCommandLineError = true; | ||||||
| return false; | ||||||
| } | ||||||
| const bool UseMultiThreading = (Value.ToInt() != 0); | ||||||
| m_Supervisor->UseMultiThreading(UseMultiThreading); | ||||||
| cout<<"Command-line parser: Using multithreading: "<<(UseMultiThreading == true ? "yes" : "no")<<endl; | ||||||
| } else if (Option == "--test" || Option == "-t") { | ||||||
| // Parse later | ||||||
| } else if (Option == "--auto" || Option == "-a") { | ||||||
| // Parse later | ||||||
| } | ||||||
|
Comment on lines
275
to
279
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this? (I guess |
||||||
| } | ||||||
|
|
||||||
| // Look if we need to change the configuration | ||||||
| for (int i = 1; i < argc; i++) { | ||||||
| Option = argv[i]; | ||||||
| if (Option == "--change-configuration" || Option == "-C") { | ||||||
| if (m_Supervisor->ChangeConfiguration(argv[++i]) == false) { | ||||||
| cout<<"ERROR: Command-line parser: Unable to change this configuration value: "<<argv[i]<<endl; | ||||||
| cout<<"ERROR: Command-line parser: Unable to change this configuration value: "<<argv[i]<<endl; | ||||||
| } else { | ||||||
| cout<<"Command-line parser: Changing this configuration value: "<<argv[i]<<endl; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| for (int i = 1; i < argc; i++) { | ||||||
| Option = argv[i]; | ||||||
| if (Option == "--geometry" || Option == "-g") { | ||||||
| m_Supervisor->SetGeometryFileName(argv[++i]); | ||||||
| cout<<"Command-line parser: Use geometry file "<<argv[i]<<endl; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Now parse all high level options | ||||||
| for (int i = 1; i < argc; i++) { | ||||||
| Option = argv[i]; | ||||||
|
|
@@ -279,21 +310,21 @@ bool MAssembly::ParseCommandLine(int argc, char** argv) | |||||
| m_Supervisor->Exit(); | ||||||
| return false; | ||||||
| } else if (Option == "--test" || Option == "-t") { | ||||||
| m_UseGui = false; | ||||||
| gROOT->SetBatch(true); | ||||||
| m_Supervisor->UseUI(false); | ||||||
| m_Supervisor->Analyze(true); | ||||||
| m_Supervisor->Exit(); | ||||||
| return false; | ||||||
| } | ||||||
| m_UseGui = false; | ||||||
| gROOT->SetBatch(true); | ||||||
| m_Supervisor->UseUI(false); | ||||||
| m_Supervisor->Analyze(true); | ||||||
| m_Supervisor->Exit(); | ||||||
| return false; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (m_UseGui == true) { | ||||||
| if (m_Supervisor->LaunchUI() == false) { | ||||||
| return false; | ||||||
| return false; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About
m_Interrupt: is it correct that this was just not used before? I can only findm_Interruptbeing used (but also defined) in theappsnow.