CMS 3D CMS Logo

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

#include <CondTools/BeamSpot/plugins/BeamSpotRcdReader.cc>

Inheritance diagram for BeamSpotRcdReader:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  theBSfromDB
 

Public Member Functions

 BeamSpotRcdReader (const edm::ParameterSet &)
 
 ~BeamSpotRcdReader () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
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::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 

Private Attributes

const edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcdbeamSpotToken_
 
TTree * bstree_
 
std::unique_ptr< std::ofstream > output_
 
edm::Service< TFileServicetFileService
 
struct BeamSpotRcdReader::theBSfromDB theBSfromDB_
 
edm::ESWatcher< BeamSpotObjectsRcdwatcher_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- 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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Description: simple emd::one::EDAnalyzer to retrieve and ntuplize BeamSpot data from the conditions database

Implementation: [Notes on implementation]

Definition at line 48 of file BeamSpotRcdReader.cc.

Constructor & Destructor Documentation

◆ BeamSpotRcdReader()

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

Definition at line 84 of file BeamSpotRcdReader.cc.

References MillePedeFileConverter_cfg::fileName, edm::ParameterSet::getUntrackedParameter(), output_, and AlCaHLTBitMon_QueryRunRegistry::string.

85  : beamSpotToken_(esConsumes()), bstree_(nullptr) {
86  //now do what ever initialization is needed
87  usesResource("TFileService");
88  std::string fileName(iConfig.getUntrackedParameter<std::string>("rawFileName"));
89  if (!fileName.empty()) {
90  output_ = std::make_unique<std::ofstream>(fileName.c_str());
91  if (!output_->good()) {
92  edm::LogError("IOproblem") << "Could not open output file " << fileName << ".";
93  output_.reset();
94  }
95  }
96 }
std::unique_ptr< std::ofstream > output_
Log< level::Error, false > LogError
const edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd > beamSpotToken_
T getUntrackedParameter(std::string const &, T const &) const

◆ ~BeamSpotRcdReader()

BeamSpotRcdReader::~BeamSpotRcdReader ( )
overridedefault

Member Function Documentation

◆ analyze()

void BeamSpotRcdReader::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 120 of file BeamSpotRcdReader.cc.

References BeamSpotRcdReader::theBSfromDB::Beamdxdz_, BeamSpotRcdReader::theBSfromDB::Beamsigmaz_, beamSpotToken_, BeamSpotObjects::beamWidthX(), BeamSpotRcdReader::theBSfromDB::BeamWidthX_, BeamSpotObjects::beamWidthY(), BeamSpotRcdReader::theBSfromDB::BeamWidthY_, bstree_, BeamSpotRcdReader::theBSfromDB::BSx0_, BeamSpotRcdReader::theBSfromDB::BSy0_, BeamSpotRcdReader::theBSfromDB::BSz0_, edm::ESWatcher< T >::check(), BeamSpotObjects::dxdz(), edm::EventSetup::getData(), iEvent, BeamSpotRcdReader::theBSfromDB::init(), BeamSpotRcdReader::theBSfromDB::ls, convertSQLitetoXML_cfg::output, output_, BeamSpotRcdReader::theBSfromDB::run, BeamSpotObjects::sigmaZ(), theBSfromDB_, watcher_, BeamSpotObjects::x(), BeamSpotObjects::y(), and BeamSpotObjects::z().

120  {
121  using namespace edm;
122  std::ostringstream output;
123 
124  // initialize the ntuple
125  theBSfromDB_.init();
126 
127  if (watcher_.check(iSetup)) { // check for new IOV for this run / LS
128 
129  output << " for runs: " << iEvent.id().run() << " - " << iEvent.id().luminosityBlock() << std::endl;
130 
131  // Get BeamSpot from EventSetup:
132  const BeamSpotObjects* mybeamspot = &iSetup.getData(beamSpotToken_);
133 
134  theBSfromDB_.run = iEvent.id().run();
135  theBSfromDB_.ls = iEvent.id().luminosityBlock();
136  theBSfromDB_.BSx0_ = mybeamspot->x();
137  theBSfromDB_.BSy0_ = mybeamspot->y();
138  theBSfromDB_.BSz0_ = mybeamspot->z();
139  theBSfromDB_.Beamsigmaz_ = mybeamspot->sigmaZ();
140  theBSfromDB_.Beamdxdz_ = mybeamspot->dxdz();
141  theBSfromDB_.BeamWidthX_ = mybeamspot->beamWidthX();
142  theBSfromDB_.BeamWidthY_ = mybeamspot->beamWidthY();
143 
144  bstree_->Fill();
145 
146  output << *mybeamspot << std::endl;
147  }
148 
149  // Final output - either message logger or output file:
150  if (output_.get())
151  *output_ << output.str();
152  else
153  edm::LogInfo("") << output.str();
154 }
double z() const
get Z beam position
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
edm::ESWatcher< BeamSpotObjectsRcd > watcher_
struct BeamSpotRcdReader::theBSfromDB theBSfromDB_
double beamWidthX() const
get average transverse beam width
std::unique_ptr< std::ofstream > output_
const edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd > beamSpotToken_
int iEvent
Definition: GenABIO.cc:224
double x() const
get X beam position
double beamWidthY() const
get average transverse beam width
Log< level::Info, false > LogInfo
double y() const
get Y beam position
double sigmaZ() const
get sigma Z, RMS bunch length
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
HLT enums.
Definition: output.py:1
double dxdz() const
get dxdz slope, crossing angle in XZ

