-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathorcaroot_minesh.cc
146 lines (126 loc) · 4.75 KB
/
orcaroot_minesh.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <stdlib.h>
#include <getopt.h>
#include <string>
#include "ORBasicTreeWriter.hh"
#include "ORDataProcManager.hh"
#include "ORFileReader.hh"
#include "ORFileWriter.hh"
#include "ORHistWriter.hh"
#include "ORLogger.hh"
#include "ORShaperShaperTreeWriter.hh"
#include "ORSocketReader.hh"
#include "ORTek754DScopeDataTreeWriter.hh"
#include "ORAD811ADCDecoder.hh"
#include "ORAD413ADCDecoder.hh"
#include "ORL2551ScalersTreeWriter.hh"
using namespace std;
static const char Usage[] =
"\n"
"\n"
"Usage: orcaroot [options] [input file(s) / socket host:port]\n"
"\n"
"The one required argument is either the name of a file to be processed or\n"
"a host and port of a socket from which to read data. For a file, you may\n"
"enter a series of files to be processed, or use a wildcard like \"file*.dat\"\n"
"For a socket, the argument should be formatted as host:port.\n"
"\n"
"Available options:\n"
" --help : print this message and exit\n"
" --verbosity [verbosity] : set the severity/verbosity for the logger.\n"
" Choices are: debug, trace, routine, warning, error, and fatal.\n"
" --label [label] : use [label] as prefix for root output file name.\n"
"\n"
"Example usage:\n"
"orcaroot run194ecpu\n"
" Rootify local file run194ecpu with default verbosity, output file label, etc.\n"
"orcaroot run*\n"
" Same as before, but run over all files beginning with \"run\".\n"
"orcaroot --verbosity debug --label mylabel run194ecpu\n"
" The same, but with example usage of the verbosity and mylabel options.\n"
" An output file will be created with name mylabel_run194.root, and lots\n"
" of debugging output will appear.\n"
"orcaroot 128.95.100.213:44666\n"
" Rootify orca stream on host 128.95.100.213, port 44666 with default verbosity,\n"
" output file label, etc.\n"
"\n"
"\n";
int main(int argc, char** argv)
{
if(argc == 1) {
ORLog(kError) << "You must supply some options" << endl << Usage;
return 1;
}
static struct option longOptions[] = {
{"help", no_argument, 0, 'h'},
{"verbosity", required_argument, 0, 'v'},
{"label", required_argument, 0, 'l'},
};
string label = "OR";
ORVReader* reader = NULL;
while(1) {
char optId = getopt_long(argc, argv, "", longOptions, NULL);
if(optId == -1) break;
switch(optId) {
case('h'): // help
cout << Usage;
return 0;
case('v'): // verbosity
if(strcmp(optarg, "debug") == 0) ORLogger::SetSeverity(ORLogger::kDebug);
else if(strcmp(optarg, "trace") == 0) ORLogger::SetSeverity(ORLogger::kTrace);
else if(strcmp(optarg, "routine") == 0) ORLogger::SetSeverity(ORLogger::kRoutine);
else if(strcmp(optarg, "warning") == 0) ORLogger::SetSeverity(ORLogger::kWarning);
else if(strcmp(optarg, "error") == 0) ORLogger::SetSeverity(ORLogger::kError);
else if(strcmp(optarg, "fatal") == 0) ORLogger::SetSeverity(ORLogger::kFatal);
else {
ORLog(kWarning) << "Unknown verbosity setting " << optarg
<< "; using kRoutine" << endl;
ORLogger::SetSeverity(ORLogger::kRoutine);
}
break;
case('l'): // label
label = optarg;
break;
default: // unrecognized option
ORLog(kError) << Usage;
return 1;
}
}
if (argc <= optind) {
ORLog(kError) << "You must supply a filename or socket host:port" << endl
<< Usage << endl;
return 1;
}
string readerArg = argv[optind];
size_t iColon = readerArg.find(":");
if (iColon == string::npos) {
reader = new ORFileReader;
for (int i=optind; i<argc; i++) {
((ORFileReader*) reader)->AddFileToProcess(argv[i]);
}
} else {
reader = new ORSocketReader(readerArg.substr(0, iColon).c_str(),
atoi(readerArg.substr(iColon+1).c_str()));
}
if (!reader->OKToRead()) {
ORLog(kError) << "Reader couldn't read" << endl;
return 1;
}
ORLog(kRoutine) << "Setting up data processing manager..." << endl;
ORDataProcManager dataProcManager(reader);
ORLog(kRoutine) << "Opening output file..." << endl;
ORFileWriter fileWriter(label);
dataProcManager.AddProcessor(&fileWriter);
ORAD811ADCDecoder camac811ADCDecoder;
ORBasicTreeWriter camac811ADCTreeWriter(&camac811ADCDecoder, "Camac811ADCTree");
dataProcManager.AddProcessor(&camac811ADCTreeWriter);
ORL2551ScalersTreeWriter scalersTreeWriter("ScalersTree");
dataProcManager.AddProcessor(&scalersTreeWriter);
// ORAD413ADCDecoder camac413ADCDecoder;
// ORBasicTreeWriter camac413ADCTreeWriter(&camac413ADCDecoder, "Camac413ADCTree");
// dataProcManager.AddProcessor(&camac413ADCTreeWriter);
ORLog(kRoutine) << "Start processing..." << endl;
dataProcManager.ProcessDataStream();
ORLog(kRoutine) << "Finished processing..." << endl;
delete reader;
return 0;
}