CMS 3D CMS Logo

scaleGains.cc
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 
15 
16 class scaleGains : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
17 public:
18  explicit scaleGains(const edm::ParameterSet&);
19  ~scaleGains() override;
20 
21 private:
22  void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
23  void analyze(edm::Event const&, edm::EventSetup const&) override;
24  void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
26  double scale;
28 };
29 
31  fileIn = iConfig.getUntrackedParameter<std::string>("FileIn");
32  fileOut = iConfig.getUntrackedParameter<std::string>("FileOut");
33  scale = iConfig.getUntrackedParameter<double>("Scale");
34  tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
35 }
36 
38 
39 void scaleGains::analyze(edm::Event const&, edm::EventSetup const& iSetup) {
40  HcalTopology topo = iSetup.getData(tok_htopo_);
41 
42  HcalGains gainsIn(&topo);
43  ;
44  std::ifstream inStream(fileIn.c_str());
45  HcalDbASCIIIO::getObject(inStream, &gainsIn);
46  inStream.close();
47 
48  HcalGains gainsOut(&topo);
49  ;
50  std::vector<DetId> channels = gainsIn.getAllChannels();
51  for (unsigned i = 0; i < channels.size(); i++) {
52  DetId id = channels[i];
53  HcalGain item(id,
54  gainsIn.getValues(id)->getValue(0) * scale,
55  gainsIn.getValues(id)->getValue(1) * scale,
56  gainsIn.getValues(id)->getValue(2) * scale,
57  gainsIn.getValues(id)->getValue(3) * scale);
58  gainsOut.addValues(item);
59  }
60 
61  std::ofstream outStream(fileOut.c_str());
62  HcalDbASCIIIO::dumpObject(outStream, gainsOut);
63  outStream.close();
64 }
65 
66 //define this as a plug-in
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: scaleGains.cc:24
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: scaleGains.cc:39
const Item * getValues(DetId fId, bool throwOnFail=true) const
T getUntrackedParameter(std::string const &, T const &) const
std::string fileOut
Definition: scaleGains.cc:25
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > tok_htopo_
Definition: scaleGains.cc:27
std::vector< DetId > getAllChannels() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string fileIn
Definition: scaleGains.cc:25
scaleGains(const edm::ParameterSet &)
Definition: scaleGains.cc:30
double scale
Definition: scaleGains.cc:26
float getValue(int fCapId) const
get value for capId = 0..3
Definition: HcalGain.h:21
Definition: DetId.h:17
~scaleGains() override
Definition: scaleGains.cc:37
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: scaleGains.cc:22
bool getObject(std::istream &fInput, HcalPedestals *fObject)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
bool addValues(const Item &myItem)
Definition: Run.h:45