Skip to content

Commit

Permalink
update shelves
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Aug 25, 2024
1 parent 9376ed7 commit 9d59a43
Show file tree
Hide file tree
Showing 12 changed files with 586 additions and 723 deletions.
2 changes: 1 addition & 1 deletion .aux/test_with_lcg
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ CMTCONFIG=$2
source /cvmfs/sft.cern.ch/lcg/views/${LCG}/${CMTCONFIG}/setup.sh
source build/INSTALL/thisostap.sh
cd build
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j4 --output-on-failure --test-output-size-failed=5000000
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j4 -R _io_ --output-on-failure --test-output-size-failed=5000000
73 changes: 6 additions & 67 deletions ostap/io/bz2shelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
#
# @endcode
#
# @attention: In case DB-name has extension ``.bz2'', the whole data base
# will be ``bzip2''-ed ".
#
# @attention: When one tries to read the database with pickled ROOT object using newer
# version of ROOT, one could get a ROOT read error,
# in case of evoltuion in ROOT streamers for some classes, e.g. <code>ROOT.TH1D</code>>
Expand Down Expand Up @@ -121,8 +118,6 @@
...
>>> abcd = db['some_key']
In case DB-name has extension ``.bz2'', the whole data base will be ``bzip2''-ed
Attention: When one tries to read the database with pickled ROOT object using newer
version of ROOT, one could get a ROOT read error,
in case of evoltuion in ROOT streamers for some classes, e.g. ROOT.TH1D
Expand Down Expand Up @@ -173,8 +168,6 @@ class Bz2Shelf(CompressShelf):
- 'c' Open database for reading and writing, creating if it does not exist
- 'n' Always create a new, empty database, open for reading and writing
"""
## the known "standard" extensions:
extensions = '.tbz' , '.tbz2' , '.bz2'
##
def __init__( self ,
dbname ,
Expand All @@ -184,67 +177,14 @@ def __init__( self ,
assert 1 <= compress <= 9 , 'Invalid `compress` for `bz2`-compression: %s' % compress

## initialize the base class
CompressShelf.__init__ ( self ,
dbname ,
mode = mode ,
compress = compress , **kwargs )

## needed for proper (un)pickling
def __getinitargs__ ( self ) :
"""for proper (un_pickling"""
return self.__init_args

## needed for proper (un)pickling
def __getstate__ ( self ) :
"""for proper (un)pickling"""
self.sync()
return {}

## needed for proper (un)pickling
def __setstate__ ( self , dct ) :
"""for proper (un)pickling"""
pass

# =========================================================================
## compress (bz2) the file into temporary location, keep original
def compress_files ( self , files ) :
"""Compress (bz2) the file into temporary location, keep original
"""
output = self.tempfile()

import tarfile
with tarfile.open ( output , 'w:bz2' ) as tfile :
for file in files :
_ , name = os.path.split ( file )
tfile.add ( file , name )
##
return output
CompressShelf.__init__ ( self ,
dbname ,
mode = mode ,
compress = compress ,
compresstype = 'bz2' , **kwargs )

# =========================================================================
## uncompress (bz2) the file into temporary location, keep original
def uncompress_file ( self , filein ) :
"""Uncompress (bz2) the file into temporary location, keep original
"""
items = []
tmpdir = self.tempdir ()
self.taropts = "x:bz2"

## 2) try compressed-tarfile
import tarfile
if tarfile.is_tarfile ( filein ) :
with tarfile.open ( filein , 'r:*' ) as tfile :
for item in tfile :
tfile.extract ( item , path = tmpdir )
items.append ( os.path.join ( tmpdir , item.name ) )
items.sort()
return tuple ( items )

import tempfile , io
fd , fileout = tempfile.mkstemp ( prefix = 'ostap-tmp-' , suffix = '-bz2db' )
with bz2.open ( filein , 'rb' ) as fin :
with io.open ( fileout , 'wb' ) as fout :
shutil.copyfileobj ( fin , fout )
return fileout ,

# ==========================================================================
## compress (bzip2) the item using <code>bz2.compress</code>
def compress_item ( self , value ) :
Expand All @@ -260,7 +200,6 @@ def uncompress_item ( self , value ) :
- see bz2.decompress
"""
return self.unpickle ( bz2.decompress ( value ) )


# =============================================================================
## helper function to access Bz2Shelve data base
Expand Down
Loading

0 comments on commit 9d59a43

Please sign in to comment.