8"""Contain utils for ROOT command line tools"""
16from contextlib
import contextmanager
20from itertools
import zip_longest
24 Look for 'fileno' attribute.
26 fd = getattr(file_or_fd,
"fileno",
lambda: file_or_fd)()
27 if not isinstance(fd, int):
28 raise ValueError(
"Expected a file (`.fileno()`) or a file descriptor")
35 Redirect the output from source to destination.
40 with os.fdopen(os.dup(stdout_fd),
"wb")
as copied:
43 os.dup2(
fileno(destination), stdout_fd)
45 with open(destination,
"wb")
as destination_file:
46 os.dup2(destination_file.fileno(), stdout_fd)
53 os.dup2(copied.fileno(), stdout_fd)
58 Redirect the output from sys.stdout to os.devnull.
65 Redirect the output from sys.stderr to os.devnull.
81ROOT.PyConfig.IgnoreCommandLineOptions =
True
82ROOT.gROOT.GetVersion()
89LOG_FORMAT =
"%(levelname)s: %(message)s"
90logging.basicConfig(format=LOG_FORMAT)
101 Get a commandline parser with the defaults of the commandline utils.
103 return argparse.ArgumentParser(
104 description=theHelp, formatter_class=argparse.RawDescriptionHelpFormatter, epilog=theEpilog
110 Get a commandline parser with the defaults of the commandline utils and a
114 parser.add_argument(
"FILE", nargs=
"?", help=
"Input file")
120 Get a commandline parser with the defaults of the commandline utils and a
121 list of source files.
124 parser.add_argument(
"FILE", nargs=
"+", help=
"Input file")
130 Get a commandline parser with the defaults of the commandline utils,
131 a list of source files and a destination file.
134 parser.add_argument(
"SOURCE", nargs=
"+", help=
"Source file")
135 parser.add_argument(
"DEST", help=
"Destination file")
148 originalLevel = ROOT.gErrorIgnoreLevel
149 ROOT.gErrorIgnoreLevel = level
151 ROOT.gErrorIgnoreLevel = originalLevel
156 Change the current directory (ROOT.gDirectory) by the corresponding (rootFile,pathSplit)
159 for directoryName
in pathSplit:
160 theDir = ROOT.gDirectory.Get(directoryName)
162 logging.warning(
"Directory %s does not exist." % directoryName)
171 Add a directory named 'pathSplit[-1]' in (rootFile,pathSplit[:-1])
175 ROOT.gDirectory.mkdir(pathSplit[-1])
181 Get the object objName from the current directory
183 return ROOT.gDirectory.Get(objName)
188 Return True if the object, corresponding to (rootFile,pathSplit), exits
191 return ROOT.gDirectory.GetListOfKeys().Contains(pathSplit[-1])
196 Return True if the object, corresponding to the key, inherits from TDirectory
198 classname = key.GetClassName()
199 cl = ROOT.gROOT.GetClass(classname)
201 logging.warning(
"Unknown class to ROOT: " + classname)
203 return cl.InheritsFrom(ROOT.TDirectory.Class())
208 Return True if the object, corresponding to the key, inherits from TTree
210 classname = key.GetClassName()
211 cl = ROOT.gROOT.GetClass(classname)
213 logging.warning(
"Unknown class to ROOT: " + classname)
215 return cl.InheritsFrom(ROOT.TTree.Class())
220 Return True if the object, corresponding to the key, inherits from THnSparse
222 classname = key.GetClassName()
223 cl = ROOT.gROOT.GetClass(classname)
225 logging.warning(
"Unknown class to ROOT: " + classname)
227 return cl.InheritsFrom(ROOT.THnSparse.Class())
232 Get the key of the corresponding object (rootFile,pathSplit)
235 return ROOT.gDirectory.GetKey(pathSplit[-1])
240 Return True if the object, corresponding to (rootFile,pathSplit), inherits from TDirectory
250 Return True if the object, corresponding to (rootFile,pathSplit), inherits from TTree
260 Get the list of keys of the directory (rootFile,pathSplit),
261 if (rootFile,pathSplit) is not a directory then get the key in a list
265 return ROOT.gDirectory.GetListOfKeys()
267 return [
getKey(rootFile, pathSplit)]
272 Sort list of keys by their names ignoring the case
274 keyList.sort(key=
lambda x: x.GetName().lower())
279 Sort list of tuples by their first elements ignoring the case
281 tupleList.sort(key=
lambda x: x[0].lower())
286 Sort list of directories by their names ignoring the case
288 dirList.sort(key=
lambda x: [n.lower()
for n
in x])
293 Return a list of directories and a list of keys corresponding
294 to the other objects, for rootls and rootprint use
298 for pathSplit
in pathSplitList:
300 dirList.append(pathSplit)
302 dirList.append(pathSplit)
304 keyList.append(
getKey(rootFile, pathSplit))
307 return keyList, dirList
312 Open the ROOT file corresponding to fileName in the corresponding mode,
313 redirecting the output not to see missing dictionnaries
320 theFile = ROOT.TFile.Open(fileName, mode)
322 logging.warning(
"File %s does not exist", fileName)
328 Open a ROOT file (like openROOTFile) with the possibility
329 to change compression settings
331 if compress !=
None and os.path.isfile(fileName):
332 logging.warning(
"can't change compression settings on existing file")
334 mode =
"recreate" if recreate
else "update"
337 theFile.SetCompressionSettings(compress)
343 Join the pathSplit with '/'
345 return "/".join(pathSplit)
348MANY_OCCURENCE_WARNING =
"Several versions of '{0}' are present in '{1}'. Only the most recent will be considered."
353 Search for double occurence of the same pathSplit and remove them
355 if len(pathSplitList) > 1:
356 for n
in pathSplitList:
357 if pathSplitList.count(n) != 1:
358 logging.warning(MANY_OCCURENCE_WARNING.format(
joinPathSplit(n), fileName))
359 while n
in pathSplitList
and pathSplitList.count(n) != 1:
360 pathSplitList.remove(n)
365 Get the list of pathSplit of objects in the ROOT file
366 corresponding to fileName that match with the pattern
374 patternSplit = [n
for n
in pattern.split(
"/")
if n !=
""]
378 for patternPiece
in patternSplit:
379 newPathSplitList = []
380 for pathSplit
in pathSplitList:
383 newPathSplitList.extend(
385 pathSplit + [key.GetName()]
386 for key
in ROOT.gDirectory.GetListOfKeys()
387 if fnmatch.fnmatch(key.GetName(), patternPiece)
390 pathSplitList = newPathSplitList
393 if pathSplitList == []:
394 logging.warning(
"can't find {0} in {1}".
format(pattern, fileName))
404 Get the list of fileName that match with objPattern
407 return [os.path.expandvars(os.path.expanduser(i))
for i
in glob.iglob(filePattern)]
409 return [os.path.expandvars(os.path.expanduser(filePattern))]
414 Get the list of pathSplit that match with objPattern
419 return [[n
for n
in objPattern.split(
"/")
if n !=
""]]
424 Get the list of tuple containing both :
426 - list of splited path (in the corresponding file) of objects that matche
427 Use unix wildcards by default
429 rootFilePattern =
"*.root"
430 rootObjPattern = rootFilePattern +
":*"
431 httpRootFilePattern =
"htt*://*.root"
432 httpRootObjPattern = httpRootFilePattern +
":*"
433 xrootdRootFilePattern =
"root://*.root"
434 xrootdRootObjPattern = xrootdRootFilePattern +
":*"
435 s3RootFilePattern =
"s3://*.root"
436 s3RootObjPattern = s3RootFilePattern +
":*"
437 gsRootFilePattern =
"gs://*.root"
438 gsRootObjPattern = gsRootFilePattern +
":*"
439 pcmFilePattern =
"*.pcm"
440 pcmObjPattern = pcmFilePattern +
":*"
443 fnmatch.fnmatch(pattern, httpRootObjPattern)
444 or fnmatch.fnmatch(pattern, xrootdRootObjPattern)
445 or fnmatch.fnmatch(pattern, s3RootObjPattern)
446 or fnmatch.fnmatch(pattern, gsRootObjPattern)
448 patternSplit = pattern.rsplit(
":", 1)
449 fileName = patternSplit[0]
450 objPattern = patternSplit[1]
452 return [(fileName, pathSplitList)]
455 fnmatch.fnmatch(pattern, httpRootFilePattern)
456 or fnmatch.fnmatch(pattern, xrootdRootFilePattern)
457 or fnmatch.fnmatch(pattern, s3RootFilePattern)
458 or fnmatch.fnmatch(pattern, gsRootFilePattern)
462 return [(fileName, pathSplitList)]
464 if fnmatch.fnmatch(pattern, rootObjPattern)
or fnmatch.fnmatch(pattern, pcmObjPattern):
465 patternSplit = pattern.split(
":")
466 filePattern = patternSplit[0]
467 objPattern = patternSplit[1]
469 return [(fileName,
pathSplitListMatch(fileName, objPattern, wildcards))
for fileName
in fileNameList]
471 if fnmatch.fnmatch(pattern, rootFilePattern)
or fnmatch.fnmatch(pattern, pcmFilePattern):
472 filePattern = pattern
475 return [(fileName, pathSplitList)
for fileName
in fileNameList]
477 logging.warning(
"{0}: No such file (or extension not supported)".
format(pattern))
490 Get arguments corresponding to parser.
492 return parser.parse_args()
497 Create a list of tuples that contain source ROOT file names
498 and lists of path in these files as well as the original arguments
503 inputFiles = args.FILE
505 inputFiles = args.SOURCE
507 return sourceList, args
512 Get the list of tuples and the dictionary with options
515 sourceList: a list of tuples with one list element per file
516 the first tuple entry being the root file,
517 the second a list of subdirectories,
518 each being represented as a list itself with a string per level
520 rootls tutorial/tmva/TMVA.root:Method_BDT/BDT turns into
521 [('tutorials/tmva/TMVA.root', [['Method_BDT','BDT']])]
522 vars(args): a dictionary of matched options, e.g.
523 {'longListing': False,
525 'treeListing': False,
526 'recursiveListing'; False,
527 'FILE': ['tutorials/tmva/TMVA.root:Method_BDT/BDT']
532 logging.error(
"Input file(s) not found!")
533 return sourceList, vars(args)
538 Get the list of tuples of sources, create destination name, destination pathSplit
539 and the dictionary with options
544 destFileName, destPathSplitList = destList[0]
545 destPathSplit = destPathSplitList[0]
549 return sourceList, destFileName, destPathSplit, vars(args)
558TARGET_ERROR =
"target '{0}' is not a directory"
559OMITTING_ERROR =
"{0} '{1}' will be copied but not its subdirectories (if any). Use the -r option if you need a recursive copy."
560OVERWRITE_ERROR =
"cannot overwrite non-directory '{0}' with directory '{1}'"
563def copyRootObject(sourceFile, sourcePathSplit, destFile, destPathSplit, oneSource, recursive, replace):
565 Initialize the recursive function 'copyRootObjectRecursive', written to be as unix-like as possible
568 isMultipleInput =
not (oneSource
and sourcePathSplit != [])
569 recursiveOption = recursive
574 and destPathSplit != []
577 logging.warning(TARGET_ERROR.format(destPathSplit[-1]))
580 if not recursiveOption:
581 if sourcePathSplit == []:
582 logging.warning(OMITTING_ERROR.format(
"file", sourceFile.GetName()))
585 logging.warning(OMITTING_ERROR.format(
"directory", sourcePathSplit[-1]))
589 if sourcePathSplit == []:
593 if not isMultipleInput
and (destPathSplit != []
and not isExisting(destFile, destPathSplit)):
594 setName = destPathSplit[-1]
595 objectName = sourcePathSplit[-1]
600 sourceFile, sourcePathSplit, destFile, destPathSplit[:-1] + [setName], replace
603 if not isExisting(destFile, destPathSplit + [objectName]):
605 if isDirectory(destFile, destPathSplit + [objectName]):
607 sourceFile, sourcePathSplit, destFile, destPathSplit + [objectName], replace
610 logging.warning(OVERWRITE_ERROR.format(objectName, objectName))
613 logging.warning(OVERWRITE_ERROR.format(destPathSplit[-1], objectName))
618 sourceFile, sourcePathSplit, destFile, destPathSplit[:-1], replace, setName
623 setName = destPathSplit[-1]
625 sourceFile, sourcePathSplit, destFile, destPathSplit[:-1], replace, setName
630DELETE_ERROR =
"object {0} was not existing, so it is not deleted"
635 Delete the object 'pathSplit[-1]' from (rootFile,pathSplit[:-1])
639 fileName = pathSplit[-1]
641 ROOT.gDirectory.Delete(fileName +
";*")
643 logging.warning(DELETE_ERROR.format(fileName))
650 Copy objects from a file or directory (sourceFile,sourcePathSplit)
651 to an other file or directory (destFile,destPathSplit)
652 - Has the will to be unix-like
653 - that's a recursive function
654 - Python adaptation of a root input/output tutorial : copyFiles.C
657 replaceOption = replace
659 for key
in getKeyList(sourceFile, sourcePathSplit):
660 objectName = key.GetName()
663 if objectName
not in seen.keys():
664 seen[objectName] = key
666 if seen[objectName].GetCycle() < key.GetCycle():
667 seen[objectName] = key
672 if not isExisting(destFile, destPathSplit + [objectName]):
674 if isDirectory(destFile, destPathSplit + [objectName]):
676 sourceFile, sourcePathSplit + [objectName], destFile, destPathSplit + [objectName], replace
679 logging.warning(OVERWRITE_ERROR.format(objectName, objectName))
682 T = key.GetMotherDir().Get(objectName +
";" + str(key.GetCycle()))
683 if replaceOption
and isExisting(destFile, destPathSplit + [T.GetName()]):
684 retcodeTemp =
deleteObject(destFile, destPathSplit + [T.GetName()])
686 retcode += retcodeTemp
689 newT = T.CloneTree(-1,
"fast")
691 newT.SetName(setName)
695 if replaceOption
and isExisting(destFile, destPathSplit + [setName]):
698 retcodeTemp =
deleteObject(destFile, destPathSplit + [setName])
700 retcode += retcodeTemp
703 if isinstance(obj, ROOT.TNamed):
707 elif issubclass(obj.__class__, ROOT.TCollection):
710 obj.Write(setName, ROOT.TObject.kSingleKey)
713 if isinstance(obj, ROOT.TNamed):
716 if isinstance(obj, ROOT.TNamed):
717 obj.SetName(objectName)
722 ROOT.gDirectory.SaveSelf(ROOT.kTRUE)
726FILE_REMOVE_ERROR =
"cannot remove '{0}': Is a ROOT file"
727DIRECTORY_REMOVE_ERROR =
"cannot remove '{0}': Is a directory"
728ASK_FILE_REMOVE =
"remove '{0}' ? (y/n) : "
729ASK_OBJECT_REMOVE =
"remove '{0}' from '{1}' ? (y/n) : "
734 Remove the object (rootFile,pathSplit)
735 -interactive : prompt before every removal
736 -recursive : allow directory, and ROOT file, removal
739 if not recursive
and isDirectory(rootFile, pathSplit):
741 logging.warning(FILE_REMOVE_ERROR.format(rootFile.GetName()))
744 logging.warning(DIRECTORY_REMOVE_ERROR.format(pathSplit[-1]))
749 answer = input(ASK_OBJECT_REMOVE.format(
"/".join(pathSplit), rootFile.GetName()))
751 answer = input(ASK_FILE_REMOVE.format(rootFile.GetName()))
752 remove = answer.lower() ==
"y"
760 os.remove(rootFile.GetName())
771SOURCE_HELP =
"path of the source."
772SOURCES_HELP =
"path of the source(s)."
773DEST_HELP =
"path of the destination."
776COMPRESS_HELP =
"""change the compression settings of the
777destination file (if not already existing)."""
778INTERACTIVE_HELP =
"prompt before every removal."
779RECREATE_HELP =
"recreate the destination file."
780RECURSIVE_HELP =
"recurse inside directories"
781REPLACE_HELP =
"replace object if already existing"
791 """This is used by _copyTreeSubset() to turn on/off branches"""
792 for branchToModify
in branchSelectionString.split(
","):
793 logging.info(
"Setting branch status to %d for %s" % (status, branchToModify))
794 tree.SetBranchStatus(branchToModify, status)
809 """Copy a subset of the tree from (sourceFile,sourcePathSplit)
810 to (destFile,destPathSplit) according to options in optDict"""
815 nbrEntries = bigTree.GetEntries()
822 lastEvent = nbrEntries - 1
823 numberOfEntries = (lastEvent - firstEvent) + 1
833 if branchexclude
or branchinclude:
834 outputTree = outputTree.CloneTree()
838 outputTree = outputTree.CopyTree(selectionString,
"", numberOfEntries, firstEvent)
845 fileName, pathSplitList, destFile, destPathSplit, first, last, selectionString, branchinclude, branchexclude
848 destFileName = destFile.GetName()
849 rootFile =
openROOTFile(fileName)
if fileName != destFileName
else destFile
852 for pathSplit
in pathSplitList:
853 if isTree(rootFile, pathSplit):
855 rootFile, pathSplit, destFile, destPathSplit, first, last, selectionString, branchinclude, branchexclude
857 if fileName != destFileName:
875 if sourceList == []
or destFileName ==
"":
877 if recreate
and destFileName
in sourceList:
878 logging.error(
"cannot recreate destination file if this is also a source file")
888 for fileName, pathSplitList
in sourceList:
890 fileName, pathSplitList, destFile, destPathSplit, first, last, selectionString, branchinclude, branchexclude
902MOVE_ERROR =
"error during copy of {0}, it is not removed from {1}"
905def _moveObjects(fileName, pathSplitList, destFile, destPathSplit, oneFile, interactive):
909 destFileName = destFile.GetName()
910 rootFile =
openROOTFile(fileName,
"update")
if fileName != destFileName
else destFile
913 ROOT.gROOT.GetListOfFiles().Remove(rootFile)
914 for pathSplit
in pathSplitList:
915 oneSource = oneFile
and len(pathSplitList) == 1
916 retcodeTemp =
copyRootObject(rootFile, pathSplit, destFile, destPathSplit, oneSource, recursive, replace)
920 logging.warning(MOVE_ERROR.format(
"/".join(pathSplit), rootFile.GetName()))
921 retcode += retcodeTemp
922 if fileName != destFileName:
927def rootMv(sourceList, destFileName, destPathSplit, compress=None, interactive=False, recreate=False):
929 if sourceList == []
or destFileName ==
"":
931 if recreate
and destFileName
in sourceList:
932 logging.error(
"cannot recreate destination file if this is also a source file")
939 ROOT.gROOT.GetListOfFiles().Remove(destFile)
943 for fileName, pathSplitList
in sourceList:
944 retcode +=
_moveObjects(fileName, pathSplitList, destFile, destPathSplit, len(sourceList) == 1, interactive)
959 for pathSplit
in dirList:
960 keyList.extend(
getKeyList(rootFile, pathSplit))
963 prefixList = [
"" for key
in keyList]
965 for subdir
in subList:
966 subkeyList, subprefixList =
_keyListExtended(ROOT.gDirectory.Get(subdir.GetName()), pathSplitList, recursive)
967 keyList.extend(subkeyList)
968 prefixList.extend([subdir.GetName() +
"_" + prefix
for prefix
in subprefixList])
970 keyList, prefixList = (list(t)
for t
in zip(*sorted(zip(keyList, prefixList), key=
lambda x: x[0].GetName().lower())))
973 return keyList, prefixList
978 directoryOption=None,
986 recursiveOption=False,
994 ROOT.gROOT.SetBatch()
998 ROOT.gInterpreter.ProcessLine(
".x {0}".
format(styleOption))
1001 if not verboseOption:
1002 ROOT.gErrorIgnoreLevel = 9999
1007 width, height = sizeOption.split(
"x")
1009 height =
int(height)
1011 logging.warning(
"canvas size is on a wrong format")
1013 canvas = ROOT.TCanvas(
"canvas",
"canvas", width, height)
1015 canvas = ROOT.TCanvas(
"canvas")
1020 x, y = divideOption.split(
",")
1024 logging.warning(
"divide is on a wrong format")
1030 if not formatOption
and outputOption:
1031 fileName = outputOption
1032 fileFormat = fileName.split(
".")[-1]
1033 formatOption = fileFormat
1036 if not formatOption:
1037 formatOption =
"pdf"
1041 if not os.path.isdir(os.path.join(os.getcwd(), directoryOption)):
1042 os.mkdir(directoryOption)
1046 if formatOption
in [
"ps",
"pdf"]:
1047 outputFileName = outputOption
1049 outputFileName = directoryOption +
"/" + outputFileName
1050 canvas.Print(outputFileName +
"[", formatOption)
1052 logging.warning(
"can't merge pictures, only postscript or pdf files")
1059 for fileName, pathSplitList
in sourceList:
1064 openRootFiles.append(rootFile)
1066 keyList, prefixList =
_keyListExtended(rootFile, pathSplitList, recursiveOption)
1067 for k, key
in enumerate(keyList):
1072 canvas.cd(objDrawnNumber % caseNumber + 1)
1075 obj.Draw(drawOption)
1077 if objDrawnNumber % caseNumber == 0:
1078 if not outputOption:
1079 outputFileName = str(objDrawnNumber // caseNumber) +
"." + formatOption
1081 outputFileName = os.path.join(directoryOption, outputFileName)
1082 canvas.Print(outputFileName, formatOption)
1086 prefix = prefixList[k]
1087 if not outputOption:
1088 outputFileName = prefix + key.GetName() +
"." + formatOption
1090 outputFileName = os.path.join(directoryOption, outputFileName)
1091 if outputOption
or formatOption ==
"pdf":
1092 objTitle =
"Title:" + key.GetClassName() +
" : " + key.GetTitle()
1093 canvas.Print(outputFileName, objTitle)
1095 canvas.Print(outputFileName, formatOption)
1099 if objDrawnNumber % caseNumber != 0:
1100 if not outputOption:
1101 outputFileName = str(objDrawnNumber // caseNumber + 1) +
"." + formatOption
1103 outputFileName = os.path.join(directoryOption, outputFileName)
1104 canvas.Print(outputFileName, formatOption)
1108 if not divideOption:
1109 canvas.Print(outputFileName +
"]", objTitle)
1111 canvas.Print(outputFileName +
"]")
1114 map(
lambda rootFile: rootFile.Close(), openRootFiles)
getFromDirectory(objName)
Get the object objName from the current directory.
manyOccurenceRemove(pathSplitList, fileName)
Search for double occurence of the same pathSplit and remove them.
rootMv(sourceList, destFileName, destPathSplit, compress=None, interactive=False, recreate=False)
getSourceListArgs(parser, wildcards=True)
Create a list of tuples that contain source ROOT file names and lists of path in these files as well ...
_keyListExtended(rootFile, pathSplitList, recursive=False)
ROOTPRINT.
rootEventselector(sourceList, destFileName, destPathSplit, compress=None, recreate=False, first=0, last=-1, selectionString="", branchinclude="", branchexclude="")
openROOTFile(fileName, mode="read")
Open the ROOT file corresponding to fileName in the corresponding mode, redirecting the output not to...
_copyTreeSubset(sourceFile, sourcePathSplit, destFile, destPathSplit, firstEvent, lastEvent, selectionString, branchinclude, branchexclude)
Copy a subset of the tree from (sourceFile,sourcePathSplit) to (destFile,destPathSplit) according to ...
getParserSingleFile(theHelp, theEpilog="")
Get a commandline parser with the defaults of the commandline utils and a source file or not.
keyClassSplitter(rootFile, pathSplitList)
Return a list of directories and a list of keys corresponding to the other objects,...
deleteRootObject(rootFile, pathSplit, interactive, recursive)
Remove the object (rootFile,pathSplit) -interactive : prompt before every removal -recursive : allow ...
tupleListSort(tupleList)
Sort list of tuples by their first elements ignoring the case.
patternToPathSplitList(fileName, pattern)
Get the list of pathSplit of objects in the ROOT file corresponding to fileName that match with the p...
fileno(file_or_fd)
Look for 'fileno' attribute.
_setBranchStatus(tree, branchSelectionString, status=0)
ROOTEVENTSELECTOR.
copyRootObjectRecursive(sourceFile, sourcePathSplit, destFile, destPathSplit, replace, setName="")
Copy objects from a file or directory (sourceFile,sourcePathSplit) to an other file or directory (des...
_moveObjects(fileName, pathSplitList, destFile, destPathSplit, oneFile, interactive)
createDirectory(rootFile, pathSplit)
Add a directory named 'pathSplit[-1]' in (rootFile,pathSplit[:-1]).
getKeyList(rootFile, pathSplit)
Get the list of keys of the directory (rootFile,pathSplit), if (rootFile,pathSplit) is not a director...
isDirectoryKey(key)
Return True if the object, corresponding to the key, inherits from TDirectory.
isTHnSparseKey(key)
Return True if the object, corresponding to the key, inherits from THnSparse.
isTree(rootFile, pathSplit)
Return True if the object, corresponding to (rootFile,pathSplit), inherits from TTree.
dirListSort(dirList)
Sort list of directories by their names ignoring the case.
rootPrint(sourceList, directoryOption=None, divideOption=None, drawOption="", formatOption=None, outputOption=None, sizeOption=None, styleOption=None, verboseOption=False, recursiveOption=False)
isTreeKey(key)
Return True if the object, corresponding to the key, inherits from TTree.
pathSplitListMatch(fileName, objPattern, wildcards)
Get the list of pathSplit that match with objPattern.
getParserSourceDest(theHelp, theEpilog="")
Get a commandline parser with the defaults of the commandline utils, a list of source files and a des...
keyListSort(keyList)
Sort list of keys by their names ignoring the case.
getSourceDestListOptDict(parser, wildcards=True)
Get the list of tuples of sources, create destination name, destination pathSplit and the dictionary ...
_copyTreeSubsets(fileName, pathSplitList, destFile, destPathSplit, first, last, selectionString, branchinclude, branchexclude)
getSourceListOptDict(parser, wildcards=True)
Get the list of tuples and the dictionary with options.
openROOTFileCompress(fileName, compress, recreate)
Open a ROOT file (like openROOTFile) with the possibility to change compression settings.
_getParser(theHelp, theEpilog)
Different functions to get a parser of arguments and options.
getParserFile(theHelp, theEpilog="")
Get a commandline parser with the defaults of the commandline utils and a list of source files.
deleteObject(rootFile, pathSplit)
Delete the object 'pathSplit[-1]' from (rootFile,pathSplit[:-1]).
getKey(rootFile, pathSplit)
Get the key of the corresponding object (rootFile,pathSplit).
getArgs(parser)
Set of functions to put the arguments in shape.
_setIgnoreLevel(level)
Several utils.
changeDirectory(rootFile, pathSplit)
Change the current directory (ROOT.gDirectory) by the corresponding (rootFile,pathSplit).
isDirectory(rootFile, pathSplit)
Return True if the object, corresponding to (rootFile,pathSplit), inherits from TDirectory.
copyRootObject(sourceFile, sourcePathSplit, destFile, destPathSplit, oneSource, recursive, replace)
Initialize the recursive function 'copyRootObjectRecursive', written to be as unix-like as possible.
joinPathSplit(pathSplit)
Join the pathSplit with '/'.
stdoutRedirected()
Redirect the output from sys.stdout to os.devnull.
fileNameListMatch(filePattern, wildcards)
Get the list of fileName that match with objPattern.
stderrRedirected()
Redirect the output from sys.stderr to os.devnull.
isExisting(rootFile, pathSplit)
Return True if the object, corresponding to (rootFile,pathSplit), exits.
streamRedirected(source=sys.stdout, destination=os.devnull)
Redirect the output from source to destination.
patternToFileNameAndPathSplitList(pattern, wildcards=True)
Get the list of tuple containing both :