agile is hosted by Hepforge, IPPP Durham

AGILeIO.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #include "AGILe/AGILe.hh"
00004 #include "AGILe/GeneratorState.hh"
00005 
00006 #include "TinyXML/tinyxml.h"
00007 
00008 namespace AGILe{
00009 
00010   ostream &operator<<(ostream &os, const GeneratorState &state){
00011 
00012     TiXmlDocument doc;
00013 
00014     TiXmlElement hepml("hepml");
00015 
00016     doc.InsertEndChild(hepml);
00017 
00018     TiXmlElement* docRoot = doc.RootElement();
00019 
00020     TiXmlElement collision("collision");
00021 
00022     vector<TiXmlElement> pdfElements;
00023     
00024     vector<Beam> beams = state.getBeams();
00025 
00026     bool gotBeams = false;
00027     
00028     for(vector<Beam>::iterator beamIt = beams.begin();
00029         beamIt != beams.end(); ++beamIt){
00030       TiXmlElement beamElement("particle");
00031       beamElement.SetAttribute("name", beamIt->name);
00032       beamElement.SetAttribute("id", beamIt->position);
00033 
00034       TiXmlElement momentumElement("momentum");
00035       momentumElement.SetAttribute("unit", "GeV");
00036 
00037       stringstream s;
00038       s<<beamIt->energy;
00039       TiXmlText val(s.str());
00040       momentumElement.InsertEndChild(val);
00041       beamElement.InsertEndChild(momentumElement);
00042       collision.InsertEndChild(beamElement);
00043       gotBeams = true;
00044       
00045       TiXmlElement pdfEl("pdf");
00046       PDF pdf = state.getPDF(beamIt->name);
00047       pdfEl.SetAttribute("set", pdf.set);
00048       pdfEl.SetAttribute("member", pdf.member);
00049       pdfEl.SetAttribute("scheme", pdf.scheme);
00050       TiXmlElement pdfParticle("particle");
00051       pdfParticle.SetAttribute("name", pdf.particleId);
00052       pdfEl.InsertEndChild(pdfParticle);
00053       pdfElements.push_back(pdfEl);
00054     }
00055 
00056     TiXmlElement reaction("reaction");
00057     
00058     if(gotBeams) reaction.InsertEndChild(collision);
00059 
00060     docRoot->InsertEndChild(reaction);
00061 
00062     TiXmlElement runseries("runseries");
00063 
00064     TiXmlElement run("run");
00065 
00066     TiXmlElement seedElements("randomSeed");
00067 
00068     vector<int> seeds = state.getSeeds();
00069     
00070     int seedIndex = 1;
00071     
00072     bool gotSeeds = false;
00073 
00074     for(vector<int>::iterator seedIt = seeds.begin();
00075     seedIt!=seeds.end(); ++seedIt){
00076       TiXmlElement seed("seed");
00077       seed.SetAttribute("index", seedIndex);
00078       stringstream s;
00079       s<<*seedIt;
00080       TiXmlText val(s.str());
00081       seed.InsertEndChild(val);
00082       seedElements.InsertEndChild(seed);
00083       ++seedIndex;
00084       gotSeeds = true;
00085     }
00086     
00087     if(gotSeeds) run.InsertEndChild(seedElements);
00088 
00089     TiXmlElement normalisation("normalisation");
00090     TiXmlElement crossSection("crossSection");
00091     crossSection.SetAttribute("unit", "pb^-1");
00092     stringstream s;
00093     s<<state.getCrossSection();
00094     TiXmlText csText(s.str());
00095     crossSection.InsertEndChild(csText);
00096     normalisation.InsertEndChild(crossSection);
00097     s.str("");
00098     s<<state.getNEvents();
00099     TiXmlElement nEvents("numberOfEvents");    
00100     TiXmlText nText(s.str());
00101     nEvents.InsertEndChild(nText);
00102     normalisation.InsertEndChild(nEvents);
00103     TiXmlElement lumi("luminosity");
00104     run.InsertEndChild(normalisation);
00105 
00106     TiXmlElement genSettings("generatorSettings");
00107     
00108     TiXmlElement gen("generator");
00109     gen.SetAttribute("name",state.name());
00110     gen.SetAttribute("version", state.version());
00111     genSettings.InsertEndChild(gen);
00112     
00113     for(vector<TiXmlElement>::iterator pdfIt = pdfElements.begin();
00114         pdfIt!=pdfElements.end(); ++pdfIt){
00115       genSettings.InsertEndChild(*pdfIt);
00116     }
00117     
00118     run.InsertEndChild(genSettings);
00119     runseries.InsertEndChild(run);
00120 
00121     docRoot->InsertEndChild(runseries);
00122 
00123     os<<doc;
00124     os<<endl;
00125 
00126     return os;
00127   }
00128 
00129 }
Generated on Tue Mar 6 10:39:38 2012 for AGILe - A Generator Interface Library (+ executable) by  doxygen 1.6.3