Class Reference for E1039 Core & Analysis Software
UtilOnline.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <iomanip>
4 #include <TSystem.h>
5 #include "UtilOnline.h"
6 using namespace std;
7 
8 std::string UtilOnline::m_dir_end = "/seaquest/e906daq/coda/data/END";
9 std::string UtilOnline::m_dir_coda = "/localdata/codadata"; // could be "/data3/data/mainDAQ" or "/data2/e1039/codadata".
10 std::string UtilOnline::m_dir_dst = "/data2/e1039/dst";
11 std::string UtilOnline::m_dir_eddst = "/data4/e1039_data/online/evt_disp";
12 std::string UtilOnline::m_dir_onlmon = "/data2/e1039/onlmon/plots";
13 std::string UtilOnline::m_sch_maindaq = "user_e1039_maindaq";
14 
16 {
17  m_dir_dst = "/data2/e1039/dst-devel";
18  m_dir_onlmon = "/data2/e1039/onlmon/plots-devel";
19  m_sch_maindaq = "user_e1039_maindaq_devel";
20 }
21 
22 void UtilOnline::SetEndFileDir(const std::string dir)
23 {
24  m_dir_end = gSystem->ExpandPathName(dir.c_str());
25 }
26 
27 void UtilOnline::SetCodaFileDir(const std::string dir)
28 {
29  m_dir_coda = gSystem->ExpandPathName(dir.c_str());
30 }
31 
32 void UtilOnline::SetDstFileDir(const std::string dir)
33 {
34  m_dir_dst = gSystem->ExpandPathName(dir.c_str());
35 }
36 
37 void UtilOnline::SetEDDstFileDir(const std::string dir)
38 {
39  m_dir_eddst = gSystem->ExpandPathName(dir.c_str());
40 }
41 
42 void UtilOnline::SetOnlMonDir(const std::string dir)
43 {
44  m_dir_onlmon = gSystem->ExpandPathName(dir.c_str());
45 }
46 
47 void UtilOnline::SetSchemaMainDaq(const std::string sch)
48 {
49  m_sch_maindaq = sch;
50 }
51 
53 
56 int UtilOnline::CodaFile2RunNum(const std::string name)
57 {
58  int length = name.length();
59  if (length < 19) return 0; // run_******_spin.dat
60  return atoi(name.substr(length-15, 6).c_str());
61 }
62 
64 std::string UtilOnline::RunNum2CodaFile(const int run)
65 {
66  ostringstream oss;
67  oss << setfill('0') << "run_" << Run6(run) << "_spin.dat";
68  return oss.str();
69 }
70 
72 std::string UtilOnline::RunNum2EndFile(const int run)
73 {
74  ostringstream oss;
75  oss << run << ".end";
76  return oss.str();
77 }
78 
80 std::string UtilOnline::RunNum2DstFile(const int run)
81 {
82  ostringstream oss;
83  oss << setfill('0') << "run_" << Run6(run) << "_spin.root";
84  return oss.str();
85 }
86 
88 std::string UtilOnline::RunNum2EDDstFile(const int run)
89 {
90  ostringstream oss;
91  oss << setfill('0') << "run_" << Run6(run) << "_evt_disp.root";
92  return oss.str();
93 }
94 
96 std::string UtilOnline::GetSpillDstDir(const int run)
97 {
98  ostringstream oss;
99  oss << setfill('0') << m_dir_dst << "/run_" << Run6(run);
100  return oss.str();
101 }
102 
104 std::string UtilOnline::GetSpillDstFile(const int run, const int spill)
105 {
106  ostringstream oss;
107  oss << setfill('0') << "run_" << Run6(run) << "_spill_" << Spill9(spill) << "_spin.root";
108  return oss.str();
109 }
110 
111 std::string UtilOnline::GetSpillDstPath(const int run, const int spill)
112 {
113  return GetSpillDstDir(run) + "/" + GetSpillDstFile(run, spill);
114 }
115 
116 std::vector<std::string> UtilOnline::GetListOfSpillDSTs(const int run, const std::string dir_dst)
117 {
118  ostringstream oss;
119  if (dir_dst != "") oss << dir_dst;
120  else oss << UtilOnline::GetDstFileDir();
121  oss << "/run_" << Run6(run);
122  string dir_run = oss.str();
123 
124  vector<string> list_dst;
125 
126  void* dirp = gSystem->OpenDirectory(dir_run.c_str());
127  if (dirp == 0) return list_dst; // The directory does not exist.
128 
129  const char* name_char;
130  while ((name_char = gSystem->GetDirEntry(dirp))) {
131  string name = name_char;
132  int length = name.length();
133  if (length < 10 ||
134  name.substr(0, 4) != "run_" ||
135  name.substr(length-10, 10) != "_spin.root") continue;
136  list_dst.push_back(dir_run+"/"+name);
137  }
138  gSystem->FreeDirectory(dirp);
139  sort(list_dst.begin(), list_dst.end());
140  return list_dst;
141 }
142 
143 std::string UtilOnline::GetCodaFilePath(const int run)
144 {
145  return GetCodaFileDir() + "/" + RunNum2CodaFile(run);
146 }
147 
148 std::string UtilOnline::GetEndFilePath(const int run)
149 {
150  return GetEndFileDir() + "/" + RunNum2EndFile(run);
151 }
152 
153 std::string UtilOnline::GetDstFilePath(const int run)
154 {
155  return GetDstFileDir() + "/" + RunNum2DstFile(run);
156 }
157 
158 std::string UtilOnline::GetEDDstFilePath(const int run)
159 {
160  return GetEDDstFileDir() + "/" + RunNum2EDDstFile(run);
161 }
162 
163 std::string UtilOnline::Run6(const int run, const int digit)
164 {
165  ostringstream oss;
166  oss << setfill('0') << setw(digit) << run;
167  return oss.str();
168 }
169 
170 std::string UtilOnline::Spill9(const int spill, const int digit)
171 {
172  ostringstream oss;
173  oss << setfill('0') << setw(digit) << spill;
174  return oss.str();
175 }
static std::string GetSpillDstFile(const int run, const int spill)
Convert a run+spill number to the corresponding name of DST file.
Definition: UtilOnline.cc:104
static std::string Spill9(const int spill, const int digit=9)
Definition: UtilOnline.cc:170
static std::string GetDstFilePath(const int run)
Definition: UtilOnline.cc:153
static void SetSchemaMainDaq(const std::string sch)
Definition: UtilOnline.cc:47
static void SetEDDstFileDir(const std::string dir)
Definition: UtilOnline.cc:37
static void UseOutputLocationForDevel()
Definition: UtilOnline.cc:15
static std::string RunNum2EndFile(const int run)
Convert a run number to the corresponding name of END file.
Definition: UtilOnline.cc:72
static int CodaFile2RunNum(const std::string name)
Convert the name of a Coda file to its run number.
Definition: UtilOnline.cc:56
static void SetCodaFileDir(const std::string dir)
Definition: UtilOnline.cc:27
static std::string RunNum2CodaFile(const int run)
Convert a run number to the corresponding name of Coda file.
Definition: UtilOnline.cc:64
static std::string GetCodaFilePath(const int run)
Definition: UtilOnline.cc:143
static void SetOnlMonDir(const std::string dir)
Definition: UtilOnline.cc:42
static std::string GetSpillDstPath(const int run, const int spill)
Definition: UtilOnline.cc:111
static std::string Run6(const int run, const int digit=6)
Definition: UtilOnline.cc:163
static std::string RunNum2DstFile(const int run)
Convert a run number to the corresponding name of DST file.
Definition: UtilOnline.cc:80
static std::string GetEDDstFilePath(const int run)
Definition: UtilOnline.cc:158
static std::vector< std::string > GetListOfSpillDSTs(const int run, const std::string dir_dst="")
Definition: UtilOnline.cc:116
static std::string GetDstFileDir()
Definition: UtilOnline.h:26
static std::string GetEndFilePath(const int run)
Definition: UtilOnline.cc:148
static void SetEndFileDir(const std::string dir)
Definition: UtilOnline.cc:22
static std::string RunNum2EDDstFile(const int run)
Convert a run number to the corresponding name of edDST file.
Definition: UtilOnline.cc:88
static std::string GetSpillDstDir(const int run)
Get a directory of spill-level DST files.
Definition: UtilOnline.cc:96
static void SetDstFileDir(const std::string dir)
Definition: UtilOnline.cc:32