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