File indexing completed on 2024-04-06 12:01:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
0013 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
0014 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0021 #include "FWCore/Utilities/interface/ESGetToken.h"
0022 #include "FWCore/Utilities/interface/ESInputTag.h"
0023 #include "FWCore/Utilities/interface/StreamID.h"
0024 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0025
0026 #include <cmath>
0027 #include <iostream>
0028
0029 namespace edmtest {
0030
0031 constexpr unsigned nLumisToTest = 200;
0032
0033 class TestConcurrentIOVsCondCore : public edm::global::EDAnalyzer<> {
0034 public:
0035 explicit TestConcurrentIOVsCondCore(edm::ParameterSet const&);
0036
0037 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0038
0039 void endJob() override;
0040
0041 void busyWait(char const* msg, unsigned int iterations) const;
0042
0043 static void fillDescriptions(edm::ConfigurationDescriptions&);
0044
0045 private:
0046 class BeamSpotTestObject {
0047 public:
0048 unsigned int lumi_;
0049 double x_ = 0;
0050 double y_ = 0;
0051 double z_ = 0;
0052 unsigned int start_ = 0;
0053 unsigned int end_ = 0;
0054 };
0055
0056 const double pi_;
0057
0058 edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> const esTokenBeamSpotObjects_;
0059
0060
0061
0062
0063
0064 CMS_THREAD_SAFE mutable std::vector<BeamSpotTestObject> testObjects_;
0065 };
0066
0067 TestConcurrentIOVsCondCore::TestConcurrentIOVsCondCore(edm::ParameterSet const&)
0068 : pi_(std::acos(-1)),
0069 esTokenBeamSpotObjects_{esConsumes<BeamSpotObjects, BeamSpotObjectsRcd>(edm::ESInputTag("", ""))},
0070 testObjects_(nLumisToTest) {}
0071
0072 void TestConcurrentIOVsCondCore::analyze(edm::StreamID,
0073 edm::Event const& event,
0074 edm::EventSetup const& eventSetup) const {
0075 unsigned int lumi = event.eventAuxiliary().luminosityBlock();
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 if (lumi == 1) {
0086 busyWait("TestConcurrentIOVsCondCore::analyze", 30 * 200 * 1000);
0087 } else if (lumi == 5) {
0088 busyWait("TestConcurrentIOVsCondCore::analyze", 29 * 200 * 1000);
0089 } else if (lumi == 6) {
0090 busyWait("TestConcurrentIOVsCondCore::analyze", 28 * 200 * 1000);
0091 } else if (lumi == 7) {
0092 busyWait("TestConcurrentIOVsCondCore::analyze", 27 * 200 * 1000);
0093 } else if (lumi == 11) {
0094 busyWait("TestConcurrentIOVsCondCore::analyze", 26 * 200 * 1000);
0095 } else if (lumi == 15) {
0096 busyWait("TestConcurrentIOVsCondCore::analyze", 25 * 200 * 1000);
0097 } else if (lumi == 16) {
0098 busyWait("TestConcurrentIOVsCondCore::analyze", 24 * 200 * 1000);
0099 } else if (lumi == 20) {
0100 busyWait("TestConcurrentIOVsCondCore::analyze", 23 * 200 * 1000);
0101 } else if (lumi == 21) {
0102 busyWait("TestConcurrentIOVsCondCore::analyze", 22 * 200 * 1000);
0103 } else if (lumi == 25) {
0104 busyWait("TestConcurrentIOVsCondCore::analyze", 21 * 200 * 1000);
0105 } else if (lumi == 30) {
0106 busyWait("TestConcurrentIOVsCondCore::analyze", 20 * 200 * 1000);
0107 } else if (lumi == 35) {
0108 busyWait("TestConcurrentIOVsCondCore::analyze", 19 * 200 * 1000);
0109 } else if (lumi == 40) {
0110 busyWait("TestConcurrentIOVsCondCore::analyze", 18 * 200 * 1000);
0111 } else if (lumi == 46) {
0112 busyWait("TestConcurrentIOVsCondCore::analyze", 17 * 200 * 1000);
0113 } else if (lumi == 48) {
0114 busyWait("TestConcurrentIOVsCondCore::analyze", 16 * 200 * 1000);
0115 } else if (lumi == 49) {
0116 busyWait("TestConcurrentIOVsCondCore::analyze", 15 * 200 * 1000);
0117 } else if (lumi == 50) {
0118 busyWait("TestConcurrentIOVsCondCore::analyze", 14 * 200 * 1000);
0119 } else if (lumi == 79) {
0120 busyWait("TestConcurrentIOVsCondCore::analyze", 13 * 200 * 1000);
0121 } else if (lumi == 90) {
0122 busyWait("TestConcurrentIOVsCondCore::analyze", 12 * 200 * 1000);
0123 } else if (lumi == 94) {
0124 busyWait("TestConcurrentIOVsCondCore::analyze", 11 * 200 * 1000);
0125 } else if (lumi == 99) {
0126 busyWait("TestConcurrentIOVsCondCore::analyze", 10 * 200 * 1000);
0127 } else if (lumi == 104) {
0128 busyWait("TestConcurrentIOVsCondCore::analyze", 9 * 200 * 1000);
0129 } else if (lumi == 113) {
0130 busyWait("TestConcurrentIOVsCondCore::analyze", 8 * 200 * 1000);
0131 } else if (lumi == 114) {
0132 busyWait("TestConcurrentIOVsCondCore::analyze", 7 * 200 * 1000);
0133 } else if (lumi == 118) {
0134 busyWait("TestConcurrentIOVsCondCore::analyze", 6 * 200 * 1000);
0135 } else if (lumi == 123) {
0136 busyWait("TestConcurrentIOVsCondCore::analyze", 5 * 200 * 1000);
0137 } else if (lumi == 128) {
0138 busyWait("TestConcurrentIOVsCondCore::analyze", 4 * 200 * 1000);
0139 } else if (lumi == 130) {
0140 busyWait("TestConcurrentIOVsCondCore::analyze", 3 * 200 * 1000);
0141 } else if (lumi == 132) {
0142 busyWait("TestConcurrentIOVsCondCore::analyze", 10 * 200 * 1000);
0143 } else if (lumi == 133) {
0144 busyWait("TestConcurrentIOVsCondCore::analyze", 9 * 200 * 1000);
0145 } else if (lumi == 134) {
0146 busyWait("TestConcurrentIOVsCondCore::analyze", 8 * 200 * 1000);
0147 } else if (lumi == 161) {
0148 busyWait("TestConcurrentIOVsCondCore::analyze", 7 * 200 * 1000);
0149 } else if (lumi == 165) {
0150 busyWait("TestConcurrentIOVsCondCore::analyze", 6 * 200 * 1000);
0151 } else if (lumi == 170) {
0152 busyWait("TestConcurrentIOVsCondCore::analyze", 5 * 200 * 1000);
0153 }
0154
0155 edm::ESHandle<BeamSpotObjects> beamSpotObjects = eventSetup.getHandle(esTokenBeamSpotObjects_);
0156 BeamSpotObjectsRcd beamSpotObjectsRcd = eventSetup.get<BeamSpotObjectsRcd>();
0157 edm::ValidityInterval iov = beamSpotObjectsRcd.validityInterval();
0158
0159 if (lumi < nLumisToTest) {
0160 BeamSpotTestObject& testObject = testObjects_[lumi];
0161 testObject.lumi_ = lumi;
0162 testObject.x_ = beamSpotObjects->x();
0163 testObject.y_ = beamSpotObjects->y();
0164 testObject.z_ = beamSpotObjects->z();
0165 testObject.start_ = iov.first().luminosityBlockNumber();
0166 testObject.end_ = iov.last().luminosityBlockNumber();
0167 }
0168 edm::LogAbsolute("TestConcurrentIOVsCondCore::busyWait")
0169 << "TestConcurrentIOVsCondCore::analyze finishing lumi " << lumi << std::endl;
0170 }
0171
0172 void TestConcurrentIOVsCondCore::endJob() {
0173
0174
0175
0176 for (auto const& object : testObjects_) {
0177 edm::LogPrint("TestConcurrentIOVsCondCore")
0178 << "TestConcurrentIOVsCondCore: lumi = " << object.lumi_ << " position: (" << object.x_ << ", " << object.y_
0179 << ", " << object.z_ << ") iov = " << object.start_ << ":" << object.end_;
0180 }
0181 }
0182
0183 void TestConcurrentIOVsCondCore::busyWait(char const* msg, unsigned int iterations) const {
0184
0185
0186 edm::LogAbsolute("TestConcurrentIOVsCondCore::busyWait") << "Start TestConcurrentIOVsCondCore::busyWait " << msg;
0187 double sum = 0.;
0188 const double stepSize = pi_ / iterations;
0189 for (unsigned int i = 0; i < iterations; ++i) {
0190 sum += stepSize * cos(i * stepSize);
0191 }
0192 edm::LogAbsolute("TestConcurrentIOVsCondCore::busyWait")
0193 << "Stop TestConcurrentIOVsCondCore::busyWait " << msg << " " << sum;
0194 }
0195
0196 void TestConcurrentIOVsCondCore::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0197 edm::ParameterSetDescription desc;
0198 descriptions.addDefault(desc);
0199 }
0200
0201 DEFINE_FWK_MODULE(TestConcurrentIOVsCondCore);
0202 }