File indexing completed on 2024-04-06 12:25:16
0001
0002
0003
0004
0005
0006
0007
0008 #include <iostream>
0009 #include <fstream>
0010 #include <sstream>
0011 #include <vector>
0012 #include <string>
0013
0014
0015 #include "FWCore/Framework/interface/ESProducer.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/Framework/interface/SourceFactory.h"
0019 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "CondFormats/DataRecord/interface/HeavyIonRcd.h"
0022 #include "CondFormats/HIObjects/interface/CentralityTable.h"
0023
0024 using namespace std;
0025
0026
0027
0028
0029
0030 class HiTrivialConditionRetriever : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0031 public:
0032 HiTrivialConditionRetriever(const edm::ParameterSet&);
0033
0034 protected:
0035
0036 void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0037 const edm::IOVSyncValue&,
0038 edm::ValidityInterval&) override;
0039
0040 private:
0041 virtual std::unique_ptr<CentralityTable> produceTable(const HeavyIonRcd&);
0042 void printBin(const CentralityTable::CBin*);
0043
0044
0045
0046 int verbose_;
0047 string inputFileName_;
0048 };
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 HiTrivialConditionRetriever::HiTrivialConditionRetriever(const edm::ParameterSet& iConfig) {
0062 setWhatProduced(this, &HiTrivialConditionRetriever::produceTable);
0063 findingRecord<HeavyIonRcd>();
0064
0065
0066 verbose_ = iConfig.getUntrackedParameter<int>("verbosity", 1);
0067 inputFileName_ = iConfig.getParameter<string>("inputFile");
0068 }
0069
0070 std::unique_ptr<CentralityTable> HiTrivialConditionRetriever::produceTable(const HeavyIonRcd&) {
0071 auto CT = std::make_unique<CentralityTable>();
0072
0073
0074 ifstream in(edm::FileInPath(inputFileName_).fullPath().c_str());
0075 string line;
0076
0077 while (getline(in, line)) {
0078 if (line.empty() || line[0] == '#') {
0079 continue;
0080 }
0081 CentralityTable::CBin thisBin;
0082 istringstream ss(line);
0083 ss >> thisBin.bin_edge >> thisBin.n_part.mean >> thisBin.n_part.var >> thisBin.n_coll.mean >> thisBin.n_coll.var >>
0084 thisBin.n_hard.mean >> thisBin.n_hard.var >> thisBin.b.mean >> thisBin.b.var;
0085 CT->m_table.push_back(thisBin);
0086 }
0087
0088 return CT;
0089 }
0090
0091 void HiTrivialConditionRetriever::printBin(const CentralityTable::CBin* thisBin) {
0092 cout << "HF Cut = " << thisBin->bin_edge << endl;
0093 cout << "Npart = " << thisBin->n_part.mean << endl;
0094 cout << "sigma = " << thisBin->n_part.var << endl;
0095 cout << "Ncoll = " << thisBin->n_coll.mean << endl;
0096 cout << "sigma = " << thisBin->n_coll.var << endl;
0097 cout << "B = " << thisBin->b.mean << endl;
0098 cout << "sigma = " << thisBin->b.var << endl;
0099 cout << "__________________________________________________" << endl;
0100 }
0101
0102 void HiTrivialConditionRetriever::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& rk,
0103 const edm::IOVSyncValue& iTime,
0104 edm::ValidityInterval& oValidity) {
0105 if (verbose_ >= 1)
0106 std::cout << "HiTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name()
0107 << "\ttime: " << iTime.time().value() << std::endl;
0108
0109 oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0110 }
0111
0112
0113 DEFINE_FWK_EVENTSETUP_SOURCE(HiTrivialConditionRetriever);