/
ThrowingSource.cc
140 lines (119 loc) · 4.97 KB
/
ThrowingSource.cc
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
#include "FWCore/Framework/interface/FileBlock.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EventPrincipal.h"
#include "FWCore/Framework/interface/InputSourceMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Sources/interface/ProducerSourceBase.h"
#include "FWCore/Utilities/interface/Exception.h"
namespace edm {
class ThrowingSource : public ProducerSourceBase {
public:
explicit ThrowingSource(ParameterSet const&, InputSourceDescription const&);
~ThrowingSource();
virtual void beginJob();
virtual void endJob();
virtual void beginLuminosityBlock(edm::LuminosityBlock&);
virtual void endLuminosityBlock(edm::LuminosityBlock&);
virtual void beginRun(edm::Run&);
virtual void endRun(edm::Run&);
virtual std::unique_ptr<edm::FileBlock> readFile_();
virtual void closeFile_();
virtual std::shared_ptr<edm::RunAuxiliary> readRunAuxiliary_();
virtual std::shared_ptr<edm::LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
virtual void readEvent_(edm::EventPrincipal&);
private:
enum {
kDoNotThrow = 0,
kConstructor = 1,
kBeginJob = 2,
kBeginRun = 3,
kBeginLumi = 4,
kEndLumi = 5,
kEndRun = 6,
kEndJob = 7,
kGetNextItemType = 8,
kReadEvent = 9,
kReadLuminosityBlockAuxiliary = 10,
kReadRunAuxiliary = 11,
kReadFile = 12,
kCloseFile = 13,
kDestructor = 14
};
virtual bool setRunAndEventInfo(EventID& id, TimeValue_t& time, edm::EventAuxiliary::ExperimentType& eType);
virtual void produce(Event &);
// To test exception throws from sources
int whenToThrow_;
};
ThrowingSource::ThrowingSource(ParameterSet const& pset,
InputSourceDescription const& desc) :
ProducerSourceBase(pset, desc, false), whenToThrow_(pset.getUntrackedParameter<int>("whenToThrow", kDoNotThrow)) {
if (whenToThrow_ == kConstructor) throw cms::Exception("TestThrow") << "ThrowingSource constructor";
}
ThrowingSource::~ThrowingSource() {
if (whenToThrow_ == kDestructor) throw cms::Exception("TestThrow") << "ThrowingSource destructor";
}
bool
ThrowingSource::setRunAndEventInfo(EventID&, TimeValue_t&, edm::EventAuxiliary::ExperimentType&) {
return true;
}
void
ThrowingSource::produce(edm::Event&) {
}
void
ThrowingSource::beginJob() {
if (whenToThrow_ == kBeginJob) throw cms::Exception("TestThrow") << "ThrowingSource::beginJob";
}
void
ThrowingSource::endJob() {
if (whenToThrow_ == kEndJob) throw cms::Exception("TestThrow") << "ThrowingSource::endJob";
}
void
ThrowingSource::beginLuminosityBlock(LuminosityBlock& lb) {
if (whenToThrow_ == kBeginLumi) throw cms::Exception("TestThrow") << "ThrowingSource::beginLuminosityBlock";
}
void
ThrowingSource::endLuminosityBlock(LuminosityBlock& lb) {
if (whenToThrow_ == kEndLumi) throw cms::Exception("TestThrow") << "ThrowingSource::endLuminosityBlock";
}
void
ThrowingSource::beginRun(Run& run) {
if (whenToThrow_ == kBeginRun) throw cms::Exception("TestThrow") << "ThrowingSource::beginRun";
}
void
ThrowingSource::endRun(Run& run) {
if (whenToThrow_ == kEndRun) throw cms::Exception("TestThrow") << "ThrowingSource::endRun";
}
std::unique_ptr<FileBlock>
ThrowingSource::readFile_() {
if (whenToThrow_ == kReadFile) throw cms::Exception("TestThrow") << "ThrowingSource::readFile_";
return std::unique_ptr<FileBlock>(new FileBlock);
}
void
ThrowingSource::closeFile_() {
if (whenToThrow_ == kCloseFile) throw cms::Exception("TestThrow") << "ThrowingSource::closeFile_";
}
std::shared_ptr<RunAuxiliary>
ThrowingSource::readRunAuxiliary_() {
if (whenToThrow_ == kReadRunAuxiliary) throw cms::Exception("TestThrow") << "ThrowingSource::readRunAuxiliary_";
Timestamp ts = Timestamp(presentTime());
resetNewRun();
return std::make_shared<RunAuxiliary>(eventID().run(), ts, Timestamp::invalidTimestamp());
}
std::shared_ptr<LuminosityBlockAuxiliary>
ThrowingSource::readLuminosityBlockAuxiliary_() {
if (whenToThrow_ == kReadLuminosityBlockAuxiliary) throw cms::Exception("TestThrow") << "ThrowingSource::readLuminosityBlockAuxiliary_";
if (processingMode() == Runs) return std::shared_ptr<LuminosityBlockAuxiliary>();
Timestamp ts = Timestamp(presentTime());
resetNewLumi();
return std::make_shared<LuminosityBlockAuxiliary>(eventID().run(), eventID().luminosityBlock(), ts, Timestamp::invalidTimestamp());
}
void
ThrowingSource::readEvent_(EventPrincipal& eventPrincipal) {
if (whenToThrow_ == kReadEvent) throw cms::Exception("TestThrow") << "ThrowingSource::readEvent_";
assert(eventCached() || processingMode() != RunsLumisAndEvents);
EventAuxiliary aux(eventID(), processGUID(), Timestamp(presentTime()), false, EventAuxiliary::Undefined);
eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry());
}
}
using edm::ThrowingSource;
DEFINE_FWK_INPUT_SOURCE(ThrowingSource);