211{
213 unsigned int size = 0;
214 CellInfo*
info =
nullptr;
215
216 int evtIndex = 0, runIndex = 0;
217 std::map<std::pair<int, int>, int> evtMap;
218 std::map<int, int> runMap;
219 std::map< std::pair<const PersistentAccessor*, int>, int > evtAccMap;
220
221 cout << "Merging runs" << endl;
223 if (!accessor) {
224 cout << "Cannot merge: one of the inputs is null!" << endl;
225 delete newAcc;
226 return nullptr;
227 }
228 for (
unsigned int i = 0;
i <
accessor->nRuns();
i++) {
230 if (runMap.find(run) != runMap.end()) continue;
231 runMap[
run] = runIndex;
232 RunData* newRun =
new RunData(*
accessor->runData(i));
234 delete newRun;
235 runIndex++;
236 }
237 }
238
239 cout << "Merging events" << endl;
240 unsigned int nEventsTotal = 0, iEvt = 0;
242 nEventsTotal +=
accessor->nEvents();
243 }
245 for (
unsigned int i = 0;
i <
accessor->nEvents();
i++) {
246 iEvt++;
247 if (iEvt % 100000 == 0) cout << "Merging event " << iEvt << "/" << nEventsTotal << endl;
248 std::pair<int, int> evtId(
accessor->eventData(i)->run(),
accessor->eventData(i)->event());
249 std::pair<const PersistentAccessor*, int> evtAccId(accessor, i);
250 if (evtMap.find(evtId) != evtMap.end()) {
251 cout <<
"ERROR: Skipping duplicate entry for run " <<
accessor->eventData(i)->run() <<
", event " <<
accessor->eventData(i)->event() << endl;
252 continue;
253 }
254 evtAccMap[evtAccId] = evtIndex;
255 evtMap[evtId] = evtIndex;
256 std::map<int, int>::const_iterator
idx = runMap.find(
accessor->eventData(i)->run());
257 int newRunIndex = (
idx == runMap.end() ? -999 :
idx->second);
258
261 delete newEvent;
262 evtIndex++;
263 }
264 }
265
266 cout << "Merging cells" << endl;
268 if (i % 10000 == 0) {
270
271 }
272 HistoryContainer* newHistory = nullptr;
274 const HistoryContainer* history =
accessor->historyContainer(i);
275 if (!history || !history->
isValid())
continue;
276 if (!newHistory) {
278 newHistory = new HistoryContainer(info);
279 }
281 DataContainer* newDC =
new DataContainer(*history->
dataContainer(j));
282 std::map<std::pair<const PersistentAccessor*, int>, int>::const_iterator newIndex
284 if (newIndex == evtAccMap.end()) cout <<
"Event not found for cell " <<
i <<
", data " << j <<
"." << endl;
285 newDC->
setEventIndex(newIndex != evtAccMap.end() ? newIndex->second : -1);
286 newHistory->
add(newDC);
289
290
292 }
293 }
294 }
296 newAcc->
add(newHistory);
297 delete newHistory;
298 }
299
300
301 cout << "Merging SC" << endl;
304 if (i % 10000 == 0) {
306
307 }
308 HistoryContainer* newHistory = nullptr;
310 const HistoryContainer* history =
accessor->historyContainerSC(i);
311 if (!history || !history->
isValid())
continue;
312 if (!newHistory) {
314 newHistory = new HistoryContainer(info);
315 }
317 DataContainer* newDC =
new DataContainer(*history->
dataContainer(j));
318 std::map<std::pair<const PersistentAccessor*, int>, int>::const_iterator newIndex
320 if (newIndex == evtAccMap.end()) cout <<
"Event not found for cell " <<
i <<
", data " << j <<
"." << endl;
321 newDC->
setEventIndex(newIndex != evtAccMap.end() ? newIndex->second : -1);
322 newHistory->
add(newDC);
325
326
328 }
329 }
330 }
332 newAcc->
addSC(newHistory);
333 delete newHistory;
334 }
335
336
337 cout <<
"Merging done, final size = " <<
size << endl;
339 return newAcc;
340}
const ShapeInfo * shape(CaloGain::CaloGain gain) const
CaloGain::CaloGain gain() const
void setEventIndex(int index)
void add(const DataContainer *data)
append data (takes ownership)
const CellInfo * cellInfo() const
const DataContainer * dataContainer(unsigned int i) const
void addEvent(EventData *eventData)
void addRun(RunData *runData)
void add(HistoryContainer *cont)
PersistentAccessor(TTree &cellTree, TTree &SCTree, TTree &eventTree, TTree *runTree, TFile *file)
Constructor.
void addSC(HistoryContainer *cont)
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
static const unsigned int nChannels
static const unsigned int nChannelsSC