[−][src]Struct lhef::Writer
Writer for the LHEF format
The general usage to write a file is
ⓘThis example is not tested
// create writer let mut writer = lhef::Writer::new(my_file, version)?; // optionally write headers writer.header(my_header)?; writer.xml_header(my_xml_header)?; // write run information writer.heprup(my_heprup)?; // write events loop { writer.hepeup(my_hepeup)?; } // wrap up writer.finish()?;
It is important to keep the proper order of method calls and to call finish() at the end.
Implementations
impl<T: Write> Writer<T>
[src]
pub fn new(stream: T, version: &str) -> Result<Writer<T>, Box<dyn Error>>
[src]
Create a new LHEF writer
Example
// write to a file in LHEF version 1.0 let mut file = std::fs::File::create("events.lhe").unwrap(); let writer = lhef::Writer::new( &mut file, "1.0" ).unwrap();
// write to a byte vector let mut output = vec![]; let writer = lhef::Writer::new( std::io::Cursor::new(&mut output), "1.0" ).unwrap();
pub fn header(&mut self, header: &str) -> Result<(), Box<dyn Error>>
[src]
Write a LHEF comment header
Example
let mut output = vec![]; let mut writer = lhef::Writer::new( std::io::Cursor::new(&mut output), "1.0" ).unwrap(); writer.header("some header text").unwrap();
pub fn xml_header(&mut self, header: &XmlTree) -> Result<(), Box<dyn Error>>
[src]
Write a LHEF xml header
If the outermost xml tag in the argument is not "header" an additional "header" tag will be wrapped around the output. Line breaks may be added to ensure conformance with the LHEF standard.
Example
let mut output = vec![]; let mut writer = lhef::Writer::new( std::io::Cursor::new(&mut output), "1.0" ).unwrap(); let header = { let mut attr = std::collections::HashMap::new(); attr.insert("attr0".to_string(), "val0".to_string()); attr.insert("attr1".to_string(), "".to_string()); lhef::XmlTree{ prefix: None, namespace: None, namespaces: None, name: String::from("header"), attributes: attr, children: vec![], text: Some(String::from("some xml header")), } }; writer.xml_header(&header).unwrap();
pub fn heprup(&mut self, runinfo: &HEPRUP) -> Result<(), Box<dyn Error>>
[src]
Write the run information in HEPRUP format
Example
let mut output = vec![]; let mut writer = lhef::Writer::new( std::io::Cursor::new(&mut output), "1.0" ).unwrap(); let heprup = lhef::HEPRUP { IDBMUP: [2212, 2212], EBMUP: [7000.0, 7000.0], PDFGUP: [0, 0], PDFSUP: [230000, 230000], IDWTUP: 2, NPRUP: 1, XSECUP: vec!(120588124.02), XERRUP: vec!(702517.48228), XMAXUP: vec!(94290.49), LPRUP: vec!(1), info: String::new(), attr: lhef::XmlAttr::new(), }; writer.heprup(&heprup).unwrap();
pub fn hepeup(&mut self, event: &HEPEUP) -> Result<(), Box<dyn Error>>
[src]
Write event in HEPEUP format
Example
let mut output = vec![]; let mut writer = lhef::Writer::new( std::io::Cursor::new(&mut output), "1.0" ).unwrap(); // ... write run information here ... let hepeup = lhef::HEPEUP { NUP: 4, IDRUP: 1, XWGTUP: 84515.12, SCALUP: 91.188, AQEDUP: 0.007546771, AQCDUP: 0.1190024, IDUP: vec!(1, 21, 21, 1), ISTUP: vec!(-1, -1, 1, 1), MOTHUP: vec!([0, 0], [0, 0], [1, 2], [1, 2]), ICOLUP: vec!([503, 0], [501, 502], [503, 502], [501, 0]), PUP: vec!( [0.0, 0.0, 4.7789443449, 4.7789443449, 0.0], [0.0, 0.0, -1240.3761329, 1240.3761329, 0.0], [37.283715118, 21.98166528, -1132.689358, 1133.5159684, 0.0], [-37.283715118, -21.98166528, -102.90783056, 111.63910879, 0.0] ), VTIMUP: vec!(0.0, 0.0, 0.0, 0.0), SPINUP: vec!(1.0, -1.0, -1.0, 1.0), info: String::new(), attr: lhef::XmlAttr::new(), }; writer.hepeup(&hepeup).unwrap();
pub fn finish(&mut self) -> Result<(), Box<dyn Error>>
[src]
Close LHEF output
Example
let mut output = vec![]; let mut writer = lhef::Writer::new( std::io::Cursor::new(&mut output), "1.0" ).unwrap(); // ... write header, run information, events ... writer.finish().unwrap();
Trait Implementations
impl<T: Debug + Write> Debug for Writer<T>
[src]
impl<T: Write> Drop for Writer<T>
[src]
impl<T: Eq + Write> Eq for Writer<T>
[src]
impl<T: PartialEq + Write> PartialEq<Writer<T>> for Writer<T>
[src]
impl<T: Write> StructuralEq for Writer<T>
[src]
impl<T: Write> StructuralPartialEq for Writer<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Writer<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Writer<T> where
T: Send,
T: Send,
impl<T> Sync for Writer<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Writer<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Writer<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,