1 package org.lcsim.lcio;
2
3 import hep.io.sio.SIOInputStream;
4 import hep.io.sio.SIOOutputStream;
5 import hep.io.sio.SIOWriter;
6
7 import java.io.IOException;
8 import java.util.ArrayList;
9 import java.util.HashSet;
10 import java.util.List;
11 import java.util.Set;
12 import org.lcsim.event.EventHeader;
13 import org.lcsim.event.Vertex;
14
15
16
17
18
19 class SIOVertexBlockHandler extends AbstractBlockHandler
20 {
21 private static final String ALGORITHM_TYPES = "_lcio.VertexAlgorithmTypes";
22 private static final String PARAMETER_NAMES = "VertexParameterNames";
23
24 private List<String> algorithmTypeKeys = new ArrayList<String>();
25 private List<String> parameterNameKeys = new ArrayList<String>();
26
27 public String getType()
28 {
29 return "Vertex";
30 }
31 public Class getClassForType()
32 {
33 return Vertex.class;
34 }
35 LCIOCallback addCollectionElements(LCIOEvent event, LCIOCollection collection, SIOInputStream in, int n, int version) throws IOException
36 {
37 String[] typeKeys = collection.getParameters().getStringMap().get(ALGORITHM_TYPES);
38 String[] parameterNames = collection.getParameters().getStringMap().get(PARAMETER_NAMES);
39
40 for (int i = 0; i < n; i++)
41 collection.add(new SIOVertex(in, collection.getFlags(), version, typeKeys, parameterNames));
42
43 return null;
44 }
45 void writeCollectionElement(Object element, SIOOutputStream out, int flags) throws IOException
46 {
47 SIOVertex.write((Vertex) element, out, flags, algorithmTypeKeys, parameterNameKeys);
48 }
49
50 public void writeBlock(SIOWriter writer, List collection, EventHeader.LCMetaData md) throws IOException
51 {
52 Set<String> types = new HashSet<String>();
53 Set<String> names = new HashSet<String>();
54 for (Vertex v : (List<Vertex>) collection)
55 {
56 types.add(v.getAlgorithmType());
57 for (String name : v.getParameters().keySet())
58 {
59 names.add(name);
60 }
61 }
62 algorithmTypeKeys = new ArrayList(types);
63 String[] keyStrings = new String[types.size()];
64 md.getStringParameters().put(ALGORITHM_TYPES,types.toArray(keyStrings));
65
66 parameterNameKeys = new ArrayList(names);
67 String[] nameStrings = new String[names.size()];
68 md.getStringParameters().put(PARAMETER_NAMES,names.toArray(nameStrings));
69
70 super.writeBlock(writer, collection, md);
71 }
72 }