Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sequencer.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Sequencer.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
19 
20 #include <cstddef>
21 #include <memory>
22 #include <optional>
23 #include <stdexcept>
24 #include <string>
25 #include <typeinfo>
26 #include <unordered_map>
27 #include <utility>
28 #include <vector>
29 
30 #include <tbb/enumerable_thread_specific.h>
31 
32 namespace ActsExamples {
33 class DataHandleBase;
34 class IAlgorithm;
35 class IContextDecorator;
36 class IReader;
37 class IWriter;
38 class SequenceElement;
39 
40 using IterationCallback = void (*)();
41 
43 class FpeFailure : public std::runtime_error {
44  using std::runtime_error::runtime_error;
45 };
46 
47 class SequenceConfigurationException : public std::runtime_error {
48  public:
50  : std::runtime_error{"Sequence configuration error"} {}
51 };
52 
58 class Sequencer {
59  public:
60  struct FpeMask {
62  std::pair<std::size_t, std::size_t> lines;
64  std::size_t count;
65  };
66 
67  struct Config {
69  size_t skip = 0;
71  std::optional<size_t> events = std::nullopt;
76  int numThreads = -1;
80  std::string outputTimingFile = "timing.tsv";
86  bool runDataFlowChecks = true;
87 
88  bool trackFpes = true;
89  std::vector<FpeMask> fpeMasks{};
90  bool failOnFirstFpe = false;
91  std::size_t fpeStackTraceLength = 8;
92  };
93 
94  Sequencer(const Config &cfg);
95 
99  void addContextDecorator(std::shared_ptr<IContextDecorator> decorator);
100 
104  void addReader(std::shared_ptr<IReader> reader);
105 
109  void addAlgorithm(std::shared_ptr<IAlgorithm> algorithm);
110 
114  void addElement(const std::shared_ptr<SequenceElement> &element);
115 
119  void addWriter(std::shared_ptr<IWriter> writer);
120 
122  void addWhiteboardAlias(const std::string &aliasName,
123  const std::string &objectName);
124 
126 
153  int run();
154 
156  const Config &config() const { return m_cfg; }
157 
158  private:
160  std::vector<std::string> listAlgorithmNames() const;
162  std::pair<size_t, size_t> determineEventsRange() const;
163 
164  std::pair<std::string, std::size_t> fpeMaskCount(
165  const boost::stacktrace::stacktrace &st, Acts::FpeType type) const;
166 
167  void fpeReport() const;
168 
170  std::shared_ptr<SequenceElement> sequenceElement;
171  tbb::enumerable_thread_specific<Acts::FpeMonitor::Result> fpeResult{};
172  };
173 
176  std::vector<std::shared_ptr<IContextDecorator>> m_decorators;
177  std::vector<std::shared_ptr<IReader>> m_readers;
178  std::vector<SequenceElementWithFpeResult> m_sequenceElements;
179  std::unique_ptr<const Acts::Logger> m_logger;
180 
181  std::unordered_map<std::string, std::string> m_whiteboardObjectAliases;
182 
183  std::unordered_map<std::string, const DataHandleBase *> m_whiteBoardState;
184 
185  std::atomic<std::size_t> m_nUnmaskedFpe = 0;
186 
187  const Acts::Logger &logger() const { return *m_logger; }
188 };
189 
190 std::ostream &operator<<(std::ostream &os,
192 
193 } // namespace ActsExamples