43 #include <TSAXParser.h> 46 #include "git-revision.h" 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, 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 <<
"examples:" << std::endl;
113 std::cout << std::endl <<
" any2many -f 2010/lem10_his_0123.root -c ROOT ASCII -rebin 25";
114 std::cout << std::endl <<
" Will take the LEM ROOT file '2010/lem10_his_0123.root' rebin it with 25";
115 std::cout << std::endl <<
" and convert it to ASCII. The output file name will be";
116 std::cout << std::endl <<
" lem10_his_0123.ascii, and the file will be saved in the current directory." << std::endl;
117 std::cout << std::endl <<
" any2many -f 2010/lem10_his_0123.root -c MusrRoot NEXUS2-HDF5 -o 2010/lem10_his_0123_v2.nxs";
118 std::cout << std::endl <<
" Will take the MusrRoot file '2010/lem10_his_0123.root' ";
119 std::cout << std::endl <<
" and convert it to NeXus IDF V2. The output file name will be";
120 std::cout << std::endl <<
" lem10_his_0123_v2.nxs, and the file will be saved in the current directory." << std::endl;
121 std::cout << std::endl <<
" any2many -r 123 137 -c PSI-BIN MUD -t d[yyyy]/deltat_tdc_gps_[rrrr].bin \\";
122 std::cout << std::endl <<
" [rrrrrr].msr -y 2001";
123 std::cout << std::endl <<
" Will take the run 123 and 137, will generate the input file names:";
124 std::cout << std::endl <<
" d2001/deltat_tdc_gps_0123.bin and d2001/deltat_tdc_gps_0137.bin, and";
125 std::cout << std::endl <<
" output file names 000123.msr and 000137.msr" << std::endl;
126 std::cout << std::endl <<
" any2many -r 100-117 -c PSI-MDU ASCII -t d[yyyy]/deltat_tdc_alc_[rrrr].mdu \\";
127 std::cout << std::endl <<
" [rrr].ascii -y 2011 -s";
128 std::cout << std::endl <<
" Will take the runs 100 through 117 and convert the PSI-MDU input files to";
129 std::cout << std::endl <<
" ASCII output and instead of saving them into a file, they will be spit to";
130 std::cout << std::endl <<
" the standard output." << std::endl;
131 std::cout << std::endl <<
" any2many -r 100-117 -c NEXUS MusrRoot -t d[yyyy]/psi_gps_[rrrr].NXS \\";
132 std::cout << std::endl <<
" psi_[yyyy]_gps_[rrrr].root -z b psi_gps_run_100to117";
133 std::cout << std::endl <<
" Will take the runs 100 through 117 and convert the NEXUS input files";
134 std::cout << std::endl <<
" to MusrRoot output. Afterwards these new files will be collected in a";
135 std::cout << std::endl <<
" compressed archive psi_gps_run_100to117.tar.bz2." << std::endl;
136 std::cout << std::endl <<
" any2many -f 2010/lem10_his_0123.root 2010/lem10_his_0012.root -c MusrRoot MusrRoot -rebin 25";
137 std::cout << std::endl <<
" Will read the two files '2010/lem10_his_0123.root' and '2010/lem10_his_0012.root',";
138 std::cout << std::endl <<
" rebin them with 25 and export them as LEM ROOT files with adding rebin25 to the";
139 std::cout << std::endl <<
" name, e.g. 2010/lem10_his_0123_rebin25.root";
140 std::cout << std::endl << std::endl;
154 int main(
int argc,
char *argv[])
156 bool show_syntax =
false;
161 TString outputFileName = TString(
"");
164 inputFormat.push_back(
"musrroot");
165 inputFormat.push_back(
"psi-bin");
166 inputFormat.push_back(
"root");
167 inputFormat.push_back(
"mud");
168 inputFormat.push_back(
"nexus");
169 inputFormat.push_back(
"psi-mdu");
170 inputFormat.push_back(
"wkm");
173 outputFormat.push_back(
"psi-bin");
174 outputFormat.push_back(
"musrroot");
175 outputFormat.push_back(
"root");
176 outputFormat.push_back(
"mud");
177 outputFormat.push_back(
"nexus1-hdf4");
178 outputFormat.push_back(
"nexus1-hdf5");
179 outputFormat.push_back(
"nexus1-xml");
180 outputFormat.push_back(
"nexus2-hdf4");
181 outputFormat.push_back(
"nexus2-hdf5");
182 outputFormat.push_back(
"nexus2-xml");
183 outputFormat.push_back(
"wkm");
184 outputFormat.push_back(
"ascii");
203 if (!strncmp(argv[1],
"--help", 128))
205 else if (strstr(argv[1],
"--v")) {
207 #ifdef HAVE_GIT_REV_H 208 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;
210 std::cout << std::endl <<
"any2many version: " << PACKAGE_VERSION <<
" (" << BUILD_TYPE <<
"), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
213 #ifdef HAVE_GIT_REV_H 214 std::cout << std::endl <<
"any2many git-branch: " << GIT_BRANCH <<
", git-rev: " << GIT_CURRENT_SHA1 << std::endl << std::endl;
216 std::cout << std::endl <<
"any2many version: unkown." << std::endl << std::endl;
230 for (
int i=1; i<argc; i++) {
232 if (!strcmp(argv[i],
"-y")) {
235 if ((strlen(argv[i+1]) != 2) && (strlen(argv[i+1]) != 4)) {
236 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;
241 status = sscanf(argv[i+1],
"%d", &ival);
243 info.
year = argv[i+1];
246 std::cerr << std::endl <<
">> any2many **ERROR** found in option '-y' the argument '" << argv[i+1] <<
"' which is not a number." << std::endl;
254 }
else if (!strcmp(argv[i],
"-s")) {
256 }
else if (!strcmp(argv[i],
"-f")) {
261 if (argv[j][0] ==
'-') {
267 }
while (!done && (j<argc));
272 std::cerr << std::endl <<
">> any2many **ERROR** found input option '-f' without any arguments" << std::endl;
276 }
else if (!strcmp(argv[i],
"-o")) {
278 outputFileName = argv[i+1];
281 std::cerr << std::endl <<
">> any2many **ERROR** found output file name option '-o' without any arguments" << std::endl;
285 }
else if (!strcmp(argv[i],
"-r")) {
288 std::string runStr{
""};
290 for (
int j=i+1; j<argc; j++) {
292 if ((argv[j][0] ==
'-') && isalpha(argv[j][1])) {
302 std::string errMsg{
""};
303 if (!rl.
Parse(errMsg)) {
304 std::cerr <<
"**ERROR** in run list: -rl " << runStr << std::endl;
305 std::cerr << errMsg << std::endl;
312 std::cerr << std::endl <<
">> any2many **ERROR** found input option '-r' without any arguments" << std::endl;
318 if (info.
runList.size() == 0) {
319 std::cerr << std::endl <<
">> any2many **ERROR** found input option '-r' without any valid arguments" << std::endl;
323 }
else if (!strcmp(argv[i],
"-c")) {
329 for (
unsigned int j=0; j<inputFormat.size(); j++) {
330 if (!inputFormat[j].CompareTo(sval, TString::kIgnoreCase)) {
337 std::cerr << std::endl <<
">> any2many **ERROR** found unkown input data file format option '" << sval <<
"'" << std::endl;
343 for (
unsigned int j=0; j<outputFormat.size(); j++) {
344 if (!outputFormat[j].CompareTo(sval, TString::kIgnoreCase)) {
351 std::cerr << std::endl <<
">> any2many **ERROR** found unkown output data file format option '" << sval <<
"'" << std::endl;
357 std::cerr << std::endl <<
">> any2many **ERROR** found option '-c' with missing arguments" << std::endl;
361 }
else if (!strcmp(argv[i],
"-h")) {
365 status = sscanf(argv[j],
"%d", &ival);
372 }
while (!done && (j<argc));
376 }
else if (!strcmp(argv[i],
"-p")) {
379 if (!info.
outPath.EndsWith(
"/"))
383 std::cerr << std::endl <<
">> any2many **ERROR** found output option '-p' without any argument." << std::endl;
387 }
else if (!strcmp(argv[i],
"-rebin")) {
389 status = sscanf(argv[i+1],
"%d", &ival);
394 std::cerr << std::endl <<
">> any2many **ERROR** found in option '-rebin " << argv[i+1] <<
"' which doesn't make any sense." << std::endl;
399 std::cerr << std::endl <<
">> any2many **ERROR** found output option '-rebin' without any argument." << std::endl;
403 }
else if (!strcmp(argv[i],
"-t")) {
405 if ((argv[i+1][0] ==
'-') || (argv[i+2][0] ==
'-')) {
406 std::cerr << std::endl <<
">> any2many **ERROR** found invalid template in option '-t'" << std::endl;
414 std::cerr << std::endl <<
">> any2many **ERROR** found option '-t' with missing arguments" << std::endl;
418 }
else if (!strcmp(argv[i],
"-z")) {
420 if ((argv[i+1][0] ==
'-') || (argv[i+2][0] ==
'-')) {
421 std::cerr << std::endl <<
">> any2many **ERROR** found invalid template in option '-t'" << std::endl;
425 if (argv[i+1][0] ==
'g') {
427 }
else if (argv[i+1][0] ==
'b') {
430 std::cerr << std::endl <<
">> any2many **ERROR** found in option '-z' compression tag '" << argv[i+1] <<
"' which is not supported." << std::endl;
437 std::cerr << std::endl <<
">> any2many **ERROR** found option '-z' with missing arguments" << std::endl;
442 std::cerr << std::endl <<
">> any2many **ERROR** found unrecognized option " << argv[i] << std::endl;
450 std::cerr << std::endl <<
">> any2many **ERROR** neither a input filename list, nor a run list was given." << std::endl;
456 std::cerr << std::endl <<
">> any2many **ERROR** conversion information is missing." << std::endl;
461 if (info.
outFormat.Contains(
"nexus1", TString::kIgnoreCase))
463 if (info.
outFormat.Contains(
"nexus2", TString::kIgnoreCase))
467 if (outputFileName.Length() > 0) {
473 std::cerr << std::endl <<
">> any2many **ERROR** found option '-o' cannot be combined with option '-t'." << std::endl;
477 std::cerr << std::endl <<
">> any2many **ERROR** found option '-o' with multiple input file names, which doesn't make any sense." << std::endl;
490 std::cerr << std::endl <<
">> any2many **ERROR** input data format == output data format, only allowed if rebin != 1.";
491 std::cerr << std::endl <<
" will ignore the request." << std::endl << std::endl;
497 std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
498 std::unique_ptr<PStartupHandler> startupHandler = std::make_unique<PStartupHandler>();
499 if (!startupHandler->StartupFileFound()) {
500 std::cerr << std::endl <<
">> any2many **WARNING** couldn't find " << startupHandler->GetStartupFilePath().Data();
501 std::cerr << std::endl;
504 saxParser->ConnectToHandler(
"PStartupHandler", startupHandler.get());
511 std::cerr << std::endl <<
">> any2many **WARNING** Reading/parsing musrfit_startup.xml failed.";
512 std::cerr << std::endl;
517 std::unique_ptr<PRunDataHandler> dataHandler;
519 dataHandler = std::make_unique<PRunDataHandler>(&info, startupHandler->GetDataPathList());
521 dataHandler = std::make_unique<PRunDataHandler>(&info);
524 dataHandler->ConvertData();
527 bool success = dataHandler->IsAllDataAvailable();
529 std::cerr << std::endl <<
">> any2many **ERROR** Couldn't read all data files, will quit ..." << std::endl;
virtual PUIntVector GetList()
int main(int argc, char *argv[])
TString year
holds the information about the year to be used
TString outFileName
holds the output file name
int parseXmlFile(TSAXParser *, const char *)
UInt_t compressionTag
0=no compression, 1=gzip compression, 2=bzip2 compression
TString inFormat
holds the information about the input data file format
PIntVector groupHistoList
holds the histo group list offset (used to define for MusrRoot files, what to be exported) ...
const char * startup_path_name
virtual bool Parse(std::string &errorMsg, bool ignoreFirstToken=false)
TString outTemplate
holds the output file template
UInt_t rebin
holds the number of bins to be packed
TString compressFileName
holds the name of the outputfile name in case of compression is used
TString outPath
holds the output path
Bool_t useStandardOutput
flag showing if the converted shall be sent to the standard output
#define PMUSR_WRONG_STARTUP_SYNTAX
PUIntVector runList
holds the run number list to be converted
std::vector< TString > PStringVector
UInt_t idf
IDF version for NeXus files.
TString outFormat
holds the information about the output data file format
PStringVector inFileName
holds the file name of the input data file
TString inTemplate
holds the input file template