11#ifndef XAOD_STANDALONE
15#include <GaudiKernel/Incident.h>
16#include <GaudiKernel/FileIncident.h>
17#include <GaudiKernel/IIncidentSvc.h>
24 ISvcLocator* pSvcLocator ) :
25 base_class(name, pSvcLocator)
27 assert( pSvcLocator );
39 return StatusCode::FAILURE;
48 incSvc->addListener(
this, IncidentType::BeginInputFile, 60);
49 incSvc->addListener(
this,
"MetaDataStop", 30);
59 return StatusCode::SUCCESS;
70 auto newCbk = std::make_unique<xAOD::CutBookkeeper>();
71 newCbk->setName(name);
81 if (newCbk->isEqualTo(cbk)) {
82 ATH_MSG_DEBUG(
"The CutBookkeeper with name '" << name <<
"' already exists"
83 <<
" and has CutID " << cbk->uniqueIdentifier() <<
"... Not adding!" );
85 return cbk->uniqueIdentifier();
90 ATH_MSG_DEBUG(
"Declaring a new filter with name '" << name <<
"' and CutID " << cutID );
106 const std::string& outputStream,
110 <<
", logic=" << logic <<
", outputStream=" << outputStream <<
")");
116 if (cbk ==
nullptr) {
117 ATH_MSG_ERROR(
"Could not find CutBookkeeper with CutID " << cutID);
118 throw std::runtime_error(
"Could not find CutBookkeeper");
124 cbk->addOutputStreamForAllUsed(outputStream);
136 <<
"' and original CutID " << parentCutID);
140 if (parentCbk ==
nullptr) {
141 ATH_MSG_ERROR(
"Could not find parent CutBookkeeper with CutID " << parentCutID);
142 throw std::runtime_error(
"Could not find CutBookkeeper");
149 if (cbk ==
nullptr) {
150 ATH_MSG_ERROR(
"Could not find CutBookkeeper with CutID " << cutID);
151 throw std::runtime_error(
"Could not find CutBookkeeper");
163 const std::string& descr )
165 ATH_MSG_DEBUG(
"calling setFilterDescription(" << cutID <<
", " << descr <<
")" );
169 if (cbk !=
nullptr) {
179 const std::vector<float>&
weights )
183 throw std::runtime_error(
"Inconsistent weights and variation sizes");
215 ATH_MSG_VERBOSE(
"Adding event with weight " << weight <<
" to cut " << cutID <<
" for variation " <<
index);
218 if (cbk ==
nullptr) {
219 ATH_MSG_ERROR(
"Could not find CutBookkeeper for CutID " << cutID <<
" and variation " <<
index);
220 throw std::runtime_error(
"Could not find CutBookkeeper");
235 if (inc.type() == IncidentType::BeginInputFile) {
237 std::string inputstream =
"";
247 ATH_MSG_DEBUG(
"No FileMetaData in input, trying EventStreamInfo");
249 std::vector<std::string> vKeys;
252 std::set<std::string> keys(vKeys.begin(), vKeys.end());
253 if (keys.size() == 1) {
254 std::string key = *keys.begin();
256 if (esi && !esi->getProcessingTags().empty()) {
258 inputstream = *esi->getProcessingTags().begin();
263 if (inputstream.empty()) {
269 "Failed to parse stream name from metadata, using "
270 "property \"InputStream\"");
275 ATH_MSG_DEBUG(
"Input stream name: \"" << inputstream <<
'"');
279 const FileIncident* finc =
dynamic_cast<const FileIncident*
>(&inc);
281 ATH_MSG_FATAL(
"File " << (finc?finc->fileName():
"???") <<
" stream " << inputstream
282 <<
" does not match previous file "
290 if (inc.type() ==
"MetaDataStop") {
295 cbk->setNAcceptedEvents(0);
296 cbk->setSumOfEventWeights(0);
297 cbk->setSumOfEventWeightsSquared(0);
311 ATH_MSG_DEBUG(
"calling determineCycleNumberFromInput('" << collName
316 ATH_MSG_VERBOSE(
"Found xAOD::CutBookkeeperContainer in input MetaStore with name: " << collName);
323 int inCycle = cbk->cycle();
324 if (inCycle > maxCycle) maxCycle = inCycle;
329 ATH_MSG_DEBUG(
"done calling determineCycleNumberFromInput('" << collName
331 return StatusCode::SUCCESS;
340 return StatusCode::SUCCESS;
345 return StatusCode::FAILURE;
355 return StatusCode::SUCCESS;
360 if (first->empty()) {
361 return StatusCode::SUCCESS;
363 for (
size_t i = 1; i <
count; ++i) {
372 return StatusCode::SUCCESS;
380 return StatusCode::SUCCESS;
400 if (cbk->uniqueIdentifier() == cutID) {
412 if (cbk ==
nullptr) {
413 return std::numeric_limits<uint64_t>::max();
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This file contains the class definition for the EventStreamInfo class.
uint32_t CutIdentifier
InstanceIdentifier is a unique identifer used for every AthFilterAlgorithm instance.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
const CutBookkeepersLocalCache & getCutBookkeepers() const
Get CutBookkeepers cache.
virtual void setFilterDescription(CutIdentifier cutID, const std::string &descr) override final
Set the description of an existing CutBookkeeper.
CutBookkeepersLocalCache m_containers
Local CutBookkeeperContainers.
Gaudi::Property< std::string > m_completeCollName
The name of the completed, i.e., fully processed, CutBookkeeperContainer.
ServiceHandle< StoreGateSvc > m_inMetaDataStore
The input meta-data store.
std::recursive_mutex m_addEventMutex
Mutex to protect adding an event.
virtual uint64_t getNAcceptedEvents(const CutIdentifier cutID) const override final
Get number of accepted events for a cut.
StatusCode setNumberOfWeightVariations(size_t count)
Set number of weight variations.
StatusCode determineCycleNumberFromInput(const std::string &collName)
Helper function to determine the processing cycle number from the input meta-data store.
StatusCode createContainers(size_t count)
Helper function to create an empty containers (and its aux store)
Gaudi::Property< bool > m_configured
CutFlow service should be explicitly configured.
virtual void handle(const Incident &incident) override final
Incident service handle listening for BeginInputFile, EndInputFile and MetaDataStop.
virtual void addEvent(CutIdentifier cutID, const std::vector< float > &weights) override final
Tells CutFlowSvc to update the weighted event counter of a CutIdentifier cutID, using CutIdentifier r...
virtual CutIdentifier registerCut(const std::string &name, const std::string &description, CutIdentifier parentCutID, bool nominalOnly) override final
Register cut as child of a filter in the CutFlowSvc and returns the CutID of the corresponding EventB...
virtual CutIdentifier registerFilter(const std::string &name, const std::string &description, bool nominalOnly) override final
Register filter in the CutFlowSvc and returns the CutID of the corresponding CutBookkeeper.
virtual StatusCode initialize() override final
Gaudi Service Implementation.
Gaudi::Property< int > m_skimmingCycle
The current skimming cycle, i.e., how many processing stages we already had.
xAOD::CutBookkeeper * getCutBookkeeper(const CutIdentifier cutID, size_t index) const
Get a CutBookkeeper given a CutID.
std::unordered_set< CutIdentifier > m_nominalOnlyCuts
List of nominal-only filters.
Gaudi::Property< std::string > m_inputStream
The name of the currently used input file stream.
CutFlowSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
This class provides the summary information stored for data written as a Event Stream.
void addSumOfEventWeights(double nWeightedEvents)
Add more sum-of-event-weights that this CutBookkeeper has seen.
void addChild(CutBookkeeper_v1 *childEB)
Add one child to this CutBookkeeper.
void addSumOfEventWeightsSquared(double nWeightedEventsSquared)
Add more sum-of-(event-weights-squared) that this CutBookkeeper has seen.
void addNAcceptedEvents(uint64_t nEvents)
Add seen events to the number of accepted events that this CutBookkeeper has seen.
CutLogic
Enumeration of the logic of a cut.
void setDescription(const std::string &description)
Set the description of this CutBookkeeper.
uint64_t nAcceptedEvents() const
Get the number of accepted events that this CutBookkeeper has seen.
void setCutLogic(CutLogic logic)
Set the cut logic of this CutBookkeeper, e.g., ACCEPT, REQUIRE, VETO.
void setTopFilter(bool isTopFilter)
Set the top-filter property of this CutBookkeeper.
std::string description
glabal timer - how long have I taken so far?
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
CutBookkeeper_v1 CutBookkeeper
Define the latest version of the CutBookkeeper class.
FileMetaData_v1 FileMetaData
Declare the latest version of the class.
CutBookkeeperContainer_v1 CutBookkeeperContainer
Define the latest version of the CutBookkeeperContainer class.
Helper in-memory structure.
static void prepareContainers(CutBookkeepersLocalCache &target, size_t size, bool extend=false)