AsciiWriter.cc

00001 #include "AsciiWriter.hh"
00002 #include "ConvertData.hh"
00003 #include "ConfigHandler.hh"
00004 #include "CommandSwitchFunctions.hh"
00005 #include "intarray.hh"
00006 AsciiWriter::AsciiWriter() : 
00007   ChannelModule(GetDefaultName(),
00008                 "Print out each sample for each channel's waveform to a text file") 
00009 {
00010   AddDependency<ConvertData>();
00011   RegisterParameter("filename", _filename = GetDefaultFilename(),
00012                     "Name of the output text file");
00013   ConfigHandler::GetInstance()->
00014     AddCommandSwitch('f',"filename", "Set output ASCII file",
00015                      CommandSwitch::DefaultRead<std::string>(_filename), 
00016                      "file");
00017 }
00018 
00019 AsciiWriter::~AsciiWriter()
00020 {
00021   
00022 }
00023 
00024 int AsciiWriter::Initialize()
00025 {
00026   _wrote_header = false;
00027   if(_filename.find(".txt") == std::string::npos)
00028     _filename.append(".txt");
00029   Message(INFO)<<"Saving text waveforms to file "<<_filename<<std::endl;
00030   _fout.open(_filename.c_str());
00031   if(!_fout.is_open()){
00032     Message(CRITICAL)<<"Unable to open file "<<_filename<<std::endl;
00033     return 1;
00034   }
00035   return 0;
00036 }
00037 
00038 int AsciiWriter::Finalize(){
00039   if(_fout.is_open())
00040     _fout.close();
00041   return 0;
00042 }
00043 
00044 int AsciiWriter::Process(ChannelData* chdata)
00045 {
00046   if(!_wrote_header){
00047     //assume only one channel, or all identical channels
00048     _fout<<chdata->nsamps<<"\t"<<chdata->sample_rate<<"\t"
00049          <<chdata->trigger_index<<std::endl;
00050     _wrote_header = true;
00051   }
00052   double* wave = chdata->GetWaveform();
00053   for(int samp = 0; samp < chdata->nsamps; samp++){
00054       _fout<<wave[samp]<<"\t";
00055   }
00056   _fout<<std::endl;
00057   return 0;
00058 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1