Print

Print


Commit in lcsim/test/org/lcsim/util/lcio on MAIN
CalorimeterHitIOTest.java+160-1591.2 -> 1.3
DeTabify

lcsim/test/org/lcsim/util/lcio
CalorimeterHitIOTest.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- CalorimeterHitIOTest.java	24 Aug 2007 19:56:42 -0000	1.2
+++ CalorimeterHitIOTest.java	9 Oct 2007 17:56:18 -0000	1.3
@@ -9,7 +9,6 @@
 
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
-import org.lcsim.event.EventHeader.LCMetaData;
 import org.lcsim.util.event.BaseCalorimeterHit;
 import org.lcsim.util.event.BaseLCSimEvent;
 import org.lcsim.util.test.TestUtil.TestOutputFile;
@@ -17,165 +16,167 @@
 /**
  * Creates an event with {@link org.lcsim.event.CalorimeterHit} collections
  * that have all permutations of the LCIO flag settings.  This event is written
- * to a file, read back in, and checked for correctness. 
- * 
+ * to a file, read back in, and checked for correctness.
+ *
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: CalorimeterHitIOTest.java,v 1.2 2007/08/24 19:56:42 jeremy Exp $
+ * @version $Id: CalorimeterHitIOTest.java,v 1.3 2007/10/09 17:56:18 tonyj Exp $
  */
