16from ROOT
import TFile, TTree, TDirectory, TStopwatch
24 msg.debug(
'Checking branch %s ...', branch.GetName())
26 nBaskets=branch.GetWriteBasket()
28 msg.debug(
'Checking %s baskets ...', nBaskets)
30 for iBasket
in range(nBaskets):
31 basket=branch.GetBasket(iBasket)
33 msg.warning(
'Basket %s of branch %s is corrupted.', iBasket, branch.GetName() )
36 listOfSubBranches=branch.GetListOfBranches()
37 msg.debug(
'Checking %s subbranches ...', listOfSubBranches.GetEntries())
38 for subBranch
in listOfSubBranches:
42 msg.debug(
'Branch %s looks ok.', branch.GetName())
80 reader=RNTupleReader.Open(ntuple)
81 except Exception
as err:
82 msg.warning(
'Could not open ntuple %s: %s', ntuple, err)
85 nEntries=reader.GetNEntries()
87 msg.debug(
'Checking %s entries ...', nEntries)
89 entry = reader.CreateEntry()
90 for i
in range(nEntries):
92 reader.LoadEntry(i, entry)
93 except Exception
as err:
94 msg.warning(
'Event %s of ntuple %s is corrupted: %s', i, reader.GetDescriptor().GetName(), err)
98 if (i%printInterval)==0
and i>0:
99 msg.info(
'Validated %s events so far ...', i)
104 """For each cluster, bulk read each top level field.
106 from ROOT
import RException
109 reader=RNTupleReader.Open(ntuple)
110 except Exception
as err:
111 msg.warning(
'Could not open ntuple %r: %r', ntuple, err)
115 descriptor = reader.GetDescriptor()
116 msg.debug(f
"ntupleName={descriptor.GetName()}")
118 model = reader.GetModel()
119 fieldZero = model.GetConstFieldZero()
120 subFields = fieldZero.GetConstSubfields()
121 msg.debug(f
"Top level fields number {subFields.size()}")
122 for clusterDescriptor
in descriptor.GetClusterIterable():
123 size = int(clusterDescriptor.GetNEntries())
124 if msg.isEnabledFor(logging.DEBUG):
125 msg.debug(f
" cluster #{clusterDescriptor.GetId()}"
126 f
" firstEntryIndex={clusterDescriptor.GetFirstEntryIndex()}"
128 clusterRange = ROOT.RNTupleLocalRange(clusterDescriptor.GetId(), 0, size)
129 for field
in subFields:
130 if msg.isEnabledFor(logging.DEBUG):
131 msg.debug(f
"fieldName={field.GetFieldName()} typeName={field.GetTypeName()}")
132 bulk = model.CreateBulk(field.GetFieldName())
133 values = bulk.ReadBulk(clusterRange)
134 if msg.isEnabledFor(logging.DEBUG):
135 msg.debug(f
" values array at {values}")
139 except RException
as err:
140 from traceback
import format_exception
141 msg.error(
"Exception reading ntuple %r\n%s", ntuple,
"".join(format_exception(err)))
148 from PyUtils
import PoolFile
152 msg.debug(
'Checking directory %s ...', directory.GetName())
154 listOfKeys=directory.GetListOfKeys()
156 msg.debug(
'Checking %s keys ... ', listOfKeys.GetEntries())
158 for key
in listOfKeys:
160 msg.debug(
'Looking at key %s ...', key.GetName())
161 msg.debug(
'Key is of class %s.', key.GetClassName())
163 the_object=directory.Get(key.GetName())
165 msg.warning(
"Can't get object of key %s.", key.GetName())
168 if requireTree
and not isinstance(the_object, TTree):
169 msg.warning(
"Object of key %s is not of class TTree!", key.GetName())
172 if isinstance(the_object,TTree):
174 msg.debug(
'Checking tree %s ...', the_object.GetName())
177 if PoolFile.PoolOpts.TTreeNames.EventData == the_object.GetName():
178 nentries = the_object.GetEntries()
179 msg.debug(f
' contains {nentries} events')
180 elif PoolFile.PoolOpts.TTreeNames.MetaData == the_object.GetName():
182 msg.debug(
' contains MetaData')
184 if the_type==
'event':
187 elif the_type==
'basket':
191 msg.debug(
'Tree %s looks ok.', the_object.GetName())
193 if isRNTuple(the_object):
195 msg.debug(
'Checking ntuple of key %s ...', key.GetName())
198 reader=RNTupleReader.Open(the_object)
199 except Exception
as err:
200 msg.warning(
'Could not open ntuple %s: %s', the_object, err)
204 if PoolFile.PoolOpts.RNTupleNames.EventData == reader.GetDescriptor().GetName():
205 nentries = reader.GetNEntries()
206 msg.debug(f
' contains {nentries} events')
207 elif PoolFile.PoolOpts.RNTupleNames.MetaData == reader.GetDescriptor().GetName():
209 msg.debug(
' contains MetaData')
211 if the_type==
'event':
214 elif the_type==
'basket':
218 msg.debug(
'NTuple of key %s looks ok.', key.GetName())
220 if isinstance(the_object, TDirectory):
221 if checkDirectory(the_object, the_type, requireTree, depth + 1)==1:
225 if depth == 0
and hasMetadata
and checkNEvents(directory.GetName(), nentries)==1:
228 msg.debug(
'Directory %s looks ok.', directory.GetName())
234 msg.info(
'Checking file %s ...', fileName)
237 if not ROOT.ROOT.IsImplicitMTEnabled()
and os.environ.keys() >= {
'TRF_MULTITHREADED_VALIDATION',
'ATHENA_CORE_NUMBER'}:
238 if (nThreads := int(os.environ[
'ATHENA_CORE_NUMBER'])) >= 0:
239 msg.info(f
"Setting the number of implicit ROOT threads to {nThreads}")
240 ROOT.ROOT.EnableImplicitMT(nThreads)
243 msg.warning(f
"Ignored negative ATHENA_CORE_NUMBER ({nThreads})")
246 file_handle=TFile.Open(fileName)
247 except OSError
as err:
248 msg.error(
'Could not open file %s: %s', fileName, err)
252 msg.warning(
"Can't access file %s.", fileName)
255 if not file_handle.IsOpen():
256 msg.warning(
"Can't open file %s.", fileName)
259 if file_handle.IsZombie():
260 msg.warning(
"File %s is a zombie.", fileName)
264 if file_handle.TestBit(TFile.kRecovered):
265 msg.warning(
"File %s needed to be recovered.", fileName)
270 msg.warning(
"File %s is corrupted.", fileName)
275 msg.info(
"File %s looks ok.", fileName)
278 ROOT.ROOT.DisableImplicitMT()