本文整理汇总了C++中FileReader::IsOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::IsOpen方法的具体用法?C++ FileReader::IsOpen怎么用?C++ FileReader::IsOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::IsOpen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
bool
GastofDQM(unsigned int address, string filename, vector<string>* outputs)
{
cout << "filename: " << filename << endl;
FileReader reader;
try { reader.Open(filename); } catch (Exception& e) { throw e; }
if (!reader.IsOpen()) throw Exception(__PRETTY_FUNCTION__, "Failed to build FileReader", JustWarning);
cout << "Run/Burst Id = " << reader.GetRunId() << " / " << reader.GetBurstId() << endl;
const unsigned int num_channels = 32;
double mean_num_events[num_channels], mean_tot[num_channels];
int trigger_td;
unsigned int num_events[num_channels];
enum plots {
kDensity,
kMeanToT,
//kTriggerTimeDiff,
kNumPlots
};
const unsigned short num_plots = kNumPlots;
DQM::GastofCanvas* canv[num_plots];
canv[kDensity] = new DQM::GastofCanvas(Form("gastof_%d_%d_%d_channels_density", reader.GetRunId(), reader.GetBurstId(), address), "Channels density");
canv[kMeanToT] = new DQM::GastofCanvas(Form("gastof_%d_%d_%d_mean_tot", reader.GetRunId(), reader.GetBurstId(), address), "Mean ToT (ns)");
//canv[kTriggerTimeDiff] = new DQM::GastofCanvas(Form("gastof_%d_%d_%d_trigger_time_difference", reader.GetRunId(), reader.GetBurstId(), address), "Time btw. each trigger (ns)");
VME::TDCMeasurement m;
for (unsigned int i=0; i<num_channels; i++) {
unsigned short nino_board, ch_id;
mean_num_events[i] = mean_tot[i] = 0.;
num_events[i] = 0;
trigger_td = 0;
try {
if (i<32) { nino_board = 1; ch_id = i; }
else { nino_board = 0; ch_id = i-32; }
while (true) {
if (!reader.GetNextMeasurement(i, &m)) break;
//if (trigger_td!=0) { canv[kTriggerTimeDiff]->FillChannel(nino_board, ch_id, (m.GetLeadingTime(0)-trigger_td)*25./1.e3); }
trigger_td = m.GetLeadingTime(0);
for (unsigned int j=0; j<m.NumEvents(); j++) {
mean_tot[i] += m.GetToT(j)*25./1.e3/m.NumEvents();
}
mean_num_events[i] += m.NumEvents();
if (m.NumEvents()!=0) num_events[i] += 1;
}
if (num_events[i]>0) {
mean_num_events[i] /= num_events[i];
mean_tot[i] /= num_events[i];
}
canv[kDensity]->FillChannel(nino_board, ch_id, mean_num_events[i]);
canv[kMeanToT]->FillChannel(nino_board, ch_id, mean_tot[i]);
cout << dec;
cout << "Finished extracting channel " << i << ": " << num_events[i] << " measurements, "
<< "mean number of hits: " << mean_num_events[i] << ", "
<< "mean tot: " << mean_tot[i] << endl;
reader.Clear();
} catch (Exception& e) {
e.Dump();
if (e.ErrorNumber()<41000) throw e;
}
}
for (unsigned int i=0; i<num_plots; i++) {
canv[i]->SetRunInfo(address, reader.GetRunId(), reader.GetBurstId(), TDatime().AsString());
canv[i]->Save("png", DQM_OUTPUT_DIR);
outputs->push_back(canv[i]->GetName());
}
return true;
}
示例2: BenchmarkDArray
void BenchmarkDArray(Sorter<char *> &sorter)
{
DArray<char *> data, rdata;
Stopwatch sw;
char buffer[512], format[64];
sprintf(format, "%s", "%4.3lfs");
FileReader file;
file.SetLineEndings(CC_LN_LF);
file.Open("dataset");
if (file.IsOpen()) {
data.setStepDouble();
rdata.setStepDouble();
console->Write("Loading... ");
sw.Start();
/* Load the file into the data DArray */
while (file.ReadLine(buffer, sizeof(buffer)) >= 0)
data.insert(cc_strdup(buffer));
sw.Stop();
console->WriteLine(format, sw.Elapsed());
file.Close();
console->WriteLine("Loaded %d items.", data.used());
console->Write("Random: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
/* Create a reverse-sorted DArray */
for (long i = (long)data.size(); i >= 0; i--) {
if (data.valid(i)) {
rdata.insert(data.get(i));
}
}
console->Write("Pre-sorted: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
console->Write("Reverse-sorted: ");
sw.Start();
rdata.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
for (size_t i = 0; i < data.size(); i++) {
if (data.valid(i)) {
free(data.get(i));
data.remove(i);
}
}
data.empty();
rdata.empty();
} else {
console->WriteLine("Dataset not found.");
}
}