-public class CalorimeterHitIOTest extends TestCase 
+public class CalorimeterHitIOTest extends TestCase
 {
-	public void testCalorimeterHitIO() throws IOException
-	{
-		// Create an empty event.
-		EventHeader event = new BaseLCSimEvent(0,0,"sdjan03");
-
-		// Create a list of test flags, all permutations of 4 settings for 16 total.
-		List<Integer> testFlags = makeTestFlags();
-														
-		// Add a hits collection to the event for every permutation of the flag settings.
-		for (int i=0; i<testFlags.size(); i++)
-		{
-			// Create a test collection of hits.
-			List<CalorimeterHit> hits = new ArrayList<CalorimeterHit>();		
-			
-			// Add two identical test hits to the collection.
-			TestCalorimeterHit testhit = new TestCalorimeterHit();
-			hits.add(testhit);		
-			testhit = new TestCalorimeterHit();
-			hits.add(testhit);
-			
-			event.put("TestCalorimeterHits_"+Integer.toHexString(testFlags.get(i)), hits, CalorimeterHit.class, testFlags.get(i));
-		}
-		
-		// Write out the event to a file.
-		File outfile = new TestOutputFile("CalorimeterHitIOTest.slcio");		
-		LCIOWriter writer = new LCIOWriter(outfile);
-		writer.write(event);
-		writer.close();
-		
-		// Read the event back.
-		LCIOReader reader = new LCIOReader(outfile);
-		EventHeader eventcheck = reader.read();
-		
-		// Test hit to compare against.
-		TestCalorimeterHit testhit = new TestCalorimeterHit();
-		
-		// Loop over all the different flag settings.
-		for (int i=0; i<testFlags.size(); i++)
-		{
-			int flag = testFlags.get(i);
- 					
-			// Get the collection with these flag settings.
-			List<CalorimeterHit> hitscheck = eventcheck.get(CalorimeterHit.class,"TestCalorimeterHits_"+Integer.toHexString(flag));					
-
-			// Check all from CalorimeterHit that do not depend on a valid LCMetaData or IDDecoder.
-			for (CalorimeterHit hit : hitscheck)
-			{				
-				// Check that cellIds are equal if full Id is stored.
-				if (LCIOUtil.bitTest(flag,LCIOConstants.RCHBIT_ID1))
-				{
-					assertEquals("cellId not equal", hit.getCellID(), testhit.getCellID());
-				}
-				else
-				{
-					assertEquals("partial cellId not equal", (int)hit.getCellID(), (int)testhit.getCellID());
-				}
-				
-				// Check position if CHBIT_LONG is set.
-				if (LCIOUtil.bitTest(flag,LCIOConstants.CHBIT_LONG))
-				{				
-					assertEquals("position[0] not equal", hit.getPosition()[0], testhit.getPosition()[0]);
-					assertEquals("position[1] not equal", hit.getPosition()[1], testhit.getPosition()[1]);
-					assertEquals("position[2] not equal", hit.getPosition()[2], testhit.getPosition()[2]);
-				}
-				// Check that an exception is thrown when trying to access position when CHBIT_LONG is not set.
-				else {
-					try {
-						hit.getPosition();
-						assertTrue("hit access should have thrown an exception",0==1);
-					}
-					catch (Exception x)
-					{
-						// OK.
-					}					
-				}
-
-				// Check that the raw energies are equal.
-				assertEquals("rawEnergy not equal", hit.getRawEnergy(), testhit.getRawEnergy());				
-				
-				// Check that times are equal.
-				if (LCIOUtil.bitTest(flag,LCIOConstants.RCHBIT_TIME))
-				{
-					assertEquals("time not equal", hit.getTime(), testhit.getTime(), 1e-7);
-				}
-				// Check that the time is 0.0 if RCHBIT_TIME is not set.
-				else 
-				{
-					assertEquals("time should be zero", hit.getTime(), 0.0);
-				}
-			}
-		}
-	}
-	
-	private List<Integer> makeTestFlags()
-	{		
-		List<Integer> flagList = new ArrayList<Integer>();
-		
-		List<int[]> perm = new ArrayList<int[]>();
-		for (int i=0; i<16; i++)
-		{
-			perm.add(new int[0]);
-		}
-		
-		perm.set(0,  new int[] {0,0,0,0} );
-		perm.set(1,  new int[] {1,0,0,0} );
-		perm.set(2,  new int[] {0,1,0,0} );
-		perm.set(3,  new int[] {0,0,1,0} );
-		perm.set(4,  new int[] {0,0,0,1} );
-		perm.set(5,  new int[] {1,1,0,0} );
-		perm.set(6,  new int[] {1,1,1,0} );
-		perm.set(7,  new int[] {1,1,0,1} );
-		perm.set(8,  new int[] {0,1,1,0} );
-		perm.set(9,  new int[] {0,1,1,1} );
-		perm.set(10, new int[] {1,0,1,0} );
-		perm.set(11, new int[] {1,0,1,1} );
-		perm.set(12, new int[] {0,0,1,1} );
-		perm.set(13, new int[] {1,0,0,1} );
-		perm.set(14, new int[] {1,1,1,1} );
-		perm.set(15, new int[] {0,1,0,1} );
-		
-		for (int i=0; i<16; i++)
-		{
-			int flag = 0;
-			
-			int[] x = perm.get(i);
-			
-			if (x[0] == 1)
-				flag |= 1 << LCIOConstants.RCHBIT_ID1;
-			
-			if (x[1] == 1)
-				flag |= 1 << LCIOConstants.RCHBIT_TIME;
-
-			if (x[2] == 1)
-				flag |= 1 << LCIOConstants.RCHBIT_NO_PTR;
-			
-			if (x[3] == 1)
-				flag |= 1 << LCIOConstants.CHBIT_LONG;
-			
-			flagList.add(flag);			
-		}
-
-		return flagList;
-	}
-	
-	class TestCalorimeterHit extends BaseCalorimeterHit
-	{
-		TestCalorimeterHit()
-		{
-			this.id = Long.parseLong("800000001",16);
-			this.position = new double[] {1.0,2.0,3.0};
-			this.rawEnergy = 10.0;
-			this.time = 1.1;
-		}
-	}
+   public void testCalorimeterHitIO() throws IOException
+   {
+      // Create an empty event.
+      EventHeader event = new BaseLCSimEvent(0,0,"sdjan03");
+      
+      // Create a list of test flags, all permutations of 4 settings for 16 total.
+      List<Integer> testFlags = makeTestFlags();
+      
+      // Add a hits collection to the event for every permutation of the flag settings.
+      for (int i=0; i<testFlags.size(); i++)
+      {
+         // Create a test collection of hits.
+         List<CalorimeterHit> hits = new ArrayList<CalorimeterHit>();
+         
+         // Add two identical test hits to the collection.
+         TestCalorimeterHit testhit = new TestCalorimeterHit();
+         hits.add(testhit);
+         testhit = new TestCalorimeterHit();
+         hits.add(testhit);
+         
+         event.put("TestCalorimeterHits_"+Integer.toHexString(testFlags.get(i)), hits, CalorimeterHit.class, testFlags.get(i));
+      }
+      
+      // Write out the event to a file.
+      File outfile = new TestOutputFile("CalorimeterHitIOTest.slcio");
+      LCIOWriter writer = new LCIOWriter(outfile);
+      writer.write(event);
+      writer.close();
+      
+      // Read the event back.
+      LCIOReader reader = new LCIOReader(outfile);
+      EventHeader eventcheck = reader.read();
+      
+      // Test hit to compare against.
+      TestCalorimeterHit testhit = new TestCalorimeterHit();
+      
+      // Loop over all the different flag settings.
+      for (int i=0; i<testFlags.size(); i++)
+      {
+         int flag = testFlags.get(i);
+         
+         // Get the collection with these flag settings.
+         List<CalorimeterHit> hitscheck = eventcheck.get(CalorimeterHit.class,"TestCalorimeterHits_"+Integer.toHexString(flag));
+         
+         // Check all from CalorimeterHit that do not depend on a valid LCMetaData or IDDecoder.
+         for (CalorimeterHit hit : hitscheck)
+         {
+            // Check that cellIds are equal if full Id is stored.
+            if (LCIOUtil.bitTest(flag,LCIOConstants.RCHBIT_ID1))
+            {
+               assertEquals("cellId not equal", hit.getCellID(), testhit.getCellID());
+            }
+            else
+            {
+               assertEquals("partial cellId not equal", (int)hit.getCellID(), (int)testhit.getCellID());
+            }
+            
+            // Check position if CHBIT_LONG is set.
+            if (LCIOUtil.bitTest(flag,LCIOConstants.CHBIT_LONG))
+            {
+               assertEquals("position[0] not equal", hit.getPosition()[0], testhit.getPosition()[0]);
+               assertEquals("position[1] not equal", hit.getPosition()[1], testhit.getPosition()[1]);
+               assertEquals("position[2] not equal", hit.getPosition()[2], testhit.getPosition()[2]);
+            }
+            // Check that an exception is thrown when trying to access position when CHBIT_LONG is not set.
+            else
+            {
+               try
+               {
+                  hit.getPosition();
+                  assertTrue("hit access should have thrown an exception",0==1);
+               }
+               catch (Exception x)
+               {
+                  // OK.
+               }
+            }
+            
+            // Check that the raw energies are equal.
+            assertEquals("rawEnergy not equal", hit.getRawEnergy(), testhit.getRawEnergy());
+            
+            // Check that times are equal.
+            if (LCIOUtil.bitTest(flag,LCIOConstants.RCHBIT_TIME))
+            {
+               assertEquals("time not equal", hit.getTime(), testhit.getTime(), 1e-7);
+            }
+            // Check that the time is 0.0 if RCHBIT_TIME is not set.
+            else
+            {
+               assertEquals("time should be zero", hit.getTime(), 0.0);
+            }
+         }
+      }
+   }
+   
+   private List<Integer> makeTestFlags()
+   {
+      List<Integer> flagList = new ArrayList<Integer>();
+      
+      List<int[]> perm = new ArrayList<int[]>();
+      for (int i=0; i<16; i++)
+      {
+         perm.add(new int[0]);
+      }
+      
+      perm.set(0,  new int[] {0,0,0,0} );
+      perm.set(1,  new int[] {1,0,0,0} );
+      perm.set(2,  new int[] {0,1,0,0} );
+      perm.set(3,  new int[] {0,0,1,0} );
+      perm.set(4,  new int[] {0,0,0,1} );
+      perm.set(5,  new int[] {1,1,0,0} );
+      perm.set(6,  new int[] {1,1,1,0} );
+      perm.set(7,  new int[] {1,1,0,1} );
+      perm.set(8,  new int[] {0,1,1,0} );
+      perm.set(9,  new int[] {0,1,1,1} );
+      perm.set(10, new int[] {1,0,1,0} );
+      perm.set(11, new int[] {1,0,1,1} );
+      perm.set(12, new int[] {0,0,1,1} );
+      perm.set(13, new int[] {1,0,0,1} );
+      perm.set(14, new int[] {1,1,1,1} );
+      perm.set(15, new int[] {0,1,0,1} );
+      
+      for (int i=0; i<16; i++)
+      {
+         int flag = 0;
+         
+         int[] x = perm.get(i);
+         
+         if (x[0] == 1)
+            flag |= 1 << LCIOConstants.RCHBIT_ID1;
+         
+         if (x[1] == 1)
+            flag |= 1 << LCIOConstants.RCHBIT_TIME;
+         
+         if (x[2] == 1)
+            flag |= 1 << LCIOConstants.RCHBIT_NO_PTR;
+         
+         if (x[3] == 1)
+            flag |= 1 << LCIOConstants.CHBIT_LONG;
+         
+         flagList.add(flag);
+      }
+      
+      return flagList;
+   }
+   
+   class TestCalorimeterHit extends BaseCalorimeterHit
+   {
+      TestCalorimeterHit()
+      {
+         this.id = Long.parseLong("800000001",16);
+         this.position = new double[] {1.0,2.0,3.0};
+         this.rawEnergy = 10.0;
+         this.time = 1.1;
+      }
+   }
 }
\ No newline at end of file
CVSspam 0.2.8