ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
process.hpp
Go to the documentation of this file.
1 #ifndef H_PROCESS
2 #define H_PROCESS
3 
4 #include <memory>
5 #include <string>
6 #include <map>
7 #include <set>
8 #include <mutex>
9 
10 #include "core/baby.hpp"
11 #include "core/named_func.hpp"
12 #include "core/utilities.hpp"
13 
14 class Process : public TAttFill, public TAttLine, public TAttMarker{
15 public:
16  enum class Type{data, background, signal};
17 
18  template<typename BabyType>
19  static std::shared_ptr<Process> MakeShared(const std::string &name,
20  Type type,
21  int color,
22  const std::set<std::string> &files,
23  const NamedFunc &cut = true){
24  return std::shared_ptr<Process>(new Process(static_cast<BabyType*>(nullptr),
25  name, type, color, files, cut));
26  }
27 
28  std::string name_;
31 
32  std::set<Baby*> Babies() const;
33 
34  ~Process();
35 
36 private:
37  template<typename BabyType>
38  Process(BabyType * dummy_baby,
39  const std::string &name,
40  Type type,
41  int color,
42  const std::set<std::string> &files,
43  const NamedFunc &cut);
44 
45  Process() = delete;
46  Process(const Process &) = delete;
47  Process& operator=(const Process &) = delete;
48  Process(Process &&) = delete;
49  Process& operator=(Process &&) = delete;
50 
51  static std::set<std::unique_ptr<Baby> > baby_pool_;
52  static std::mutex mutex_;
53 };
54 
55 template<typename BabyType>
56 Process::Process(BabyType * /*dummy_baby*/,
57  const std::string &name,
58  Type type,
59  int color,
60  const std::set<std::string> &files,
61  const NamedFunc &cut):
62  TAttFill(color, type == Type::background ? 1001 : 0),
63  TAttLine(type == Type::background ? 1 : color,
64  1,
65  type == Type::background ? 1 :
66  type == Type::signal ? 5
67  : 3),
68  TAttMarker(color, 20, 1.2),
69  name_(name),
70  type_(type),
71  cut_(cut){
72  std::lock_guard<std::mutex> lock(mutex_);
73  for(const auto &file: files){
74  const auto &full_files = Glob(file);
75  for(const auto &full_file: full_files){
76  bool found = false;
77  for(auto &baby_p: baby_pool_){
78  auto &baby = *baby_p;
79  if(typeid(baby) != typeid(BabyType)) continue;
80  const auto &baby_files = baby.FileNames();
81  if(baby_files.find(full_file) != baby_files.end()){
82  baby.processes_.insert(this);
83  found = true;
84  break;
85  }
86  }
87  if(!found){
88  baby_pool_.emplace(static_cast<Baby*>(new BabyType(std::set<std::string>{full_file},
89  std::set<const Process*>{this})));
90  }
91  }
92  }
93  }
94 
95 #endif
static std::mutex mutex_
Definition: process.hpp:52
Process()=delete
Combines a callable function taking a Baby and returning a scalar or vector with its string represent...
Definition: named_func.hpp:13
Process & operator=(const Process &)=delete
static std::set< std::unique_ptr< Baby > > baby_pool_
Definition: process.hpp:51
static std::shared_ptr< Process > MakeShared(const std::string &name, Type type, int color, const std::set< std::string > &files, const NamedFunc &cut=true)
Definition: process.hpp:19
~Process()
Definition: process.cpp:22
std::string name_
Definition: process.hpp:28
Type type_
Definition: process.hpp:29
std::set< std::string > Glob(const std::string &pattern)
Definition: utilities.cpp:27
std::set< Baby * > Babies() const
Definition: process.cpp:10
NamedFunc cut_
Definition: process.hpp:30