Hi,
for some work I need to use only one directory (EgammaV) instead of all wich are provided into a ROOT file.
With a small python script [1] I can do it but there is no significant file size reduction. For exemple if the initial size was 194 Mo, then at the end the final size is 180 Mo. Is it correct or is there an other operation I can do in order to reduce significantly the size.
Thanks.
Arnaud
P.S. if there is another way to get only the EgammaV branch, I would like to know it.
[1] : script
f_rel = ROOT.TFile(‘SomeROOTFile.root’, “UPDATE”)
t2 = f_rel.Get(“DQMData/Run 1”)
f_rel.cd(“DQMData/Run 1”)
a = t2.GetListOfKeys()
for elem in a:
print(elem.GetTitle())
if (elem.GetTitle() == ‘EgammaV’):
print(’… kept’)
else:
name = elem.GetTitle() + “;1”
gDirectory.Delete(name) # → OK
print(’… Removed’)
f_rel.Close()
Hi, thanks for your answer.
with a small shell script [1] it can be done in a faster way than mine … except that the final ROOT file size is the same as the initial size.
More, when I tried to used with CMSSW version 12_1_0_pre4 I had the following msg :
Traceback (most recent call last):
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/cms/cmssw/CMSSW_12_1_0_pre4/external/slc7_amd64_gcc900/bin/rootrm", line 10, in <module>
import cmdLineUtils
ImportError: No module named cmdLineUtils
Some tests with 11_3_X or 12_0_Y are fine.
Arnaud
[1] : shell script
#!/bin/sh
dList=rootls TITI.root:DQMData/'Run 1'
for j in $dList
do
echo $j
if [[ “$j” == “EgammaV” ]];
then
echo “OK”
else
echo “-----”
rootrm TITI.root:DQMData/‘Run 1’/$j -r
fi
done
ROOT files can only “grow” in size. They are never “shrank”.
You need to create a new file and copy the contents (that you want to keep) from your old file.
I found this link but rootcp always gone to an error :
Traceback (most recent call last):
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/cms/cmssw/CMSSW_12_0_0_pre3/external/slc7_amd64_gcc900/bin/rootcp", line 58, in <module>
sys.exit(execute())
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/cms/cmssw/CMSSW_12_0_0_pre3/external/slc7_amd64_gcc900/bin/rootcp", line 56, in execute
recursive=optDict["recursive"], replace=optDict["replace"])
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/lcg/root/6.22.08-llifpc3/lib/cmdLineUtils.py", line 781, in rootCp
len(sourceList)==1, recursive, replace)
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/lcg/root/6.22.08-llifpc3/lib/cmdLineUtils.py", line 760, in _copyObjects
oneSource, recursive, replace)
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/lcg/root/6.22.08-llifpc3/lib/cmdLineUtils.py", line 545, in copyRootObject
destFile,destPathSplit+[objectName],replace)
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/lcg/root/6.22.08-llifpc3/lib/cmdLineUtils.py", line 613, in copyRootObjectRecursive
destFile,destPathSplit+[objectName],replace)
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/lcg/root/6.22.08-llifpc3/lib/cmdLineUtils.py", line 613, in copyRootObjectRecursive
destFile,destPathSplit+[objectName],replace)
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/lcg/root/6.22.08-llifpc3/lib/cmdLineUtils.py", line 656, in copyRootObjectRecursive
obj.SetName(objectName)
AttributeError: 'TObjString' object has no attribute 'SetName'
I do not see the errors you mentioned in points 2 and 3. They seems Python related errors. The modules cmdLineUtils seems to be missing in your python installation.
For point 1, I guess the behaviour of rootcp is similar to the unix cp command ?
If you do:
cp aaa/bbb/ccc/ ccc
It will create (in the local directory) the ccc folder only …
Hi,
I tried to use : rootcp SOURCE.root:'DQMData/Run 1/EgammaV' TARGETroot:'DQMData/Run 1/EgammaV' -r
or rootcp SOURCE.root:'DQMData/Run 1/EgammaV' TARGET.root:'DQMData/Run 1' -r
with or without the ‘/’ at the end, and without any success.
The error returned is : ReferenceError: attempt to access a null-pointer
For the errors mentioned in points 2 and 3, I only use :
something like :
cmsrel CMSSW_12_1_0_pre2
cd CMSSW_12_1_0_pre2/src
cmsenv
and launching my files (python or sh file). Nothing else.
It looks like if the rootcp/rm tools are only working with old releases and could not read correctly the root files for ROOT version up to 6.22
I just created a new root file (using $ROOTSYS/tutorials/hsimple.C) using the latest root version and I can use rootcp and rootrm on it without problems.
Traceback (most recent call last):
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/cms/cmssw/CMSSW_12_1_0_pre4/external/slc7_amd64_gcc900/bin/rootls", line 10, in <module>
import cmdLineUtils
ImportError: No module named cmdLineUtils
Traceback (most recent call last):
File "/cvmfs/cms.cern.ch/slc7_amd64_gcc900/cms/cmssw/CMSSW_12_1_0_pre4/external/slc7_amd64_gcc900/bin/rootcp", line 10, in <module>
import cmdLineUtils
ImportError: No module named cmdLineUtils
it is two commands used to create a local copy of the repository of the CMSSW framework cmsrel
for a given release and its environment (i.e. ROOT PATH for this release, python path and so on) with cmsenv.
If I don’t do this, when launching the lote.sh I had :