The Gaudi Framework  v29r0 (ff2e7097)
DataFlowManager.cpp
Go to the documentation of this file.
1 #include "DataFlowManager.h"
2 
3 //---------------------------------------------------------------------------
4 // Static members
8 //---------------------------------------------------------------------------
14 {
15 
16  // Count how many products are actually requested
17  unsigned int nProducts( 0 );
18  for ( auto& thisAlgoDependencies : algosDependencies ) {
19  nProducts += thisAlgoDependencies.size();
20  }
21  m_dataObjectsCatalog.resize( nProducts );
22 
23  // If it's not the first instance, nothing to do here
24  if ( m_algosRequirements.size() == 0 ) {
25  // This is the first instance, compile the requirements
26  m_algosRequirements.resize( algosDependencies.size(), dependency_bitset( nProducts ) );
27 
28  // Fill the requirements
29  unsigned int algoIndex = 0;
30  long int productIndex = 0;
31  for ( auto& thisAlgoDependencies : algosDependencies ) {
32  // Make a local alias for better readability
33  auto& dependency_bits = m_algosRequirements[algoIndex];
34  for ( auto& product : thisAlgoDependencies ) {
35  auto ret_val = m_productName_index_map.insert( std::pair<DataObjID, long int>( product, productIndex ) );
36  // insert successful means product wasn't known before. So increment counter
37  if ( ret_val.second == true ) ++productIndex;
38  // in any case the return value holds the proper product index
39  dependency_bits[ret_val.first->second] = true;
40  } // end loop on products on which the algo depends
41  algoIndex++;
42  } // end loop on algorithms
43 
44  // Now the vector of products
46  for ( auto& name_idx : m_productName_index_map ) m_productName_vec[name_idx.second] = name_idx.first;
47  }
48 }
49 
50 //---------------------------------------------------------------------------
51 
56 bool DataFlowManager::canAlgorithmRun( unsigned int iAlgo )
57 {
58  const dependency_bitset& thisAlgoRequirements = m_algosRequirements[iAlgo];
59  return thisAlgoRequirements.is_subset_of( m_dataObjectsCatalog );
60 }
61 
62 //---------------------------------------------------------------------------
63 
66 {
67  for ( const auto& new_product : newProducts ) {
68  m_fc.insert( new_product );
69  const int index = productName2index( new_product );
70  if ( index >= 0 ) m_dataObjectsCatalog[index] = true;
71  }
72 }
73 
74 //---------------------------------------------------------------------------
75 
78 {
79  m_dataObjectsCatalog.reset();
80  m_fc.clear();
81 }
82 
83 //---------------------------------------------------------------------------
84 
87 {
88  DataObjIDColl products;
89  for ( const auto& p : m_fc ) {
90  products.insert( p );
91  }
92  return products;
93 }
94 
95 //---------------------------------------------------------------------------
98 {
99  // with move semantics this is ~fine
100  DataObjIDColl deps;
101  for ( unsigned int i = 0; i < m_productName_vec.size(); ++i ) {
102  if ( m_algosRequirements[iAlgo][i] ) deps.insert( m_productName_vec[i] );
103  }
104  return deps;
105 }
106 
107 //---------------------------------------------------------------------------
boost::dynamic_bitset dependency_bitset
Type holding the dependencies for one single algorithm.
void updateDataObjectsCatalog(const DataObjIDColl &newProducts)
Update the catalog of available products in the slot.
DataObjIDColl dataDependencies(unsigned int iAlgo) const
Get the dependencies of a single algo;.
static std::vector< DataObjID > m_productName_vec
Track the products, assigning an index to them. Static since the same for all events.
DataObjIDColl content() const
Get the content of the catalog.
static std::unordered_map< productName_t, long int, DataObjID_Hasher > m_productName_index_map
DataObjIDColl m_fc
static std::vector< dependency_bitset > m_algosRequirements
Requirements of algos. Static since the same for all events.
T resize(T...args)
T clear(T...args)
long int productName2index(const productName_t &productName)
Simple helper method to convert the product name into an index.
T insert(T...args)
T size(T...args)
STL class.
void reset()
Reset to default values.
dependency_bitset m_dataObjectsCatalog
Catalog of the products in the whiteboard.
DataFlowManager(const std::list< IAlgorithm * > &)
Constructor.
bool canAlgorithmRun(unsigned int iAlgo)
Needed data products are available.