FindNearlineFiles.h
Go to the documentation of this file.
1 #ifndef FINDNEARLINEFILES_H
2 #define FINDNEARLINEFILES_H
3 
4 #include <string>
5 
7 {
8 public:
9  int fMinAge = 0;
10  int fMaxAge = 1;
11  std::string fBaseDataPath = "/nova/data/nearline-";
12  std::string fDetector = "NearDet";
13  std::string fType = "OnMon";
16  std::string fOutFileName = "nearline-file-list.txt";
17 
18 public:
19  // ..........................................................................
20  void PrintUsage()
21  {
23  std::cout << "Usage: FindNearlineFiles [options]" << std::endl;
24 
25  std::cout << "\n options:" << std::endl;
26  std::cout << "\t -d (--detector) : FarDet, NearDet, TestBeam" << std::endl;
27  std::cout << "\t -h (--help) : print this screen" << std::endl;
28  std::cout << "\t -m (--minage) : minimum age of returned files (days, default: 0)" <<std::endl;
29  std::cout << "\t -a (--maxage) : maximum age of returned files (days, default: 1)" <<std::endl;
30  std::cout << "\t -o (--outfile) : path to out file" << std::endl;
31  std::cout << "\t -p (--path) : path to data releases" << std::endl;
32  std::cout << "\t -s (--stream) : data stream" << std::endl;
33  std::cout << "\t -t (--type) : filetypes (onmon or ana)" << std::endl;
35  }
36 
37  // ..........................................................................
39  {
40  std::string fMinLabel = (this->fMinAge) == 1 ? " day" : " days";
41  std::string fMaxLabel = (this->fMaxAge) == 1 ? " day" : " days";
43  std::cout << "NEARLINE FILE FINDER" << std::endl;
45  std::cout << "Detector: " << this->fDetector << std::endl;
46  std::cout << "Type: " << this->fType << std::endl;
47  std::cout << "Stream: " << this->fStream << std::endl;
48  std::cout << "Min age: " << this->fMinAge << fMinLabel << std::endl;
49  std::cout << "Max age: " << this->fMaxAge << fMaxLabel << std::endl;
50  std::cout << "Period: " << this->fDetector << std::endl;
51  std::cout << "Save to file: " << this->fOutFileName << std::endl;
55 
56  };
57 
58  //..........................................................................
59  bool ParseArguments(int argc, char **argv)
60  {
61 
62  // connects short args to long args
63  struct option long_options[] = {
64  {"help", 0, 0, 'h'},
65  {"detector", 1, 0, 'd'},
66  {"minage", 1, 0, 'm'},
67  {"maxage", 1, 0, 'a'},
68  {"outfile", 1, 0, 'o'},
69  {"path", 1, 0, 'p'},
70  {"stream", 1, 0, 's'},
71  {"type", 1, 0, 't'},
72  {0, 0, 0, 0}
73  };
74 
75  // loop over arguments
76  while (1) {
77  int optindx;
78  int c = getopt_long(argc, argv, "d:m:a:o:p:s:t:h", long_options, &optindx);
79 
80  if (c == -1) break; // Something will have gone terribly wrong...
81 
82  switch (c) {
83  case 'h':
84  PrintUsage();
85  exit(0);
86  case 'm':
87  this->fMinAge = atoi(optarg);
88  break;
89  case 'a':
90  this->fMaxAge = atoi(optarg);
91  break;
92  case 'd':
93  this->fDetector = (std::string)optarg;
94  std::transform(this->fDetector.begin(), this->fDetector.end(), this->fDetector.begin(), ::tolower);
95  if (this->fDetector == "fardet"){
96  this->fDetector = "FarDet";
97  break;
98  }
99  if (this->fDetector == "neardet") {
100  this->fDetector = "NearDet";
101  break;
102  }
103  if (this->fDetector == "testbeam") {
104  this->fDetector = "TestBeam";
105  break;
106  }
107  std::cerr << "Invalid detector specified: " << this->fDetector << std::endl;
108  return false;
109  case 'o':
110  this->fOutFileName = (std::string)optarg;
111  break;
112  case 'p':
113  this->fBaseDataPath = (std::string)optarg;
114  break;
115  case 's':
116  this->fStream = (std::string)optarg;
117  break;
118  case 't':
119  this->fType = (std::string)optarg;
120  std::transform(this->fType.begin(), this->fType.end(), this->fType.begin(), ::tolower);
121  if (this->fType == "onmon") {
122  this->fType = "OnMon";
123  break;
124  }
125  if (this->fType == "ana") {
126  this->fType = "Ana";
127  this->fForm = "hist";
128  break;
129  }
130  std::cerr << "Invalid file type specified: " << this->fType << std::endl;
131  return false;
132  default:
133  break;
134  }
135  }
136 
137  // something went wrong if we made it this far
138  return true;
139  }
140 };
141 
142 #endif
std::string fOutFileName
OStream cerr
Definition: OStream.cxx:7
bool ParseArguments(int argc, char **argv)
std::string fBaseDataPath
OStream cout
Definition: OStream.cxx:6
exit(0)
enum BeamMode string