ROOTPWA
addisokey.cc
Go to the documentation of this file.
1 
3 //
4 // Copyright 2009 Sebastian Neubert
5 //
6 // This file is part of rootpwa
7 //
8 // rootpwa is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // rootpwa is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
20 //
22 
23 
25 // This utility compares two keys and returns an isospin-added key if
26 // possible. Otherwise it exits with an error
27 //
28 // The two keys to compare are the only arguments
30 
31 #include "TString.h"
32 #include "TObjString.h"
33 #include "TObjArray.h"
34 #include <vector>
35 #include <iostream>
36 
37 using namespace std;
38 
39 int main(int argc, char** argv) {
40 
41  if(strlen(argv[1])!=strlen(argv[2])){
42  cerr << "Different Key Lengths" << endl;
43  return 1;
44  }
45 
46  TString key1(argv[1]);
47  TString key2(argv[2]);
48 
49  //cout << key1 << endl;
50  //cout << key2 << endl;
51 
52  //if(key1.Length()!=key2.Length()){
53  // cerr << "Different Key Lengths" << endl;
54  // return 1;
55  //}
56 
57  TString key1head=key1(0,7);
58  key1.Remove(0,7);
59  TString key2head=key2(0,7);
60  key2.Remove(0,7);
61 
62  if(key1head!=key2head){
63  cerr << "Different Headers" << endl;
64  return 2;
65  }
66 
67  TObjArray* key1tokens=key1.Tokenize("_=.");
68  TObjArray* key2tokens=key2.Tokenize("_=.");
69 
70  int l=key1tokens->GetEntries();
71  if(l!=key2tokens->GetEntries()){
72  delete key1tokens;
73  delete key2tokens;
74  cerr << "Different Number of Tokens" << endl;
75  return 3;
76  }
77 
78  TString output(key1head);
79  TString rest(key1);
80 
81  // loop through tokens, check if everything agrees except pi+ pi-
82  for(int i=0;i<l;++i){
83  TObjString* objtok1=(TObjString*)key1tokens->At(i);
84  TObjString* objtok2=(TObjString*)key2tokens->At(i);
85  TString tok1=objtok1->GetString();
86  TString tok2=objtok2->GetString();
87 
88  if(tok1!=tok2){
89  if(tok1=="pi+" && tok2=="pi-"){
90  output.Append("pi+-");
91  }
92  else if(tok1=="pi-" && tok2=="pi+"){
93  output.Append("pi-+");
94  }
95  else {
96  delete key1tokens;
97  delete key2tokens;
98  cerr << "Different Tokens" << endl;
99  return 4;
100  }
101  }
102  else output.Append(tok1);
103 
104  rest.Remove(0,tok1.Length());
105  // append correct token
106  output.Append(rest(0,1));
107  rest.Remove(0,1);
108 
109  }
110 
111  delete key1tokens;
112  delete key2tokens;
113 
114  cout << output << endl;
115 
116  return 0;
117 }