59 std::cout << std::endl <<
"usage: any2many [--help] : will show this help.";
60 std::cout << std::endl <<
" any2many --version : will show the git version.";
61 std::cout << std::endl <<
" any2many -f <filenameList-input> | -r <runList-input>";
62 std::cout << std::endl <<
" -c <convert-options> [-p <output-path>] [-y <year>]";
63 std::cout << std::endl <<
" [-o <outputFileName> | -t <in-template> <out-template>] [-s]";
64 std::cout << std::endl <<
" [-rebin <n>] [-z <compressed>]";
65 std::cout << std::endl <<
" -f <filenameList-input> : where <filenameList-input> is space";
66 std::cout << std::endl <<
" separeted a list of file names (not starting with a '-'),";
67 std::cout << std::endl <<
" e.g. 2010/lem10_his_0111.root 2010/lem10_his_0112.root";
68 std::cout << std::endl <<
" -o <outputFileName> : this option only makes sense, if <filenameList-input>";
69 std::cout << std::endl <<
" is a single input file name!";
70 std::cout << std::endl <<
" -r <runList-input> : can be:";
71 std::cout << std::endl <<
" (i) <run0>, <run1>, <run2>, ... <runN> : run numbers, e.g. 123 124";
72 std::cout << std::endl <<
" (ii) <run0>-<runN> : a range, e.g. 123-125 -> 123 124 125";
73 std::cout << std::endl <<
" (iii) <run0>:<runN>:<step> : a sequence, e.g. 123:127:2 -> 123 125 127";
74 std::cout << std::endl <<
" <step> will give the step width and has to be a positive number!";
75 std::cout << std::endl <<
" a <runList> can also combine (i)-(iii), e.g. 123 128-130 133, etc.";
76 std::cout << std::endl <<
" -t <in-template> <out-template> : ";
77 std::cout << std::endl <<
" <in-/out-template> : template file name. Needed for run-lists in";
78 std::cout << std::endl <<
" order to generate the proper file names. The following template";
79 std::cout << std::endl <<
" tags can be used: [yy] for year, and [rrrr] for the run number.";
80 std::cout << std::endl <<
" If the run number tag is used, the number of 'r' will give the";
81 std::cout << std::endl <<
" number of digits used with leading zeros, e.g. [rrrrrr] and run";
82 std::cout << std::endl <<
" number 123 will result in 000123. The same is true for the";
83 std::cout << std::endl <<
" year, i.e. [yyyy] will result in something like 1999.";
84 std::cout << std::endl <<
" -c <convert-options> : <inFormat> <outFormat>";
85 std::cout << std::endl <<
" <inFormat> : input data file format. Supported formats are:";
86 std::cout << std::endl <<
" MusrRoot, PSI-BIN, ROOT (LEM), MUD, NeXus, PSI-MDU, WKM";
87 std::cout << std::endl <<
" <outFormat> : ouput data file format. Supported formats are:";
88 std::cout << std::endl <<
" PSI-BIN, MusrRoot, MusrRootDir, ROOT, MUD, NeXus1-HDF4, NeXus1-HDF5, NeXus1-XML,";
89 std::cout << std::endl <<
" NeXus2-HDF4, NeXus2-HDF5, NeXus2-XML, WKM, ASCII";
90 std::cout << std::endl <<
" Comment: ROOT is superseeded by MusrRoot. If there is not a very good";
91 std::cout << std::endl <<
" reason, avoid it!";
92 std::cout << std::endl <<
" -h <histo-group-list> : This option is for MusrRoot input files only!";
93 std::cout << std::endl <<
" Select the the histo groups to be exported. <histo-group-list> is a space";
94 std::cout << std::endl <<
" separated list of the histo group, e.g. -h 0, 20 will try to export the histo";
95 std::cout << std::endl <<
" 0 (NPP) and 20 (PPC).";
96 std::cout << std::endl <<
" -p <output-path> : where <output-path> is the output path for the";
97 std::cout << std::endl <<
" converted files. If nothing is given, the current directory";
98 std::cout << std::endl <<
" will be used, unless the option '-s' is used.";
99 std::cout << std::endl <<
" -y <year> : if the option -y is used, here a year in the form 'yy' or 'yyyy' can";
100 std::cout << std::endl <<
" be given, if this is the case, any automatic file name";
101 std::cout << std::endl <<
" generation needs a year, this number will be used.";
102 std::cout << std::endl <<
" -s : with this option the output data file will be sent to the stdout.";
103 std::cout << std::endl <<
" -rebin <n> : where <n> is the number of bins to be packed";
104 std::cout << std::endl <<
" -z [g|b] <compressed> : where <compressed> is the output file name";
105 std::cout << std::endl <<
" (without extension) of the compressed data collection, and";
106 std::cout << std::endl <<
" 'g' will result in .tar.gz, and 'b' in .tar.bz2 files.";
107 std::cout << std::endl;
108 std::cout << std::endl <<
" If the template option '-t' is absent, the output file name will be";
109 std::cout << std::endl <<
" generated according to the input data file name, and the output data";
110 std::cout << std::endl <<
" format.";
111 std::cout << std::endl;
112 std::cout << std::endl <<
"NOTE to MusrRoot and MusrRootDir <outFormat>: MusrRoot will convert to the deprecated TFolder format,";
113 std::cout << std::endl <<
" whereas MusrRootDir will convert to the TDirectory based format. Typically MusrRootDir should be the";
114 std::cout << std::endl <<
" preferred MusrRoot-file-format output format.";
115 std::cout << std::endl;
116 std::cout << std::endl <<
"examples:" << std::endl;
117 std::cout << std::endl <<
" any2many -f 2010/lem10_his_0123.root -c ROOT ASCII -rebin 25";
118 std::cout << std::endl <<
" Will take the LEM ROOT file '2010/lem10_his_0123.root' rebin it with 25";
119 std::cout << std::endl <<
" and convert it to ASCII. The output file name will be";
120 std::cout << std::endl <<
" lem10_his_0123.ascii, and the file will be saved in the current directory." << std::endl;
121 std::cout << std::endl <<
" any2many -f 2010/lem10_his_0123.root -c MusrRoot NEXUS2-HDF5 -o 2010/lem10_his_0123_v2.nxs";
122 std::cout << std::endl <<
" Will take the MusrRoot file '2010/lem10_his_0123.root' ";
123 std::cout << std::endl <<
" and convert it to NeXus IDF V2. The output file name will be";
124 std::cout << std::endl <<
" lem10_his_0123_v2.nxs, and the file will be saved in the current directory." << std::endl;
125 std::cout << std::endl <<
" any2many -r 123 137 -c PSI-BIN MUD -t d[yyyy]/deltat_tdc_gps_[rrrr].bin \\";
126 std::cout << std::endl <<
" [rrrrrr].msr -y 2001";
127 std::cout << std::endl <<
" Will take the run 123 and 137, will generate the input file names:";
128 std::cout << std::endl <<
" d2001/deltat_tdc_gps_0123.bin and d2001/deltat_tdc_gps_0137.bin, and";
129 std::cout << std::endl <<
" output file names 000123.msr and 000137.msr" << std::endl;
130 std::cout << std::endl <<
" any2many -r 100-117 -c PSI-MDU ASCII -t d[yyyy]/deltat_tdc_alc_[rrrr].mdu \\";
131 std::cout << std::endl <<
" [rrr].ascii -y 2011 -s";
132 std::cout << std::endl <<
" Will take the runs 100 through 117 and convert the PSI-MDU input files to";
133 std::cout << std::endl <<
" ASCII output and instead of saving them into a file, they will be spit to";
134 std::cout << std::endl <<
" the standard output." << std::endl;
135 std::cout << std::endl <<
" any2many -r 100-117 -c NEXUS MusrRoot -t d[yyyy]/psi_gps_[rrrr].NXS \\";
136 std::cout << std::endl <<
" psi_[yyyy]_gps_[rrrr].root -z b psi_gps_run_100to117";
137 std::cout << std::endl <<
" Will take the runs 100 through 117 and convert the NEXUS input files";
138 std::cout << std::endl <<
" to MusrRoot output. Afterwards these new files will be collected in a";
139 std::cout << std::endl <<
" compressed archive psi_gps_run_100to117.tar.bz2." << std::endl;
140 std::cout << std::endl <<
" any2many -f 2010/lem10_his_0123.root 2010/lem10_his_0012.root -c MusrRoot MusrRoot -rebin 25";
141 std::cout << std::endl <<
" Will read the two files '2010/lem10_his_0123.root' and '2010/lem10_his_0012.root',";
142 std::cout << std::endl <<
" rebin them with 25 and export them as LEM ROOT files with adding rebin25 to the";
143 std::cout << std::endl <<
" name, e.g. 2010/lem10_his_0123_rebin25.root";
144 std::cout << std::endl << std::endl;
158int main(
int argc,
char *argv[])
160 bool show_syntax =
false;
165 TString outputFileName = TString(
"");
168 inputFormat.push_back(
"musrroot");
169 inputFormat.push_back(
"psi-bin");
170 inputFormat.push_back(
"root");
171 inputFormat.push_back(
"mud");
172 inputFormat.push_back(
"nexus");
173 inputFormat.push_back(
"psi-mdu");
174 inputFormat.push_back(
"wkm");
177 outputFormat.push_back(
"psi-bin");
178 outputFormat.push_back(
"musrroot");
179 outputFormat.push_back(
"musrrootdir");
180 outputFormat.push_back(
"root");
181 outputFormat.push_back(
"mud");
182 outputFormat.push_back(
"nexus1-hdf4");
183 outputFormat.push_back(
"nexus1-hdf5");
184 outputFormat.push_back(
"nexus1-xml");
185 outputFormat.push_back(
"nexus2-hdf4");
186 outputFormat.push_back(
"nexus2-hdf5");
187 outputFormat.push_back(
"nexus2-xml");
188 outputFormat.push_back(
"wkm");
189 outputFormat.push_back(
"ascii");
208 if (!strncmp(argv[1],
"--help", 128))
210 else if (strstr(argv[1],
"--v")) {
213 std::cout << std::endl <<
"any2many version: " << PACKAGE_VERSION <<
", git-branch: " << GIT_BRANCH <<
", git-rev: " << GIT_CURRENT_SHA1 <<
" (" << BUILD_TYPE <<
"), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
215 std::cout << std::endl <<
"any2many version: " << PACKAGE_VERSION <<
" (" << BUILD_TYPE <<
"), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
219 std::cout << std::endl <<
"any2many git-branch: " << GIT_BRANCH <<
", git-rev: " << GIT_CURRENT_SHA1 << std::endl << std::endl;
221 std::cout << std::endl <<
"any2many version: unkown." << std::endl << std::endl;
235 for (
int i=1; i<argc; i++) {
237 if (!strcmp(argv[i],
"-y")) {
240 if ((strlen(argv[i+1]) != 2) && (strlen(argv[i+1]) != 4)) {
241 std::cerr << std::endl <<
">> any2many **ERROR** found in option '-y' the argument '" << argv[i+1] <<
"' which is neither of the form 'yy' nor 'yyyy'." << std::endl;
246 status = sscanf(argv[i+1],
"%d", &ival);
248 info.
year = argv[i+1];
251 std::cerr << std::endl <<
">> any2many **ERROR** found in option '-y' the argument '" << argv[i+1] <<
"' which is not a number." << std::endl;
259 }
else if (!strcmp(argv[i],
"-s")) {
261 }
else if (!strcmp(argv[i],
"-f")) {
266 if (argv[j][0] ==
'-') {
272 }
while (!done && (j<argc));
277 std::cerr << std::endl <<
">> any2many **ERROR** found input option '-f' without any arguments" << std::endl;
281 }
else if (!strcmp(argv[i],
"-o")) {
283 outputFileName = argv[i+1];
286 std::cerr << std::endl <<
">> any2many **ERROR** found output file name option '-o' without any arguments" << std::endl;
290 }
else if (!strcmp(argv[i],
"-r")) {
293 std::string runStr{
""};
295 for (
int j=i+1; j<argc; j++) {
297 if ((argv[j][0] ==
'-') && isalpha(argv[j][1])) {
307 std::string errMsg{
""};
308 if (!rl.
Parse(errMsg)) {
309 std::cerr <<
"**ERROR** in run list: -rl " << runStr << std::endl;
310 std::cerr << errMsg << std::endl;
317 std::cerr << std::endl <<
">> any2many **ERROR** found input option '-r' without any arguments" << std::endl;
323 if (info.
runList.size() == 0) {
324 std::cerr << std::endl <<
">> any2many **ERROR** found input option '-r' without any valid arguments" << std::endl;
328 }
else if (!strcmp(argv[i],
"-c")) {
334 for (
unsigned int j=0; j<inputFormat.size(); j++) {
335 if (!inputFormat[j].CompareTo(sval, TString::kIgnoreCase)) {
342 std::cerr << std::endl <<
">> any2many **ERROR** found unkown input data file format option '" << sval <<
"'" << std::endl;
348 for (
unsigned int j=0; j<outputFormat.size(); j++) {
349 if (!outputFormat[j].CompareTo(sval, TString::kIgnoreCase)) {
356 std::cerr << std::endl <<
">> any2many **ERROR** found unkown output data file format option '" << sval <<
"'" << std::endl;
362 std::cerr << std::endl <<
">> any2many **ERROR** found option '-c' with missing arguments" << std::endl;
366 }
else if (!strcmp(argv[i],
"-h")) {
370 status = sscanf(argv[j],
"%d", &ival);
377 }
while (!done && (j<argc));
381 }
else if (!strcmp(argv[i],
"-p")) {
384 if (!info.
outPath.EndsWith(
"/"))
388 std::cerr << std::endl <<
">> any2many **ERROR** found output option '-p' without any argument." << std::endl;
392 }
else if (!strcmp(argv[i],
"-rebin")) {
394 status = sscanf(argv[i+1],
"%d", &ival);
399 std::cerr << std::endl <<
">> any2many **ERROR** found in option '-rebin " << argv[i+1] <<
"' which doesn't make any sense." << std::endl;
404 std::cerr << std::endl <<
">> any2many **ERROR** found output option '-rebin' without any argument." << std::endl;
408 }
else if (!strcmp(argv[i],
"-t")) {
410 if ((argv[i+1][0] ==
'-') || (argv[i+2][0] ==
'-')) {
411 std::cerr << std::endl <<
">> any2many **ERROR** found invalid template in option '-t'" << std::endl;
419 std::cerr << std::endl <<
">> any2many **ERROR** found option '-t' with missing arguments" << std::endl;
423 }
else if (!strcmp(argv[i],
"-z")) {
425 if ((argv[i+1][0] ==
'-') || (argv[i+2][0] ==
'-')) {
426 std::cerr << std::endl <<
">> any2many **ERROR** found invalid template in option '-z'" << std::endl;
430 if (argv[i+1][0] ==
'g') {
432 }
else if (argv[i+1][0] ==
'b') {
435 std::cerr << std::endl <<
">> any2many **ERROR** found in option '-z' compression tag '" << argv[i+1] <<
"' which is not supported." << std::endl;
442 std::cerr << std::endl <<
">> any2many **ERROR** found option '-z' with missing arguments" << std::endl;
447 std::cerr << std::endl <<
">> any2many **ERROR** found unrecognized option " << argv[i] << std::endl;
455 std::cerr << std::endl <<
">> any2many **ERROR** neither a input filename list, nor a run list was given." << std::endl;
461 std::cerr << std::endl <<
">> any2many **ERROR** conversion information is missing." << std::endl;
466 if (info.
outFormat.Contains(
"nexus1", TString::kIgnoreCase))
468 if (info.
outFormat.Contains(
"nexus2", TString::kIgnoreCase))
472 if (outputFileName.Length() > 0) {
478 std::cerr << std::endl <<
">> any2many **ERROR** found option '-o' cannot be combined with option '-t'." << std::endl;
482 std::cerr << std::endl <<
">> any2many **ERROR** found option '-o' with multiple input file names, which doesn't make any sense." << std::endl;
495 std::cerr << std::endl <<
">> any2many **ERROR** input data format == output data format, only allowed if rebin != 1.";
496 std::cerr << std::endl <<
" will ignore the request." << std::endl << std::endl;
503 std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
504 std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>();
505 if (!startupHandler->StartupFileFound()) {
506 std::cerr << std::endl <<
">> any2many **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
507 std::cerr << std::endl;
510 saxParser->ConnectToHandler(
"PStartupHandler", startupHandler.get());
517 std::cerr << std::endl <<
">> any2many **WARNING** Reading/parsing musrfit_startup.xml failed.";
518 std::cerr << std::endl;
523 std::unique_ptr<PRunDataHandler> dataHandler;
525 dataHandler = std::make_unique<PRunDataHandler>(&info, startupHandler->GetDataPathList());
527 dataHandler = std::make_unique<PRunDataHandler>(&info);
530 dataHandler->ConvertData();
533 bool success = dataHandler->IsAllDataAvailable();
535 std::cerr << std::endl <<
">> any2many **ERROR** Couldn't read all data files, will quit ..." << std::endl;