LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_splitting.cc
Go to the documentation of this file.
1 // test splitting
4 
5 #include "tutil.h"
6 #include "lcio.h"
7 
8 #include "EVENT/LCIO.h"
9 #include "IO/LCReader.h"
10 #include "IO/LCWriter.h"
11 #include "UTIL/LCSplitWriter.h"
12 #include "IMPL/LCEventImpl.h"
13 #include "IMPL/LCCollectionVec.h"
14 #include "IMPL/ClusterImpl.h"
15 #include "IMPL/LCFlagImpl.h"
16 
17 //#include <iostream>
18 #include <cstdio>
19 
20 using namespace std ;
21 using namespace lcio ;
22 
23 //static const int NRUN = 10 ;
24 static const int NEVENT = 40 ; // events
25 static const int NHITS = 100 ; // calorimeter hits per event
26 static const int SPLIT_SIZE_KB = 9 ;
27 
28 static string FILE_BASENAME = "splitting" ;
29 static string FILE_EXTENSION = ".slcio" ;
30 
31 // replace mytest with the name of your test
32 const static string testname="test_splitting";
33 
34 //=============================================================================
35 
36 int main(int /*argc*/, char** /*argv*/ ){
37 
38  // this should be the first line in your test
39  TEST MYTEST=TEST( testname, std::cout );
40 
41  try{
42 
43  MYTEST.LOG( "test splitting" );
44 
45 
46  vector<string> inputFilesVec ;
47  inputFilesVec.push_back( FILE_BASENAME + ".000" + FILE_EXTENSION );
48  inputFilesVec.push_back( FILE_BASENAME + ".001" + FILE_EXTENSION );
49  inputFilesVec.push_back( FILE_BASENAME + ".002" + FILE_EXTENSION );
50  inputFilesVec.push_back( FILE_BASENAME + ".003" + FILE_EXTENSION );
51  inputFilesVec.push_back( FILE_BASENAME + ".004" + FILE_EXTENSION );
52 
53  // remove files if needed
54  for(unsigned i=0 ; i<inputFilesVec.size() ; i++){
55  remove( inputFilesVec[i].c_str() );
56  }
57 
58  // create sio writer
59  //LCWriter* lcWrt = LCFactory::getInstance()->createLCWriter() ;
60  LCWriter* lcWrt = new LCSplitWriter( LCFactory::getInstance()->createLCWriter(), SPLIT_SIZE_KB*1024 ) ;
61 
62  //lcWrt->open( FILE_BASENAME + FILE_EXTENSION, LCIO::WRITE_NEW ) ;
63  lcWrt->open( FILE_BASENAME + FILE_EXTENSION );
64 
65  // EventLoop - create some events and write them to the file
66  for(int i=0;i<NEVENT;i++){
67 
68  // we need to use the implementation classes here
69  LCEventImpl* evt = new LCEventImpl() ;
70 
71 
72  evt->setRunNumber( 4711 ) ;
73  evt->setEventNumber( i ) ;
74 
75  LCCollectionVec* clusters = new LCCollectionVec( LCIO::CLUSTER ) ;
76 
77  for(int j=0;j<NHITS;j++){
78  ClusterImpl* clu = new ClusterImpl ;
79  clu->setEnergy( i*j*117. ) ;
80  float pos[3] = { float(i) , float(j) ,float(i*j) } ;
81  clu->setPosition( pos ) ;
82  clusters->addElement( clu ) ;
83  }
84 
85  evt->addCollection( clusters , "Clusters") ;
86 
87  lcWrt->writeEvent(evt) ;
88 
89  delete evt ;
90  }
91 
92 
93  lcWrt->close() ;
94 
95  MYTEST.LOG("test reading back from split files" ) ;
96 
97  // create sio reader
98  LCReader* lcRdr = LCFactory::getInstance()->createLCReader() ;
99 
100  lcRdr->open( inputFilesVec ) ;
101 
102  for(int i=0;i<NEVENT;i++){
103 
104  std::cout << " testing event " << i << std::endl ;
105 
106  LCEvent* evt = lcRdr->readNextEvent() ;
107 
108  MYTEST( evt->getRunNumber() , 4711 , " run number " ) ;
109 
110  MYTEST( evt->getEventNumber() , i , " event number " ) ;
111 
112  LCCollection* clusters = evt->getCollection( "Clusters") ;
113 
114  for(int j=0;j<NHITS;j++) {
115 
116  //std::cout << " testing hit " << j << std::endl ;
117 
118  Cluster* clu = dynamic_cast<Cluster*>(clusters->getElementAt(j)) ;
119 
120  MYTEST( clu->getEnergy() , i*j*117. , "energy" ) ;
121 
122  const float* pos = clu->getPosition() ;
123 
124  MYTEST( pos[0] , i , " pos[0] " ) ;
125  MYTEST( pos[1] , j , " pos[1] " ) ;
126  MYTEST( pos[2] , i*j , " pos[2] " ) ;
127 
128  }
129  }
130  lcRdr->close() ;
131 
132  } catch( Exception &e ){
133  MYTEST.FAILED( e.what() );
134  }
135 
136  return 0;
137 }
138 
139 //=============================================================================
140 
static string FILE_BASENAME
static const int NEVENT
T endl(T...args)
Definition: tutil.h:7
void FAILED(const std::string &msg)
Definition: tutil.h:42
T push_back(T...args)
int main(int argc, char **argv)
Simple program that opens existing LCIO files and appends the records needed for direct access - if t...
static string FILE_EXTENSION
T size(T...args)
STL class.
static const string testname
static const int NHITS
static const int SPLIT_SIZE_KB
void LOG(const std::string &msg)
Definition: tutil.h:21