7 #include "TObjString.h"
13 #include "boost/tokenizer.hpp"
14 #include <boost/algorithm/string.hpp>
15 #include "boost/algorithm/string/erase.hpp"
16 #include "boost/algorithm/string/split.hpp"
37 if (! refsourcedata) {
38 std::cerr <<
"You are setting a bad refsourcedata! This will cause you trouble later!" << std::endl;
51 std::cerr <<
"Unable to figure out refsource mapping: THIS IS ALSO REALLY BAD!!!" << std::endl;
52 std::cerr <<
"This happened for reference " << rawref << std::endl;
55 return value->GetName();
59 std::stringstream oss;
60 oss<<
"reference-"<<std::setfill(
'0')<<std::setw(9)<<
m_numRefHisto;
67 boost::algorithm::erase_all(inp,
" ");
70 std::vector<std::string> refs;
72 if(inp.find(
'=')!=std::string::npos){
73 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
74 boost::char_separator<char> refSep(
";");
75 boost::char_separator<char> condSep(
",:");
76 tokenizer referenceConditionPairs(inp, refSep);
77 std::string defaultRef(
"");
79 tok_iter!=referenceConditionPairs.end();++tok_iter){
80 if(std::string((*tok_iter)).
find(
'=')!=std::string::npos){
81 if(std::string(*tok_iter).find(
':')!=std::string::npos){
82 std::vector<std::string> conds;
83 boost::split(conds,*tok_iter,boost::is_any_of(std::string(
":")));
85 std::cerr<<
"Warning malformed reference \""<<inp<<
"\""<<std::endl;
86 }
else if(conds.size()<2){
87 std::cerr<<
"Warning malformed reference \""<<inp<<
"\""<<std::endl;
90 refs.push_back(conds.at(conds.size()-1));
94 if(defaultRef.empty()){
97 std::cout<<
"WARNING! overwriting old default reference \""
98 <<defaultRef<<
"\" with \""
99 <<*tok_iter<<
"\""<<std::endl;
100 defaultRef=*tok_iter;
102 std::cout<<
"Default reference = "<<defaultRef<<std::endl;
109 if(!defaultRef.empty())refs.push_back(defaultRef);
121 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
123 boost::algorithm::erase_all(cleanCond,
" ");
124 boost::char_separator<char> condSep(
",");
125 tokenizer conditionPairs(
condition, condSep);
126 for (tokenizer::const_iterator tok_iter = conditionPairs.begin();
127 tok_iter != conditionPairs.end(); ++tok_iter) {
128 std::vector<std::string> splitpairs;
129 boost::split(splitpairs, *tok_iter, boost::is_any_of(std::string(
"=")));
130 if (splitpairs.size() != 2) {
131 std::cerr <<
"WARNING: malformed condition \"" << *tok_iter <<
"\"" << std::endl;
134 if (cmap.find(splitpairs[0]) != cmap.end()) {
135 std::cerr <<
"WARNING: redefinition of condition " << splitpairs[0] << std::endl;
137 cmap[splitpairs[0]] = splitpairs[1];
143 std::map<std::string, std::string>& currentConds)
const {
144 for (std::map<std::string, std::string>::const_iterator cond_iter = refConds.begin();
145 cond_iter != refConds.end(); ++cond_iter) {
147 if (currentConds.find((*cond_iter).first) == currentConds.end())
return false;
148 if ((*cond_iter).second != currentConds[(*cond_iter).first])
return false;
156 boost::algorithm::erase_all(cleanCond,
" ");
157 std::map<std::string, std::string> condition_map, reference_map;
159 boost::algorithm::erase_all(inp,
" ");
161 if(inp.find(
'=')!=std::string::npos){
162 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
163 boost::char_separator<char> refSep(
";");
164 boost::char_separator<char> condSep(
",:");
165 tokenizer referenceConditionPairs(inp, refSep);
166 std::string defaultRef(
"");
167 std::map<std::string,std::string> conditionalReferences;
169 tok_iter!=referenceConditionPairs.end();++tok_iter){
170 if(std::string((*tok_iter)).
find(
'=')!=std::string::npos){
171 if(std::string(*tok_iter).find(
':')!=std::string::npos){
172 std::vector<std::string> conds;
173 boost::split(conds,*tok_iter,boost::is_any_of(std::string(
":")));
175 std::cerr<<
"Warning malformed reference \""<<inp<<
"\""<<std::endl;
176 }
else if(conds.size()<2){
177 std::cerr<<
"Warning malformed reference \""<<inp<<
"\""<<std::endl;
182 reference_map.clear();
185 return conds.at(conds.size()-1);
190 if(defaultRef.empty()){
191 defaultRef=*tok_iter;
193 std::cout<<
"WARNING! overwriting old default reference \""
194 <<defaultRef<<
"\" with \""
195 <<*tok_iter<<
"\""<<std::endl;
196 defaultRef=*tok_iter;
218 std::vector<std::pair<std::string,std::string> > condPairs;
219 std::map<std::string,std::string> pairMap;
220 boost::algorithm::erase_all(inp,
" ");
221 std::string defaultRef(
"");
222 if(inp.find(
'=')!=std::string::npos){
223 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
224 boost::char_separator<char> refSep(
";");
225 boost::char_separator<char> condSep(
",:");
226 tokenizer referenceConditionPairs(inp, refSep);
227 std::map<std::string,std::string> conditionalReferences;
229 tok_iter!=referenceConditionPairs.end();++tok_iter){
230 if(std::string((*tok_iter)).
find(
'=')!=std::string::npos){
231 if(std::string(*tok_iter).find(
':')!=std::string::npos){
232 std::vector<std::string> conds;
233 boost::split(conds,*tok_iter,boost::is_any_of(std::string(
":")));
235 std::cerr<<
"Warning malformed reference \""<<inp<<
"\""<<std::endl;
236 }
else if(conds.size()<2){
237 std::cerr<<
"Warning malformed reference \""<<inp<<
"\""<<std::endl;
240 condPairs.push_back(std::make_pair(conds.at(conds.size()-2),conds.at(conds.size()-1)));
244 if(defaultRef.empty()){
245 defaultRef=*tok_iter;
247 std::cout<<
"WARNING! overwriting old default reference \""
248 <<defaultRef<<
"\" with \""
249 <<*tok_iter<<
"\""<<std::endl;
250 defaultRef=*tok_iter;
258 if(!defaultRef.empty())condPairs.push_back(std::make_pair(
"",defaultRef));
261 condPairs.push_back(std::make_pair(
"",inp));
267 std::cerr<<
"Warning old name of the reference is empty. New name is \""<<
newName<<
"\""<<std::endl;
271 std::cerr<<
"Warning new name of the reference is empty. Old name is \""<<oldName<<
"\""<<std::endl;
277 std::cerr<<
"Warning reference \""<<oldName<<
"\" is added to map before as \""
284 std::cerr<<
"Reference must have a name"<<std::endl;
290 if(!
quiet)std::cerr<<
"Non-existent reference\""<<oldName<<
"\". Returning empty string"<<std::endl;