1 | #include <valarray>
|
---|
2 |
|
---|
3 | #include <boost/filesystem.hpp>
|
---|
4 |
|
---|
5 | #include "Dim.h"
|
---|
6 | #include "Event.h"
|
---|
7 | #include "Shell.h"
|
---|
8 | #include "StateMachineDim.h"
|
---|
9 | #include "Connection.h"
|
---|
10 | #include "Configuration.h"
|
---|
11 | #include "Console.h"
|
---|
12 |
|
---|
13 | #include "tools.h"
|
---|
14 |
|
---|
15 | #include "externals/zfits.h"
|
---|
16 |
|
---|
17 | namespace ba = boost::asio;
|
---|
18 | namespace bs = boost::system;
|
---|
19 |
|
---|
20 | using namespace std;
|
---|
21 |
|
---|
22 | // ------------------------------------------------------------------------
|
---|
23 |
|
---|
24 | #include "DimDescriptionService.h"
|
---|
25 | #include "DimState.h"
|
---|
26 |
|
---|
27 | // ------------------------------------------------------------------------
|
---|
28 |
|
---|
29 | void SetupConfiguration(Configuration &conf)
|
---|
30 | {
|
---|
31 | po::options_description control("Program options");
|
---|
32 | control.add_options()
|
---|
33 | ("target,t", var<string>()->required(), "")
|
---|
34 | ("event,e", var<uint32_t>()->required(), "")
|
---|
35 | ;
|
---|
36 |
|
---|
37 | po::positional_options_description p;
|
---|
38 | p.add("target", 1); // The first positional options
|
---|
39 | p.add("event", 2); // The second positional options
|
---|
40 |
|
---|
41 | conf.AddOptions(control);
|
---|
42 | conf.SetArgumentPositions(p);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /*
|
---|
46 | Extract usage clause(s) [if any] for SYNOPSIS.
|
---|
47 | Translators: "Usage" and "or" here are patterns (regular expressions) which
|
---|
48 | are used to match the usage synopsis in program output. An example from cp
|
---|
49 | (GNU coreutils) which contains both strings:
|
---|
50 | Usage: cp [OPTION]... [-T] SOURCE DEST
|
---|
51 | or: cp [OPTION]... SOURCE... DIRECTORY
|
---|
52 | or: cp [OPTION]... -t DIRECTORY SOURCE...
|
---|
53 | */
|
---|
54 | void PrintUsage()
|
---|
55 | {
|
---|
56 | cout <<
|
---|
57 | "Retrieve an event from a file in binary representation.\n"
|
---|
58 | "\n"
|
---|
59 | "Usage: getevent [-c type] [OPTIONS]\n"
|
---|
60 | " or: getevent [OPTIONS]\n";
|
---|
61 | cout << endl;
|
---|
62 | }
|
---|
63 |
|
---|
64 | void PrintHelp()
|
---|
65 | {
|
---|
66 | //Main::PrintHelp<StateMachineEventServer>();
|
---|
67 |
|
---|
68 | /* Additional help text which is printed after the configuration
|
---|
69 | options goes here */
|
---|
70 |
|
---|
71 | /*
|
---|
72 | cout << "bla bla bla" << endl << endl;
|
---|
73 | cout << endl;
|
---|
74 | cout << "Environment:" << endl;
|
---|
75 | cout << "environment" << endl;
|
---|
76 | cout << endl;
|
---|
77 | cout << "Examples:" << endl;
|
---|
78 | cout << "test exam" << endl;
|
---|
79 | cout << endl;
|
---|
80 | cout << "Files:" << endl;
|
---|
81 | cout << "files" << endl;
|
---|
82 | cout << endl;
|
---|
83 | */
|
---|
84 | }
|
---|
85 |
|
---|
86 | /*
|
---|
87 | boost::filesystem::recursive_directory_iterator createRIterator(boost::filesystem::path path)
|
---|
88 | {
|
---|
89 | try
|
---|
90 | {
|
---|
91 | return boost::filesystem::recursive_directory_iterator(path);
|
---|
92 | }
|
---|
93 | catch(boost::filesystem::filesystem_error& fex)
|
---|
94 | {
|
---|
95 | std::cout << fex.what() << std::endl;
|
---|
96 | return boost::filesystem::recursive_directory_iterator();
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | void dump(boost::filesystem::path path, int level)
|
---|
101 | {
|
---|
102 | try
|
---|
103 | {
|
---|
104 | std::cout << (boost::filesystem::is_directory(path) ? 'D' : ' ') << ' ';
|
---|
105 | std::cout << (boost::filesystem::is_symlink(path) ? 'L' : ' ') << ' ';
|
---|
106 |
|
---|
107 | for(int i = 0; i < level; ++i)
|
---|
108 | std::cout << ' ';
|
---|
109 |
|
---|
110 | std::cout << path.filename() << std::endl;
|
---|
111 | }
|
---|
112 | catch(boost::filesystem::filesystem_error& fex)
|
---|
113 | {
|
---|
114 | std::cout << fex.what() << std::endl;
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | void plainListTree(boost::filesystem::path path) // 1.
|
---|
119 | {
|
---|
120 | dump(path, 0);
|
---|
121 |
|
---|
122 | boost::filesystem::recursive_directory_iterator it = createRIterator(path);
|
---|
123 | boost::filesystem::recursive_directory_iterator end;
|
---|
124 |
|
---|
125 | while(it != end) // 2.
|
---|
126 | {
|
---|
127 | dump(*it, it.level()); // 3.
|
---|
128 |
|
---|
129 | if (boost::filesystem::is_directory(*it) && boost::filesystem::is_symlink(*it)) // 4.
|
---|
130 | it.no_push();
|
---|
131 |
|
---|
132 | try
|
---|
133 | {
|
---|
134 | ++it; // 5.
|
---|
135 | }
|
---|
136 | catch(std::exception& ex)
|
---|
137 | {
|
---|
138 | std::cout << ex.what() << std::endl;
|
---|
139 | it.no_push(); // 6.
|
---|
140 | try { ++it; } catch(...) { std::cout << "!!" << std::endl; return; } // 7.
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|
144 | */
|
---|
145 |
|
---|
146 | int main(int argc, const char* argv[])
|
---|
147 | {
|
---|
148 | Configuration conf(argv[0]);
|
---|
149 | conf.SetPrintUsage(PrintUsage);
|
---|
150 | SetupConfiguration(conf);
|
---|
151 |
|
---|
152 | if (!conf.DoParse(argc, argv, PrintHelp))
|
---|
153 | return 127;
|
---|
154 |
|
---|
155 | const string name = conf.Get<string>("target");
|
---|
156 | /*
|
---|
157 | if (!conf.Has("event"))
|
---|
158 | {
|
---|
159 | plainListTree(name);
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 | */
|
---|
163 | const uint32_t event = conf.Get<uint32_t>("event");
|
---|
164 |
|
---|
165 | zfits file(name);
|
---|
166 | if (!file)
|
---|
167 | {
|
---|
168 | cerr << name << ": " << strerror(errno) << endl;
|
---|
169 | return 1;
|
---|
170 | }
|
---|
171 |
|
---|
172 | // Php can only read 32bit ints
|
---|
173 | const uint32_t nRows = file.GetNumRows();
|
---|
174 |
|
---|
175 | const uint32_t nRoi = file.GetUInt("NROI");
|
---|
176 | const uint32_t nPix = file.GetUInt("NPIX");
|
---|
177 |
|
---|
178 | const double start = file.GetUInt("TSTARTI")+file.GetFloat("TSTARTF");
|
---|
179 | const double stop = file.GetUInt("TSTOPI")+file.GetFloat("TSTOPF");
|
---|
180 |
|
---|
181 | const bool isDrsCalib = file.GetStr("DRSCALIB")=="T";
|
---|
182 | const int16_t drsStep = isDrsCalib ? file.GetUInt("DRSSTEP") : -1;
|
---|
183 | const string runType = file.GetStr("RUNTYPE");
|
---|
184 | const uint16_t scale = file.HasKey("SCALE") ? file.GetUInt("SCALE") : 0;
|
---|
185 |
|
---|
186 | vector<char> run(80);
|
---|
187 | strncpy(run.data(), runType.c_str(), 79);
|
---|
188 |
|
---|
189 | vector<int16_t> data(nRoi*nPix);
|
---|
190 | vector<uint32_t> unixTimeUTC(2);
|
---|
191 |
|
---|
192 | //uint32_t boardTime[40];
|
---|
193 | uint32_t eventNum;
|
---|
194 | //uint32_t numBoards;
|
---|
195 | //uint16_t startCellData[1440];
|
---|
196 | //uint16_t startCellTimeMarker[160];
|
---|
197 | //uint32_t triggerNum;
|
---|
198 | uint16_t triggerType;
|
---|
199 |
|
---|
200 | file.SetRefAddress("EventNum", eventNum);
|
---|
201 | //file.SetRefAddress("TriggerNum", triggerNum);
|
---|
202 | file.SetRefAddress("TriggerType", triggerType);
|
---|
203 | file.SetVecAddress("UnixTimeUTC", unixTimeUTC);
|
---|
204 | file.SetVecAddress("Data", data);
|
---|
205 |
|
---|
206 | if (!file.GetRow(event))
|
---|
207 | return 2;
|
---|
208 |
|
---|
209 | cout.write(run.data(), 80);
|
---|
210 | cout.write((char*)&start, sizeof(double));
|
---|
211 | cout.write((char*)&stop, sizeof(double));
|
---|
212 | cout.write((char*)&drsStep, sizeof(drsStep));
|
---|
213 | cout.write((char*)&nRows, sizeof(nRows));
|
---|
214 | cout.write((char*)&scale, sizeof(scale));
|
---|
215 |
|
---|
216 | cout.write((char*)&nRoi, sizeof(nRoi));
|
---|
217 | cout.write((char*)&nPix, sizeof(nPix));
|
---|
218 | cout.write((char*)&eventNum, sizeof(eventNum));
|
---|
219 | //cout.write((char*)&triggerNum, sizeof(triggerNum));
|
---|
220 | cout.write((char*)&triggerType, sizeof(triggerType));
|
---|
221 | cout.write((char*)unixTimeUTC.data(), sizeof(uint32_t)*2);
|
---|
222 | cout.write((char*)data.data(), sizeof(int16_t)*nRoi*nPix);
|
---|
223 |
|
---|
224 | return 0;
|
---|
225 | }
|
---|