getDUNEPedestals.cc
Go to the documentation of this file.
2 
3 #include <getopt.h>
4 #include <iostream>
5 #include <boost/tokenizer.hpp>
6 #include <boost/lexical_cast.hpp>
7 
8 bool gUseDB = false;
9 bool gPrintPedRun = false;
10 int gRun = -1;
13 std::vector<uint64_t> gChannelList{};
14 
15 //------------------------------------------------------------
16 
17 void PrintUsage()
18 {
19  std::cout << "Usage: RunInfo [options] -r|--run [run number] -d|--detector [detector name, eg, dune35t]" << std::endl;
20  std::cout << "Options:" << std::endl;
21  std::cout << "-f (--file) [fhicl file] : use fhicl config file" << std::endl;
22  std::cout << "-D (--database) : get peds from database" << std::endl;
23  std::cout << "-P (--pedestalRun) : print pedestal run" << std::endl;
24  std::cout << "-C [chan1,chan2,...] : print only specific channels" << std::endl;
25 }
26 
27 //------------------------------------------------------------
28 
29 bool ParseCLArgs(int argc, char* argv[])
30 {
31 
32  if (argc < 2) return false;
33 
34  struct option long_options[] = {
35  {"help", 0, 0, 'h'},
36  {"run", 0, 0, 'r'},
37  {"detector", 0, 0, 'd'},
38  {"file", 0, 0, 'f'},
39  {"database", 0, 0, 'D'},
40  {"pedestalRun", 0, 0, 'P'},
41  {0,0,0,0}
42  };
43 
44  while (1) {
45  int optindx;
46 
47  int c = getopt_long(argc,argv,"r:d:f:C:DPh",long_options,&optindx);
48 
49  if (c==-1) break;
50 
51  switch(c) {
52  case 'r':
53  {
54  int run = atoi(optarg);
55  if (run < 0) {
56  std::cout << "Invalid run number." << std::endl;
57  exit(0);
58  }
59  gRun = run;
60  break;
61  }
62  case 'd':
63  {
64  gDetName = optarg;
65  break;
66  }
67  case 'D':
68  {
69  gUseDB = true;
70  break;
71  }
72  case 'P':
73  {
74  gPrintPedRun = true;
75  break;
76  }
77  case 'f':
78  {
79  gCfgFile = optarg;
80  break;
81  }
82  case 'h':
83  {
84  PrintUsage();
85  exit(0);
86  break;
87  }
88  case 'C':
89  {
90  std::vector<std::string> cList;
91  std::string channels = optarg;
92  boost::tokenizer< boost::escaped_list_separator<char> > tok(channels);
93  cList.assign(tok.begin(),tok.end());
94  for (size_t i=0; i<cList.size(); ++i) {
95  try {
96  gChannelList.push_back(boost::lexical_cast<uint64_t>(cList[i]));
97  }
98  catch (const boost::bad_lexical_cast &) {
99  std::cout << cList[i] << " does not appear to be a channel id, skipping"
100  << std::endl;
101  continue;
102  }
103  }
104  break;
105  }
106  default:
107  break;
108  }
109  }
110 
111  return true;
112 }
113 
114 //------------------------------------------------------------
115 
116 int main(int argc, char **argv)
117 {
118  if (!ParseCLArgs(argc,argv)) {
119  PrintUsage();
120  return 1;
121  }
122 
124 
125  /*
126  if (gCfgFile != "")
127  ped->Configure(gCfgFile);
128  */
129 
130  if (gUseDB) {
131  ped->SetUseDB(gUseDB);
132  ped->Update(gRun);
133  }
134 
135  if (gPrintPedRun) {
136  std::cout << "Pedestal run: " << ped->VldTimeUsed() << std::endl;
137  }
138 
139  if (gChannelList.empty())
140  ped->PrintAllValues();
141  else {
142  for (size_t i=0; i<gChannelList.size(); ++i)
143  std::cout << "Channel: " << gChannelList[i]
144  << ", Mean = " << ped->PedMean(gChannelList[i])
145  << ", RMS = " << ped->PedRms(gChannelList[i])
146  << std::endl;
147  }
148 
149  delete ped;
150 
151  return 0;
152 }
153 
std::string string
Definition: nybbler.cc:12
int main(int argc, char **argv)
void PrintUsage()
uint64_t VldTimeUsed() const
std::string gDetName
virtual float PedMean(raw::ChannelID_t ch) const
Retrieve pedestal information.
virtual float PedRms(raw::ChannelID_t ch) const
bool gPrintPedRun
std::string gCfgFile
int gRun
bool ParseCLArgs(int argc, char *argv[])
bool Update(uint64_t ts)
std::vector< uint64_t > gChannelList
bool gUseDB
QTextStream & endl(QTextStream &s)
unsigned int run