Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Daemon4MainDaq.C
Go to the documentation of this file.
1 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
3 R__LOAD_LIBRARY(libdecoder_maindaq)
4 #endif
5 
6 bool FindExistingRuns(vector<int>& list_run)
7 {
8  list_run.clear();
9  void *dirp = gSystem->OpenDirectory(UtilOnline::GetCodaFileDir().c_str());
10  if (dirp == 0) return false; // The directory does not exist.
11  const char* name_char;
12  while ((name_char = gSystem->GetDirEntry(dirp))) {
13  string name = name_char;
14  int length = name.length();
15  if (length < 4 || name.substr(length-4, 4) != ".dat") continue;
16  int run = UtilOnline::CodaFile2RunNum(name);
17  list_run.push_back(run);
18  }
19 
20  gSystem->FreeDirectory(dirp);
21 
22  sort(list_run.begin(), list_run.end());
23  //cout << "Runs:";
24  //for (vector<int>::iterator it = list_run.begin(); it != list_run.end(); it++) cout << " " << *it;
25  //cout << endl;
26  return true;
27 }
28 
29 void StartDecoder(const int run, const int n_evt=0, const bool is_online=true)
30 {
31  ostringstream oss;
32  oss << "/dev/shm/decoder_maindaq";
33  gSystem->mkdir(oss.str().c_str(), true);
34  oss << "/log_" << setfill('0') << setw(6) << run << ".txt";
35  string fn_log = oss.str();
36  if (! gSystem->AccessPathName(fn_log.c_str())) { // if exists
37  for (int ii = 1; true; ii++) {
38  oss.str("");
39  oss << fn_log << "." << ii;
40  if (gSystem->AccessPathName(oss.str().c_str())) {
41  cout << "Rename the existing log file with suffix=" << ii << "." << endl;
42  gSystem->Rename(fn_log.c_str(), oss.str().c_str());
43  break;
44  }
45  }
46  }
47 
48  oss.str("");
49  oss << "root.exe -b -q '" << gSystem->Getenv("E1039_CORE")
50  << "/macros/online/Fun4MainDaq.C(" << run << ", " << n_evt << ", " << is_online << ")' &>" << fn_log << " &";
51 
52  cout << "Start the decoder for run " << run << ":\n"
53  << " Log file = " << fn_log << "\n"
54  << " Command: " << oss.str() << endl;
55  gSystem->Exec(oss.str().c_str());
56 }
57 
58 int Daemon4MainDaq(const int interval=30)
59 {
60  gSystem->Load("libdecoder_maindaq.so");
61 
62  vector<int> list_run_done;
63  while (! FindExistingRuns(list_run_done)) {
64  cout << "The Coda-file directory seems not mounted. Wait for 1 min." << endl;
65  sleep(60);
66  }
67  //list_run_done.clear(); // for test
68 
69  while (true) {
70  cout << "Sleep for " << interval << " sec. Hit Ctrl-C to quit..." << endl;
71  sleep(interval);
72  vector<int> list_run;
73  if (! FindExistingRuns(list_run)) {
74  cout << "The Coda-file directory doesn't exist. Strange but just wait." << endl;
75  continue;
76  }
77  for (vector<int>::iterator it = list_run.begin(); it != list_run.end(); it++) {
78  int run = *it;
79  if (find(list_run_done.begin(), list_run_done.end(), run) == list_run_done.end()) {
80  list_run_done.push_back(run);
81  StartDecoder(run);
82  }
83  }
84  }
85 
86  return 0;
87 }
int run(const int nEvents=1)
Definition: run.C:10
static std::string GetCodaFileDir()
Definition: UtilOnline.h:24
static int CodaFile2RunNum(const std::string name)
Convert the name of a Coda file to its run number.
Definition: UtilOnline.cc:25
bool FindExistingRuns(vector< int > &list_run)
Daemon4MainDaq.C.
Definition: Daemon4MainDaq.C:6
void StartDecoder(const int run, const int n_evt=0, const bool is_online=true)
int Daemon4MainDaq(const int interval=30)