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