#include "tutil.h"
#include "lcio.h"
#include <cstdlib>
#include "SIO/LCIORandomAccess.h"
#include "SIO/LCIORandomAccessMgr.h"
#include "SIO/RunEventMap.h"
#include "UTIL/LCTOOLS.h"
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
Include dependency graph for test_randomaccess.cc:
Go to the source code of this file.
Functions | |
int | main (int argc, char **argv) |
Variables | |
static const string | testname = "random_access" |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 35 of file test_randomaccess.cc.
00035 { 00036 00037 // this should be the first line in your test 00038 TEST MYTEST=TEST( testname, std::cout ); 00039 00040 00041 MYTEST.LOG( " ---------------------------- testing class RunEvent" ) ; 00042 00043 // fill a few RunEvents into a set - test ordering with operator<() 00044 00045 set< RunEvent > reSet ; 00046 reSet.insert( RunEvent( 123456, -1 ) ) ; 00047 reSet.insert( RunEvent( 123456, 1 ) ) ; 00048 reSet.insert( RunEvent( 123456, 12 ) ) ; 00049 reSet.insert( RunEvent( 123450, -1 ) ) ; 00050 reSet.insert( RunEvent( 123450, 112345 ) ) ; 00051 00052 reSet.insert( EVENT::long64(123400) << 32 | (12345678LL & 0xffffffff) ) ; 00053 00054 MYTEST( reSet.size() , unsigned(6) , " set< RunEvent>.size() != 6 " ) ; 00055 00056 std::vector< RunEvent > v ; // copy to vector for easier comparison 00057 std::copy( reSet.begin() , reSet.end() , std::back_inserter( v ) ) ; 00058 00059 // int d=-1 ; 00060 // for( std::set< RunEvent >::iterator it = reSet.begin() ; it != reSet.end() ; ++it ){ 00061 // std::cout << " set[" << ++d <<"] " << *it << std::endl ; 00062 // } 00063 00064 std::stringstream err ; 00065 err << " v[0] : " << v[0] << std::endl 00066 << " v[1] : " << v[1] << std::endl 00067 << " v[2] : " << v[2] << std::endl 00068 << " v[3] : " << v[3] << std::endl 00069 << " v[4] : " << v[4] << std::endl 00070 << " v[5] : " << v[5] << std::endl ; 00071 00072 MYTEST( v[0] < v[1] , true , err.str() ) ; 00073 MYTEST( v[1] < v[2] , true , err.str() ) ; 00074 MYTEST( v[2] < v[3] , true , err.str() ) ; 00075 MYTEST( v[3] < v[4] , true , err.str() ) ; 00076 MYTEST( v[4] < v[5] , true , err.str() ) ; 00077 00078 00079 MYTEST.LOG( " ------------------------------------- testing class RunEventMap" ) ; 00080 00081 RunEventMap map ; 00082 00083 int count = 0 ; 00084 for( std::set< RunEvent >::iterator it = reSet.begin() ; it != reSet.end() ; ++it , ++count ){ 00085 00086 // std::cout << " set[" << count <<"] " << *it << std::endl ; 00087 map.add( *it , 1024 * count ) ; 00088 } 00089 MYTEST( map.getPosition( v[2] ), 2048 , " EventMap::getPosition() return for exisiting event " ) ; 00090 00091 MYTEST( unsigned (map.getNumberOfRunRecords() + map.getNumberOfEventRecords() ), 00092 map.size(), "RunEventMap invariant: nRun+nEvt = map.size " ); 00093 00094 MYTEST( map.getNumberOfEventRecords(), 4 , "RunEventMap::getNumberOfEventRecords() " ); 00095 MYTEST( map.getNumberOfRunRecords(), 2 , "RunEventMap::getNumberOfRunRecords() " ); 00096 00097 map.add( v[2] , 2048000 ) ; // overwrite existing entry 00098 00099 MYTEST( map.getPosition( v[2] ), 2048000 , " test if EventMap::add() overwrites existing entry " ) ; 00100 00101 MYTEST( map.getNumberOfEventRecords(), 4 , "RunEventMap::getNumberOfEventRecords() after addition of duplicate (overwrite) " ); 00102 00103 00104 00105 //if( true ){ 00106 if( false ){ 00107 // force test program to fail in this way: 00108 MYTEST.FAILED( "oops, something went wrong..." ); 00109 } 00110 00111 00112 MYTEST.LOG( " ------------------------------------- test random access in file simjob.slcio - file must exist in : " ) ; 00113 std::system("pwd") ; 00114 00115 // simjob.slcio has written 100 events in 10 runs, closing and re-opening the file after every run 00116 // this tests writing the random access records in append mode ... 00117 // here we make just one simple test of reading a given event 00118 00119 LCReader* lcReader = LCFactory::getInstance()->createLCReader( IO::LCReader::directAccess ) ; 00120 00121 // LCReader* lcReader = LCFactory::getInstance()->createLCReader( ) ; 00122 00123 try{ 00124 00125 lcReader->open( "c_sim.slcio" ) ; 00126 00127 00128 // test that we can still use read next for runheaders ..... 00129 LCRunHeader* rHdr = lcReader->readNextRunHeader() ; 00130 MYTEST( rHdr->getRunNumber() , 0 , " LCReader::readNextRunHeader() - run number is not 0" ); 00131 00132 LCEvent* evt = lcReader->readNextEvent() ; 00133 MYTEST( evt->getEventNumber() , 0 , " LCReader::readNextEvent() - event number is not 0" ); 00134 MYTEST( evt->getRunNumber() , 0 , " LCReader::readNextEvent() - run number is not 0" ); 00135 00136 00137 evt = lcReader->readEvent( 3 , 4 ) ; 00138 00139 MYTEST( evt !=0 , true , " LCReader::readEvent( 3 , 4 ) - evt is NULL" ); 00140 MYTEST( evt->getRunNumber() , 3 , " LCReader::readEvent( 3, 4 ) - run number is not 3" ); 00141 MYTEST( evt->getEventNumber() , 4 , " LCReader::readEvent( 3, 4 ) - event number is not 4" ); 00142 00143 } 00144 catch( Exception &e ){ 00145 00146 MYTEST.FAILED( e.what() ); 00147 } 00148 00149 lcReader->close(); 00150 00151 delete lcReader; 00152 /////////////////////////////////////////////////////////////////////// 00153 00154 return 0; 00155 }
const string testname = "random_access" [static] |
Definition at line 31 of file test_randomaccess.cc.