4 added + 10 modified, total 14 files
lcio/rootio
diff -u -r1.1.2.3 -r1.1.2.4
--- README 14 Jul 2009 12:22:48 -0000 1.1.2.3
+++ README 18 Sep 2009 09:33:39 -0000 1.1.2.4
@@ -5,17 +5,13 @@
ROOTDict.mk: example make file for creating an LCIO dictionary (A.Naumann)
- lciotree.C: example macro for reading in an example tree w/ LCIO data
-
+ readevent.C: example macro for reading in an example tree w/ LCIO data
+
additional files added for ROOT I/O :
- $LCIO/src/cpp/src/EXAMPLES/rootio.cc: example main program that creates a root tree
- $LCIO//src/cpp/src/EXAMPLE/LCCol2Branch.h: create and fill ROOT branches
-
- $LCIO/src/cpp/include/IOIMPL/rootio_templates.h: define some template instantiations used in tree
-
-
+ $LCIO/src/cpp/include/RIO/*.h
+ $LCIO/src/cpp/src/RIO/*.cc
###############################################################
@@ -25,7 +21,7 @@
. /data/gaede/root/5.24.00/bin/thisroot.sh
-
+cd
mkdir lcio
cd lcio
lcio/rootio
diff -u -r1.1.2.1 -r1.1.2.2
--- ToDo.txt 14 Sep 2009 13:50:47 -0000 1.1.2.1
+++ ToDo.txt 18 Sep 2009 09:33:39 -0000 1.1.2.2
@@ -5,13 +5,17 @@
- dependency structure of libraries:
liblcio.so should not depend on ROOT libraries !
- -> can we use a dlopen mechanism ala marlin::ProcessorLoader ?
+ -> can we use a dlopen mechanism a la 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)
+ -> try to resolve based on filename extension (slcio/rlcio)
+ -> implement 'generic decorator' that resolves type at open() ...
+
+
+ - RIOWriter: write Runheader
lcio/rootio
diff -u -r1.1.2.1 -r1.1.2.2
--- readevent.C 16 Sep 2009 08:42:15 -0000 1.1.2.1
+++ readevent.C 18 Sep 2009 09:33:39 -0000 1.1.2.2
@@ -2,9 +2,9 @@
#include "TFile.h"
#include "TBranch.h"
#ifndef __CINT__
-#include "include/IMPL/ReconstructedParticleImpl.h"
-#include "include/IMPL/LCEventImpl.h"
-#include "include/IMPL/TrackImpl.h"
+#include "include/EVENT/LCEvent.h"
+#include "include/EVENT/ReconstructedParticle.h"
+#include "include/EVENT/MCParticle.h"
#endif
#include <vector>
@@ -69,23 +69,24 @@
//--------- loop over particles in the events ------------
- IMPL::LCEventImpl* evt = new IMPL::LCEventImpl ; // 0 ;
+ // IMPL::LCEventImpl* evt = new IMPL::LCEventImpl ; // 0 ;
+ EVENT::LCEvent* evt = 0 ;
TBranch* bevt = t->GetBranch("LCEvent") ;
bevt->SetAddress( &evt ) ;
branches.push_back( bevt ) ;
- IMPL::LCCollectionVec* col = new IMPL::LCCollectionVec ;
- branches.push_back( t->GetBranch("MCParticlesSkimmed") ) ;
- branches.back()->SetAddress( &col ) ;
-
- IMPL::LCCollectionVec* cpfo = new IMPL::LCCollectionVec ;
- branches.push_back( t->GetBranch("PandoraPFOs") ) ;
- branches.back()->SetAddress( &cpfo ) ;
+// IMPL::LCCollectionVec* col = new IMPL::LCCollectionVec ;
+// branches.push_back( t->GetBranch("MCParticlesSkimmed") ) ;
+// branches.back()->SetAddress( &col ) ;
+
+// IMPL::LCCollectionVec* cpfo = new IMPL::LCCollectionVec ;
+// branches.push_back( t->GetBranch("PandoraPFOs") ) ;
+// branches.back()->SetAddress( &cpfo ) ;
- IMPL::LCCollectionVec* crml = new IMPL::LCCollectionVec ;
- branches.push_back( t->GetBranch("RecoMCTruthLink") ) ;
- branches.back()->SetAddress( &crml ) ;
+// IMPL::LCCollectionVec* crml = new IMPL::LCCollectionVec ;
+// branches.push_back( t->GetBranch("RecoMCTruthLink") ) ;
+// branches.back()->SetAddress( &crml ) ;
int nBranches = branches.size() ;
@@ -94,8 +95,8 @@
int nevt = t->GetEntries();
- // for (Int_t i = 0; i < nevt ; i++) {
- for (Int_t i = 0; i < 1 ; i++) {
+ for (Int_t i = 0; i < nevt ; i++) {
+ //for (Int_t i = 0; i < 1 ; i++) {
Long64_t tentry = t->LoadTree(i);
@@ -106,6 +107,12 @@
// cout << " read " << nbyte << " bytes for branch " << branches[k]->GetName()
// << std::endl ;
}
+
+ EVENT::LCCollection* col = evt->getCollection("MCParticlesSkimmed") ;
+ EVENT::LCCollection* cpfo = evt->getCollection("PandoraPFOs") ;
+ EVENT::LCCollection* crml = evt->getCollection("RecoMCTruthLink") ;
+
+
int nMCP = col->getNumberOfElements() ;
@@ -114,7 +121,7 @@
EVENT::MCParticle* mcp = dynamic_cast<EVENT::MCParticle*>( col->getElementAt(j) ) ;
- cout << " -- " << mcp << endl ;
+ // cout << " -- " << mcp << endl ;
if( mcp->getGeneratorStatus() == 1 )
eMCP += mcp->getEnergy() ;
@@ -144,7 +151,7 @@
EVENT::ReconstructedParticle* pfo = dynamic_cast<EVENT::ReconstructedParticle*>( rel->getFrom() ) ;
EVENT::MCParticle* mcp = dynamic_cast<EVENT::MCParticle*>( rel->getTo() ) ;
- cout << " ++ " << mcp << endl ;
+ // cout << " ++ " << mcp << endl ;
herm->Fill( pfo->getEnergy() , mcp->getEnergy() ) ;
lcio/src/cpp
diff -u -r1.22.2.5 -r1.22.2.6
--- CMakeLists.txt 15 Sep 2009 15:45:00 -0000 1.22.2.5
+++ CMakeLists.txt 18 Sep 2009 09:33:39 -0000 1.22.2.6
@@ -65,6 +65,8 @@
SET( LCIO_IOIMPL_SRCS
./src/IOIMPL/LCFactory.cc
+ ./src/IOIMPL/WriterDecorator.cc
+ ./src/IOIMPL/ReaderDecorator.cc
)
SET( LCIO_RIO_SRCS
lcio/src/cpp/include/IMPL
diff -u -r1.19.8.3 -r1.19.8.4
--- LCEventImpl.h 15 Sep 2009 15:45:00 -0000 1.19.8.3
+++ LCEventImpl.h 18 Sep 2009 09:33:39 -0000 1.19.8.4
@@ -175,8 +175,8 @@
std::string _detectorName ;
// map has to be defined mutable in order to use _map[] for const methods ...
- mutable LCCollectionMap _colMap ; //! no RIO
- mutable std::vector<std::string> _colNames ;
+ mutable LCCollectionMap _colMap ;
+ mutable std::vector<std::string> _colNames ; //! no RIO
LCParametersImpl _params ;
lcio/src/cpp/include/RIO
diff -u -r1.1.2.3 -r1.1.2.4
--- RIOReader.h 15 Sep 2009 15:45:00 -0000 1.1.2.3
+++ RIOReader.h 18 Sep 2009 09:33:39 -0000 1.1.2.4
@@ -13,6 +13,7 @@
#include "IOIMPL/LCRunHeaderIOImpl.h"
#include "LCIOTypes.h"
+#include "RIO.h"
class TFile ;
class TTree ;
@@ -28,7 +29,7 @@
/** Concrete implementation of LCWriter using ROOT I/O.
*
* @author gaede
- * @version $Id: RIOReader.h,v 1.1.2.3 2009/09/15 15:45:00 gaede Exp $
+ * @version $Id: RIOReader.h,v 1.1.2.4 2009/09/18 09:33:39 gaede Exp $
*/
class RIOReader : public IO::LCReader {
lcio/src/cpp/include/RIO
diff -u -r1.1.2.1 -r1.1.2.2
--- RIOWriter.h 14 Sep 2009 13:50:48 -0000 1.1.2.1
+++ RIOWriter.h 18 Sep 2009 09:33:39 -0000 1.1.2.2
@@ -1,13 +1,13 @@
#ifndef RIO_RIOWriter_H
#define RIO_RIOWriter_H 1
+#include "RIO/RIO.h"
+
#include <string>
#include <vector>
#include "IO/LCWriter.h"
#include "IMPL/LCEventImpl.h"
-#include "EVENT/LCRunHeader.h"
-
-#include "RIOLCCollectionHandler.h"
+#include "IMPL/LCRunHeaderImpl.h"
class TFile ;
class TTree ;
@@ -106,11 +106,11 @@
*/
void setUpHandlers(const EVENT::LCEvent * evt) ;
- /** Creates a proper filename with extension '.lcio.root'
- * in sioFilename.
+ /** Creates a proper filename with extension RIO_FILE_EXTENSION
+ * in rioFilename.
*/
void getRIOFileName(const std::string& filename,
- std::string& sioFilename) ;
+ std::string& rioFilename) ;
protected:
@@ -120,13 +120,13 @@
TTree* _tree ;
const IMPL::LCEventImpl* _evtImpl ;
-
- BranchVector _branches ;
+ const IMPL::LCRunHeaderImpl* _runImpl ;
+ BranchVector _branches ;
bool _haveBranches ;
+
}; // class
-
} // namespace.
#endif /* ifndef RIO_RIOWriter_H */
lcio/src/cpp/src/IOIMPL
diff -N ReaderDecorator.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ReaderDecorator.cc 18 Sep 2009 09:33:39 -0000 1.1.2.1
@@ -0,0 +1,35 @@
+#include "ReaderDecorator.h"
+
+#include "SIO/LCSIO.h"
+#include "SIO/SIOReader.h"
+
+#include "RIO/RIOReader.h"
+
+
+
+namespace IOIMPL{
+
+
+ void ReaderDecorator::initialize(const std::string& filename){
+
+ if( _rdr != 0 )
+ return ; // already initialized
+
+ // check whether filename ends on .slcio or .rlcio
+ if( filename.rfind( RIO_FILE_EXTENSION ) + strlen( RIO_FILE_EXTENSION ) == filename.length() ) {
+
+ _rdr = new RIO::RIOReader(_lcReaderFlag ) ;
+ }
+ else if( filename.rfind( SIO::LCSIO::FILE_EXTENSION ) + strlen( SIO::LCSIO::FILE_EXTENSION ) == filename.length() ) {
+
+ _rdr = new SIO::SIOReader(_lcReaderFlag ) ;
+ }
+ else{
+
+ _rdr = new SIO::SIOReader(_lcReaderFlag ) ; // default
+ }
+
+
+ }
+
+}
lcio/src/cpp/src/IOIMPL
diff -N ReaderDecorator.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ReaderDecorator.h 18 Sep 2009 09:33:40 -0000 1.1.2.1
@@ -0,0 +1,214 @@
+#ifndef IOIMPL_ReaderDecorator_H
+#define IOIMPL_ReaderDecorator_H 1
+
+#include <string>
+// #include <set>
+// #include <map>
+#include "IO/LCReader.h"
+#include "IO/LCEventListener.h"
+#include "IO/LCRunListener.h"
+
+
+
+namespace IOIMPL {
+
+
+ /** Decorator for LCReader that decides on io type in open.
+ *
+ * @see LCFactory
+ * @author gaede
+ * @version Sep, 2009
+ */
+
+ class ReaderDecorator : public IO::LCReader {
+
+ IO::LCReader* _rdr ;
+ int _lcReaderFlag ;
+
+ public:
+
+ /** Default constructor.
+ */
+ ReaderDecorator( int lcReaderFlag=0 ) :
+ _rdr(0) ,
+ _lcReaderFlag( lcReaderFlag ) {
+
+ }
+
+ // Destructor
+ virtual ~ReaderDecorator() {
+
+ delete _rdr ;
+ }
+
+ /** 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) {
+
+ if( filenames.size() > 0 )
+
+ initialize( filenames[0] ) ;
+
+ else{
+ std::string empty("") ;
+ initialize( empty ) ;
+ }
+ _rdr->open( filenames ) ;
+ }
+
+
+
+ /** Opens a file for reading (read-only).
+ * @throws IOException
+ */
+ virtual void open(const std::string & filename) throw (IO::IOException, std::exception){
+
+ initialize( filename ) ;
+ _rdr->open( filename ) ;
+ }
+
+ /** Reads the next run header from the file.
+ *
+ * @throws IOException
+ */
+ virtual EVENT::LCRunHeader * readNextRunHeader() throw (IO::IOException, std::exception) {
+
+ return _rdr->readNextRunHeader() ;
+ }
+
+ /** 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) {
+
+ return _rdr->readNextRunHeader( accessMode ) ;
+ }
+
+
+ /** Reads the next event from the file.
+ *
+ * @throws IOException
+ */
+ virtual EVENT::LCEvent* readNextEvent() throw (IO::IOException, std::exception) {
+
+ return _rdr->readNextEvent() ;
+ }
+
+
+ /** 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) {
+
+ return _rdr->readNextEvent( accessMode ) ;
+ }
+
+
+
+
+ /** 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) {
+
+ _rdr->skipNEvents( 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 */) {
+
+ return _rdr->readEvent( runNumber, evtNumber ) ;
+ }
+
+ /** Closes the output file/stream etc.
+ *
+ * @throws IOException
+ */
+ virtual void close() throw (IO::IOException, std::exception) {
+
+ _rdr->close() ;
+ }
+
+ // interface for listeners
+
+ /** Registers a listener for reading LCEvents from a stream.
+ */
+ virtual void registerLCEventListener(IO::LCEventListener * ls) {
+
+ _rdr->registerLCEventListener( ls ) ;
+ }
+
+ /** Remove a listener for reading LCEvents from a stream.
+ */
+ virtual void removeLCEventListener(IO::LCEventListener * ls ) {
+
+ _rdr->removeLCEventListener( ls ) ;
+ }
+
+ /** Registers a listener for reading LCEventsLCRunHeaders from a stream.
+ */
+ virtual void registerLCRunListener(IO::LCRunListener * ls) {
+
+ _rdr->registerLCRunListener( ls ) ;
+ }
+
+ /** Remove a listener for reading LCRunHeaders from a stream.
+ */
+ virtual void removeLCRunListener(IO::LCRunListener * ls) {
+
+ _rdr->removeLCRunListener( 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) {
+
+ _rdr->readStream() ;
+ }
+
+ /** 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) {
+
+ _rdr->readStream( maxRecord ) ;
+ }
+
+
+
+
+ protected:
+
+ void initialize(const std::string& filename ) ;
+
+
+ }; // class
+} // namespace
+
+#endif /* ifndef SIO_SIOREADER_H */
lcio/src/cpp/src/IOIMPL
diff -N WriterDecorator.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ WriterDecorator.cc 18 Sep 2009 09:33:40 -0000 1.1.2.1
@@ -0,0 +1,39 @@
+#include "WriterDecorator.h"
+
+#include "SIO/LCSIO.h"
+#include "SIO/SIOWriter.h"
+
+#include "RIO/RIOWriter.h"
+
+
+
+namespace IOIMPL{
+
+
+ void WriterDecorator::initialize(const std::string& filename){
+
+ if( _wrt != 0 )
+ return ; // already initialized
+
+ // check whether filename ends on .slcio or .rlcio
+ if( filename.rfind( RIO_FILE_EXTENSION ) + strlen( RIO_FILE_EXTENSION ) == filename.length() ) {
+
+ _wrt = new RIO::RIOWriter ;
+ }
+ else if( filename.rfind( SIO::LCSIO::FILE_EXTENSION ) + strlen( SIO::LCSIO::FILE_EXTENSION ) == filename.length() ) {
+
+ _wrt = new SIO::SIOWriter ;
+ }
+ else{
+
+ _wrt = new SIO::SIOWriter ; // default
+ }
+
+
+ if( _compressionLevel != -1 )
+
+ _wrt->setCompressionLevel( _compressionLevel ) ;
+
+ }
+
+}
lcio/src/cpp/src/IOIMPL
diff -N WriterDecorator.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ WriterDecorator.h 18 Sep 2009 09:33:40 -0000 1.1.2.1
@@ -0,0 +1,129 @@
+#ifndef IOIMPL_WriterDecorator_H
+#define IOIMPL_WriterDecorator_H 1
+
+#include <string>
+#include <vector>
+#include "IO/LCWriter.h"
+#include "EVENT/LCEvent.h"
+#include "EVENT/LCRunHeader.h"
+
+namespace IOIMPL {
+
+ /** Decorator for LCWriter that decides on io type in open.
+ *
+ * @see LCFactory
+ * @author gaede
+ * @version Sep, 2009
+ */
+ class WriterDecorator : public IO::LCWriter {
+
+ IO::LCWriter* _wrt ;
+
+ public:
+
+ /**Default constructor.
+ */
+ WriterDecorator() : _wrt(0) , _compressionLevel(-1) {}
+
+ /**
+ * Destructor
+ */
+ virtual ~WriterDecorator(){
+ delete _wrt ;
+ }
+
+ /** 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) {
+
+ initialize( filename ) ;
+ _wrt->open( filename ) ;
+ }
+
+
+ /** 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){
+
+ initialize( filename ) ;
+ _wrt->open( filename , writeMode) ;
+ }
+
+ /** 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) {
+
+ if( _wrt )
+ _wrt->setCompressionLevel( level ) ;
+ else
+ _compressionLevel = level ;
+ }
+
+
+ /** Writes the given run header to file.
+ *
+ *@throws IOException
+ */
+ virtual void writeRunHeader(const EVENT::LCRunHeader * hdr) throw (IO::IOException, std::exception) {
+
+ _wrt->writeRunHeader( hdr ) ;
+ }
+
+ /** Writes the given event to file.
+ *
+ *@throws IOException
+ */
+ virtual void writeEvent(const EVENT::LCEvent * evt) throw (IO::IOException, std::exception) {
+
+ _wrt->writeEvent( evt ) ;
+ }
+
+
+ /** Closes the output file/stream etc.
+ *
+ *@throws IOException
+ */
+ virtual void close() throw (IO::IOException, std::exception) {
+
+ _wrt->close() ;
+ }
+
+
+ /** Flushes the output file/stream etc.
+ *
+ *@throws IOException
+ */
+ virtual void flush() throw (IO::IOException, std::exception) {
+
+ _wrt->flush() ;
+ }
+
+ protected:
+
+ void initialize(const std::string& filename) ;
+
+
+ int _compressionLevel ;
+
+ }; // class
+} // namespace.
+
+#endif
lcio/src/cpp/src/IOIMPL
diff -u -r1.3.2.2 -r1.3.2.3
--- LCFactory.cc 15 Sep 2009 15:45:00 -0000 1.3.2.2
+++ LCFactory.cc 18 Sep 2009 09:33:39 -0000 1.3.2.3
@@ -1,85 +1,68 @@
#include "IOIMPL/LCFactory.h"
-
-
#include "IO/LCWriter.h"
#include "IO/LCReader.h"
-#include "SIO/SIOWriter.h"
-#include "SIO/SIOReader.h"
+#include "WriterDecorator.h"
+#include "ReaderDecorator.h"
+
+// #include "SIO/SIOWriter.h"
+// #include "SIO/SIOReader.h"
+// #include "RIO/RIOWriter.h"
+// #include "RIO/RIOReader.h"
-#include "RIO/RIOWriter.h"
-#include "RIO/RIOReader.h"
+
+//fg: 09/2009 - modified to return generic decorators that decide on the io type based on the file
+// name extension in open()
using namespace IO ;
-//using namespace SIO ;
+
namespace IOIMPL{
-// LCFactory* LCFactory::_me = 0 ;
+ LCFactory::LCFactory(){}
- LCFactory::LCFactory() {
-
- // for now get I/O type from $LCIO_IO_TYPE
- // one of "ss","sr","rs","rr"
- // i.e. SIOReader/SIOWriter, SIOReader/RIOWriter, ...
-
- char* t = getenv("LCIO_IO_TYPE");
-
- if( t==0 )
- t = "ss" ;
-
- _readerType = t[0] ;
- _writerType = t[1] ;
-
- }
-
LCFactory* LCFactory::getInstance() {
-
+
static LCFactory _me ;
- // if( !_me ) _me = new LCFactory ;
-
+
return &_me ;
}
-
- LCFactory::~LCFactory() {
- // delete _me ;
- }
+ LCFactory::~LCFactory(){}
+
LCWriter * LCFactory::createLCWriter() {
- // the reason for having this class
- // so far we just create SIO objects
- switch(_writerType ) {
-
- case 'r':
- return new RIO::RIOWriter ;
- break ;
-
- default :
- return new SIO::SIOWriter ;
- }
+ return new IOIMPL::WriterDecorator ;
+
+ // switch(_writerType ) {
+ // case 'r':
+ // return new RIO::RIOWriter ;
+ // break ;
+ // default :
+ // return new SIO::SIOWriter ;
+ // }
}
LCReader * LCFactory::createLCReader(int lcReaderFlag) {
- switch(_readerType ) {
-
- case 'r':
- return new RIO::RIOReader( lcReaderFlag );
- break;
-
- default :
- return new SIO::SIOReader( lcReaderFlag ) ;
- }
-
+ return new IOIMPL::ReaderDecorator ;
+
+// switch(_readerType ) {
+// case 'r':
+// return new RIO::RIOReader( lcReaderFlag );
+// break;
+// default :
+// return new SIO::SIOReader( lcReaderFlag ) ;
+// }
+
}
lcio/src/cpp/src/RIO
diff -u -r1.1.2.4 -r1.1.2.5
--- RIOReader.cc 15 Sep 2009 15:45:00 -0000 1.1.2.4
+++ RIOReader.cc 18 Sep 2009 09:33:40 -0000 1.1.2.5
@@ -337,6 +337,8 @@
void RIOReader::skipNEvents(int n) {
+ _entry += n ;
+
// int eventsSkipped = 0 ;
// RIOUnpack hdrUnp( RIOUnpack::EVENTHDR ) ;
@@ -372,6 +374,8 @@
throw (IOException , std::exception) {
+ // FIXME: here we should use an index of the LCEvent branch for the event map
+
// EventMap::iterator it = _evtMap.find( EVENTKEY( runNumber,evtNumber ) ) ;
// if( it != _evtMap.end() ) {
lcio/src/cpp/src/RIO
diff -u -r1.1.2.2 -r1.1.2.3
--- RIOWriter.cc 15 Sep 2009 15:45:00 -0000 1.1.2.2
+++ RIOWriter.cc 18 Sep 2009 09:33:40 -0000 1.1.2.3
@@ -21,15 +21,11 @@
#include <cstring>
-//#define ROOTIO_FILE_EXTENSION ".lcio.root"
-#define ROOTIO_FILE_EXTENSION ".rlcio"
#include "TFile.h"
#include "TTree.h"
#include "RIO/RIOLCCollectionHandler.h"
-//#include "TSystem.h"
-//#include "TClassTable.h"
using namespace EVENT ;
@@ -80,16 +76,16 @@
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
+ if( filename.rfind(RIO_FILE_EXTENSION) == std::string::npos || // .rlcio not found at all
+ !( filename.rfind(RIO_FILE_EXTENSION)
+ + strlen( RIO_FILE_EXTENSION ) == filename.length() ) ) { // found, but not at end
- rioFilename = filename + ROOTIO_FILE_EXTENSION ;
+ rioFilename = filename + RIO_FILE_EXTENSION ;
}
else
@@ -101,47 +97,40 @@
// 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 ) {
+ if( _compressionLevel < 0 ){
- throw IOException( std::string( "[RIOWriter::open()] LCIO tree not found in file: "
- + rioFilename ) ) ;
- } else {
+ _compressionLevel = RIO_DEFAULT_COMPRESS ;
+ }
- _file->Delete( "LCIO;1") ; // delete the existing old cycle
- }
- break ;
+ switch( writeMode ) {
+
+ case EVENT::LCIO::WRITE_NEW :
+
+ _file = new TFile( rioFilename.c_str() , "RECREATE" , " LCIO file " , _compressionLevel );
+ _tree = new TTree( RIO_LCIO_TREENAME , "lcio tree");
+ break ;
+
+ case EVENT::LCIO::WRITE_APPEND :
+
+ _file = new TFile( rioFilename.c_str() , "UPDATE" , " LCIO file " , _compressionLevel );
+ _tree = (TTree*) _file->Get( RIO_LCIO_TREENAME ) ;
+
+ if( _tree == 0 ) {
+
+ throw IOException( std::string( "[RIOWriter::open()] LCIO tree not found in file: "
+ + rioFilename ) ) ;
+ } else {
+
+ _file->Delete( RIO_LCIO_TREENAME_CYCLE_1 ) ; // delete the existing old cycle
}
+
+ break ;
+ }
if( _file->IsZombie() )
throw IOException( std::string( "[RIOWriter::open()] zombie root file : "
@@ -151,8 +140,6 @@
if( !_file->IsOpen() )
throw IOException( std::string( "[RIOWriter::open()] Couldn't open file: "
+ rioFilename ) ) ;
-
-
}
@@ -202,11 +189,6 @@
}
-
-
- /** 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 ) {
@@ -214,7 +196,7 @@
// first we create a branch for the event (header)
- TBranch* br = (TBranch*) _tree->GetBranch( "LCEvent" ) ;
+ TBranch* br = (TBranch*) _tree->GetBranch( RIO_LCEVENT_BRANCHNAME ) ;
if( br != 0 ){ // branch allready exists -> update/append mode
@@ -223,45 +205,19 @@
} else {
//FIXME: make split level and 'record size' parameters ....
- _tree->Branch( "LCEvent" , &_evtImpl, 16000, 2 );
+ br = _tree->Branch( RIO_LCEVENT_BRANCHNAME , &_evtImpl, RIO_RECORD_SIZE, RIO_SPLIT_LEVEL );
}
-
-
- // 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 ;
-
- _branches.push_back( new RIO::RIOLCCollectionHandler( *name, typeName, _tree) ) ;
-
-// //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 ....
-
- }
+ // if we want to have one branch per collection (when pointer isssue is resolved)
+// //---- 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 ) ;
+// std::string typeName = col->getTypeName() ;
+// std::cout << " registering collection " << *name << " of " << typeName << std::endl ;
+// _branches.push_back( new RIO::RIOLCCollectionHandler( *name, typeName, _tree) ) ;
+// }
_haveBranches = true ;
}
@@ -270,90 +226,43 @@
void RIOWriter::writeEvent(const LCEvent* evt) throw(IOException, std::exception) {
+#ifdef DEBUG
std::cout << " RIOWriter::writeEvent : " << std::endl ;
-
+#endif
+
if( !_haveBranches ) {
setUpHandlers( evt ) ;
}
-
_evtImpl = dynamic_cast<const IMPL::LCEventImpl*> ( evt ) ;
- for( BranchVector::iterator it=_branches.begin() ; it!=_branches.end() ; ++it){
+ if( !_evtImpl ){
- (*it)->toBranch( evt ) ;
+ throw IO::IOException(" evt is not IMPL::LCEventImpl !???" ) ;
}
+ // ---- only if we can split the event into one branch per collection (pointers between branches) :
+ // 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