7 added + 6 modified, total 13 files
lcio/rootio
diff -N ToDo.txt
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ToDo.txt 14 Sep 2009 13:50:47 -0000 1.1.2.1
@@ -0,0 +1,17 @@
+
+ To Do for ROOT I/O for LCIO
+ ===========================
+
+
+ - dependency structure of libraries:
+ liblcio.so should not depend on ROOT libraries !
+ -> can we use a dlopen mechanism ala marlin::ProcessorLoader ?
+
+ -> for now simply add ROOT libraries ....
+
+
+ - LCFactory needs to have mechanism to choose either SIO or RIO
+ -> could use default arguments (problem: createLCReader already has one)
+
+
+
lcio/rootio
diff -N instantLCIO.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ instantLCIO.C 14 Sep 2009 13:50:47 -0000 1.1.2.1
@@ -0,0 +1,38 @@
+#ifndef __CINT__
+#include "include/IMPL/MCParticleImpl.h"
+#include "include/IMPL/LCCollectionVec.h"
+#include "include/IMPL/LCEventImpl.h"
+#endif
+
+ //--------- loop over particles in the events ------------
+
+
+void instantLCIO() {
+
+
+ if (!TClassTable::GetDict("IMPL::ReconstructedParticleImpl")) {
+ unsigned res ;
+
+ res = gSystem->Load("./lib/liblcio.so");
+ res = gSystem->Load("./lib/liblcioDict.so");
+
+ // if (res != 0 ) {
+ // std::cout << " can't load ./liblcioDict.so ! err = " <<res<<std::endl;
+ // }
+ }
+
+
+ IMPL::MCParticleImpl* mcp = new IMPL::MCParticleImpl ;
+
+ IMPL::LCCollectionVec* col = new IMPL::LCCollectionVec ;
+
+ IMPL::LCEventImpl* evt = new IMPL::LCEventImpl ;
+
+
+
+ std::cout << " mcp pdg: " << mcp->getPDG() << std::endl ;
+ std::cout << " col #entries: " << col->getNumberOfEntries() << std::endl ;
+ std::cout << " evt : " << evt << std::endl ;
+
+
+}
lcio/src/cpp
diff -u -r1.22.2.2 -r1.22.2.3
--- CMakeLists.txt 8 Jul 2009 15:09:02 -0000 1.22.2.2
+++ CMakeLists.txt 14 Sep 2009 13:50:48 -0000 1.22.2.3
@@ -67,6 +67,11 @@
./src/IOIMPL/LCFactory.cc
)
+SET( LCIO_RIO_SRCS
+ ./src/RIO/RIOWriter.cc
+ ./src/RIO/RIOReader.cc
+)
+
SET( LCIO_SIO_SRCS
./src/SIO/LCSIO.cc
./src/SIO/SIOCalHitHandler.cc
@@ -118,7 +123,10 @@
-
+# -------- ROOT libraries -----------------
+IF( BUILD_ROOTIO )
+ INCLUDE( ${PROJECT_SOURCE_DIR}/FindROOT.cmake )
+ENDIF( BUILD_ROOTIO )
#------ require proper C++ -------
@@ -179,6 +187,9 @@
# MESSAGE( STATUS " in ADD_LCIO_BIN : " ${file} " " ./src/EXAMPLE/${file}.cc )
SET_TARGET_PROPERTIES( bin_${file} PROPERTIES OUTPUT_NAME ${file} )
TARGET_LINK_LIBRARIES( bin_${file} lib_LCIO )
+ IF( BUILD_ROOTIO )
+ TARGET_LINK_LIBRARIES( bin_${file} ${ROOT_LIBRARIES} lib_LCIODICT )
+ ENDIF( BUILD_ROOTIO )
INSTALL( TARGETS bin_${file} DESTINATION bin )
ENDMACRO()
#===================================================================
@@ -332,7 +343,9 @@
# #include "include/IOIMPL/TrackerRawDataIOImpl.h"
INCLUDE_DIRECTORIES( "${CMAKE_CURRENT_SOURCE_DIR}" )
- ADD_LIBRARY( lib_LCIODICT ${dict_lib_srcs} )
+ ADD_LIBRARY( lib_LCIODICT ${dict_lib_srcs} ${LCIO_RIO_SRCS} )
+ ADD_LIBRARY( lib_LCIO ${LCIO_RIO_SRCS} )
+
IF( APPLE )
SET( ROOT_DICT_LINK_FLAGS "-single_module -undefined dynamic_lookup -bind_at_load")
lcio/src/cpp/include/IMPL
diff -u -r1.19 -r1.19.8.1
--- LCEventImpl.h 8 Nov 2007 19:35:37 -0000 1.19
+++ LCEventImpl.h 14 Sep 2009 13:50:48 -0000 1.19.8.1
@@ -1,5 +1,5 @@
-#ifndef EVENT_LCEVENTIMPL_H
-#define EVENT_LCEVENTIMPL_H 1
+#ifndef IMPL_LCEventImpl_H
+#define IMPL_LCEventImpl_H 1
#include <string>
#include <map>
@@ -169,7 +169,7 @@
protected:
int _runNumber ;
int _eventNumber ;
- EVENT::long64 _timeStamp ;
+ EVENT::long64 _timeStamp ;
std::string _detectorName ;
// map has to be defined mutable in order to use _map[] for const methods ...
lcio/src/cpp/include/IOIMPL
diff -u -r1.3 -r1.3.2.1
--- LCFactory.h 10 Dec 2008 08:10:59 -0000 1.3
+++ LCFactory.h 14 Sep 2009 13:50:48 -0000 1.3.2.1
@@ -9,46 +9,46 @@
namespace IOIMPL {
-/**Factory to create LCWriter and Reader object for the known data
- * formats, e.g. SIO. Singleton class
- * that knows all concrete reader/writer implementations.
- *
- * @author gaede
- * @version Mar 10, 2003
- */
-class LCFactory : public IO::ILCFactory {
+ /**Factory to create LCWriter and Reader object for the known data
+ * formats, e.g. SIO. Singleton class
+ * that knows all concrete reader/writer implementations.
+ *
+ * @author gaede
+ * @version Mar 10, 2003
+ */
+ class LCFactory : public IO::ILCFactory {
-protected:
+ protected:
LCFactory() ;
-public:
+ public:
- /** Returns the instance of the factory.
- * In the future we need to specify the data format here...
- * This doesn't work for java as an interface can't have static members ...
- */
- static LCFactory* getInstance() ;
+ /** Returns the instance of the factory.
+ * In the future we need to specify the data format here...
+ * This doesn't work for java as an interface can't have static members ...
+ */
+ static LCFactory* getInstance() ;
- /// Destructor.
- virtual ~LCFactory() ;
+ /// Destructor.
+ virtual ~LCFactory() ;
- /**Creates an LCWriter object for the current persistency type.
- */
- virtual IO::LCWriter * createLCWriter() ;
+ /**Creates an LCWriter object for the current persistency type.
+ */
+ virtual IO::LCWriter * createLCWriter() ;
- /** Creates an LCReader object for the current persistency type.
- * lcReaderFlag: configuration options for the LCReader object -
- * combine multible options with '|'. So far only LCReader::directAccess.
- */
- virtual IO::LCReader * createLCReader(int lcReaderFlag=0 ) ;
+ /** Creates an LCReader object for the current persistency type.
+ * lcReaderFlag: configuration options for the LCReader object -
+ * combine multible options with '|'. So far only LCReader::directAccess.
+ */
+ virtual IO::LCReader * createLCReader(int lcReaderFlag=0 ) ;
-private:
+ private:
- static LCFactory * _me ;
+ static LCFactory * _me ;
-}; // class
+ }; // class
} // namespace IOIMPL
#endif /* ifndef IOIMPL_LCFactory_h */
lcio/src/cpp/include/RIO
diff -N RIOLCCollectionHandler.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RIOLCCollectionHandler.h 14 Sep 2009 13:50:48 -0000 1.1.2.1
@@ -0,0 +1,152 @@
+#ifndef RIOLCCollectionHandler_h
+#define RIOLCCollectionHandler_h 1
+
+#include "lcio.h"
+#include "EVENT/LCEvent.h"
+
+#include "IMPL/LCCollectionVec.h"
+#include "UTIL/LCTypedVector.h"
+
+#include "TTree.h"
+
+
+namespace RIO{
+ /* Abstract interface for handling collections of different types.
+ **/
+
+ class RIOBranchHandler{
+
+ public:
+
+ virtual void toBranch( const EVENT::LCEvent* evt )=0 ;
+
+ virtual void fromBranch( EVENT::LCEvent* evt )=0 ;
+
+ } ;
+
+
+
+ /** Branch handler class for (typed) LCCollections.
+ */
+
+ template <typename T>
+ class RIOLCCollectionHandler : public RIOBranchHandler{
+
+ protected:
+
+ std::string _name ;
+ std::vector<T*>* _tv ;
+ IMPL::LCParametersImpl* _params ;
+
+ public:
+
+ /** C'tor.
+ */
+ RIOLCCollectionHandler(const char* name, TTree* tree ) :
+
+ _name(name) {
+
+ std::cout << " RIOLCCollectionHandler( " << name << ", " << tree << ")" << std::endl ;
+
+ _tv = new std::vector<T*> ;
+
+ TBranch* br = (TBranch*) tree->GetBranch( name ) ;
+
+ if( br != 0 ){ // branch allready exists -> update/append mode
+
+ br->SetAddress( &_tv ) ;
+
+ } else {
+
+ //FIXME: make split level and 'record size' parameters ....
+ tree->Branch( name , &_tv, 16000, 2 );
+ }
+
+
+ _params = 0 ; //new IMPL::LCParametersImpl ;
+
+ std::string pName(name) ;
+
+ pName += "_param" ;
+
+ br = (TBranch*) tree->GetBranch( pName.c_str() ) ;
+
+ if( br != 0 ){ // branch allready exists -> update/append mode
+
+ br->SetAddress( &_params ) ;
+
+ } else {
+
+ //FIXME: make split level and 'record size' parameters ....
+ tree->Branch( pName.c_str() , &_params, 16000, 2 );
+ }
+
+
+
+
+
+
+
+ }
+
+
+
+ virtual void toBranch( const EVENT::LCEvent* evt ){
+
+ _tv->clear() ;
+
+ try{
+
+ EVENT::LCCollection* col = evt->getCollection( _name ) ;
+
+ int n = col->getNumberOfElements() ;
+
+ _tv->resize( n ) ;
+
+ for( int i=0; i<n ; ++i){
+
+ (*_tv)[i] = dynamic_cast<T*>( col->getElementAt(i) ) ;
+ }
+
+
+ IMPL::LCParametersImpl* lcp = dynamic_cast<IMPL::LCParametersImpl*> ( & col->parameters() ) ;
+ _params = lcp ;
+
+
+ //FIXME: we also need to add the collection flags to the meta data branch ...
+
+
+ } catch(const lcio::DataNotAvailableException& e){
+
+ _tv->resize( 0 ) ;
+
+ std::cout << " collection not found : " << _name << std::endl ;
+ }
+
+
+ // std::cout << " size of _tv " << _tv->size() << " for " << _name << std::endl ;
+
+ }
+
+
+ virtual void fromBranch( EVENT::LCEvent* evt ){
+
+ // read branch (if requested) from file and add collection to the event
+ }
+
+
+
+ virtual ~RIOLCCollectionHandler() {
+
+ delete _tv ;
+ }
+
+
+
+ }; // class
+
+
+} // end namespace
+
+#endif
+//=============================================================================
lcio/src/cpp/include/RIO
diff -N RIOReader.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RIOReader.h 14 Sep 2009 13:50:48 -0000 1.1.2.1
@@ -0,0 +1,189 @@
+#ifndef RIO_RIOReader_H
+#define RIO_RIOReader_H 1
+
+#include <string>
+#include <set>
+#include <map>
+
+#include "IO/LCReader.h"
+#include "IO/LCEventListener.h"
+#include "IO/LCRunListener.h"
+
+#include "IOIMPL/LCEventIOImpl.h"
+#include "IOIMPL/LCRunHeaderIOImpl.h"
+#include "LCIOTypes.h"
+
+
+class TFile ;
+class TTree ;
+
+namespace RIO {
+
+
+ class RIOBranchHandler ;
+
+ typedef std::vector< RIOBranchHandler * > BranchVector ;
+
+
+ /** Concrete implementation of LCWriter using ROOT I/O.
+ *
+ * @author gaede
+ * @version $Id: RIOReader.h,v 1.1.2.1 2009/09/14 13:50:48 gaede Exp $
+ */
+ class RIOReader : public IO::LCReader {
+
+ typedef std::map< EVENT::long64 , EVENT::long64 > EventMap ;
+
+ public:
+
+ /** Default constructor.
+ */
+ RIOReader( int lcReaderFlag=0 ) ;
+
+ // Destructor
+ virtual ~RIOReader() ;
+
+
+ /** Opens a list of files for reading (read-only). All subsequent
+ * read operations will operate on the list, i.e. if an EOF is encountered
+ * the next file in the list will be opened and read transparently to the
+ * user.
+ * @throws IOException
+ */
+ virtual void open(const std::vector<std::string>& filenames)
+ throw (IO::IOException, std::exception) ;
+
+
+ /** Opens a file for reading (read-only).
+ * @throws IOException
+ */
+ virtual void open(const std::string & filename) throw (IO::IOException, std::exception) ;
+
+ /** Reads the next run header from the file.
+ *
+ * @throws IOException
+ */
+ virtual EVENT::LCRunHeader * readNextRunHeader() throw (IO::IOException, std::exception) ;
+
+ /** Same as readNextRunHeader() but allows to set the access mode
+ * LCIO::READ_ONLY (default) or LCIO::Update.
+ *
+ * @throws IOException
+ */
+ virtual EVENT::LCRunHeader * readNextRunHeader(int accessMode) throw (IO::IOException, std::exception) ;
+
+
+ /** Reads the next event from the file.
+ *
+ * @throws IOException
+ */
+ virtual EVENT::LCEvent* readNextEvent() throw (IO::IOException, std::exception) ;
+
+
+ /** Same as readNextRunHeader() but allows to set the access mode
+ * LCIO::READ_ONLY (default) or LCIO::Update
+ *
+ * @throws IOException
+ */
+ virtual EVENT::LCEvent* readNextEvent( int accessMode) throw (IO::IOException, std::exception) ;
+
+
+ /** Skips the next n events from the current position. In fact simply reads the next n
+ * event headers so that the next event read is the (n+1)-th event.
+ */
+ virtual void skipNEvents(int n) ;
+
+
+ /** Reads the specified event from file.
+ * To be used with care: events have to be read in sequential
+ * order (as LCIO has no direct access yet).
+ *
+ * @throws IOException
+ */
+ virtual EVENT::LCEvent * readEvent(int runNumber, int evtNumber)
+ throw (IO::IOException, std::exception/*, EVENT::NotAvailableException */) ;
+
+ /** Closes the output file/stream etc.
+ *
+ * @throws IOException
+ */
+ virtual void close() throw (IO::IOException, std::exception) ;
+
+ // interface for listeners
+
+ /** Registers a listener for reading LCEvents from a stream.
+ */
+ virtual void registerLCEventListener(IO::LCEventListener * ls) ;
+
+ /** Remove a listener for reading LCEvents from a stream.
+ */
+ virtual void removeLCEventListener(IO::LCEventListener * ls) ;
+
+ /** Registers a listener for reading LCEventsLCRunHeaders from a stream.
+ */
+ virtual void registerLCRunListener(IO::LCRunListener * ls) ;
+
+ /** Remove a listener for reading LCRunHeaders from a stream.
+ */
+ virtual void removeLCRunListener(IO::LCRunListener * ls) ;
+
+ /** Reads the input stream and notifies registered
+ * listeners according to the object type
+ * found in the stream.
+ *
+ * @throws IOException
+ * @throws EndOfException
+ */
+ virtual void readStream() throw (IO::IOException, std::exception) ;
+
+ /** Reads maxRecord from the input stream and notifies registered
+ * listeners according to the object type found in the stream.
+ * Throws EndOfException if less than maxRecord records are found in the stream.
+ *
+ * @throws IOException
+ * @throws EndOfException
+ */
+ virtual void readStream(int maxRecord) throw (IO::IOException, std::exception) ;
+
+
+
+
+ protected:
+
+ void setUpHandlers( const EVENT::LCEvent * evt ) ;
+ // void readRecord() throw (IO::IOException , IO::EndOfDataException , std::exception) ;
+
+
+ void postProcessEvent() ;
+
+ void getEventMap() ;
+
+
+
+ protected:
+
+ TFile* _file ;
+ TTree* _tree ;
+
+ BranchVector _branches ;
+ bool _haveBranches ;
+
+ IOIMPL::LCEventIOImpl *_evtImpl ;
+
+ IOIMPL::LCRunHeaderIOImpl *_runImpl ;
+
+ std::set<IO::LCRunListener*> _runListeners ;
+ std::set<IO::LCEventListener*> _evtListeners ;
+
+ const std::vector<std::string>* _myFilenames ;
+ unsigned int _currentFileIndex ;
+
+ EventMap _evtMap ;
+ const bool _readEventMap ;
+
+ int _entry ;
+
+ }; // class
+} // namespace
+
+#endif /* ifndef RIO_RIOREADER_H */
lcio/src/cpp/include/RIO
diff -N RIOWriter.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RIOWriter.h 14 Sep 2009 13:50:48 -0000 1.1.2.1
@@ -0,0 +1,132 @@
+#ifndef RIO_RIOWriter_H
+#define RIO_RIOWriter_H 1
+
+#include <string>
+#include <vector>
+#include "IO/LCWriter.h"
+#include "IMPL/LCEventImpl.h"
+#include "EVENT/LCRunHeader.h"
+
+#include "RIOLCCollectionHandler.h"
+
+class TFile ;
+class TTree ;
+
+namespace RIO {
+
+
+ class RIOBranchHandler ;
+
+ typedef std::vector< RIOBranchHandler * > BranchVector ;
+
+
+ // class RIOReader ;
+
+
+ /** Concrete implementation of LCWriter using ROOT I/O
+ * Use LCFactory to instantiate.
+ *
+ * @see LCFactory
+ * @author gaede
+ * @version Sep 9, 2009
+ */
+
+ class RIOWriter : public IO::LCWriter {
+
+ // friend class RIOReader ;
+
+ public:
+
+ /**Default constructor.
+ */
+ RIOWriter() ;
+ /**
+ * Destructor
+ */
+ virtual ~RIOWriter() ;
+
+ /** Opens a file for writing. If file with given name exists,
+ * an exception is thrown. Use append or new mode instead.
+ *
+ *@throws IOException
+ */
+ virtual void open(const std::string & filename) throw (IO::IOException, std::exception) ;
+
+ /** Opens a file for writing.
+ * Possible write modes are: LCIO::WRITE_NEW
+ * (existing files are replaced) and LCIO::WRITE_APPEND.
+ *
+ *@throws IOException
+ */
+ virtual void open(const std::string & filename, int writeMode)throw (IO::IOException, std::exception) ;
+
+ /** Set the compression level - needs to be called before open() otherwise
+ * call will have no effect. If not called the Writer will use default compression.<br>
+ * Valid compression levels are:
+ * <ul>
+ * <li> level < 0 : default compression </li>
+ * <li> level == 0 : no compression</li>
+ * <li> level > 0 : 1 (fastest) - 9 (best compression)
+ * </li>
+ * </ul>
+ * Experimental code - don't use for production.
+ *
+ *@param level compression level
+ */
+ virtual void setCompressionLevel(int level) ;
+
+
+ /** Writes the given run header to file.
+ *
+ *@throws IOException
+ */
+ virtual void writeRunHeader(const EVENT::LCRunHeader * hdr)throw (IO::IOException, std::exception) ;
+
+ /** Writes the given event to file.
+ *
+ *@throws IOException
+ */
+ virtual void writeEvent(const EVENT::LCEvent * evt) throw (IO::IOException, std::exception) ;
+
+ /** Closes the output file/stream etc.
+ *
+ *@throws IOException
+ */
+ virtual void close() throw (IO::IOException, std::exception) ;
+
+ /** Flushes the output file/stream etc.
+ *
+ *@throws IOException
+ */
+ virtual void flush() throw (IO::IOException, std::exception) ;
+
+ protected:
+
+ /** Sets up the handlers for writing the current event.
+ */
+ void setUpHandlers(const EVENT::LCEvent * evt) ;
+
+ /** Creates a proper filename with extension '.lcio.root'
+ * in sioFilename.
+ */
+ void getRIOFileName(const std::string& filename,
+ std::string& sioFilename) ;
+
+ protected:
+
+ int _compressionLevel ;
+
+ TFile* _file ;
+ TTree* _tree ;
+
+ const IMPL::LCEventImpl* _evtImpl ;
+
+ BranchVector _branches ;
+
+ bool _haveBranches ;
+
+ }; // class
+
+} // namespace.
+
+#endif /* ifndef RIO_RIOWriter_H */
lcio/src/cpp/include/RIO
diff -u -r1.1.2.1 -r1.1.2.2
--- rootio_templates.h 9 Sep 2009 13:27:44 -0000 1.1.2.1
+++ rootio_templates.h 14 Sep 2009 13:50:48 -0000 1.1.2.2
@@ -6,6 +6,8 @@
#include "IMPL/ReconstructedParticleImpl.h"
#include "IMPL/MCParticleImpl.h"
+#include "IMPL/SimCalorimeterHitImpl.h"
+#include "IMPL/SimTrackerHitImpl.h"
#include "IMPL/VertexImpl.h"
#include "IMPL/TrackImpl.h"
#include "IMPL/ClusterImpl.h"
@@ -18,31 +20,22 @@
#ifdef __MAKECINT__
#pragma link C++ class std::vector<IMPL::ReconstructedParticleImpl*>+;
#pragma link C++ class std::vector<IMPL::MCParticleImpl*>+;
+#pragma link C++ class std::vector<IMPL::SimTrackerHitImpl*>+;
+#pragma link C++ class std::vector<IMPL::SimCalorimeterHitImpl*>+;
#pragma link C++ class std::vector<IMPL::TrackImpl*>+;
#pragma link C++ class std::vector<IMPL::ClusterImpl*>+;
#pragma link C++ class std::vector<IMPL::LCRelationImpl*>+;
#pragma link C++ class std::vector<IMPL::VertexImpl*>+;
+#pragma link C++ class std::vector<EVENT::LCObject*>+;
#pragma link C++ class std::vector<EVENT::ReconstructedParticle*>+;
#pragma link C++ class std::vector<EVENT::MCParticle*>+;
+#pragma link C++ class std::vector<EVENT::SimTrackerHit*>+;
+#pragma link C++ class std::vector<EVENT::SimCalorimeterHit*>+;
#pragma link C++ class std::vector<EVENT::Track*>+;
#pragma link C++ class std::vector<EVENT::Cluster*>+;
#pragma link C++ class std::vector<EVENT::LCRelation*>+;
#pragma link C++ class std::vector<EVENT::Vertex*>+;
#endif
-
-
-
-
-
-// seperate data members and pointer members in ROOT
-struct ReconstructedParticleROOT{
- EVENT::ReconstructedParticle* Particle ;
- TRefArray Tracks ;
-} ;
-
-
-
-
#endif
lcio/src/cpp/src/EXAMPLE
diff -u -r1.1.2.2 -r1.1.2.3
--- rootio.cc 13 Jul 2009 08:30:47 -0000 1.1.2.2
+++ rootio.cc 14 Sep 2009 13:50:48 -0000 1.1.2.3
@@ -13,7 +13,7 @@
#include "IMPL/LCEventImpl.h"
// #include "EVENT/LCRunHeader.h"
-#include "IOIMPL/rootio_templates.h"
+//#include "IOIMPL/rootio_templates.h"
#include "LCCol2Branch.h"
@@ -130,12 +130,11 @@
// the event loop
while( (evt = lcReader->readNextEvent()) != 0 ) {
-
for( BV::const_iterator it = _branches.begin() ; it != _branches.end() ; ++it) {
-
+
(*it)->fill( evt ) ;
}
-
+
_tree->Fill() ;
nEvents ++ ;
lcio/src/cpp/src/IOIMPL
diff -u -r1.3 -r1.3.2.1
--- LCFactory.cc 10 Dec 2008 08:10:59 -0000 1.3
+++ LCFactory.cc 14 Sep 2009 13:50:48 -0000 1.3.2.1
@@ -9,9 +9,12 @@
#include "SIO/SIOReader.h"
+#include "RIO/RIOWriter.h"
+#include "RIO/RIOReader.h"
+
using namespace IO ;
-using namespace SIO ;
+//using namespace SIO ;
namespace IOIMPL{
@@ -38,13 +41,15 @@
// the reason for having this class
// so far we just create SIO objects
- return new SIOWriter ;
+ // return new SIO::SIOWriter ;
+ return new RIO::RIOWriter ;
}
LCReader * LCFactory::createLCReader(int lcReaderFlag) {
// so far we just create SIO objects
- return new SIOReader( lcReaderFlag );
+ // return new SIO::SIOReader( lcReaderFlag );
+ return new RIO::RIOReader( lcReaderFlag );
}
lcio/src/cpp/src/RIO
diff -N RIOReader.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RIOReader.cc 14 Sep 2009 13:50:48 -0000 1.1.2.1
@@ -0,0 +1,521 @@
+#include "RIO/RIOReader.h"
+
+#include "RIO/RIOLCCollectionHandler.h"
+
+#include "LCIOSTLTypes.h"
+
+#include "EVENT/LCIO.h"
+#include "IMPL/LCIOExceptionHandler.h"
+#include "EVENT/MCParticle.h"
+#include "EVENT/SimCalorimeterHit.h"
+#include "EVENT/SimTrackerHit.h"
+
+#include "TFile.h"
+#include "TTree.h"
+
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include <algorithm>
+#include <cstring>
+#include <climits>
+
+#include <sys/stat.h>
+
+using namespace EVENT ;
+using namespace IO ;
+using namespace IOIMPL ;
+using namespace IMPL ;
+
+#define EVENTKEY(RN,EN) ( EVENT::long64( RN ) << 32 ) | EN
+
+namespace RIO {
+
+ //#define DEBUG 1
+
+ RIOReader::RIOReader( int lcReaderFlag ) :
+ _file(0),
+ _tree(0),
+ _haveBranches( false ),
+ _evtImpl(0),
+ _runImpl(0),
+ _myFilenames(0),
+ _currentFileIndex(0),
+ _readEventMap( lcReaderFlag & LCReader::directAccess ),
+ _entry(-1) {
+
+#ifdef DEBUG
+#else
+#endif
+
+ LCIOExceptionHandler::createInstance() ;
+ }
+
+
+ RIOReader::~RIOReader(){
+
+
+// delete _evtP ;
+// delete _runP ;
+ }
+
+
+ void RIOReader::open(const std::vector<std::string>& filenames)
+ throw( IOException , std::exception){
+
+ unsigned int i;
+ struct stat fileinfo ;
+ std::string missing_files;
+
+ // JE: first we check if all files exist
+ for(i=0; i < filenames.size(); i++){
+
+ if ( stat( filenames[i].c_str(), &fileinfo ) != 0 ){
+ missing_files += filenames[i] ;
+ missing_files += " " ;
+ }
+ }
+
+ // JE: if not raise IOException
+ if( missing_files.size() != 0 ){
+ throw IOException( std::string( "[RIOReader::open()] File(s) not found: " + missing_files )) ;
+ }
+
+ _myFilenames = &filenames ;
+
+ _currentFileIndex = 0 ;
+
+ open( (*_myFilenames)[ _currentFileIndex ] ) ;
+ }
+
+
+
+ void RIOReader::open(const std::string& filename) throw( IOException , std::exception) {
+
+
+ std::string rioFilename ;
+ // ---- we don't require the standard file extension for reading any more
+ //if( !( filename.rfind(".") filename.length() ))
+ // sioFilename = filename + LCRIO::FILE_EXTENRION ;
+ //else
+
+ rioFilename = filename ;
+
+ _file = new TFile( rioFilename.c_str() , "READ");
+
+ if( _file->IsZombie() )
+ throw IOException( std::string( "[RIOReader::open()] zombie root file : "
+ + rioFilename ) ) ;
+
+ if( !_file->IsOpen() )
+ throw IOException( std::string( "[RIOReader::open()] Couldn't open file: "
+ + rioFilename ) ) ;
+
+
+ _tree = (TTree*) _file->Get("LCIO") ;
+
+ if( !_tree ){
+
+ throw IOException( std::string( "[RIOReader::open()] Couldn't find \"LCIO\"-TTree "
+ + rioFilename ) ) ;
+ }
+
+
+ if( _readEventMap ){
+ getEventMap() ;
+ }
+ }
+
+ void RIOReader::getEventMap() {
+
+
+// // int status = _stream->seek(0) ; // go to start - FIXME - should we store the current position ?
+
+// // if( status != RIO_STREAM_SUCCESS )
+// // throw IOException( std::string( "[RIOReader::getEventMap()] Can't seek stream to 0" ) ) ;
+
+// // // std::cout << " RIOReader::getEventMap() recreating event map for direct access ..."
+// // // << std::endl ;
+
+// // { // -- scope for unpacking evt header --------
+// // RIOUnpack hdrUnp( RIOUnpack::EVENTHDR ) ;
+
+// // while( true ){
+
+// // RIO_blockManager::remove( LCRIO::HEADERBLOCKNAME ) ;
+// // RIO_blockManager::add( _evtHandler ) ;
+
+// // //---- readRecord() ;
+// // // read the next record from the stream
+// // if( _stream->getState()== RIO_STATE_OPEN ){
+
+// // unsigned int status = _stream->read( &_dummyRecord ) ;
+
+// // if( ! (status & 1) ){
+
+// // if( status & RIO_STREAM_EOF ){
+// // break ;
+// // }
+
+// // throw IOException( std::string(" io error on stream: ") + *_stream->getName() ) ;
+// // }
+// // } else {
+// // throw IOException( std::string(" stream not open: ")+ *_stream->getName() ) ;
+// // }
+
+// // //--
+// // int runNum = (*_evtP)->getRunNumber() ;
+// // int evtNum = (*_evtP)->getEventNumber() ;
+
+// // _evtMap[ EVENTKEY( runNum , evtNum ) ] = _stream->lastRecordStart() ;
+
+// // // EVENT::long64 key = (EVENT::long64( runNum ) << 32 ) | evtNum ;
+// // // std::cout << " " << key << " - " << _stream->lastRecordStart()
+// // // << " evt: " << evtNum << std::endl ;
+
+// // } // while
+
+// // _stream->seek(0) ; // go to start - FIXME - should we store the current
+
+// // if( status != RIO_STREAM_SUCCESS )
+// // throw IOException( std::string( "[RIOReader::getEventMap()] Can't seek stream to 0" ) ) ;
+
+// // }// -- end of scope for unpacking evt header --
+
+// // // std::cout << " RIOReader::getEventMap() : done " << std::endl ;
+
+ }
+
+
+
+ LCRunHeader* RIOReader::readNextRunHeader() throw (IOException , std::exception ) {
+ return readNextRunHeader( LCIO::READ_ONLY ) ;
+ }
+
+ LCRunHeader* RIOReader::readNextRunHeader(int accessMode) throw (IOException , std::exception ) {
+
+ // ToDo ...
+
+// // // set the _runRecord to unpack for this scope
+// // // RIORecordUnpack runUnp( RIOWriter::_runRecord ) ;
+// // RIOUnpack runUnp( RIOUnpack::RUN ) ;
+
+
+// // // this might throw the exceptions
+// // try{
+// // readRecord() ;
+// // }
+// // catch(EndOfDataException){
+// // return 0 ;
+// // }
+
+// // // set the proper acces mode before returning the event
+// // (*_runP)->setReadOnly( accessMode == LCIO::READ_ONLY ) ;
+
+ return _runImpl ;
+ }
+
+ void RIOReader::setUpHandlers(const LCEvent * evt){
+
+ if( !_haveBranches ) {
+
+
+ // first we create a branch for the event (header)
+
+ TBranch* br = (TBranch*) _tree->GetBranch( "LCEvent" ) ;
+
+ if( br != 0 ){ // branch allready exists -> update/append mode
+
+ br->SetAddress( &_evtImpl ) ;
+
+ } else {
+
+ //FIXME: make split level and 'record size' parameters ....
+ _tree->Branch( "LCEvent" , &_evtImpl , 16000, 2 );
+ }
+
+ // loop over all collections in first event ...
+ typedef std::vector< std::string > StrVec ;
+
+ const StrVec* strVec = evt->getCollectionNames() ;
+
+ for( StrVec::const_iterator name = strVec->begin() ; name != strVec->end() ; name++){
+
+ LCCollection* col = evt->getCollection( *name ) ;
+
+ const LCParameters& params = col->getParameters() ;
+ std::string typeName = col->getTypeName() ;
+
+ std::cout << " registering collection " << *name << " of " << typeName << std::endl ;
+
+
+ //FIXME: these should be held by a singleton handler manager (registry)
+ if( typeName == LCIO::MCPARTICLE ){
+
+ _branches.push_back( new RIO::RIOLCCollectionHandler<EVENT::MCParticle>(name->c_str() ,_tree) ) ;
+ }
+ if( typeName == LCIO::SIMCALORIMETERHIT ){
+
+ _branches.push_back( new RIO::RIOLCCollectionHandler<EVENT::SimCalorimeterHit>(name->c_str() ,_tree) ) ;
+ }
+ if( typeName == LCIO::SIMTRACKERHIT ){
+
+ _branches.push_back( new RIO::RIOLCCollectionHandler<EVENT::SimTrackerHit>(name->c_str() ,_tree) ) ;
+ }
+
+
+ // ToDo: add all other LCIO types ....
+
+ }
+
+ _haveBranches = true ;
+ }
+// // use event *_evtP to setup the block readers from header information ....
+// const std::vector<std::string>* strVec = (*_evtP)->getCollectionNames() ;
+// for( std::vector<std::string>::const_iterator name = strVec->begin() ; name != strVec->end() ; name++){
+
+// const LCCollection* col = (*_evtP)->getCollection( *name ) ;
+
+
+// // check if block handler exists in manager
+// RIOCollectionHandler* ch = dynamic_cast<RIOCollectionHandler*>
+// ( RIO_blockManager::get( name->c_str() ) ) ;
+
+// // if not, create a new block handler
+// if( ch == 0 ) {
+
+// // create collection handler for event
+// try{
+// ch = new RIOCollectionHandler( *name, col->getTypeName() , _evtP ) ;
+// // calls RIO_blockManager::add( ch ) in the c'tor !
+// }
+// catch(Exception& ex){ // unsuported type !
+// delete ch ;
+// ch = 0 ;
+// }
+
+// }
+// // else { // handler already exists
+// if( ch != 0 )
+// ch->setEvent( _evtP ) ;
+// // }
+// }
+
+
+ }
+
+
+ LCEvent* RIOReader::readNextEvent() throw (IOException , std::exception ) {
+
+ return readNextEvent( LCIO::READ_ONLY ) ;
+
+ }
+
+ LCEvent* RIOReader::readNextEvent(int accessMode) throw (IOException, std::exception ) {
+
+// if( _evtImpl != 0 )
+// delete _evtImpl ;
+
+
+ //------------------------------------------------------
+
+ if( !_haveBranches ) {
+
+ _entry ++ ;
+
+ // read event header first
+ TBranch* br = (TBranch*) _tree->GetBranch( "LCEvent" ) ;
+
+ if( br == 0 ){ // branch allready exists -> update/append mode
+
+ throw IOException( std::string( "[RIOReader::readNextEvent()] cant open branch \"LCEvent\" " ) ) ;
+
+ }
+
+ br->SetAddress( &_evtImpl ) ;
+
+
+ int nbyte = _tree->LoadTree( _entry );
+
+ std::cout << " nbyte : " << nbyte << " _entry " << _entry << std::endl ;
+
+ setUpHandlers( _evtImpl ) ;
+ }
+
+
+ //------------------------------------------------------
+
+ return _evtImpl ;
+ }
+
+ void RIOReader::skipNEvents(int n) {
+
+// int eventsSkipped = 0 ;
+
+// RIOUnpack hdrUnp( RIOUnpack::EVENTHDR ) ;
+
+// while( eventsSkipped++ < n ){
+
+// try {
+
+// readRecord() ;
+
+// }
+// catch(EndOfDataException){
+
+// return ;
+// }
+// }
+
+// // now we need to also read the next record which suposedly is an event record
+// // in order to prevent readStream from reading this event (the last to be skipped)
+// RIOUnpack evtUnp( RIOUnpack::EVENT ) ;
+
+// try{
+// readRecord() ;
+// }
+// catch(EndOfDataException){
+// return ;
+// }
+
+ }
+
+
+ EVENT::LCEvent * RIOReader::readEvent(int runNumber, int evtNumber)
+ throw (IOException , std::exception) {
+
+
+ // EventMap::iterator it = _evtMap.find( EVENTKEY( runNumber,evtNumber ) ) ;
+
+ // if( it != _evtMap.end() ) {
+
+ // int status = _stream->seek( it->second ) ;
+
+ // if( status != RIO_STREAM_SUCCESS )
+ // throw IOException( std::string( "[RIOReader::readEvent()] Can't seek stream to"
+ // " requested position" ) ) ;
+
+ // return readNextEvent() ;
+ // }
+ // else
+
+ // return 0 ;
+
+
+ return _evtImpl ;
+ }
+
+
+ void RIOReader::close() throw (IOException, std::exception ){
+
+ _file->Close() ;
+ }
+
+
+
+
+ void RIOReader::registerLCEventListener(LCEventListener * ls){
+ _evtListeners.insert( _evtListeners.end() , ls );
+ }
+ void RIOReader::removeLCEventListener(LCEventListener * ls){
+ _evtListeners.erase( _evtListeners.find( ls ) );
+ }
+
+ void RIOReader::registerLCRunListener(LCRunListener * ls){
+ _runListeners.insert( _runListeners.end() , ls );
+ }
+
+ void RIOReader::removeLCRunListener(LCRunListener * ls){
+ _runListeners.erase( _runListeners.find( ls ) );
+ }
+
+ void RIOReader::readStream() throw ( IO::IOException, std::exception ){
+
+ int maxInt = INT_MAX ; // numeric_limits<int>::max() ;
+ readStream( maxInt ) ;
+ }
+
+
+ void RIOReader::readStream(int maxRecord) throw (IOException, std::exception ){
+
+
+// bool readUntilEOF = false ;
+// if( maxRecord == INT_MAX )
+// readUntilEOF = true ;
+
+// // here we need to read all the records on the stream
+// // and then notify the listeners depending on the type ....
+
+// int recordsRead = 0 ;
+// while( recordsRead < maxRecord ){
+
+// try{
+// readRecord() ;
+// }
+// catch(EndOfDataException){
+
+// // only throw exception if a 'finite' number of records was
+// // specified that couldn't be read from the file
+// if( readUntilEOF ){
+// return ;
+// }else{
+// std::stringstream message ;
+// message << "RIOReader::readStream(int maxRecord) : EOF before "
+// << maxRecord << " records read from file" << std::ends ;
+// throw EndOfDataException( message.str()) ;
+// }
+// }
+
+// // notify LCRunListeners
+// if( ! strcmp( _dummyRecord->getName()->c_str() , LCRIO::RUNRECORDNAME )){
+
+// recordsRead++ ;
+
+// std::set<IO::LCRunListener*>::iterator iter = _runListeners.begin() ;
+// while( iter != _runListeners.end() ){
+
+// _runImpl->setReadOnly( false ) ;
+// (*iter)->modifyRunHeader( *_runP ) ;
+
+// _runImpl->setReadOnly( true ) ;
+// (*iter)->processRunHeader( *_runP ) ;
+
+// iter++ ;
+// }
+// }
+// // notify LCEventListeners
+// if( ! strcmp( _dummyRecord->getName()->c_str() , LCRIO::EVENTRECORDNAME )){
+
+// recordsRead++ ;
+
+// std::set<IO::LCEventListener*>::iterator iter = _evtListeners.begin() ;
+// while( iter != _evtListeners.end() ){
+
+// // // restore the daughter relations from the parent relations
+// // RIOParticleHandler::restoreParentDaughterRelations( *_evtP ) ;
+// postProcessEvent() ;
+
+// // fg20070813 changed order of update and process (needed for
+// // Marlin modifying processors )
+// (*_evtP)->setAccessMode( LCIO::UPDATE ) ;
+// (*iter)->modifyEvent( *_evtP ) ;
+
+// (*_evtP)->setAccessMode( LCIO::READ_ONLY ) ; // set the proper acces mode
+// (*iter)->processEvent( *_evtP ) ;
+
+
+// iter++ ;
+
+// }
+// }
+// }
+ }
+
+ void RIOReader::postProcessEvent() {
+ // restore the daughter relations from the parent relations
+ // RIOParticleHandler::restoreParentDaughterRelations( *_evtP ) ;
+ // // fill the relation map from intermediate vector
+ // RIOLCRelationHandler::fillRelationMap( *_evtP ) ;
+ }
+
+} // namespace
lcio/src/cpp/src/RIO
diff -N RIOWriter.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ RIOWriter.cc 14 Sep 2009 13:50:48 -0000 1.1.2.1
@@ -0,0 +1,360 @@
+#include "RIO/RIOWriter.h"
+
+#include "EVENT/LCEvent.h"
+#include "EVENT/LCRunHeader.h"
+#include "EVENT/LCIO.h"
+#include "EVENT/LCCollection.h"
+
+#include "LCIOSTLTypes.h"
+
+#include "EVENT/MCParticle.h"
+#include "EVENT/SimCalorimeterHit.h"
+#include "EVENT/SimTrackerHit.h"
+
+#include "IMPL/LCIOExceptionHandler.h"
+
+
+//#define DEBUG 1
+#include "IMPL/LCTOOLS.h"
+
+#include "IMPL/LCRelationImpl.h"
+
+#include <cstring>
+
+#define ROOTIO_FILE_EXTENSION ".lcio.root"
+
+#include "TFile.h"
+#include "TTree.h"
+
+#include "RIO/RIOLCCollectionHandler.h"
+//#include "TSystem.h"
+//#include "TClassTable.h"
+
+
+using namespace EVENT ;
+using namespace IO ;
+using namespace IMPL ;
+
+namespace RIO {
+
+ RIOWriter::RIOWriter() :
+ _compressionLevel(-1) ,
+ _file(0),
+ _tree(0),_evtImpl(0),
+ _haveBranches( false ) {
+
+ // file needs
+
+
+#ifdef DEBUG
+#else
+#endif
+
+ LCIOExceptionHandler::createInstance() ;
+ }
+
+
+ RIOWriter::~RIOWriter(){
+ }
+
+ void RIOWriter::open(const std::string & filename) throw(IOException, std::exception){
+
+ std::string rioFilename ;
+ getRIOFileName( filename, rioFilename ) ;
+
+ // if the file exists we throw an exception
+ _file = new TFile( rioFilename.c_str() , "NEW");
+
+ bool _haveBranches ;
+
+ if( _file->IsOpen() ){
+
+ _file->Close() ;
+
+ throw IOException( std::string( "[RIOWriter::open()] File already exists: "
+ + rioFilename
+ + " \n open it in append or new mode !\n"
+ )) ;
+ }
+
+ // open new file for writing
+ return open( filename, EVENT::LCIO::WRITE_NEW ) ;
+ }
+
+
+ void RIOWriter::getRIOFileName(const std::string& filename,
+ std::string& rioFilename ) {
+
+
+ if( filename.rfind(ROOTIO_FILE_EXTENSION) == std::string::npos || // .lcio.root not found at all
+ !( filename.rfind(ROOTIO_FILE_EXTENSION)
+ + strlen( ROOTIO_FILE_EXTENSION ) == filename.length() ) ) { // found, but not at end
+
+ rioFilename = filename + ROOTIO_FILE_EXTENSION ;
+ }
+ else
+
+ rioFilename = filename ;
+ }
+
+ void RIOWriter::open(const std::string& filename, int writeMode) throw(IOException, std::exception) {
+
+
+ // make sure filename has the proper extension (.slcio)
+ std::string rioFilename ;
+
+ getRIOFileName( filename, rioFilename ) ;
+
+
+ // does ROOT have some rules about valid names for streams, records, ???
+ // std::string stream_name = LCRIO::getValidRIOName(rioFilename) ;
+ // _stream = RIO_streamManager::add( stream_name.c_str() , 32*RIO_KBYTE*RIO_KBYTE ) ;
+ // if( _stream == 0 )
+ // throw IOException( std::string( "[RIOWriter::open()] Bad or duplicate stream name: "
+ // + stream_name )) ;
+
+
+ unsigned int status = 0 ;
+
+
+ // std::cout << " ******** open ( " << filename << ", " << writeMode << ") " << std::endl ;
+
+ switch( writeMode )
+ {
+ case EVENT::LCIO::WRITE_NEW :
+
+ _file = new TFile( rioFilename.c_str() , "RECREATE" , " LCIO file " , _compressionLevel );
+ _tree = new TTree("LCIO", "lcio tree");
+ break ;
+
+ case EVENT::LCIO::WRITE_APPEND :
+
+ _file = new TFile( rioFilename.c_str() , "UPDATE" , " LCIO file " , _compressionLevel );
+ _tree = (TTree*) _file->Get("LCIO") ;
+
+ if( _tree == 0 ) {
+
+ throw IOException( std::string( "[RIOWriter::open()] LCIO tree not found in file: "
+ + rioFilename ) ) ;
+ } else {
+
+ _file->Delete( "LCIO;1") ; // delete the existing old cycle
+ }
+
+ break ;
+ }
+
+ if( _file->IsZombie() )
+ throw IOException( std::string( "[RIOWriter::open()] zombie root file : "
+ + rioFilename ) ) ;
+
+
+ if( !_file->IsOpen() )
+ throw IOException( std::string( "[RIOWriter::open()] Couldn't open file: "
+ + rioFilename ) ) ;
+
+
+ }
+
+
+ void RIOWriter::setCompressionLevel(int level) {
+ _compressionLevel = level ;
+ }
+
+
+ void RIOWriter::writeRunHeader(const EVENT::LCRunHeader * hdr) throw(IOException, std::exception) {
+
+// // create a new handler for every new run
+
+// // if( !_runHandler){
+// // _runHandler = dynamic_cast<RIORunHeaderHandler*>
+// // ( RIO_blockManager::get( LCRIO::RUNBLOCKNAME ) ) ;
+
+// // if( _runHandler == 0 )
+// // _runHandler = new RIORunHeaderHandler( LCRIO::RUNBLOCKNAME ) ;
+
+// _runRecord->disconnect(LCRIO::RUNBLOCKNAME ) ;
+// _runRecord->connect( _runHandler );
+// // }
+// _file->Close() ;
+
+
+
+// _runHandler->setRunHeader( hdr ) ;
+
+// if( _stream->getState()== RIO_STATE_OPEN ){
+
+// _hdrRecord->setCompress( _compressionLevel != 0 ) ;
+// _evtRecord->setCompress( _compressionLevel != 0 ) ;
+// _runRecord->setCompress( _compressionLevel != 0 ) ;
+
+// // write LCRunHeader record
+// unsigned int status = _stream->write( LCRIO::RUNRECORDNAME ) ;
+
+// if( !(status & 1) )
+// throw IOException( std::string( "[RIOWriter::writeRunHeader] couldn't write run header to stream: "
+// + *_stream->getName() ) ) ;
+// } else {
+
+// throw IOException( std::string( "[RIOWriter::writeRunHeader] stream not opened: "
+// + *_stream->getName() ) ) ;
+
+// }
+
+ }
+
+
+
+ /** Creates Handlers needed for writing the event on this stream.
+ * Needs to be called for every event.
+ */
+ void RIOWriter::setUpHandlers(const LCEvent * evt){
+
+ if( !_haveBranches ) {
+
+
+ // first we create a branch for the event (header)
+
+ TBranch* br = (TBranch*) _tree->GetBranch( "LCEvent" ) ;
+
+ if( br != 0 ){ // branch allready exists -> update/append mode
+
+ br->SetAddress( &_evtImpl ) ;
+
+ } else {
+
+ //FIXME: make split level and 'record size' parameters ....
+ _tree->Branch( "LCEvent" , &_evtImpl, 16000, 2 );
+ }
+
+
+
+ // loop over all collections in first event ...
+ typedef std::vector< std::string > StrVec ;
+
+ const StrVec* strVec = evt->getCollectionNames() ;
+
+ for( StrVec::const_iterator name = strVec->begin() ; name != strVec->end() ; name++){
+
+ LCCollection* col = evt->getCollection( *name ) ;
+
+ const LCParameters& params = col->getParameters() ;
+ std::string typeName = col->getTypeName() ;
+
+ std::cout << " registering collection " << *name << " of " << typeName << std::endl ;
+
+
+ //FIXME: these should be held by a singleton handler manager (registry)
+ if( typeName == LCIO::MCPARTICLE ){
+
+ _branches.push_back( new RIO::RIOLCCollectionHandler<EVENT::MCParticle>(name->c_str() ,_tree) ) ;
+ }
+ if( typeName == LCIO::SIMCALORIMETERHIT ){
+
+ _branches.push_back( new RIO::RIOLCCollectionHandler<EVENT::SimCalorimeterHit>(name->c_str() ,_tree) ) ;
+ }
+ if( typeName == LCIO::SIMTRACKERHIT ){
+
+ _branches.push_back( new RIO::RIOLCCollectionHandler<EVENT::SimTrackerHit>(name->c_str() ,_tree) ) ;
+ }
+
+
+ // ToDo: add all other LCIO types ....
+
+ }
+
+ _haveBranches = true ;
+ }
+ }
+
+
+ void RIOWriter::writeEvent(const LCEvent* evt) throw(IOException, std::exception) {
+
+ std::cout << " RIOWriter::writeEvent : " << std::endl ;
+
+ if( !_haveBranches ) {
+
+ setUpHandlers( evt ) ;
+ }
+
+
+ _evtImpl = dynamic_cast<const IMPL::LCEventImpl*> ( evt ) ;
+
+
+ for( BranchVector::iterator it=_branches.begin() ; it!=_branches.end() ; ++it){
+
+ (*it)->toBranch( evt ) ;
+ }
+
+ _tree->Fill() ;
+ _file->Flush() ;
+
+
+ // //here we set up the collection handlers
+ // try{ setUpHandlers( evt) ;
+
+ // }catch(...){
+ // throw IOException( "[RIOWriter::writeEvent] could not set up handlers " ) ;
+ // }
+
+ // _hdrRecord->setCompress( _compressionLevel != 0 ) ;
+ // _evtRecord->setCompress( _compressionLevel != 0 ) ;
+ // _runRecord->setCompress( _compressionLevel != 0 ) ;
+
+ // if( _stream->getState()== RIO_STATE_OPEN ){
+
+ // // need to set the event in event header handler
+ // _hdrHandler->setEvent( evt ) ;
+
+ // unsigned int status = 0 ;
+
+ // // write LCEventHeader record
+ // status = _stream->write( LCRIO::HEADERRECORDNAME ) ;
+
+ // if( ! (status & 1) )
+ // throw IOException( std::string("[RIOWriter::writeEvent] couldn't write event header to stream: "
+ // + *_stream->getName() )) ;
+
+
+ // // write the event record
+ // status = _stream->write( LCRIO::EVENTRECORDNAME ) ;
+
+ // if( ! (status & 1) )
+ // throw IOException( std::string("[RIOWriter::writeEvent] couldn't write event header to stream: "
+ // + *_stream->getName() )) ;
+ // }
+ // else
+
+ // throw IOException( std::string("[RIOWriter::writeEvent] stream not opened : "
+ // + *_stream->getName() )) ;
+
+ }
+
+
+ void RIOWriter::close() throw (IOException, std::exception) {
+
+
+ _file->Write() ;
+ _file->Close() ;
+
+ // if(! (status &1) )
+ // throw IOException( std::string("[RIOWriter::close] couldn't close stream : "
+ // + *streamName )) ;
+
+ }
+
+ void RIOWriter::flush() throw (IOException, std::exception) {
+
+ _file->Flush() ;
+
+
+ // const std::string* streamName = _stream->getName() ;
+ // int status = _stream->flush() ;
+ // if(! (status &1) )
+ // throw IOException( std::string("[RIOWriter::flush] couldn't flush stream : "
+ // + *streamName )) ;
+
+ }
+
+} // namespace
+
CVSspam 0.2.8