CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
LumiProducerFromBrilcalc Class Reference

#include <RecoLuminosity/LumiProducer/plugins/LumiProducerFromBrilcalc.cc>

Inheritance diagram for LumiProducerFromBrilcalc:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 LumiProducerFromBrilcalc (const edm::ParameterSet &)
 
 ~LumiProducerFromBrilcalc ()=default
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

virtual void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

const bool doBunchByBunch_
 
std::map< std::pair< int, int >, std::pair< float, float > > lumiData_
 
const std::string lumiFile_
 
const bool throwIfNotFound_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: Takes a csv file with luminosity information produced by brilcalc and reads it into the event.

Implementation: [Notes on implementation]

Definition at line 42 of file LumiProducerFromBrilcalc.cc.

Constructor & Destructor Documentation

LumiProducerFromBrilcalc::LumiProducerFromBrilcalc ( const edm::ParameterSet iConfig)
explicit

Definition at line 63 of file LumiProducerFromBrilcalc.cc.

References doBunchByBunch_, Exception, callgraph::fields, mps_splice::line, eostools::ls(), lumiData_, lumiFile_, writedatasetfile::run, and AlCaHLTBitMon_QueryRunRegistry::string.

64  : lumiFile_(iConfig.getParameter<std::string>("lumiFile")),
65  throwIfNotFound_(iConfig.getParameter<bool>("throwIfNotFound")),
66  doBunchByBunch_(iConfig.getParameter<bool>("doBunchByBunch")) {
67  //register your products
68  produces<LumiInfo>("brilcalc");
69 
70  //now do what ever other initialization is needed
71  if (doBunchByBunch_) {
72  throw cms::Exception("LumiProducerFromBrilcalc")
73  << "Sorry, bunch-by-bunch luminosity is not yet supported. Please bug your friendly lumi expert!";
74  }
75 
76  // Read luminosity data and store it in lumiData_.
77  edm::LogInfo("LumiProducerFromBrilcalc") << "Reading luminosity data from " << lumiFile_ << "...one moment...";
78  std::ifstream lumiFile(lumiFile_);
79  if (!lumiFile.is_open()) {
80  throw cms::Exception("LumiProducerFromBrilcalc") << "Failed to open input luminosity file " << lumiFile_;
81  }
82 
83  int nLS = 0;
85  while (1) {
86  std::getline(lumiFile, line);
87  if (lumiFile.eof() || lumiFile.fail())
88  break;
89  if (line.empty())
90  continue; // skip blank lines
91  if (line.at(0) == '#')
92  continue; // skip comment lines
93 
94  // Break into fields. These should be, in order: run:fill, brills:cmsls, time, beam status, beam energy,
95  // delivered lumi, recorded lumi, average pileup, source.
96  std::stringstream ss(line);
97  std::string field;
98  std::vector<std::string> fields;
99 
100  while (std::getline(ss, field, ','))
101  fields.push_back(field);
102 
103  if (fields.size() != 9) {
104  edm::LogWarning("LumiProducerFromBrilcalc") << "Malformed line in csv file: " << line;
105  continue;
106  }
107 
108  // Extract the run number from fields[0] and the lumisection number from fields[1]. Fortunately since the
109  // thing we want is before the colon, we don't have to split them again.
110  int run, ls;
111  std::stringstream runfill(fields[0]);
112  runfill >> run;
113  std::stringstream lsls(fields[1]);
114  lsls >> ls;
115 
116  // Extract the delivered and recorded lumi from fields[5] and fields[6].
117  float lumiDel, lumiRec, dtFrac;
118  std::stringstream lumiDelString(fields[5]);
119  lumiDelString >> lumiDel;
120  std::stringstream lumiRecString(fields[6]);
121  lumiRecString >> lumiRec;
122 
123  // Calculate the deadtime fraction
124  dtFrac = 1.0 - lumiRec / lumiDel;
125 
126  // Finally, store it all.
127  lumiData_[std::make_pair(run, ls)] = std::make_pair(lumiDel, dtFrac);
128  nLS++;
129  }
130  edm::LogInfo("LumiProducerFromBrilcalc") << "Read " << nLS << " lumisections from " << lumiFile_;
131  lumiFile.close();
132 }
T getParameter(std::string const &) const
std::map< std::pair< int, int >, std::pair< float, float > > lumiData_
def ls(path, rec=False)
Definition: eostools.py:349
LumiProducerFromBrilcalc::~LumiProducerFromBrilcalc ( )
default

Member Function Documentation

void LumiProducerFromBrilcalc::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 164 of file LumiProducerFromBrilcalc.cc.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addDefault(), DEFINE_FWK_MODULE, and AlCaHLTBitMon_QueryRunRegistry::string.

164  {
165  // Allowed parameters
167  desc.add<std::string>("lumiFile");
168  desc.add<bool>("throwIfNotFound", false);
169  desc.add<bool>("doBunchByBunch", false);
170  descriptions.addDefault(desc);
171 }
void addDefault(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void LumiProducerFromBrilcalc::produce ( edm::StreamID  iStreamID,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Definition at line 139 of file LumiProducerFromBrilcalc.cc.

References Exception, LogDebug, lumiData_, edm::EventBase::luminosityBlock(), edm::Event::put(), edm::Event::run(), and throwIfNotFound_.

141  {
142  std::vector<float> bxlumi(3564, 0);
143  std::pair<int, int> runls = std::make_pair(iEvent.run(), iEvent.luminosityBlock());
144  if (lumiData_.count(runls) == 1) {
145  // if we have data for this run/LS, put it in the event
146  LogDebug("LumiProducerFromBrilcalc") << "Filling for run " << runls.first << " ls " << runls.second
147  << " with delivered " << lumiData_.at(runls).first << " dt "
148  << lumiData_.at(runls).second;
149  iEvent.put(std::make_unique<LumiInfo>(lumiData_.at(runls).second, bxlumi, lumiData_.at(runls).first), "brilcalc");
150  } else {
151  if (throwIfNotFound_) {
152  throw cms::Exception("LumiProducerFromBrilcalc")
153  << "Failed to find luminosity for run " << runls.first << " LS " << runls.second;
154  } else {
155  // just put in zeroes
156  edm::LogWarning("LumiProducerFromBrilcalc")
157  << "Failed to find luminosity for run " << runls.first << " ls " << runls.second;
158  iEvent.put(std::make_unique<LumiInfo>(0, bxlumi, 0), "brilcalc");
159  }
160  }
161 }
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
RunNumber_t run() const
Definition: Event.h:101
std::map< std::pair< int, int >, std::pair< float, float > > lumiData_

Member Data Documentation

const bool LumiProducerFromBrilcalc::doBunchByBunch_
private

Definition at line 55 of file LumiProducerFromBrilcalc.cc.

Referenced by LumiProducerFromBrilcalc().

std::map<std::pair<int, int>, std::pair<float, float> > LumiProducerFromBrilcalc::lumiData_
private

Definition at line 56 of file LumiProducerFromBrilcalc.cc.

Referenced by LumiProducerFromBrilcalc(), and produce().

const std::string LumiProducerFromBrilcalc::lumiFile_
private

Definition at line 53 of file LumiProducerFromBrilcalc.cc.

Referenced by LumiProducerFromBrilcalc().

const bool LumiProducerFromBrilcalc::throwIfNotFound_
private

Definition at line 54 of file LumiProducerFromBrilcalc.cc.

Referenced by produce().