LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
RFBase.cc
Go to the documentation of this file.
1 // RestFrames: particle physics event analysis library
3 // --------------------------------------------------------------------
4 // Copyright (c) 2014-2016, Christopher Rogan
14 // This file is part of RestFrames.
15 //
16 // RestFrames is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; either version 2 of the License, or
19 // (at your option) any later version.
20 //
21 // RestFrames is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with RestFrames. If not, see <http://www.gnu.org/licenses/>.
29 
30 #include "RestFrames/RestFrames_config.h"
31 #include "RestFrames/RFBase.hh"
32 
33 namespace RestFrames {
34 
35  using std::max;
36 
38  // RFBase class methods
40 
41  RFBase::RFBase()
42  : m_Log(), m_Key(-1)
43  {
44  m_Name = "Empty";
45  m_Title = "Empty";
46  m_Body = false;
47  m_Mind = false;
48  m_Spirit = false;
49  m_This = this;
50  m_Owns.clear();
51  m_Log.SetSource("RFBase "+GetName());
52  }
53 
54  RFBase::RFBase(const std::string& sname,
55  const std::string& stitle, int key)
56  : m_Log(), m_Key(key) {
57  m_Name = sname;
58  m_Title = stitle;
59  m_Body = false;
60  m_Mind = false;
61  m_Spirit = false;
62  m_This = this;
63  m_Owns.clear();
64  m_Log.SetSource("RFBase "+GetName());
65  }
66 
67  RFBase::~RFBase(){
68  RFBase::Clear();
69  }
70 
71  void RFBase::Clear(){
72  SetBody(false);
73  int N = m_Owns.size();
74  for(int i = 0; i < N; i++){
75  delete m_Owns[i];
76  }
77  m_Owns.clear();
78  }
79 
80  RFBase& RFBase::Empty(){
81  return RFBase::m_Empty;
82  }
83 
84  bool RFBase::IsEmpty() const {
85  return m_Key == -1;
86  }
87 
89  if(dep) m_Owns.push_back(dep);
90  }
91 
92  bool RFBase::IsSame(const RFKey& key) const {
93  return (m_Key == key);
94  }
95 
96  bool RFBase::IsSame(const RFBase& obj) const {
97  return obj == m_Key;
98  }
99 
101  return RFKey(m_Key);
102  }
103 
104  std::string RFBase::GetName() const {
105  return m_Name;
106  }
107 
108  std::string RFBase::GetTitle() const {
109  return m_Title;
110  }
111 
112  bool RFBase::SetBody(bool body) const {
113  m_Body = body;
114  if(!body) SetMind(body);
115  return m_Body;
116  }
117 
118  bool RFBase::SetMind(bool mind) const {
119  m_Mind = mind;
120  if(!mind) SetSpirit(mind);
121  return m_Mind;
122  }
123 
124  bool RFBase::SetSpirit(bool spirit) const {
125  m_Spirit = spirit;
126  return m_Spirit;
127  }
128 
129  bool RFBase::IsSoundBody() const {
130  return m_Body;
131  }
132 
133  bool RFBase::IsSoundMind() const {
134  return m_Mind;
135  }
136 
137  bool RFBase::IsSoundSpirit() const {
138  return m_Spirit;
139  }
140 
141  void RFBase::Print(LogType type) const {
142  std::string output = PrintString(type);
143  m_Log << type << output << LogEnd;
144  }
145 
146  std::string RFBase::PrintString(LogType type) const {
147  std::string output = "\n";
148  output += " Name: "+GetName()+"\n";
149  output += " Title: "+GetTitle()+"\n";
150  return output;
151  }
152 
153  void RFBase::UnSoundBody(const std::string& function) const {
154  m_Log << LogWarning;
155  m_Log << "Unable to evaluate function \"" << function << "\". ";
156  m_Log << "Requires a successful call to \"InitializeTree()\" ";
157  m_Log << "from the LabFrame associated with this tree.";
158  m_Log << LogEnd;
159 
160  RFBase::m_BodyCount++;
161  if(RFBase::m_BodyCount > m_WarningTolerance &&
162  m_WarningTolerance > 0) TooManyBodies(*this);
163  }
164 
165  void RFBase::UnSoundMind(const std::string& function) const {
166  m_Log << LogWarning;
167  m_Log << "Unable to evaluate function \"" << function << "\". ";
168  m_Log << "Requires a successful call to \"InitializeAnalysis()\" ";
169  m_Log << "from the LabFrame associated with this tree.";
170  m_Log << LogEnd;
171 
172  RFBase::m_MindCount++;
173  if(RFBase::m_MindCount > m_WarningTolerance &&
174  m_WarningTolerance > 0) TooManyMinds(*this);
175  }
176 
177  void RFBase::UnSoundSpirit(const std::string& function) const {
178  m_Log << LogWarning;
179  m_Log << "Unable to evaluate function \"" << function << "\". ";
180  m_Log << "Requires a successful call to \"AnalyzeEvent()\" ";
181  m_Log << "from the LabFrame associated with this tree.";
182  m_Log << LogEnd;
183 
184  RFBase::m_SpiritCount++;
185  if(RFBase::m_SpiritCount > m_WarningTolerance &&
186  m_WarningTolerance > 0) TooManySpirits(*this);
187  }
188 
189  // Initializer.
190  __attribute__((constructor))
191  static void initializer(void){
192  printf("\n" "\x1b[36m");
193  printf(PACKAGE_NAME);
194  printf(" v");
195  printf(PACKAGE_VERSION);
196  printf(" -- Developed by Christopher Rogan (crogan@cern.ch)\n");
197  printf(" ");
198  printf("Copyright (c) 2014-2016, Christopher Rogan\n");
199  printf(" ");
200  printf("http://RestFrames.com\n");
201  printf("\x1b[0m" "\n");
202  RestFrames::RFKey key(0);
203  }
204 
205  int RFBase::m_BodyCount = 0;
206  int RFBase::m_MindCount = 0;
207  int RFBase::m_SpiritCount = 0;
208 
209  int RFBase::m_WarningTolerance = 100;
210 
211  RFBase RFBase::m_Empty;
212 
213  const TVector3 RFBase::m_Empty3Vector;
214  const TLorentzVector RFBase::m_Empty4Vector;
215 
216  double GetP(double Mp, double Mc1, double Mc2){
217  if(Mp <= 0.) return 0.;
218  Mc1 = std::max(Mc1, 0.);
219  Mc2 = std::max(Mc2, 0.);
220  return sqrt(std::max(0., (Mp*Mp-Mc1*Mc1-Mc2*Mc2)*(Mp*Mp-Mc1*Mc1-Mc2*Mc2)-4.*Mc1*Mc1*Mc2*Mc2) )/2./Mp;
221  }
222 
223  void SetWarningTolerance(int NMAX){
224  RFBase::m_WarningTolerance = NMAX;
225  }
226 
227  void TooManyBodies(const RFBase& obj){
228  g_Log << LogError;
229  g_Log << "Too many warnings. ";
230  g_Log << "Need a successful call to \"InitializeTree()\" ";
231  g_Log << "from the LabFrame associated with the offending/";
232  g_Log << "unsuccessful function calls. The last call came from:";
233  g_Log << Log(obj);
234  g_Log << "Please edit your code and try again." << LogEnd;
235  }
236 
237  void TooManyMinds(const RFBase& obj){
238  g_Log << LogError;
239  g_Log << "Too many warnings. ";
240  g_Log << "Need a successful call to \"InitializeAnalysis()\" ";
241  g_Log << "from the LabFrame associated with the offending/";
242  g_Log << "unsuccessful function calls. The last call came from:";
243  g_Log << Log(obj);
244  g_Log << "Please edit your code and try again." << LogEnd;
245  }
246 
247  void TooManySpirits(const RFBase& obj){
248  g_Log << LogError;
249  g_Log << "Too many warnings. ";
250  g_Log << "Need a successful call to \"AnalyzeEvent()\" ";
251  g_Log << "from the LabFrame associated with the offending/";
252  g_Log << "unsuccessful function calls. The last call came from:";
253  g_Log << Log(obj);
254  g_Log << "Please edit your code and try again." << LogEnd;
255  }
256 
257 }
virtual std::string PrintString(LogType type) const
String of information associated with object.
Definition: RFBase.cc:146
Base class for all RestFrame package objects.
Definition: RFBase.hh:53
std::string GetName() const
Returns object name.
Definition: RFBase.cc:104
std::string GetTitle() const
Returns object title.
Definition: RFBase.cc:108
virtual void Clear()
Clears RFBase of all connections to other objects.
Definition: RFBase.cc:71
bool IsEmpty() const
Checks whether this is default (empty) instance of class.
Definition: RFBase.cc:84
RFKey GetKey() const
gets object identification key
Definition: RFBase.cc:100
void AddDependent(RFBase *dep)
pointer to RFBase object owned by this one
Definition: RFBase.cc:88
bool IsSame(const RFKey &key) const
Tests whether key is the same as this.
Definition: RFBase.cc:92
void Print(LogType type) const
Print information associated with object.
Definition: RFBase.cc:141