DAS  3.0
Das Analysis System
MetaInfo.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
4 #include <map>
5 #include <optional>
6 #include <regex>
7 #include <set>
8 #include <string>
9 
10 #include "UserInfo.h"
11 #include "Variation.h"
12 
13 #ifndef DARWIN_GIT_REPO
14 # ifndef DARWIN
15 # error "Provide the location of the Git repository at compile time."
16 # else
17 # define DARWIN_GIT_REPO DARWIN
18 # endif
19 #endif
20 
21 struct git_repository;
22 
23 namespace Darwin::Tools {
24 
25 static std::ostream dev_null(nullptr);
26 
68 class MetaInfo : public UserInfo {
69 
70  git_repository * repo;
71  mutable int git_error;
72  char sha[16];
74  const std::filesystem::path origin;
75 
80  static int get_one_status (const char *,
81  unsigned int,
82  void *
83  );
84 
87  void GitInit ();
88 
96  void PrintStatus () const;
97 
103  bool AllChangesCommitted () const;
104 
107  void SetupGit (bool);
108 
111  void SetupVersions ();
112 
117  void UpdateList (const bool
118  ) const;
119 
120 
123  MetaInfo (bool, const char*);
124 
127  MetaInfo (TTree *, const boost::property_tree::ptree&, bool,
128  const char*);
129 
132  MetaInfo (TTree *, bool, const char*);
133 
136  MetaInfo (TList *, bool, const char*);
137 public:
138 
141  struct IKnowWhatIAmDoing {};
142 
153  MetaInfo (const IKnowWhatIAmDoing&, bool git_init = true)
154  : MetaInfo(git_init, DARWIN_GIT_REPO)
155  {}
156 
164  MetaInfo (TTree *t,
165  const boost::property_tree::ptree& config,
166  bool git_init = true
167  )
168  : MetaInfo(t, config, git_init, DARWIN_GIT_REPO)
169  {}
170 
175  MetaInfo (TTree *t,
176  bool git_init = true
177  )
178  : MetaInfo(t, git_init, DARWIN_GIT_REPO)
179  {}
180 
184  MetaInfo (TList *l,
185  bool git_init = true
186  )
187  : MetaInfo(l, git_init, DARWIN_GIT_REPO)
188  {}
189 
192  template<typename Ptr, typename ...Args>
193  MetaInfo (const Ptr& t, Args... args)
194  : MetaInfo(&*t, args...) { }
195 
198  ~MetaInfo ();
199 
204  void Check (const boost::property_tree::ptree&) const;
205 
208  static std::string libgit2_version ();
209 
210  static std::map<std::string, std::string> versions;
211 
222  template<unsigned h
223  > unsigned Seed (std::pair<unsigned short, unsigned short> slice = {1,0}
224  ) const
225  {
226  unsigned b = Get<int>("preseed");
227  unsigned k = slice.second;
228  return h + (k+1) * b;
229  }
230 
253  std::set<Darwin::Physics::Variation> AddVars
254  (const std::string&,
255  const std::vector<std::string>&,
256  const int = Darwin::Physics::symmetric,
257  const int = 1
258  );
259 
262  std::set<Darwin::Physics::Variation> GetVars
263  (const std::string&,
264  const std::string& = ""
265  ) const;
266 
269  std::set<Darwin::Physics::Variation> GetVars () const;
270 };
271 
272 } // end of namespace
Darwin::Tools::UserInfo::l
TList * l
main list (typically from TTree::GetUserInfo())
Definition: UserInfo.h:64
Darwin::Tools::MetaInfo::SetupVersions
void SetupVersions()
Fills in software version information in the MetaInfo.
Definition: MetaInfo.cc:198
Darwin::Tools::MetaInfo::git_error
int git_error
Definition: MetaInfo.h:71
Ntupliser_cfg.args
args
Definition: Ntupliser_cfg.py:11
Darwin::Tools::MetaInfo::GetVars
std::set< Darwin::Physics::Variation > GetVars() const
Retrieve all variations, including the nominal one.
Definition: MetaInfo.cc:520
Darwin::Tools::MetaInfo::Check
void Check(const boost::property_tree::ptree &) const
Definition: MetaInfo.cc:375
Darwin::Tools::MetaInfo
Generic meta-information for n-tuple (including speficities to Darwin).
Definition: MetaInfo.h:68
Darwin::Tools::MetaInfo::GitInit
void GitInit()
Inits and opens git repo, sets sha to the value at running time.
Definition: MetaInfo.cc:50
Darwin::Tools::MetaInfo::MetaInfo
MetaInfo(TList *l, bool git_init=true)
Definition: MetaInfo.h:184
Variation.h
DARWIN_GIT_REPO
#define DARWIN_GIT_REPO
Definition: main.cc:21
Darwin::Tools::MetaInfo::MetaInfo
MetaInfo(const Ptr &t, Args... args)
Generic constsructor for smart pointers.
Definition: MetaInfo.h:193
Darwin::Tools::MetaInfo::AllChangesCommitted
bool AllChangesCommitted() const
Definition: MetaInfo.cc:173
Darwin::Tools::MetaInfo::AddVars
std::set< Darwin::Physics::Variation > AddVars(const std::string &, const std::vector< std::string > &, const int=Darwin::Physics::symmetric, const int=1)
Define a family of uncertainties.
Definition: MetaInfo.cc:449
Darwin::Tools::MetaInfo::PrintStatus
void PrintStatus() const
Definition: MetaInfo.cc:92
Darwin::Tools::MetaInfo::MetaInfo
MetaInfo(TTree *t, bool git_init=true)
Definition: MetaInfo.h:175
Darwin::Tools::MetaInfo::MetaInfo
MetaInfo(const IKnowWhatIAmDoing &, bool git_init=true)
Definition: MetaInfo.h:153
Darwin::Tools
Classes and functions related to the framework.
Definition: Dict_rdict.cxx:990
UserInfo.h
Darwin::Tools::MetaInfo::MetaInfo
MetaInfo(bool, const char *)
Used internally to set the git repo location (last parameter).
Definition: MetaInfo.cc:282
Darwin::Tools::MetaInfo::IKnowWhatIAmDoing
If you use this, you're supposed to know what you are doing.
Definition: MetaInfo.h:141
Darwin::Tools::MetaInfo::repo
git_repository * repo
pointer to local Git repo
Definition: MetaInfo.h:70
Darwin::Tools::MetaInfo::UpdateList
void UpdateList(const bool) const
Definition: MetaInfo.cc:207
Darwin::Tools::MetaInfo::origin
const std::filesystem::path origin
path to local repo determined at compilation time
Definition: MetaInfo.h:74
Darwin::Tools::MetaInfo::get_one_status
static int get_one_status(const char *, unsigned int, void *)
Definition: MetaInfo.cc:39
Darwin::Tools::MetaInfo::sha
char sha[16]
commit SHA at running time
Definition: MetaInfo.h:73
Darwin::Tools::dev_null
static std::ostream dev_null(nullptr)
to redirect output stream to nowhere
Darwin::Tools::MetaInfo::SetupGit
void SetupGit(bool)
Fills in git information in the MetaInfo.
Definition: MetaInfo.cc:179
Darwin::Tools::MetaInfo::MetaInfo
MetaInfo(TTree *t, const boost::property_tree::ptree &config, bool git_init=true)
Definition: MetaInfo.h:164
Darwin::Tools::UserInfo
Generic meta-information for n-tuple (can be used out of Darwin).
Definition: UserInfo.h:52
Darwin::Tools::MetaInfo::libgit2_version
static std::string libgit2_version()
Definition: MetaInfo.cc:263
Darwin::Tools::MetaInfo::Seed
unsigned Seed(std::pair< unsigned short, unsigned short > slice={1, 0}) const
Definition: MetaInfo.h:223
Darwin::Tools::MetaInfo::versions
static std::map< std::string, std::string > versions
software version
Definition: MetaInfo.h:210
Darwin::Physics::symmetric
@ symmetric
Definition: Variation.h:15
Darwin::Tools::config
@ config
activate -c option to provide config file
Definition: Options.h:25
Darwin::Tools::MetaInfo::~MetaInfo
~MetaInfo()
Destructor (releases memory & shuts down Git).
Definition: MetaInfo.cc:368