Home | News | Documentation | Download

Remove directory

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()


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22.08
Platform: linux, lxplus
Compiler: none


Have you tried the rootrm command line tool ?

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'

Arnaud

What is your rootcp command ?

it is :

rootcp --recreate MyROOTFile.root:'DQMData/Run 1/EgammaV' MyNEWFile.root

I tried without “–recreate” with the same error msg.
Arnaud

Can you provide a the non-working root file (MyROOTFile.root) ? or a smaller version of it showing the problem ?

I used the following ‘official’ ROOT files :

  • DQM_V0001_R000000001__RelValZEE_14__CMSSW_12_1_0_pre4-121X_mcRun3_2021_realistic_v10-v1__DQMIO.root [1]

  • DQM_V0001_R000000001__RelValZEE_14__CMSSW_12_0_0_pre3-120X_mcRun3_2021_realistic_v1-v1__DQMIO.root [2]

and the following script :

#!/bin/sh

dList=`rootls DQM_V0001_R000000001__RelValZEE_14__CMSSW_12_1_0_pre4-121X_mcRun3_2021_realistic_v10-v1__DQMIO.root:'DQMData/Run 1'`
echo $dList

rootcp DQM_V0001_R000000001__RelValZEE_14__CMSSW_12_1_0_pre4-121X_mcRun3_2021_realistic_v10-v1__DQMIO.root:'DQMData/Run 1/EgammaV' TUTU.root -r

The first part (dList=…) is only here in order to list the directories, and the copy is into the second part (rootcp …).
Arnaud

[1] : https://cmsweb.cern.ch/dqm/relval/data/browse/ROOT/RelVal/CMSSW_12_1_x/
[2] : https://cmsweb.cern.ch/dqm/relval/data/browse/ROOT/RelVal/CMSSW_12_0_x/

I seems I am not allowed to access them.

I have the following file but with this, it works !
DQM_V0001_R000000001__RelValZEE_13__CMSSW_10_6_20-106X_mc2017_realistic_v9_miniv2-v1__DQMIO.root (2.7 MB)

if you can access to /afs/cern.ch/user/a/archiron/public/ROOT_SIZE, there is the root files.
Arnaud

Yes i just tried with that file. It works fine.

yes it works with a little pbm : we only have EgammaV instead of DQMData/Run 1/EgammaV in order to keep the same structure and the same opening.

so the questions remain :

  • how to keep the structure ?
  • why it does not work with recent ROOT files (>= 11_3_0_pre4) ? here the error msg : NameError: global name 'OMITTING_DIRECTORY_ERROR' is not defined
  • why with CMSSW release (>= 12_1_0_pre2) do we have : ImportError: No module named cmdLineUtils ?

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.

OK, but what is false in :

cmsrel CMSSW_12_1_0_pre5
cd CMSSW_12_1_0_pre5/src
cmsenv
cp ../../ROOT_SIZE/lote.sh .
. lote.sh 

and for lote.sh

#!/bin/sh

SOURCE="/afs/cern.ch/user/a/archiron/public/ROOT_SIZE/DQM_V0001_R000000001__RelValZEE_14__CMSSW_12_1_0_pre4-121X_mcRun3_2021_realistic_v10-v1__DQMIO.root"
DEST="/afs/cern.ch/user/a/archiron/public/ROOT_SIZE/result3.root"

dList=`rootls $SOURCE:'DQMData/Run 1'`
echo $dList

# recreate if file exist
rootcp --recreate $SOURCE:'DQMData/Run 1/EgammaV' $DEST -r

I always have :

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

I’m a little bit lost.

What are the commands cmsrel and cmsenv ?

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 :

-bash: rootls : unknown command

-bash: rootcp : unknown command

perhaps it’s only a pbm of ROOT path.

I went back tot you initial message. I looked at the afs directory. I see:

$ ls /afs/cern.ch/user/a/archiron/public/ROOT_SIZE
DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO.root                                                 TITI.root    hsimple.C     result2.root
DQM_V0001_R000000001__RelValZEE_13__CMSSW_10_6_20-106X_mc2017_realistic_v9-v1__DQMIO.root            TOTO.root    hsimple.root  rootLite.py
DQM_V0001_R000000001__RelValZEE_13__CMSSW_10_6_20-106X_mc2017_realistic_v9_miniv2-v1__DQMIO.root     TUTU.root    lite.sh       tot100.root
DQM_V0001_R000000001__RelValZEE_14__CMSSW_12_0_0_pre3-120X_mcRun3_2021_realistic_v1-v1__DQMIO.root   copyFiles.C  lote.sh       uprootBranch.py
DQM_V0001_R000000001__RelValZEE_14__CMSSW_12_1_0_pre4-121X_mcRun3_2021_realistic_v10-v1__DQMIO.root  f_out        result.root

In that folder which file has problem with rootls and rootcp ?