◆ beginJob()

void BeamSpotRcdReader::beginJob ( )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 157 of file BeamSpotRcdReader.cc.

References BeamSpotRcdReader::theBSfromDB::Beamdxdz_, BeamSpotRcdReader::theBSfromDB::Beamsigmaz_, BeamSpotRcdReader::theBSfromDB::BeamWidthX_, BeamSpotRcdReader::theBSfromDB::BeamWidthY_, bstree_, BeamSpotRcdReader::theBSfromDB::BSx0_, BeamSpotRcdReader::theBSfromDB::BSy0_, BeamSpotRcdReader::theBSfromDB::BSz0_, BeamSpotRcdReader::theBSfromDB::ls, TFileService::make(), BeamSpotRcdReader::theBSfromDB::run, tFileService, and theBSfromDB_.

157  {
158  bstree_ = tFileService->make<TTree>("BSNtuple", "BeamSpot analyzer ntuple");
159 
160  //Tree Branches
161  bstree_->Branch("run", &theBSfromDB_.run, "run/I");
162  bstree_->Branch("ls", &theBSfromDB_.ls, "ls/I");
163  bstree_->Branch("BSx0", &theBSfromDB_.BSx0_, "BSx0/F");
164  bstree_->Branch("BSy0", &theBSfromDB_.BSy0_, "BSy0/F");
165  bstree_->Branch("BSz0", &theBSfromDB_.BSz0_, "BSz0/F");
166  bstree_->Branch("Beamsigmaz", &theBSfromDB_.Beamsigmaz_, "Beamsigmaz/F");
167  bstree_->Branch("Beamdxdz", &theBSfromDB_.Beamdxdz_, "Beamdxdz/F");
168  bstree_->Branch("BeamWidthX", &theBSfromDB_.BeamWidthX_, "BeamWidthX/F");
169  bstree_->Branch("BeamWidthY", &theBSfromDB_.BeamWidthY_, "BeamWidthY/F");
170 }
struct BeamSpotRcdReader::theBSfromDB theBSfromDB_
edm::Service< TFileService > tFileService
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64

◆ fillDescriptions()

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

Definition at line 173 of file BeamSpotRcdReader.cc.

References edm::ConfigurationDescriptions::addDefault(), and submitPVResolutionJobs::desc.

173  {
174  //The following says we do not know what parameters are allowed so do no validation
175  // Please change this to state exactly what you do use, even if it is no parameters
177  desc.setUnknown();
178  descriptions.addDefault(desc);
179 }
void addDefault(ParameterSetDescription const &psetDescription)

Member Data Documentation

◆ beamSpotToken_

const edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> BeamSpotRcdReader::beamSpotToken_
private

Definition at line 72 of file BeamSpotRcdReader.cc.

Referenced by analyze().

◆ bstree_

TTree* BeamSpotRcdReader::bstree_
private

Definition at line 74 of file BeamSpotRcdReader.cc.

Referenced by analyze(), and beginJob().

◆ output_

std::unique_ptr<std::ofstream> BeamSpotRcdReader::output_
private

Definition at line 78 of file BeamSpotRcdReader.cc.

Referenced by analyze(), and BeamSpotRcdReader().

◆ tFileService

edm::Service<TFileService> BeamSpotRcdReader::tFileService
private

Definition at line 73 of file BeamSpotRcdReader.cc.

Referenced by beginJob().

◆ theBSfromDB_

struct BeamSpotRcdReader::theBSfromDB BeamSpotRcdReader::theBSfromDB_
private

Referenced by analyze(), and beginJob().

◆ watcher_

edm::ESWatcher<BeamSpotObjectsRcd> BeamSpotRcdReader::watcher_
private

Definition at line 77 of file BeamSpotRcdReader.cc.

Referenced by analyze().