41 #include <TApplication.h> 42 #include <TSAXParser.h> 46 #include "git-revision.h" 63 std::cout << std::endl <<
"usage: musrview <msr-file> [Options]";
64 std::cout << std::endl <<
" <msr-file>: msr/mlog input file";
65 std::cout << std::endl <<
" Options:";
66 std::cout << std::endl <<
" --help : display this help and exit.";
67 std::cout << std::endl <<
" --version : output version information and exit.";
68 std::cout << std::endl <<
" --show-dynamic-path : dumps the dynamic search paths and exit.";
69 std::cout << std::endl <<
" -f, --fourier: will directly present the Fourier transform of the <msr-file>.";
70 std::cout << std::endl <<
" -a, --avg: will directly present the averaged data/Fourier of the <msr-file>.";
71 std::cout << std::endl <<
" -1, --one_to_one: calculate theory points only at data points.";
72 std::cout << std::endl <<
" --<graphic-format-extension>: ";
73 std::cout << std::endl <<
" will produce a graphics-output-file without starting a root session.";
74 std::cout << std::endl <<
" the name is based on the <msr-file>, e.g. 3310.msr -> 3310_0.png";
75 std::cout << std::endl <<
" supported graphic-format-extension:";
76 std::cout << std::endl <<
" eps, pdf, gif, jpg, png, svg, xpm, root";
77 std::cout << std::endl <<
" example: musrview 3310.msr --png, will produce a files 3310_X.png";
78 std::cout << std::endl <<
" where 'X' stands for the plot number (starting form 0)";
79 std::cout << std::endl <<
" --ascii: ";
80 std::cout << std::endl <<
" will produce an ascii dump of the data and fit as plotted.";
81 std::cout << std::endl <<
" --timeout <timeout>: <timeout> given in seconds after which musrview terminates.";
82 std::cout << std::endl <<
" If <timeout> <= 0, no timeout will take place. Default <timeout> is 0.";
83 std::cout << std::endl << std::endl;
104 int main(
int argc,
char *argv[])
107 bool show_syntax =
false;
111 bool fourier =
false;
113 bool theoAtData =
false;
114 bool graphicsOutput =
false;
115 bool asciiOutput =
false;
116 char graphicsExtension[128];
119 memset(fileName,
'\0',
sizeof(fileName));
122 const char *dsp = gSystem->GetDynamicPath();
123 if (strstr(dsp,
"/usr/local/lib") ==
nullptr)
124 gSystem->AddDynamicPath(
"/usr/local/lib");
131 for (
int i=1; i<argc; i++) {
132 if (strstr(argv[i],
".msr") || strstr(argv[i],
".mlog")) {
133 if (strlen(fileName) == 0) {
134 strcpy(fileName, argv[i]);
136 std::cerr << std::endl <<
"**ERROR** only one file name allowed." << std::endl;
140 }
else if (!strcmp(argv[i],
"--version")) {
142 #ifdef HAVE_GIT_REV_H 143 std::cout << std::endl <<
"musrview version: " << PACKAGE_VERSION <<
", git-branch: " << GIT_BRANCH <<
", git-rev: " << GIT_CURRENT_SHA1 <<
" (" << BUILD_TYPE <<
"), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
145 std::cout << std::endl <<
"musrview version: " << PACKAGE_VERSION <<
" (" << BUILD_TYPE <<
"), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
148 #ifdef HAVE_GIT_REV_H 149 std::cout << std::endl <<
"musrview git-branch: " << GIT_BRANCH <<
", git-rev: " << GIT_CURRENT_SHA1 << std::endl << std::endl;
151 std::cout << std::endl <<
"musrview version: unknown." << std::endl << std::endl;
155 }
else if (!strcmp(argv[i],
"--show-dynamic-path")) {
156 std::cout << std::endl <<
"musrview: internal dynamic search paths for shared libraries/root dictionaries:";
157 std::cout << std::endl <<
" '" << gSystem->GetDynamicPath() <<
"'" << std::endl << std::endl;
159 }
else if (!strcmp(argv[i],
"--help")) {
162 }
else if (!strcmp(argv[i],
"-f") || !strcmp(argv[i],
"--fourier")) {
164 }
else if (!strcmp(argv[i],
"-a") || !strcmp(argv[i],
"--avg")) {
166 }
else if (!strcmp(argv[i],
"-1") || !strcmp(argv[i],
"--one_to_one")) {
168 }
else if (!strcmp(argv[i],
"--eps") || !strcmp(argv[i],
"--pdf") || !strcmp(argv[i],
"--gif") ||
169 !strcmp(argv[i],
"--jpg") || !strcmp(argv[i],
"--png") || !strcmp(argv[i],
"--svg") ||
170 !strcmp(argv[i],
"--xpm") || !strcmp(argv[i],
"--root")) {
172 graphicsOutput =
true;
173 strcpy(graphicsExtension, argv[i]+2);
174 }
else if (!strcmp(argv[i],
"--ascii")) {
176 }
else if (!strcmp(argv[i],
"--timeout")) {
178 TString str(argv[i+1]);
203 std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
204 std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>();
205 if (!startupHandler->StartupFileFound()) {
206 std::cerr << std::endl <<
">> musrview **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
207 std::cerr << std::endl;
210 saxParser->ConnectToHandler(
"PStartupHandler", startupHandler.get());
217 std::cerr << std::endl <<
">> musrview **WARNING** Reading/parsing musrfit_startup.xml failed.";
218 std::cerr << std::endl <<
">> Any graph will appear with random symbols and colors!";
219 std::cerr << std::endl;
221 startupHandler->CheckLists();
226 std::unique_ptr<PMsrHandler> msrHandler = std::make_unique<PMsrHandler>(fileName);
227 status = msrHandler->ReadMsrFile();
231 std::cerr << std::endl <<
">> musrview **ERROR** couldn't find '" << fileName <<
"'" << std::endl << std::endl;
234 std::cerr << std::endl <<
">> musrview **SYNTAX ERROR** in file " << fileName <<
", full stop here." << std::endl << std::endl;
237 std::cerr << std::endl <<
">> musrview **UNKNOWN ERROR** when trying to read the msr-file" << std::endl << std::endl;
243 PMsrPlotList *msrPlotList = msrHandler->GetMsrPlotList();
246 for (
unsigned int i=0; i<msrPlotList->size(); i++) {
247 for (
unsigned int j=0; j<msrPlotList->at(i).fRuns.size(); j++) {
250 for (
unsigned int k=0; k<plotList.size(); k++) {
251 if (msrPlotList->at(i).fRuns[j] ==
static_cast<int>(plotList[k])) {
257 plotList.push_back(static_cast<int>(msrPlotList->at(i).fRuns[j]));
263 std::unique_ptr<PRunDataHandler> dataHandler;
265 dataHandler = std::make_unique<PRunDataHandler>(msrHandler.get(), startupHandler->GetDataPathList());
267 dataHandler = std::make_unique<PRunDataHandler>(msrHandler.get());
269 dataHandler->ReadData();
271 success = dataHandler->IsAllDataAvailable();
273 std::cerr << std::endl <<
">> musrview **ERROR** Couldn't read all data files, will quit ..." << std::endl;
278 std::unique_ptr<PRunListCollection> runListCollection;
281 runListCollection = std::make_unique<PRunListCollection>(msrHandler.get(), dataHandler.get(), theoAtData);
282 for (
unsigned int i=0; i<msrHandler->GetMsrRunList()->size(); i++) {
285 for (
unsigned int j=0; j<plotList.size(); j++) {
286 if (static_cast<unsigned int>(plotList[j]) == i+1) {
292 success = runListCollection->Add(i,
kView);
294 std::cerr << std::endl <<
">> musrview **ERROR** Couldn't handle run no " << i <<
" ";
295 std::cerr << (*msrHandler->GetMsrRunList())[i].GetRunName()->Data();
305 if (graphicsOutput || asciiOutput) {
306 argv[argc] = (
char*)malloc(16*
sizeof(
char));
307 strcpy(argv[argc],
"-b");
310 TApplication app(
"App", &argc, argv);
312 std::vector<PMusrCanvas*> canvasVector;
316 for (
unsigned int i=0; i<msrHandler->GetMsrPlotList()->size(); i++) {
319 musrCanvas =
new PMusrCanvas(i, msrHandler->GetMsrTitle()->Data(),
320 10+i*100, 10+i*100, 800, 600,
321 startupHandler->GetFourierDefaults(),
322 startupHandler->GetMarkerList(),
323 startupHandler->GetColorList(),
324 graphicsOutput||asciiOutput,
325 fourier, avg, theoAtData);
327 musrCanvas =
new PMusrCanvas(i, msrHandler->GetMsrTitle()->Data(),
328 10+i*100, 10+i*100, 800, 600,
329 graphicsOutput||asciiOutput,
330 fourier, avg, theoAtData);
333 std::cerr << std::endl <<
">> musrview **SEVERE ERROR** Couldn't invoke all necessary objects, will quit.";
334 std::cerr << std::endl;
354 musrCanvas->Connect(
"Done(Int_t)",
"TApplication", &app,
"Terminate(Int_t)");
356 if (graphicsOutput) {
362 TString str(fileName);
363 str.Remove(str.Last(
'.'));
371 canvasVector.push_back(musrCanvas);
380 for (
unsigned int i=0; i<canvasVector.size(); i++) {
382 snprintf(canvasName,
sizeof(canvasName),
"fMainCanvas%d", i);
383 if (gROOT->GetListOfCanvases()->FindObject(canvasName) !=
nullptr) {
384 canvasVector[i]->~PMusrCanvas();
387 canvasVector.clear();
virtual void ExportData(const Char_t *fileName)
virtual void UpdateInfoPad()
#define PMUSR_MSR_RUN_ERROR
virtual void UpdateParamTheoryPad()
int main(int argc, char *argv[])
int parseXmlFile(TSAXParser *, const char *)
#define PMUSR_MSR_FILE_NOT_FOUND
std::vector< PMsrPlotStructure > PMsrPlotList
std::vector< Int_t > PIntVector
#define PMUSR_SYNTAX_REQUEST
#define PMUSR_DATA_FILE_READ_ERROR
const char * startup_path_name
#define PMUSR_MSR_SYNTAX_ERROR
virtual void SetMsrHandler(PMsrHandler *msrHandler)
virtual void SetRunListCollection(PRunListCollection *runList)
#define PMUSR_WRONG_STARTUP_SYNTAX
virtual void Done(Int_t status=0)
virtual void UpdateDataTheoryPad()
virtual void SetTimeout(Int_t ival)
virtual void SaveGraphicsAndQuit(Char_t *fileName, Char_t *graphicsFormat)