QwAnalysis
QwRunCondition.cc
Go to the documentation of this file.
1 /**
2  * \file QwRunCondition.cc
3  * \brief
4  * \author jhlee@jlab.org
5  * \date Thursday, September 9 21:42:26 EDT 2010
6  */
7 
8 #include "QwRunCondition.h"
9 #include "QwSVNVersion.h"
10 
11 const Int_t QwRunCondition::fCharLength = 127;
12 
13 QwRunCondition::QwRunCondition(Int_t argc, Char_t* argv[], TString name)
14 {
15 
16  fROCFlagFileName = "qwvmets.flags";
17 
18  fRunConditionList = new TList;
19  fRunConditionList -> SetOwner(true);
20  this->SetArgs(argc, argv);
21  this->SetName(name);
22 
23 }
24 
25 
27 {
29 }
30 
31 
32 void
33 QwRunCondition::SetArgs(Int_t argc, Char_t* argv[])
34 {
35 
36  // get ROOT release version, date, svn revision and branch
37  // TROOT.h (ROOT)
38  TString root_version = gROOT->GetVersion();
39  root_version += ", Date : ";
40  root_version += gROOT->GetVersionDate();
41 #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
42  root_version += ", SVN : ";
43  root_version += gROOT->GetSvnRevision();
44  root_version += " ";
45  root_version += gROOT->GetSvnBranch();
46 #else // ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
47  root_version += ", GIT : ";
48  root_version += gROOT->GetGitCommit();
49  root_version += " ";
50  root_version += gROOT->GetGitBranch();
51 #endif
52 
53  // get hostname and user name
54  char host_string[fCharLength];
55  char user_string[fCharLength];
56 
57  gethostname(host_string, fCharLength);
58  getlogin_r (user_string, fCharLength);
59 
60  TString host_name = host_string;
61  TString user_name = user_string;
62 
63  // get program name and its arguments (options)
64  TString program_name = argv[0];
65  TString argv_list;
66  for (Int_t i=1; i<argc; i++) argv_list += argv[i];
67 
68  // get current time when a ROOT file is created
69  TTimeStamp time_stamp;
70  TString current_time = time_stamp.AsString("l"); // local time
71 
72  // get svn revision, url, and last changed revision
73  // QwSVNVersion.h (GNUmakefile)
74  TString svn_revision;
75  TString svn_url;
76  TString svn_lc_revision;
77  svn_revision = QWANA_SVN_REVISION;
78  svn_url = QWANA_SVN_URL;
79  svn_lc_revision = QWANA_SVN_LASTCHANGEDREVISION;
80 
81  // get current ROC flags
82  TString roc_flags;
83  // if one of the cdaq cluster AND the user must be a "cdaq",
84  if( (host_name.Contains("cdaql")) and (not user_name.CompareTo("cdaq", TString::kExact)) ) {
85  roc_flags = this->GetROCFlags();
86  }
87  else {
88  roc_flags = "Invalid, because the system is not cdaqlx and the user is not cdaq.";
89  }
90 
91 
92  // insert some comments at the beginning of strings...
93  root_version.Insert (0, "ROOT Version : ");
94  current_time.Insert (0, "ROOT file creating time : ");
95  host_name.Insert (0, "ROOT file created on Hostname : ");
96  user_name.Insert (0, "ROOT file created by the user : ");
97 
98  program_name.Insert (0, "QwAnalyzer Name : ");
99  argv_list.Insert (0, "QwAnalyzer Options : ");
100  svn_revision.Insert (0, "QwAnalyzer SVN Revision : ");
101  svn_url.Insert (0, "QwAnalyzer SVN URL : ");
102  svn_lc_revision.Insert(0, "QwAnalyzer SVN Last Changed Revision : ");
103 
104  roc_flags.Insert (0, "DAQ ROC flags when QwAnalyzer runs : ");
105 
106  // add them into list to be returned to main program.
107 
108  this -> Add(root_version);
109  this -> Add(program_name);
110  this -> Add(host_name);
111  this -> Add(user_name);
112  this -> Add(argv_list);
113  this -> Add(current_time);
114  this -> Add(svn_revision);
115  this -> Add(svn_url);
116  this -> Add(svn_lc_revision);
117  this -> Add(roc_flags);
118 
119  return;
120 }
121 
122 
123 void
125 {
126  fRunConditionList -> AddLast(new TObjString(in));
127  return;
128 }
129 
130 
131 TList *
133 {
134  return fRunConditionList;
135 }
136 
137 
138 
139 TString
141 {
142  TString name = fRunConditionList->GetName();
143  return name;
144 }
145 
146 
147 void
149 {
150  fRunConditionList->SetName(name);
151  return;
152 }
153 
154 
155 
156 TString
158 {
159 
160  Bool_t local_debug = false;
161  TString flags;
162 
163  std::ifstream flag_file;
164  flag_file.clear();
165 
166  fROCFlagFileName.Insert(0, "/home/cdaq/qweak/Settings/");
167 
168  flag_file.open(fROCFlagFileName);
169 
170  if(not flag_file.is_open()) {
171  std::cout << "There is no flag file, which you try to access "
172  << fROCFlagFileName
173  << std::endl;
174  flags = fROCFlagFileName;
175  flags += " is not found";
176 
177  }
178  else {
179  while (not flag_file.eof() )
180  {
181  TString line;
182  line.ReadLine(flag_file);
183  if(not line.IsNull()) {
184  if(local_debug) {
185  std::cout << line << std::endl;
186  }
187  if(not line.Contains(";")) {
188  flags = line;
189  }
190  } // if(not line.IsNull()) {
191  } // while (not flag_file.eof() ) {
192  }
193  flag_file.close();
194 
195  return flags;
196 
197 }
TString GetROCFlags()
virtual ~QwRunCondition()
#define QWANA_SVN_REVISION
static const double in
Definition: QwUnits.h:66
void Add(TString in)
TString fROCFlagFileName
#define QWANA_SVN_LASTCHANGEDREVISION
void SetArgs(Int_t argc, Char_t *argv[])
void SetName(const TString name)
TList * fRunConditionList
static const Int_t fCharLength
#define QWANA_SVN_URL