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}")
137 except RException
as err:
138 from traceback
import format_exception
139 msg.error(
"Exception reading ntuple %r\n%s", ntuple,
"".join(format_exception(err)))
146 from PyUtils
import PoolFile
150 msg.debug(
'Checking directory %s ...', directory.GetName())
152 listOfKeys=directory.GetListOfKeys()
154 msg.debug(
'Checking %s keys ... ', listOfKeys.GetEntries())
156 for key
in listOfKeys:
158 msg.debug(
'Looking at key %s ...', key.GetName())
159 msg.debug(
'Key is of class %s.', key.GetClassName())
161 the_object=directory.Get(key.GetName())
163 msg.warning(
"Can't get object of key %s.", key.GetName())
166 if requireTree
and not isinstance(the_object, TTree):
167 msg.warning(
"Object of key %s is not of class TTree!", key.GetName())
170 if isinstance(the_object,TTree):
172 msg.debug(
'Checking tree %s ...', the_object.GetName())
175 if PoolFile.PoolOpts.TTreeNames.EventData == the_object.GetName():
176 nentries = the_object.GetEntries()
177 msg.debug(f
' contains {nentries} events')
178 elif PoolFile.PoolOpts.TTreeNames.MetaData == the_object.GetName():
180 msg.debug(
' contains MetaData')
182 if the_type==
'event':
185 elif the_type==
'basket':
189 msg.debug(
'Tree %s looks ok.', the_object.GetName())
191 if isRNTuple(the_object):
193 msg.debug(
'Checking ntuple of key %s ...', key.GetName())
196 reader=RNTupleReader.Open(the_object)
197 except Exception
as err:
198 msg.warning(
'Could not open ntuple %s: %s', the_object, err)
202 if PoolFile.PoolOpts.RNTupleNames.EventData == reader.GetDescriptor().GetName():
203 nentries = reader.GetNEntries()
204 msg.debug(f
' contains {nentries} events')
205 elif PoolFile.PoolOpts.RNTupleNames.MetaData == reader.GetDescriptor().GetName():
207 msg.debug(
' contains MetaData')
209 if the_type==
'event':
212 elif the_type==
'basket':
216 msg.debug(
'NTuple of key %s looks ok.', key.GetName())
218 if isinstance(the_object, TDirectory):
219 if checkDirectory(the_object, the_type, requireTree, depth + 1)==1:
223 if depth == 0
and hasMetadata
and checkNEvents(directory.GetName(), nentries)==1:
226 msg.debug(
'Directory %s looks ok.', directory.GetName())
232 msg.info(
'Checking file %s ...', fileName)
235 if not ROOT.ROOT.IsImplicitMTEnabled()
and os.environ.keys() >= {
'TRF_MULTITHREADED_VALIDATION',
'ATHENA_CORE_NUMBER'}:
236 if (nThreads := int(os.environ[
'ATHENA_CORE_NUMBER'])) >= 0:
237 msg.info(f
"Setting the number of implicit ROOT threads to {nThreads}")
238 ROOT.ROOT.EnableImplicitMT(nThreads)
241 msg.warning(f
"Ignored negative ATHENA_CORE_NUMBER ({nThreads})")
244 file_handle=TFile.Open(fileName)
245 except OSError
as err:
246 msg.error(
'Could not open file %s: %s', fileName, err)
250 msg.warning(
"Can't access file %s.", fileName)
253 if not file_handle.IsOpen():
254 msg.warning(
"Can't open file %s.", fileName)
257 if file_handle.IsZombie():
258 msg.warning(
"File %s is a zombie.", fileName)
262 if file_handle.TestBit(TFile.kRecovered):
263 msg.warning(
"File %s needed to be recovered.", fileName)
268 msg.warning(
"File %s is corrupted.", fileName)
273 msg.info(
"File %s looks ok.", fileName)
276 ROOT.ROOT.DisableImplicitMT()