38 #include <TObjArray.h> 39 #include <TObjString.h> 43 #define MSR_TAG_TITLE 0 44 #define MSR_TAG_FITPARAMETER 1 45 #define MSR_TAG_THEORY 2 46 #define MSR_TAG_FUNCTIONS 3 48 #define MSR_TAG_COMMANDS 5 49 #define MSR_TAG_PLOT 6 50 #define MSR_TAG_STATISTIC 7 51 #define MSR_TAG_NO_BLOCK 8 55 #define MSR_THEORY_INTERN_FLD 0 56 #define MSR_THEORY_INTERN_BESSEL 1 64 std::cout << std::endl <<
"usage: msr2msr <msr-file-in> <msr-file-out> | [--help]";
65 std::cout << std::endl <<
" <msr-file-in> : input msr-file";
66 std::cout << std::endl <<
" <msr-file-out>: converted msr-output-file";
67 std::cout << std::endl <<
" if the <msr-file-in> is already in the 2008 format";
68 std::cout << std::endl <<
" the output file will be identical to the input file.";
69 std::cout << std::endl << std::endl;
86 if (!strstr(str,
"RUN"))
98 Ssiz_t idx = line.Index(
"(");
103 tokens = line.Tokenize(
" \t");
104 if (tokens->GetEntries() < 4) {
105 std::cout << std::endl <<
"**ERROR**: Something is wrong with the RUN block header:";
106 std::cout << std::endl <<
" >> " << str;
107 std::cout << std::endl <<
" >> no <msr-file-out> is created";
108 std::cout << std::endl;
112 if (tokens->GetEntries() == 5) {
113 snprintf(str, size,
"%s (name beamline institute data-file-format)", line.Data());
117 if (run.Contains(
"NEMU")) {
118 ostr[0] =
dynamic_cast<TObjString*
>(tokens->At(1));
119 snprintf(str, size,
"RUN %s MUE4 PSI WKM (name beamline institute data-file-format)", ostr[0]->GetString().Data());
120 }
else if (run.Contains(
"PSI")) {
121 ostr[0] =
dynamic_cast<TObjString*
>(tokens->At(1));
122 ostr[1] =
dynamic_cast<TObjString*
>(tokens->At(2));
123 snprintf(str, size,
"RUN %s %s PSI PSI-BIN (name beamline institute data-file-format)",
124 ostr[0]->GetString().Data(), ostr[1]->GetString().Data());
125 }
else if (run.Contains(
"TRIUMF")) {
126 ostr[0] =
dynamic_cast<TObjString*
>(tokens->At(1));
127 ostr[1] =
dynamic_cast<TObjString*
>(tokens->At(2));
128 snprintf(str, size,
"RUN %s %s TRIUMF MUD (name beamline institute data-file-format)",
129 ostr[0]->GetString().Data(), ostr[1]->GetString().Data());
130 }
else if (run.Contains(
"RAL")) {
131 ostr[0] =
dynamic_cast<TObjString*
>(tokens->At(1));
132 ostr[1] =
dynamic_cast<TObjString*
>(tokens->At(2));
133 snprintf(str, size,
"RUN %s %s RAL NEXUS (name beamline institute data-file-format)",
134 ostr[0]->GetString().Data(), ostr[1]->GetString().Data());
161 if (strstr(str,
"Nr.")) {
162 strcpy(str,
"# No Name Value Step Pos_Error Boundaries");
173 tokens = line.Tokenize(
" \t");
174 Int_t noTokens = tokens->GetEntries();
176 for (
unsigned int i=0; i<4; i++)
177 ostr[i] = dynamic_cast<TObjString*>(tokens->At(i));
179 snprintf(sstr,
sizeof(sstr),
"%10s", ostr[0]->GetString().Data());
182 strcat(sstr, ostr[1]->GetString().Data());
183 memset(spaces, 0,
sizeof(spaces));
184 memset(spaces,
' ', 12-strlen(ostr[1]->GetString().Data()));
185 strcat(sstr, spaces);
187 strcat(sstr, ostr[2]->GetString().Data());
188 if (strlen(ostr[2]->GetString().Data()) < 10) {
189 memset(spaces, 0,
sizeof(spaces));
190 memset(spaces,
' ', 10-strlen(ostr[2]->GetString().Data()));
191 strcat(sstr, spaces);
196 strcat(sstr, ostr[3]->GetString().Data());
197 if (strlen(ostr[3]->GetString().Data()) < 12) {
198 memset(spaces, 0,
sizeof(spaces));
199 memset(spaces,
' ', 12-strlen(ostr[3]->GetString().Data()));
200 strcat(sstr, spaces);
204 strcat(sstr,
"none");
206 }
else if (noTokens == 6) {
207 for (
unsigned int i=0; i<6; i++)
208 ostr[i] = dynamic_cast<TObjString*>(tokens->At(i));
210 snprintf(sstr,
sizeof(sstr),
"%10s", ostr[0]->GetString().Data());
213 strcat(sstr, ostr[1]->GetString().Data());
214 memset(spaces, 0,
sizeof(spaces));
215 memset(spaces,
' ', 12-strlen(ostr[1]->GetString().Data()));
216 strcat(sstr, spaces);
218 strcat(sstr, ostr[2]->GetString().Data());
219 if (strlen(ostr[2]->GetString().Data()) < 10) {
220 memset(spaces, 0,
sizeof(spaces));
221 memset(spaces,
' ', 10-strlen(ostr[2]->GetString().Data()));
222 strcat(sstr, spaces);
227 strcat(sstr, ostr[3]->GetString().Data());
228 if (strlen(ostr[3]->GetString().Data()) < 12) {
229 memset(spaces, 0,
sizeof(spaces));
230 memset(spaces,
' ', 12-strlen(ostr[3]->GetString().Data()));
231 strcat(sstr, spaces);
236 strcat(sstr,
"none ");
238 strcat(sstr, ostr[4]->GetString().Data());
239 if (strlen(ostr[4]->GetString().Data()) < 8) {
240 memset(spaces, 0,
sizeof(spaces));
241 memset(spaces,
' ', 8-strlen(ostr[4]->GetString().Data()));
242 strcat(sstr, spaces);
247 strcat(sstr, ostr[5]->GetString().Data());
281 if ((line.Contains(
"sktt") || line.Contains(
"statKTTab")) && line.Contains(
"glf")) {
283 strcpy(sstr,
"statGssKTLF ");
286 tokens = line.Tokenize(
" \t");
287 Int_t noTokens = tokens->GetEntries();
289 std::cout << std::endl <<
"**ERROR** in THEORY block";
290 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid statKTTab statement.";
291 std::cout << std::endl <<
" Cannot handle file." << std::endl;
294 for (Int_t i=1; i<3; i++) {
296 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
297 strcat(sstr, ostr->GetString().Data());
299 strcat(sstr,
" (frequency damping)");
301 }
else if ((line.Contains(
"sktt") || line.Contains(
"statKTTab")) && line.Contains(
"llf")) {
303 strcpy(sstr,
"statExpKTLF ");
306 tokens = line.Tokenize(
" \t");
307 Int_t noTokens = tokens->GetEntries();
309 std::cout << std::endl <<
"**ERROR** in THEORY block";
310 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid statKTTab statement.";
311 std::cout << std::endl <<
" Cannot handle file." << std::endl;
314 for (Int_t i=1; i<3; i++) {
316 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
317 strcat(sstr, ostr->GetString().Data());
319 strcat(sstr,
" (frequency damping)");
321 }
else if ((line.Contains(
"dktt") || line.Contains(
"dynmKTTab")) && line.Contains(
"kdglf")) {
323 strcpy(sstr,
"dynGssKTLF ");
326 tokens = line.Tokenize(
" \t");
327 Int_t noTokens = tokens->GetEntries();
329 std::cout << std::endl <<
"**ERROR** in THEORY block";
330 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid dynmKTTab statement.";
331 std::cout << std::endl <<
" Cannot handle file." << std::endl;
334 for (Int_t i=1; i<4; i++) {
336 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
337 strcat(sstr, ostr->GetString().Data());
339 strcat(sstr,
" (frequency damping hopping-rate)");
341 }
else if ((line.Contains(
"dktt") || line.Contains(
"dynmKTTab")) && line.Contains(
"kdllf")) {
343 strcpy(sstr,
"dynExpKTLF ");
346 tokens = line.Tokenize(
" \t");
347 Int_t noTokens = tokens->GetEntries();
349 std::cout << std::endl <<
"**ERROR** in THEORY block";
350 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid dynmKTTab statement.";
351 std::cout << std::endl <<
" Cannot handle file." << std::endl;
354 for (Int_t i=1; i<4; i++) {
356 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
357 strcat(sstr, ostr->GetString().Data());
359 strcat(sstr,
" (frequency damping hopping-rate)");
361 }
else if (line.Contains(
"internFld")) {
363 noOfAddionalParams++;
366 strcpy(sstr,
"internFld ");
369 tokens = line.Tokenize(
" \t");
370 Int_t noTokens = tokens->GetEntries();
372 std::cout << std::endl <<
"**ERROR** in THEORY block";
373 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid internFld statement.";
374 std::cout << std::endl <<
" Cannot handle file." << std::endl;
377 strcat(sstr,
" _x_");
378 for (Int_t i=1; i<4; i++) {
380 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
381 strcat(sstr, ostr->GetString().Data());
383 strcat(sstr,
" (fraction phase frequency Trate Lrate)");
385 }
else if (line.Contains(
"internBsl")) {
387 noOfAddionalParams++;
390 strcpy(sstr,
"internBsl ");
393 tokens = line.Tokenize(
" \t");
394 Int_t noTokens = tokens->GetEntries();
396 std::cout << std::endl <<
"**ERROR** in THEORY block";
397 std::cout << std::endl <<
" Line: '" << str <<
"' is not a valid internBsl statement.";
398 std::cout << std::endl <<
" Cannot handle file." << std::endl;
401 strcat(sstr,
" _x_");
402 for (Int_t i=1; i<4; i++) {
404 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
405 strcat(sstr, ostr->GetString().Data());
407 strcat(sstr,
" (fraction phase frequency Trate Lrate)");
427 bool isComment =
false;
429 for (
unsigned int i=0; i<strlen(str); i++) {
430 if ((str[i] ==
' ') || (str[i] ==
'\t'))
456 bool isWhitespace =
true;
458 if (strlen(str) != 0) {
459 for (
unsigned int i=0; i<strlen(str); i++) {
460 if ((str[i] !=
' ') && (str[i] !=
'\t')) {
461 isWhitespace =
false;
482 memset(temp, 0,
sizeof(temp));
484 snprintf(no,
sizeof(no),
"%d", paramNo);
487 for (
unsigned int i=0; i<strlen(str); i++) {
492 for (
unsigned int k=0; k<strlen(no); k++)
514 fin.open(fln, std::iostream::in);
515 if (!fin.is_open()) {
516 std::cout << std::endl <<
"**ERROR**: Couldn't open input msr-file " << fln;
517 std::cout << std::endl <<
" Will quit." << std::endl;
523 fout.open(
"__temp.msr", std::iostream::out);
524 if (!fout.is_open()) {
525 std::cout << std::endl <<
"**ERROR**: Couldn't open output msr-file __temp.msr";
526 std::cout << std::endl <<
" Will quit." << std::endl;
536 while (!fin.eof() && success) {
537 fin.getline(str,
sizeof(str));
539 if (strstr(str,
"FITPARAMETER")) {
541 }
else if (strstr(str,
"THEORY")) {
551 for (
int i=0; i<noOfAddionalParams; i++) {
552 fout <<
" " << param+i <<
" frac" << i+1 <<
" 0.333333 0.0 none" << std::endl;
561 if (strstr(str,
"_x_")) {
568 fout << str << std::endl;
577 snprintf(str,
sizeof(str),
"cp __temp.msr %s", fln);
578 if (system(str) == -1) {
579 std::cerr <<
"**ERROR** cmd: " << str <<
" failed." << std::endl;
583 strcpy(str,
"rm __temp.msr");
584 if (system(str) == -1) {
585 std::cerr <<
"**ERROR** cmd: " << str <<
" failed." << std::endl;
609 double chisq, chisqred;
610 if (strstr(str,
" chi")) {
611 pstr = strstr(str,
"abs = ");
612 if (pstr !=
nullptr) {
613 status = sscanf(pstr,
"abs = %lf", &chisq);
618 pstr = strstr(str,
"norm = ");
619 if (pstr !=
nullptr) {
620 status = sscanf(pstr,
"norm = %lf", &chisqred);
626 snprintf(str, size,
" chisq = %lf, NDF = %d, chisq/NDF = %lf", chisq, static_cast<int>(chisq/chisqred), chisqred);
641 int main(
int argc,
char *argv[])
652 fin.open(argv[1], std::iostream::in);
653 if (!fin.is_open()) {
654 std::cout << std::endl <<
"**ERROR**: Couldn't open input msr-file " << argv[1];
655 std::cout << std::endl <<
" Will quit." << std::endl;
661 fout.open(argv[2], std::iostream::out);
662 if (!fout.is_open()) {
663 std::cout << std::endl <<
"**ERROR**: Couldn't open output msr-file " << argv[2];
664 std::cout << std::endl <<
" Will quit." << std::endl;
673 int noOfAddionalParams = 0;
675 while (!fin.eof() && success) {
676 fin.getline(str,
sizeof(str));
678 if (strstr(str,
"FITPARAMETER")) {
680 }
else if (strstr(str,
"RUN")) {
682 }
else if (strstr(str,
"THEORY")) {
684 }
else if (strstr(str,
"STATISTIC")) {
705 fout << str << std::endl;
714 snprintf(str,
sizeof(str),
"rm -rf %s", argv[2]);
715 if (system(str) == -1) {
716 std::cerr <<
"**ERROR** cmd: " << str <<
" failed." << std::endl;
721 if (theoryTag != -1) {
725 std::cout << std::endl <<
"done ..." << std::endl;
bool msr2msr_param(char *str)
bool msr2msr_finalize_theory(char *fln, int theoryTag, int noOfAddionalParams)
bool msr2msr_statistic(char *str, const std::size_t size)
#define MSR_THEORY_INTERN_FLD
#define MSR_TAG_STATISTIC
int main(int argc, char *argv[])
bool msr2msr_is_whitespace(char *str)
void msr2msr_replace(char *str, int paramNo)
#define MSR_THEORY_INTERN_BESSEL
bool msr2msr_theory(char *str, int &tag, int &noOfAddionalParams)
bool msr2msr_is_comment(char *str)
bool msr2msr_run(char *str, const std::size_t size)
#define MSR_TAG_FITPARAMETER