1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
// -*- C++ -*-
//
// Package: FWLite
// Class : BranchMapReader
//
// Implementation:
// <Notes on implementation>
//
// Original Author: Dan Riley
// Created: Tue May 20 10:31:32 EDT 2008
//
// system include files
// user include files
#include "FWCore/FWLite/interface/BranchMapReader.h"
#include "DataFormats/Provenance/interface/BranchIDList.h"
#include "DataFormats/Provenance/interface/BranchListIndex.h"
#include "DataFormats/Provenance/interface/BranchType.h"
#include "DataFormats/Provenance/interface/EventEntryInfo.h"
#include "DataFormats/Provenance/interface/EventSelectionID.h"
#include "DataFormats/Provenance/interface/FileFormatVersion.h"
#include "DataFormats/Provenance/interface/History.h"
#include "DataFormats/Provenance/interface/ProductIDToBranchID.h"
#include "DataFormats/Provenance/interface/ProductRegistry.h"
#include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/propagate_const.h"
#include "TBranch.h"
#include "TFile.h"
#include "TTree.h"
#include <cassert>
namespace fwlite {
namespace internal {
static const edm::ProductDescription kDefaultProductDescription;
BMRStrategy::BMRStrategy(TFile* file, int fileVersion)
: currentFile_(file),
eventTree_(nullptr),
luminosityBlockTree_(nullptr),
runTree_(nullptr),
eventEntry_(-1),
luminosityBlockEntry_(-1),
runEntry_(-1),
fileVersion_(fileVersion) {
// do in derived obects
// updateFile(file);
}
BMRStrategy::~BMRStrategy() {}
class Strategy : public BMRStrategy {
public:
typedef std::map<edm::BranchID, edm::ProductDescription> bidToDesc;
Strategy(TFile* file, int fileVersion);
~Strategy() override;
bool updateFile(TFile* file) override;
bool updateEvent(Long_t eventEntry) override {
eventEntry_ = eventEntry;
return true;
}
bool updateLuminosityBlock(Long_t luminosityBlockEntry) override {
luminosityBlockEntry_ = luminosityBlockEntry;
return true;
}
bool updateRun(Long_t runEntry) override {
runEntry_ = runEntry;
return true;
}
bool updateMap() override { return true; }
edm::BranchID productToBranchID(edm::ProductID const& pid) override;
edm::ProductDescription const& productToBranch(edm::ProductID const& pid) override;
edm::ProductDescription const& branchIDToBranch(edm::BranchID const& bid) const override;
std::vector<edm::ProductDescription> const& getProductDescriptions() override;
edm::ThinnedAssociationsHelper const& thinnedAssociationsHelper() const override {
return *thinnedAssociationsHelper_;
}
TBranch* getBranchRegistry(edm::ProductRegistry** pReg);
bidToDesc productDescriptionMap_;
std::vector<edm::ProductDescription> bDesc_;
bool mapperFilled_;
edm::propagate_const<std::unique_ptr<edm::ThinnedAssociationsHelper>> thinnedAssociationsHelper_;
};
Strategy::Strategy(TFile* file, int fileVersion)
: BMRStrategy(file, fileVersion),
mapperFilled_(false),
thinnedAssociationsHelper_(new edm::ThinnedAssociationsHelper) {
// do in derived obects
// updateFile(file);
}
Strategy::~Strategy() {
// probably need to clean up something here...
}
bool Strategy::updateFile(TFile* file) {
currentFile_ = file;
eventTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventTreeName().c_str()));
luminosityBlockTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::luminosityBlockTreeName().c_str()));
runTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::runTreeName().c_str()));
fileUUID_ = currentFile_->GetUUID();
productDescriptionMap_.clear();
bDesc_.clear();
return nullptr != eventTree_;
}
TBranch* Strategy::getBranchRegistry(edm::ProductRegistry** ppReg) {
TBranch* bReg(nullptr);
TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
if (nullptr != metaDataTree) {
bReg = metaDataTree->GetBranch(edm::poolNames::productDescriptionBranchName().c_str());
bReg->SetAddress(ppReg);
bReg->GetEntry(0);
}
return bReg;
}
std::vector<edm::ProductDescription> const& Strategy::getProductDescriptions() {
if (bDesc_.empty()) {
for (auto const& item : productDescriptionMap_) {
bDesc_.push_back(item.second);
}
}
return bDesc_;
}
edm::BranchID Strategy::productToBranchID(edm::ProductID const&) {
throw edm::Exception(edm::errors::UnimplementedFeature) << "Unsupported EDM file version";
}
edm::ProductDescription const& Strategy::productToBranch(edm::ProductID const& pid) {
edm::BranchID bid = productToBranchID(pid);
bidToDesc::const_iterator bdi = productDescriptionMap_.find(bid);
if (productDescriptionMap_.end() == bdi) {
return kDefaultProductDescription;
}
return bdi->second;
}
edm::ProductDescription const& Strategy::branchIDToBranch(edm::BranchID const& bid) const {
bidToDesc::const_iterator bdi = productDescriptionMap_.find(bid);
if (productDescriptionMap_.end() == bdi) {
return kDefaultProductDescription;
}
return bdi->second;
}
class BranchMapReaderStrategyV1 : public Strategy {
public:
BranchMapReaderStrategyV1(TFile* file, int fileVersion);
bool updateFile(TFile* file) override;
bool updateMap() override;
edm::BranchListIndexes const& branchListIndexes() const override { return dummyBranchListIndexes_; }
private:
edm::BranchListIndexes dummyBranchListIndexes_;
};
BranchMapReaderStrategyV1::BranchMapReaderStrategyV1(TFile* file, int fileVersion) : Strategy(file, fileVersion) {
updateFile(file);
}
bool BranchMapReaderStrategyV1::updateFile(TFile* file) {
if (Strategy::updateFile(file)) {
mapperFilled_ = false;
return true;
}
return false;
}
bool BranchMapReaderStrategyV1::updateMap() {
if (mapperFilled_) {
return true;
}
productDescriptionMap_.clear();
bDesc_.clear();
edm::ProductRegistry reg;
edm::ProductRegistry* pReg = ®
TBranch* br = getBranchRegistry(&pReg);
if (nullptr != br) {
edm::ProductRegistry::ProductList& prodList = reg.productListUpdator();
for (auto& item : prodList) {
edm::ProductDescription& prod = item.second;
if (edm::InEvent == prod.branchType()) {
// call to regenerate branchName
prod.init();
productDescriptionMap_.insert(bidToDesc::value_type(prod.branchID(), prod));
}
}
mapperFilled_ = true;
}
reg.setFrozen(false);
return nullptr != br;
}
// v7 has differences in product status that are not implemented in BranchMapReader yet
class BranchMapReaderStrategyV7 : public BranchMapReaderStrategyV1 {
public:
BranchMapReaderStrategyV7(TFile* file, int fileVersion);
edm::BranchListIndexes const& branchListIndexes() const override { return dummyBranchListIndexes_; }
private:
edm::BranchListIndexes dummyBranchListIndexes_;
};
BranchMapReaderStrategyV7::BranchMapReaderStrategyV7(TFile* file, int fileVersion)
: BranchMapReaderStrategyV1(file, fileVersion) {
updateFile(file);
}
class BranchMapReaderStrategyV8 : public Strategy {
public:
BranchMapReaderStrategyV8(TFile* file, int fileVersion);
bool updateFile(TFile* file) override;
bool updateEvent(Long_t eventEntry) override;
bool updateLuminosityBlock(Long_t luminosityBlockEntry) override;
bool updateRun(Long_t runEntry) override;
bool updateMap() override;
edm::BranchListIndexes const& branchListIndexes() const override { return dummyBranchListIndexes_; }
private:
edm::propagate_const<TBranch*> entryInfoBranch_;
edm::EventEntryInfoVector eventEntryInfoVector_;
edm::EventEntryInfoVector const* pEventEntryInfoVector_;
edm::BranchListIndexes dummyBranchListIndexes_;
};
BranchMapReaderStrategyV8::BranchMapReaderStrategyV8(TFile* file, int fileVersion)
: Strategy(file, fileVersion), eventEntryInfoVector_(), pEventEntryInfoVector_(&eventEntryInfoVector_) {
updateFile(file);
}
bool BranchMapReaderStrategyV8::updateEvent(Long_t newevent) {
// std::cout << "v8 updateevent " << newevent << std::endl;
if (newevent != eventEntry_) {
eventEntry_ = newevent;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV8::updateLuminosityBlock(Long_t newLumi) {
if (newLumi != luminosityBlockEntry_) {
luminosityBlockEntry_ = newLumi;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV8::updateRun(Long_t newRun) {
if (newRun != runEntry_) {
runEntry_ = newRun;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV8::updateFile(TFile* file) {
Strategy::updateFile(file);
mapperFilled_ = false;
entryInfoBranch_ = nullptr;
TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventMetaDataTreeName().c_str()));
if (nullptr != metaDataTree) {
entryInfoBranch_ = metaDataTree->GetBranch(BranchTypeToBranchEntryInfoBranchName(edm::InEvent).c_str());
// std::cout << "entryInfoBranch for " << BranchTypeToBranchEntryInfoBranchName(edm::InEvent) << " " << entryInfoBranch_ << std::endl;
} else {
return false;
}
pEventEntryInfoVector_ = &eventEntryInfoVector_;
entryInfoBranch_->SetAddress(&pEventEntryInfoVector_);
productDescriptionMap_.clear();
bDesc_.clear();
edm::ProductRegistry reg;
edm::ProductRegistry* pReg = ®
TBranch* br = getBranchRegistry(&pReg);
if (nullptr != br) {
edm::ProductRegistry::ProductList& prodList = reg.productListUpdator();
for (auto& item : prodList) {
edm::ProductDescription& prod = item.second;
if (edm::InEvent == prod.branchType()) {
// call to regenerate branchName
prod.init();
productDescriptionMap_.insert(bidToDesc::value_type(prod.branchID(), prod));
}
}
}
reg.setFrozen(false);
return nullptr != br;
}
bool BranchMapReaderStrategyV8::updateMap() {
if (mapperFilled_) {
return true;
}
assert(entryInfoBranch_);
entryInfoBranch_->GetEntry(eventEntry_);
// for(auto const& item : *pEventEntryInfoVector_) {
// eventInfoMap_.insert(item);
// }
mapperFilled_ = true;
return true;
}
class BranchMapReaderStrategyV11 : public Strategy {
public:
BranchMapReaderStrategyV11(TFile* file, int fileVersion);
bool updateFile(TFile* file) override;
bool updateEvent(Long_t eventEntry) override;
bool updateLuminosityBlock(Long_t luminosityBlockEntry) override;
bool updateRun(Long_t runEntry) override;
bool updateMap() override;
edm::BranchID productToBranchID(edm::ProductID const& pid) override;
edm::BranchListIndexes const& branchListIndexes() const override { return history_.branchListIndexes(); }
private:
edm::propagate_const<std::unique_ptr<edm::BranchIDLists>> branchIDLists_;
edm::propagate_const<TTree*> eventHistoryTree_;
edm::History history_;
edm::History const* pHistory_;
};
BranchMapReaderStrategyV11::BranchMapReaderStrategyV11(TFile* file, int fileVersion)
: Strategy(file, fileVersion), eventHistoryTree_(nullptr), pHistory_(&history_) {
updateFile(file);
}
bool BranchMapReaderStrategyV11::updateEvent(Long_t newevent) {
// std::cout << "v11 updateevent " << newevent << std::endl;
if (newevent != eventEntry_) {
eventEntry_ = newevent;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV11::updateLuminosityBlock(Long_t newlumi) {
if (newlumi != luminosityBlockEntry_) {
luminosityBlockEntry_ = newlumi;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV11::updateRun(Long_t newRun) {
if (newRun != runEntry_) {
runEntry_ = newRun;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV11::updateFile(TFile* file) {
Strategy::updateFile(file);
mapperFilled_ = false;
TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
if (nullptr == metaDataTree) {
throw edm::Exception(edm::errors::EventCorruption)
<< "No " << edm::poolNames::metaDataTreeName() << " TTree in file";
}
branchIDLists_ = std::make_unique<edm::BranchIDLists>();
edm::BranchIDLists* branchIDListsPtr = branchIDLists_.get();
if (metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != nullptr) {
TBranch* b = metaDataTree->GetBranch(edm::poolNames::branchIDListBranchName().c_str());
b->SetAddress(&branchIDListsPtr);
b->GetEntry(0);
// std::cout << "--> " << branchIDLists_->size() << std::endl;
} else {
throw edm::Exception(edm::errors::EventCorruption) << "FindBranch of branchIDList failed";
return false;
}
eventHistoryTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventHistoryTreeName().c_str()));
productDescriptionMap_.clear();
bDesc_.clear();
edm::ProductRegistry reg;
edm::ProductRegistry* pReg = ®
TBranch* br = getBranchRegistry(&pReg);
if (nullptr != br) {
edm::ProductRegistry::ProductList& prodList = reg.productListUpdator();
for (auto& item : prodList) {
edm::ProductDescription& prod = item.second;
if (edm::InEvent == prod.branchType()) {
// call to regenerate branchName
prod.init();
productDescriptionMap_.insert(bidToDesc::value_type(prod.branchID(), prod));
// std::cout << "v11 updatefile " << prod.branchID() << std::endl;
}
}
}
reg.setFrozen(false);
return nullptr != br;
}
bool BranchMapReaderStrategyV11::updateMap() {
if (!mapperFilled_) {
TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
if (!eventHistoryBranch) {
throw edm::Exception(edm::errors::EventCorruption) << "Failed to find history branch in event history tree";
return false;
}
// yes, SetAddress really does need to be called every time...
eventHistoryBranch->SetAddress(&pHistory_);
eventHistoryTree_->GetEntry(eventEntry_);
mapperFilled_ = true;
}
return true;
}
edm::BranchID BranchMapReaderStrategyV11::productToBranchID(edm::ProductID const& pid) {
updateMap();
return edm::productIDToBranchID(pid, *branchIDLists_, history_.branchListIndexes());
}
class BranchMapReaderStrategyV17 : public Strategy {
public:
BranchMapReaderStrategyV17(TFile* file, int fileVersion);
bool updateFile(TFile* file) override;
bool updateEvent(Long_t eventEntry) override;
bool updateLuminosityBlock(Long_t luminosityBlockEntry) override;
bool updateRun(Long_t runEntry) override;
bool updateMap() override;
edm::BranchID productToBranchID(edm::ProductID const& pid) override;
edm::BranchListIndexes const& branchListIndexes() const override { return branchListIndexes_; }
private:
edm::propagate_const<std::unique_ptr<edm::BranchIDLists>> branchIDLists_;
edm::propagate_const<TTree*> eventsTree_;
edm::BranchListIndexes branchListIndexes_;
edm::propagate_const<edm::BranchListIndexes*> pBranchListIndexes_;
};
BranchMapReaderStrategyV17::BranchMapReaderStrategyV17(TFile* file, int fileVersion)
: Strategy(file, fileVersion), eventsTree_(nullptr), pBranchListIndexes_(&branchListIndexes_) {
updateFile(file);
}
bool BranchMapReaderStrategyV17::updateEvent(Long_t newevent) {
// std::cout << "v11 updateevent " << newevent << std::endl;
if (newevent != eventEntry_) {
eventEntry_ = newevent;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV17::updateLuminosityBlock(Long_t newlumi) {
if (newlumi != luminosityBlockEntry_) {
luminosityBlockEntry_ = newlumi;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV17::updateRun(Long_t newRun) {
if (newRun != runEntry_) {
runEntry_ = newRun;
mapperFilled_ = false;
}
return true;
}
bool BranchMapReaderStrategyV17::updateFile(TFile* file) {
Strategy::updateFile(file);
mapperFilled_ = false;
TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
if (nullptr == metaDataTree) {
throw edm::Exception(edm::errors::EventCorruption)
<< "No " << edm::poolNames::metaDataTreeName() << " TTree in file";
}
thinnedAssociationsHelper_ = std::make_unique<edm::ThinnedAssociationsHelper>();
edm::ThinnedAssociationsHelper* thinnedAssociationsHelperPtr = thinnedAssociationsHelper_.get();
if (metaDataTree->FindBranch(edm::poolNames::thinnedAssociationsHelperBranchName().c_str()) != nullptr) {
TBranch* b = metaDataTree->GetBranch(edm::poolNames::thinnedAssociationsHelperBranchName().c_str());
b->SetAddress(&thinnedAssociationsHelperPtr);
b->GetEntry(0);
}
branchIDLists_ = std::make_unique<edm::BranchIDLists>();
edm::BranchIDLists* branchIDListsPtr = branchIDLists_.get();
if (metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != nullptr) {
TBranch* b = metaDataTree->GetBranch(edm::poolNames::branchIDListBranchName().c_str());
b->SetAddress(&branchIDListsPtr);
b->GetEntry(0);
// std::cout << "--> " << branchIDLists_->size() << std::endl;
} else {
throw edm::Exception(edm::errors::EventCorruption) << "FindBranch of branchIDList failed";
return false;
}
eventsTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventTreeName().c_str()));
productDescriptionMap_.clear();
bDesc_.clear();
edm::ProductRegistry reg;
edm::ProductRegistry* pReg = ®
TBranch* br = getBranchRegistry(&pReg);
if (nullptr != br) {
edm::ProductRegistry::ProductList& prodList = reg.productListUpdator();
for (auto& item : prodList) {
edm::ProductDescription& prod = item.second;
if (edm::InEvent == prod.branchType()) {
// call to regenerate branchName
prod.init();
productDescriptionMap_.insert(bidToDesc::value_type(prod.branchID(), prod));
// std::cout << "v11 updatefile " << prod.branchID() << std::endl;
}
}
}
reg.setFrozen(false);
return nullptr != br;
}
bool BranchMapReaderStrategyV17::updateMap() {
if (!mapperFilled_) {
TBranch* branchListIndexesBranch =
eventsTree_->GetBranch(edm::poolNames::branchListIndexesBranchName().c_str());
if (!branchListIndexesBranch) {
throw edm::Exception(edm::errors::EventCorruption)
<< "Failed to find branch list indexes branch in event tree";
return false;
}
// yes, SetAddress really does need to be called every time...
branchListIndexesBranch->SetAddress(&pBranchListIndexes_);
branchListIndexesBranch->GetEntry(eventEntry_);
mapperFilled_ = true;
}
return true;
}
edm::BranchID BranchMapReaderStrategyV17::productToBranchID(edm::ProductID const& pid) {
updateMap();
return edm::productIDToBranchID(pid, *branchIDLists_, branchListIndexes_);
}
} // namespace internal
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
BranchMapReader::BranchMapReader(TFile* file) : fileVersion_(-1) {
if (nullptr == file) {
throw cms::Exception("NoFile") << "The TFile pointer is null";
}
strategy_ = newStrategy(file, getFileVersion(file));
}
//
// member functions
//
int BranchMapReader::getFileVersion(TFile* file) {
TTree* metaDataTree = dynamic_cast<TTree*>(file->Get(edm::poolNames::metaDataTreeName().c_str()));
if (nullptr == metaDataTree) {
return 0;
}
edm::FileFormatVersion v;
edm::FileFormatVersion* pV = &v;
TBranch* bVer = metaDataTree->GetBranch(edm::poolNames::fileFormatVersionBranchName().c_str());
if (nullptr == bVer) {
return 0;
}
bVer->SetAddress(&pV);
bVer->GetEntry(0);
fileVersion_ = v.value();
return v.value();
}
bool BranchMapReader::updateEvent(Long_t newevent) { return strategy_->updateEvent(newevent); }
bool BranchMapReader::updateLuminosityBlock(Long_t newlumi) { return strategy_->updateLuminosityBlock(newlumi); }
bool BranchMapReader::updateRun(Long_t newRun) { return strategy_->updateRun(newRun); }
bool BranchMapReader::updateFile(TFile* file) {
if (nullptr == strategy_.get()) {
strategy_ = newStrategy(file, getFileVersion(file));
return true;
}
TFile* currentFile(strategy_->currentFile_);
bool isNew(file != currentFile);
if (!isNew) {
//could still have a new TFile which just happens to share the same memory address as the previous file
//will assume that if the Event tree's address and UUID are the same as before then we do not have
// to treat this like a new file
TTree* eventTreeTemp = dynamic_cast<TTree*>(currentFile->Get(edm::poolNames::eventTreeName().c_str()));
isNew = eventTreeTemp != strategy_->eventTree_ || strategy_->fileUUID_ != currentFile->GetUUID();
}
if (isNew) {
int fileVersion = getFileVersion(file);
if (fileVersion != strategy_->fileVersion_) {
strategy_ = newStrategy(file, fileVersion);
} else {
strategy_->updateFile(file);
}
}
return isNew;
}
edm::ProductDescription const& BranchMapReader::productToBranch(edm::ProductID const& pid) {
return strategy_->productToBranch(pid);
}
std::vector<edm::ProductDescription> const& BranchMapReader::getProductDescriptions() {
return strategy_->getProductDescriptions();
}
std::unique_ptr<internal::BMRStrategy> BranchMapReader::newStrategy(TFile* file, int fileVersion) {
std::unique_ptr<internal::BMRStrategy> s;
if (fileVersion >= 17) {
s = std::make_unique<internal::BranchMapReaderStrategyV17>(file, fileVersion);
} else if (fileVersion >= 11) {
s = std::make_unique<internal::BranchMapReaderStrategyV11>(file, fileVersion);
} else if (fileVersion >= 8) {
s = std::make_unique<internal::BranchMapReaderStrategyV8>(file, fileVersion);
} else if (fileVersion >= 7) {
s = std::make_unique<internal::BranchMapReaderStrategyV7>(file, fileVersion);
} else {
s = std::make_unique<internal::BranchMapReaderStrategyV1>(file, fileVersion);
}
return s;
}
} // namespace fwlite
|