11 #ifndef Pythia8_LHEF3_H
12 #define Pythia8_LHEF3_H
14 #include "Pythia8/PythiaStdlib.h"
15 #include "Pythia8/Streams.h"
30 typedef string::size_type pos_t;
33 static const pos_t end;
37 for (
int i = 0, N = tags.size(); i < N; ++i )
38 if (tags[i])
delete tags[i];
45 map<string,string> attr;
55 bool getattr(
string n,
double & v)
const {
56 map<string,string>::const_iterator it = attr.find(n);
57 if ( it == attr.end() )
return false;
58 v = atof(it->second.c_str());
64 bool getattr(
string n,
bool & v)
const {
65 map<string,string>::const_iterator it = attr.find(n);
66 if ( it == attr.end() )
return false;
67 if ( it->second ==
"yes" ) v =
true;
73 bool getattr(
string n,
long & v)
const {
74 map<string,string>::const_iterator it = attr.find(n);
75 if ( it == attr.end() )
return false;
76 v = atoi(it->second.c_str());
82 bool getattr(
string n,
int & v)
const {
83 map<string,string>::const_iterator it = attr.find(n);
84 if ( it == attr.end() )
return false;
85 v = int(atoi(it->second.c_str()));
91 bool getattr(
string n,
string & v)
const {
92 map<string,string>::const_iterator it = attr.find(n);
93 if ( it == attr.end() )
return false;
100 static vector<XMLTag*> findXMLTags(
string str,
101 string * leftover = 0) {
102 vector<XMLTag*> tags;
105 while ( curr != end ) {
108 pos_t begin = str.find(
"<", curr);
111 if ( begin != end && str.find(
"<!--", curr) == begin ) {
112 pos_t endcom = str.find(
"-->", begin);
113 if ( endcom == end ) {
114 if ( leftover ) *leftover += str.substr(curr);
117 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
128 if ( str.find(
"<![CDATA[", curr) == begin ) {
129 pos_t endcom = str.find(
"]]>", begin);
130 if ( endcom == end ) {
131 if ( leftover ) *leftover += str.substr(curr);
134 if ( leftover ) *leftover += str.substr(curr, endcom - curr);
139 if ( leftover ) *leftover += str.substr(curr, begin - curr);
140 if ( begin == end || begin > str.length() - 3 || str[begin + 1] ==
'/' )
143 pos_t close = str.find(
">", curr);
144 if ( close == end )
return tags;
147 curr = str.find_first_of(
" \t\n/>", begin);
148 tags.push_back(
new XMLTag());
149 tags.back()->name = str.substr(begin + 1, curr - begin - 1);
154 curr = str.find_first_not_of(
" \t\n", curr);
155 if ( curr == end || curr >= close )
break;
157 pos_t tend = str.find_first_of(
"= \t\n", curr);
158 if ( tend == end || tend >= close )
break;
160 string name = str.substr(curr, tend - curr);
161 curr = str.find(
"=", curr) + 1;
164 curr = str.find(
"\"", curr);
165 if ( curr == end || curr >= close )
break;
167 curr = str.find(
"\"", curr);
168 while ( curr != end && str[curr - 1] ==
'\\' )
169 curr = str.find(
"\"", curr + 1);
171 string value = str.substr(bega, curr == end? end: curr - bega);
173 tags.back()->attr[name] = value;
180 if ( str[close - 1] ==
'/' )
continue;
182 pos_t endtag = str.find(
"</" + tags.back()->name +
">", curr);
183 if ( endtag == end ) {
184 tags.back()->contents = str.substr(curr);
187 tags.back()->contents = str.substr(curr, endtag - curr);
188 curr = endtag + tags.back()->name.length() + 3;
192 tags.back()->tags = findXMLTags(tags.back()->contents, &leftovers);
193 if ( leftovers.find_first_not_of(
" \t\n") == end ) leftovers=
"";
194 tags.back()->contents = leftovers;
203 void list(ostream & os)
const {
205 for ( map<string,string>::const_iterator it = attr.begin();
206 it != attr.end(); ++it )
207 os <<
" " << it->first <<
"=\"" << it->second <<
"\"";
208 if ( contents.empty() && tags.empty() ) {
213 for (
int i = 0, N = tags.size(); i < N; ++i )
216 os <<
"````" << contents <<
"''''</" << name <<
">" << endl;
234 void list(ostream & file)
const;
244 vector<double> weights;
253 int size() {
return int(weights.size()); }
265 : muf(defscale), mur(defscale), mups(defscale), SCALUP(defscale) {}
271 void list(ostream & file)
const;
309 : name(
""), version(
""), contents(
"") {}
315 void list(ostream & file)
const;
346 LHAwgt(
double defwgt = 1.0)
347 : id(
""), contents(defwgt) {}
353 void list(ostream & file)
const;
381 : id(defname), contents(defname) {}
387 void list(ostream & file)
const;
421 void list(ostream & file)
const;
438 map<string, LHAweight> weights;
439 vector<string> weightsKeys;
445 int size() {
return int(weights.size()); }
463 void list(ostream & file)
const;
476 map<string, LHAwgt> wgts;
477 vector<string> wgtsKeys;
483 int size() {
return int(wgts.size()); }
501 void list(ostream & file)
const;
507 weightgroups.clear();
515 map<string, LHAweight> weights;
516 vector<string> weightsKeys;
519 map<string, LHAweightgroup> weightgroups;
520 vector<string> weightgroupsKeys;
526 int size() {
return int(weights.size());}
529 int sizeWeightGroups() {
return int(weightgroups.size()); }
547 HEPRUP() : IDWTUP(0), NPRUP(0) {}
561 initrwgt = x.initrwgt;
562 generators = x.generators;
563 weightgroups = x.weightgroups;
574 void resize(
int nrup) {
583 XSECUP.resize(NPRUP);
584 XERRUP.resize(NPRUP);
585 XMAXUP.resize(NPRUP);
593 pair<long,long> IDBMUP;
596 pair<double,double> EBMUP;
600 pair<int,int> PDFGUP;
604 pair<int,int> PDFSUP;
615 vector<double> XSECUP;
619 vector<double> XERRUP;
623 vector<double> XMAXUP;
632 vector<LHAgenerator> generators;
635 map<string,LHAweightgroup> weightgroups;
638 map<string,LHAweight> weights;
657 : NUP(0), IDPRUP(0), XWGTUP(0.0), XPDWUP(0.0, 0.0),
658 SCALUP(0.0), AQEDUP(0.0), AQCDUP(0.0), heprup(0) {}
691 void resize(
int nup) {
697 double weight()
const {
719 pair<double,double> XPDWUP;
739 vector< pair<int,int> > MOTHUP;
743 vector< pair<int,int> > ICOLUP;
747 vector< vector<double> > PUP;
751 vector<double> VTIMUP;
756 vector<double> SPINUP;
762 map<string,double> weights_detailed;
765 vector<double> weights_compressed;
810 : filename(filenameIn), intstream(NULL), file(NULL) {
811 intstream =
new igzstream(filename.c_str());
817 : filename(
""), intstream(NULL), file(is) {
823 if (intstream)
delete intstream;
834 bool setup(
string filenameIn) {
835 filename = filenameIn;
836 if (intstream)
delete intstream;
837 intstream =
new igzstream(filename.c_str());
853 bool readEvent(
HEPEUP * peup = 0);
860 weights_detailed_vec.resize(0);
868 if(!getline(*file, currentLine))
return false;
870 replace(currentLine.begin(),currentLine.end(),
'\'',
'\"');
881 igzstream* intstream;
904 string headerComments;
916 string eventComments;
919 vector<double> weights_detailed_vec;
920 vector<double> weights_detailed_vector() {
return weights_detailed_vec; }
982 : file(os), version(3) {}
987 : intstream(filename.c_str()), file(intstream), version(3) {}
993 ostream & headerBlock() {
998 ostream & initComments() {
1003 ostream & eventComments() {
1008 void list_end_tag() {
1009 file <<
"</LesHouchesEvents>" << endl;
1018 bool writeEvent(
HEPEUP * peup = 0,
int pDigits = 15);
1020 string getEventString(
HEPEUP * peup = 0);
1026 string hashline(
string s,
bool comment =
false);
1041 ostringstream headerStream;
1047 ostringstream initStream;
1053 ostringstream eventStream;
1075 #endif // end Pythia8_LHEF3_H