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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
|
// -*- C++ -*-
//
// Package: Subsystem/Package
// Class : TestProcessor
//
// Implementation:
// [Notes on implementation]
//
// Original Author: Chris Jones
// Created: Mon, 30 Apr 2018 18:51:08 GMT
//
// system include files
// user include files
#include "FWCore/TestProcessor/interface/TestProcessor.h"
#include "FWCore/TestProcessor/interface/EventSetupTestHelper.h"
#include "FWCore/Common/interface/ProcessBlockHelper.h"
#include "FWCore/Concurrency/interface/FinalWaitingTask.h"
#include "FWCore/Concurrency/interface/WaitingTaskHolder.h"
#include "FWCore/Framework/interface/ScheduleItems.h"
#include "FWCore/Framework/interface/EventPrincipal.h"
#include "FWCore/Framework/interface/EventSetupProvider.h"
#include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
#include "FWCore/Framework/interface/ProcessBlockPrincipal.h"
#include "FWCore/Framework/interface/ExceptionActions.h"
#include "FWCore/Framework/interface/HistoryAppender.h"
#include "FWCore/Framework/interface/RunPrincipal.h"
#include "FWCore/Framework/interface/ESRecordsToProductResolverIndices.h"
#include "FWCore/Framework/interface/EventSetupsController.h"
#include "FWCore/Framework/interface/TransitionInfoTypes.h"
#include "FWCore/Framework/interface/ProductPutterBase.h"
#include "FWCore/Framework/interface/DelayedReader.h"
#include "FWCore/Framework/interface/ensureAvailableAccelerators.h"
#include "FWCore/Framework/interface/makeModuleTypeResolverMaker.h"
#include "FWCore/Framework/interface/FileBlock.h"
#include "FWCore/Framework/interface/MergeableRunProductMetadata.h"
#include "FWCore/Framework/interface/ProductResolversFactory.h"
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
#include "FWCore/ServiceRegistry/interface/SystemBounds.h"
#include "FWCore/ParameterSetReader/interface/ProcessDescImpl.h"
#include "FWCore/ParameterSet/interface/ProcessDesc.h"
#include "FWCore/ParameterSet/interface/validateTopLevelParameterSets.h"
#include "FWCore/Utilities/interface/ExceptionCollector.h"
#include "oneTimeInitialization.h"
#include <mutex>
#define xstr(s) str(s)
#define str(s) #s
namespace edm {
namespace test {
//
// constructors and destructor
//
TestProcessor::TestProcessor(Config const& iConfig, ServiceToken iToken)
: globalControl_(oneapi::tbb::global_control::max_allowed_parallelism, 1),
arena_(1),
historyAppender_(std::make_unique<HistoryAppender>()),
moduleRegistry_(std::make_shared<ModuleRegistry>()) {
//Setup various singletons
(void)testprocessor::oneTimeInitialization();
ProcessDescImpl desc(iConfig.pythonConfiguration(), false);
auto psetPtr = desc.parameterSet();
moduleTypeResolverMaker_ = makeModuleTypeResolverMaker(*psetPtr);
espController_ = std::make_unique<eventsetup::EventSetupsController>(moduleTypeResolverMaker_.get());
validateTopLevelParameterSets(psetPtr.get());
ensureAvailableAccelerators(*psetPtr);
labelOfTestModule_ = psetPtr->getParameter<std::string>("@moduleToTest");
auto procDesc = desc.processDesc();
// Now do general initialization
ScheduleItems items;
//initialize the services
auto& serviceSets = procDesc->getServicesPSets();
ServiceToken token = items.initServices(serviceSets, *psetPtr, iToken, serviceregistry::kOverlapIsError, true);
serviceToken_ = items.addTNS(*psetPtr, token);
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
// intialize miscellaneous items
std::shared_ptr<CommonParams> common(items.initMisc(*psetPtr));
// intialize the event setup provider
esp_ = espController_->makeProvider(*psetPtr, items.actReg_.get());
auto nThreads = 1U;
auto nStreams = 1U;
auto nConcurrentLumis = 1U;
auto nConcurrentRuns = 1U;
preallocations_ = PreallocationConfiguration{nThreads, nStreams, nConcurrentLumis, nConcurrentRuns};
if (not iConfig.esProduceEntries().empty()) {
esHelper_ = std::make_unique<EventSetupTestHelper>(iConfig.esProduceEntries());
esp_->add(std::dynamic_pointer_cast<eventsetup::ESProductResolverProvider>(esHelper_));
esp_->add(std::dynamic_pointer_cast<EventSetupRecordIntervalFinder>(esHelper_));
}
auto tempReg = items.preg();
processConfiguration_ = items.processConfiguration();
edm::ParameterSet emptyPSet;
emptyPSet.registerIt();
auto psetid = emptyPSet.id();
for (auto const& p : iConfig.extraProcesses()) {
processHistory_.emplace_back(p, psetid, xstr(PROJECT_VERSION), HardwareResourcesDescription());
processHistoryRegistry_.registerProcessHistory(processHistory_);
}
//setup the products we will be adding to the event
for (auto const& produce : iConfig.produceEntries()) {
auto processName = produce.processName_;
if (processName.empty()) {
processName = processConfiguration_->processName();
}
edm::TypeWithDict twd(produce.type_.typeInfo());
edm::ProductDescription product(edm::InEvent,
produce.moduleLabel_,
processName,
twd.userClassName(),
twd.friendlyClassName(),
produce.instanceLabel_,
twd,
true //force this to come from 'source'
);
product.init();
dataProducts_.emplace_back(product, std::unique_ptr<WrapperBase>());
tempReg->addProduct(product);
}
processBlockHelper_ = std::make_shared<ProcessBlockHelper>();
schedule_ = items.initSchedule(
*psetPtr, preallocations_, &processContext_, moduleTypeResolverMaker_.get(), *processBlockHelper_);
// set the data members
act_table_ = std::move(items.act_table_);
actReg_ = items.actReg_;
branchIDListHelper_ = items.branchIDListHelper();
thinnedAssociationsHelper_ = items.thinnedAssociationsHelper();
processContext_.setProcessConfiguration(processConfiguration_.get());
principalCache_.setNumberOfConcurrentPrincipals(preallocations_);
tempReg->setFrozen();
preg_ = std::make_shared<edm::ProductRegistry>(tempReg->moveTo());
mergeableRunProductProcesses_.setProcessesWithMergeableRunProducts(*preg_);
for (unsigned int index = 0; index < preallocations_.numberOfStreams(); ++index) {
// Reusable event principal
auto ep = std::make_shared<EventPrincipal>(preg_,
edm::productResolversFactory::makePrimary,
branchIDListHelper_,
thinnedAssociationsHelper_,
*processConfiguration_,
historyAppender_.get(),
index);
principalCache_.insert(std::move(ep));
}
for (unsigned int index = 0; index < preallocations_.numberOfRuns(); ++index) {
auto rp = std::make_unique<RunPrincipal>(preg_,
edm::productResolversFactory::makePrimary,
*processConfiguration_,
historyAppender_.get(),
index,
&mergeableRunProductProcesses_);
principalCache_.insert(std::move(rp));
}
for (unsigned int index = 0; index < preallocations_.numberOfLuminosityBlocks(); ++index) {
auto lp = std::make_unique<LuminosityBlockPrincipal>(
preg_, edm::productResolversFactory::makePrimary, *processConfiguration_, historyAppender_.get(), index);
principalCache_.insert(std::move(lp));
}
{
auto pb = std::make_unique<ProcessBlockPrincipal>(
preg_, edm::productResolversFactory::makePrimary, *processConfiguration_);
principalCache_.insert(std::move(pb));
}
}
TestProcessor::~TestProcessor() noexcept(false) { teardownProcessing(); }
//
// member functions
//
void TestProcessor::put(unsigned int index, std::unique_ptr<WrapperBase> iWrapper) {
if (index >= dataProducts_.size()) {
throw cms::Exception("LogicError") << "Products must be declared to the TestProcessor::Config object\n"
"with a call to the function \'produces\' BEFORE passing the\n"
"TestProcessor::Config object to the TestProcessor constructor";
}
dataProducts_[index].second = std::move(iWrapper);
}
edm::test::Event TestProcessor::testImpl() {
bool result = arena_.execute([this]() {
setupProcessing();
event();
return schedule_->totalEventsPassed() > 0;
});
schedule_->clearCounters();
if (esHelper_) {
//We want each test to have its own ES data products
esHelper_->resetAllResolvers();
}
return edm::test::Event(
principalCache_.eventPrincipal(0), labelOfTestModule_, processConfiguration_->processName(), result);
}
edm::test::LuminosityBlock TestProcessor::testBeginLuminosityBlockImpl(edm::LuminosityBlockNumber_t iNum) {
arena_.execute([this, iNum]() {
if (not beginJobCalled_) {
beginJob();
}
if (not respondToOpenInputFileCalled_) {
respondToOpenInputFile();
}
if (not beginProcessBlockCalled_) {
beginProcessBlock();
}
if (not openOutputFilesCalled_) {
openOutputFiles();
}
if (not beginRunCalled_) {
beginRun();
}
if (beginLumiCalled_) {
endLuminosityBlock();
assert(lumiNumber_ != iNum);
}
lumiNumber_ = iNum;
beginLuminosityBlock();
});
if (esHelper_) {
//We want each test to have its own ES data products
esHelper_->resetAllResolvers();
}
return edm::test::LuminosityBlock(lumiPrincipal_, labelOfTestModule_, processConfiguration_->processName());
}
edm::test::LuminosityBlock TestProcessor::testEndLuminosityBlockImpl() {
//using a return value from arena_.execute lead to double delete of shared_ptr
// based on valgrind output when exception occurred. Use lambda capture instead.
std::shared_ptr<edm::LuminosityBlockPrincipal> lumi;
arena_.execute([this, &lumi]() {
if (not beginJobCalled_) {
beginJob();
}
if (not respondToOpenInputFileCalled_) {
respondToOpenInputFile();
}
if (not beginProcessBlockCalled_) {
beginProcessBlock();
}
if (not openOutputFilesCalled_) {
openOutputFiles();
}
if (not beginRunCalled_) {
beginRun();
}
if (not beginLumiCalled_) {
beginLuminosityBlock();
}
lumi = endLuminosityBlock();
});
if (esHelper_) {
//We want each test to have its own ES data products
esHelper_->resetAllResolvers();
}
return edm::test::LuminosityBlock(std::move(lumi), labelOfTestModule_, processConfiguration_->processName());
}
edm::test::Run TestProcessor::testBeginRunImpl(edm::RunNumber_t iNum) {
arena_.execute([this, iNum]() {
if (not beginJobCalled_) {
beginJob();
}
if (not respondToOpenInputFileCalled_) {
respondToOpenInputFile();
}
if (not beginProcessBlockCalled_) {
beginProcessBlock();
}
if (not openOutputFilesCalled_) {
openOutputFiles();
}
if (beginRunCalled_) {
assert(runNumber_ != iNum);
endRun();
}
runNumber_ = iNum;
beginRun();
});
if (esHelper_) {
//We want each test to have its own ES data products
esHelper_->resetAllResolvers();
}
return edm::test::Run(runPrincipal_, labelOfTestModule_, processConfiguration_->processName());
}
edm::test::Run TestProcessor::testEndRunImpl() {
//using a return value from arena_.execute lead to double delete of shared_ptr
// based on valgrind output when exception occurred. Use lambda capture instead.
std::shared_ptr<edm::RunPrincipal> rp;
arena_.execute([this, &rp]() {
if (not beginJobCalled_) {
beginJob();
}
if (not respondToOpenInputFileCalled_) {
respondToOpenInputFile();
}
if (not beginProcessBlockCalled_) {
beginProcessBlock();
}
if (not openOutputFilesCalled_) {
openOutputFiles();
}
if (not beginRunCalled_) {
beginRun();
}
rp = endRun();
});
if (esHelper_) {
//We want each test to have its own ES data products
esHelper_->resetAllResolvers();
}
return edm::test::Run(rp, labelOfTestModule_, processConfiguration_->processName());
}
edm::test::ProcessBlock TestProcessor::testBeginProcessBlockImpl() {
arena_.execute([this]() {
if (not beginJobCalled_) {
beginJob();
}
beginProcessBlock();
});
return edm::test::ProcessBlock(
&principalCache_.processBlockPrincipal(), labelOfTestModule_, processConfiguration_->processName());
}
edm::test::ProcessBlock TestProcessor::testEndProcessBlockImpl() {
auto pbp = arena_.execute([this]() {
if (not beginJobCalled_) {
beginJob();
}
if (not beginProcessBlockCalled_) {
beginProcessBlock();
}
return endProcessBlock();
});
return edm::test::ProcessBlock(pbp, labelOfTestModule_, processConfiguration_->processName());
}
void TestProcessor::setupProcessing() {
if (not beginJobCalled_) {
beginJob();
}
if (not respondToOpenInputFileCalled_) {
respondToOpenInputFile();
}
if (not beginProcessBlockCalled_) {
beginProcessBlock();
}
if (not openOutputFilesCalled_) {
openOutputFiles();
}
if (not beginRunCalled_) {
beginRun();
}
if (not beginLumiCalled_) {
beginLuminosityBlock();
}
}
void TestProcessor::teardownProcessing() {
arena_.execute([this]() {
if (beginLumiCalled_) {
endLuminosityBlock();
beginLumiCalled_ = false;
}
if (beginRunCalled_) {
endRun();
beginRunCalled_ = false;
}
if (respondToOpenInputFileCalled_) {
respondToCloseInputFile();
}
if (beginProcessBlockCalled_) {
endProcessBlock();
beginProcessBlockCalled_ = false;
}
if (openOutputFilesCalled_) {
closeOutputFiles();
openOutputFilesCalled_ = false;
}
if (beginJobCalled_) {
endJob();
}
edm::FinalWaitingTask task{taskGroup_};
espController_->endIOVsAsync(edm::WaitingTaskHolder(taskGroup_, &task));
task.waitNoThrow();
});
}
void TestProcessor::beginJob() {
ServiceRegistry::Operate operate(serviceToken_);
service::SystemBounds bounds(preallocations_.numberOfStreams(),
preallocations_.numberOfLuminosityBlocks(),
preallocations_.numberOfRuns(),
preallocations_.numberOfThreads());
actReg_->preallocateSignal_(bounds);
schedule_->convertCurrentProcessAlias(processConfiguration_->processName());
espController_->finishConfiguration();
actReg_->eventSetupConfigurationSignal_(esp_->recordsToResolverIndices(), processContext_);
schedule_->beginJob(*preg_, esp_->recordsToResolverIndices(), *processBlockHelper_, processContext_);
for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) {
schedule_->beginStream(i);
}
beginJobCalled_ = true;
}
void TestProcessor::beginProcessBlock() {
ProcessBlockPrincipal& processBlockPrincipal = principalCache_.processBlockPrincipal();
processBlockPrincipal.fillProcessBlockPrincipal(processConfiguration_->processName());
ProcessBlockTransitionInfo transitionInfo(processBlockPrincipal);
using Traits = OccurrenceTraits<ProcessBlockPrincipal, BranchActionGlobalBegin>;
processGlobalTransition<Traits>(transitionInfo);
beginProcessBlockCalled_ = true;
}
void TestProcessor::openOutputFiles() {
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
edm::FileBlock fb;
schedule_->openOutputFiles(fb);
openOutputFilesCalled_ = true;
}
void TestProcessor::closeOutputFiles() {
if (openOutputFilesCalled_) {
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
schedule_->closeOutputFiles();
openOutputFilesCalled_ = false;
}
}
void TestProcessor::respondToOpenInputFile() {
respondToOpenInputFileCalled_ = true;
edm::FileBlock fb;
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
schedule_->respondToOpenInputFile(fb);
}
void TestProcessor::respondToCloseInputFile() {
if (respondToOpenInputFileCalled_) {
edm::FileBlock fb;
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
schedule_->respondToCloseInputFile(fb);
respondToOpenInputFileCalled_ = false;
}
}
void TestProcessor::beginRun() {
runPrincipal_ = principalCache_.getAvailableRunPrincipalPtr();
runPrincipal_->clearPrincipal();
assert(runPrincipal_);
edm::RunAuxiliary aux(runNumber_, Timestamp(), Timestamp());
aux.setProcessHistoryID(processHistory_.id());
runPrincipal_->setAux(aux);
runPrincipal_->fillRunPrincipal(processHistoryRegistry_);
IOVSyncValue ts(EventID(runPrincipal_->run(), 0, 0), runPrincipal_->beginTime());
eventsetup::synchronousEventSetupForInstance(ts, taskGroup_, *espController_);
auto const& es = esp_->eventSetupImpl();
RunTransitionInfo transitionInfo(*runPrincipal_, es, nullptr);
{
using Traits = OccurrenceTraits<RunPrincipal, BranchActionGlobalBegin>;
processGlobalTransition<Traits>(transitionInfo);
}
{
using Traits = OccurrenceTraits<RunPrincipal, BranchActionStreamBegin>;
processTransitionForAllStreams<Traits>(transitionInfo);
}
beginRunCalled_ = true;
}
void TestProcessor::beginLuminosityBlock() {
LuminosityBlockAuxiliary aux(runNumber_, lumiNumber_, Timestamp(), Timestamp());
aux.setProcessHistoryID(processHistory_.id());
lumiPrincipal_ = principalCache_.getAvailableLumiPrincipalPtr();
lumiPrincipal_->clearPrincipal();
assert(lumiPrincipal_);
lumiPrincipal_->setAux(aux);
lumiPrincipal_->setRunPrincipal(runPrincipal_);
lumiPrincipal_->fillLuminosityBlockPrincipal(&processHistory_);
IOVSyncValue ts(EventID(runNumber_, lumiNumber_, eventNumber_), lumiPrincipal_->beginTime());
eventsetup::synchronousEventSetupForInstance(ts, taskGroup_, *espController_);
auto const& es = esp_->eventSetupImpl();
LumiTransitionInfo transitionInfo(*lumiPrincipal_, es, nullptr);
{
using Traits = OccurrenceTraits<LuminosityBlockPrincipal, BranchActionGlobalBegin>;
processGlobalTransition<Traits>(transitionInfo);
}
{
using Traits = OccurrenceTraits<LuminosityBlockPrincipal, BranchActionStreamBegin>;
processTransitionForAllStreams<Traits>(transitionInfo);
}
beginLumiCalled_ = true;
}
void TestProcessor::event() {
auto pep = &(principalCache_.eventPrincipal(0));
//this resets the EventPrincipal (if it had been used before)
pep->clearEventPrincipal();
edm::EventAuxiliary aux(EventID(runNumber_, lumiNumber_, eventNumber_), "", Timestamp(), false);
aux.setProcessHistoryID(processHistory_.id());
pep->fillEventPrincipal(aux, nullptr, nullptr);
assert(lumiPrincipal_.get() != nullptr);
pep->setLuminosityBlockPrincipal(lumiPrincipal_.get());
for (auto& p : dataProducts_) {
if (p.second) {
pep->put(p.first, std::move(p.second), ProductProvenance(p.first.branchID()));
} else {
//The data product was not set so we need to
// tell the ProductResolver not to wait
auto r = pep->getProductResolver(p.first.branchID());
dynamic_cast<ProductPutterBase const*>(r)->putProduct(std::unique_ptr<WrapperBase>());
}
}
ServiceRegistry::Operate operate(serviceToken_);
FinalWaitingTask waitTask{taskGroup_};
EventTransitionInfo info(*pep, esp_->eventSetupImpl());
schedule_->processOneEventAsync(edm::WaitingTaskHolder(taskGroup_, &waitTask), 0, info, serviceToken_);
waitTask.wait();
++eventNumber_;
}
std::shared_ptr<LuminosityBlockPrincipal> TestProcessor::endLuminosityBlock() {
auto lumiPrincipal = lumiPrincipal_;
if (beginLumiCalled_) {
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
beginLumiCalled_ = false;
lumiPrincipal_.reset();
IOVSyncValue ts(EventID(runNumber_, lumiNumber_, eventNumber_), lumiPrincipal->endTime());
eventsetup::synchronousEventSetupForInstance(ts, taskGroup_, *espController_);
auto const& es = esp_->eventSetupImpl();
LumiTransitionInfo transitionInfo(*lumiPrincipal, es, nullptr);
{
using Traits = OccurrenceTraits<LuminosityBlockPrincipal, BranchActionStreamEnd>;
processTransitionForAllStreams<Traits>(transitionInfo);
}
{
using Traits = OccurrenceTraits<LuminosityBlockPrincipal, BranchActionGlobalEnd>;
processGlobalTransition<Traits>(transitionInfo);
}
{
FinalWaitingTask globalWaitTask{taskGroup_};
schedule_->writeLumiAsync(
WaitingTaskHolder(taskGroup_, &globalWaitTask), *lumiPrincipal, &processContext_, actReg_.get());
globalWaitTask.wait();
}
}
lumiPrincipal->setRunPrincipal(std::shared_ptr<RunPrincipal>());
return lumiPrincipal;
}
std::shared_ptr<edm::RunPrincipal> TestProcessor::endRun() {
auto runPrincipal = runPrincipal_;
runPrincipal_.reset();
if (beginRunCalled_) {
beginRunCalled_ = false;
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
IOVSyncValue ts(
EventID(runPrincipal->run(), LuminosityBlockID::maxLuminosityBlockNumber(), EventID::maxEventNumber()),
runPrincipal->endTime());
eventsetup::synchronousEventSetupForInstance(ts, taskGroup_, *espController_);
auto const& es = esp_->eventSetupImpl();
RunTransitionInfo transitionInfo(*runPrincipal, es);
{
using Traits = OccurrenceTraits<RunPrincipal, BranchActionStreamEnd>;
processTransitionForAllStreams<Traits>(transitionInfo);
}
{
using Traits = OccurrenceTraits<RunPrincipal, BranchActionGlobalEnd>;
processGlobalTransition<Traits>(transitionInfo);
}
{
FinalWaitingTask globalWaitTask{taskGroup_};
schedule_->writeRunAsync(WaitingTaskHolder(taskGroup_, &globalWaitTask),
*runPrincipal,
&processContext_,
actReg_.get(),
runPrincipal->mergeableRunProductMetadata());
globalWaitTask.wait();
}
}
return runPrincipal;
}
ProcessBlockPrincipal const* TestProcessor::endProcessBlock() {
ProcessBlockPrincipal& processBlockPrincipal = principalCache_.processBlockPrincipal();
if (beginProcessBlockCalled_) {
beginProcessBlockCalled_ = false;
ProcessBlockTransitionInfo transitionInfo(processBlockPrincipal);
using Traits = OccurrenceTraits<ProcessBlockPrincipal, BranchActionGlobalEnd>;
processGlobalTransition<Traits>(transitionInfo);
}
return &processBlockPrincipal;
}
void TestProcessor::endJob() {
if (!beginJobCalled_) {
return;
}
beginJobCalled_ = false;
// Collects exceptions, so we don't throw before all operations are performed.
ExceptionCollector c(
"Multiple exceptions were thrown while executing endJob. An exception message follows for each.\n");
std::mutex collectorMutex;
//make the services available
ServiceRegistry::Operate operate(serviceToken_);
//NOTE: this really should go elsewhere in the future
for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) {
schedule_->endStream(i, c, collectorMutex);
}
auto actReg = actReg_.get();
c.call([actReg]() { actReg->preEndJobSignal_(); });
schedule_->endJob(c);
c.call([actReg]() { actReg->postEndJobSignal_(); });
if (c.hasThrown()) {
c.rethrow();
}
}
void TestProcessor::setRunNumber(edm::RunNumber_t iRun) {
if (beginRunCalled_) {
endLuminosityBlock();
endRun();
}
runNumber_ = iRun;
}
void TestProcessor::setLuminosityBlockNumber(edm::LuminosityBlockNumber_t iLumi) {
endLuminosityBlock();
lumiNumber_ = iLumi;
}
void TestProcessor::setEventNumber(edm::EventNumber_t iEv) { eventNumber_ = iEv; }
template <typename Traits>
void TestProcessor::processTransitionForAllStreams(typename Traits::TransitionInfoType& transitionInfo) {
FinalWaitingTask finalWaitTask{taskGroup_};
{
WaitingTaskHolder holder(taskGroup_, &finalWaitTask);
// Currently numberOfStreams is always one in TestProcessor and this for loop is unnecessary...
for (unsigned int i = 0; i < preallocations_.numberOfStreams(); ++i) {
schedule_->processOneStreamAsync<Traits>(holder, i, transitionInfo, serviceToken_);
}
}
finalWaitTask.wait();
}
template <typename Traits>
void TestProcessor::processGlobalTransition(typename Traits::TransitionInfoType& transitionInfo) {
FinalWaitingTask finalWaitTask{taskGroup_};
schedule_->processOneGlobalAsync<Traits>(
WaitingTaskHolder(taskGroup_, &finalWaitTask), transitionInfo, serviceToken_);
finalWaitTask.wait();
}
} // namespace test
} // namespace edm
|