3 #include <boost/filesystem.hpp> 17 namespace ba = boost::asio;
18 namespace bs = boost::system;
31 po::options_description control(
"Program options");
33 (
"target,t", var<string>()->required(),
"")
34 (
"event,e", var<uint32_t>(),
"")
37 po::positional_options_description p;
57 "Retrieve an event from a file in binary representation.\n" 59 "Usage: getevent [-c type] [OPTIONS]\n" 60 " or: getevent [OPTIONS]\n";
146 int main(
int argc,
const char* argv[])
155 const string name = conf.
Get<
string>(
"target");
163 const uint32_t
event = conf.
Has(
"event") ? conf.
Get<uint32_t>(
"event") : 0;
168 cerr << name <<
": " << strerror(errno) << endl;
173 const uint32_t nRows = file.GetNumRows();
175 const uint32_t nRoi = file.GetUInt(
"NROI");
176 const uint32_t nPix = file.GetUInt(
"NPIX");
178 const bool isMC = file.HasKey(
"ISMC") && file.GetStr(
"ISMC")==
"T";
181 const int8_t step = file.HasKey(
"STEP") ? file.GetUInt(
"STEP") : -1;
183 const string strbeg = isMC ?
"DATE" :
"RUN"+to_string(step)+
"-BEG";
184 const string strend = isMC ?
"DATE" :
"RUN"+to_string(step)+
"-END";
186 const double start = step==-1 && !isMC ? file.GetUInt(
"TSTARTI")+file.GetFloat(
"TSTARTF") :
Time(file.GetStr(strbeg)).UnixDate();
187 const double stop = step==-1 && !isMC ? file.GetUInt(
"TSTOPI")+file.GetFloat(
"TSTOPF") :
Time(file.GetStr(strend)).UnixDate();
189 const bool isDrsCalib = file.HasKey(
"DRSCALIB") && file.GetStr(
"DRSCALIB")==
"T";
190 const int16_t drsStep = isDrsCalib ? file.GetUInt(
"DRSSTEP") : step;
191 const string runType = step==-1 ? file.GetStr(
"RUNTYPE") :
"";
192 const uint16_t scale = file.HasKey(
"SCALE") ? file.GetUInt(
"SCALE") : (step==-1?0:10);
194 vector<char>
run(80);
195 vector<int16_t>
data(nRoi*nPix);
196 vector<float> mean(nRoi*nPix);
197 vector<uint32_t> unixTimeUTC(2);
205 uint16_t triggerType;
209 file.SetRefAddress(
"EventNum", eventNum);
211 file.SetRefAddress(
"TriggerType", triggerType);
213 file.SetVecAddress(
"UnixTimeUTC", unixTimeUTC);
229 case 0: file.SetVecAddress(
"BaselineMean", mean); strcpy( run.data(),
"DRS (pedestal 1024)");
break;
230 case 1: file.SetVecAddress(
"GainMean", mean); strcpy( run.data(),
"DRS (gain)");
break;
231 case 2: file.SetVecAddress(
"TriggerOffsetMean", mean); strcpy( run.data(),
"DRS (pedestal roi)");
break;
232 default: file.SetVecAddress(
"Data", data); strncpy(run.data(), runType.c_str(), 79);
break;
235 if (!file.GetRow(step==-1 ? event : 0))
239 for (uint32_t
i=0;
i<nRoi*nPix;
i++)
240 data[
i] = round(mean[
i]*10);
242 cout.write(run.data(), 80);
243 cout.write((
char*)&start,
sizeof(
double));
244 cout.write((
char*)&stop,
sizeof(
double));
245 cout.write((
char*)&drsStep,
sizeof(drsStep));
246 cout.write((
char*)&nRows,
sizeof(nRows));
247 cout.write((
char*)&scale,
sizeof(scale));
249 cout.write((
char*)&nRoi,
sizeof(nRoi));
250 cout.write((
char*)&nPix,
sizeof(nPix));
251 cout.write((
char*)&eventNum,
sizeof(eventNum));
253 cout.write((
char*)&triggerType,
sizeof(triggerType));
254 cout.write((
char*)unixTimeUTC.data(),
sizeof(uint32_t)*2);
255 cout.write((
char*)data.data(),
sizeof(int16_t)*nRoi*nPix);
Adds some functionality to boost::posix_time::ptime for our needs.
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
int main(int argc, const char *argv[])
void SetArgumentPositions(const po::positional_options_description &desc)
bool Has(const std::string &var)
void AddOptions(const po::options_description &opt, bool visible=true)
Commandline parsing, resource file parsing and database access.
void SetupConfiguration(Configuration &conf)
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())