#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <unistd.h>
#include "RawData/RawRecord.h"
#include "RawData/RawRecordFormat.h"
#include "RawData/RawDataReader.h"
#include "RootRawWriter/RRawTree.h"
Include dependency graph for RootRawWriter.cc:
Go to the source code of this file.
Functions | |
int | usage (int code, string extra_message) |
Print the usage. | |
int | main (int argc, char **argv) |
Start of the code. | |
Variables | |
const char * | usage_string |
char * | optarg |
Version dependent. | |
int | optind |
int | opterr |
int | optopt |
int usage | ( | int | code, | |
const string | extra_message = "" | |||
) |
Print the usage.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Start of the code.
Process file names
Hold the file names of all dat files
Test suffix which must be '.data' or '.list'
For single file input
For a list of files
record each line
Loop over every file. Do the conversion
Make reader an open raw data file
Open a ".data" file
rraw writter
Open a ".rraw" file, and the new file will be stored at the same location
Loop over each record
Check errors
Get buffer size
For DataSeparator, the size of the buffer is the sum of DataSeparator and the its following data block.
It is in byte, anyway.
Convert .data to .rraw
Stop at the record of 'end of file'
Definition at line 51 of file RootRawWriter.cc.
00051 { 00052 int c=0; 00053 const char* outdir = 0; 00054 while ((c=getopt(argc,argv,"d:h?")) != EOF) { 00055 switch(c) { 00056 case 'd': 00057 outdir = optarg; 00058 break; 00059 case 'h': 00060 case '?': 00061 return usage(0); 00062 } 00063 } 00064 00066 if( argc == 1 ) { 00067 return usage(1,"Require at least one input file."); 00068 } 00069 00071 vector<string> filenames; 00072 00073 for (int ind = optind; ind < argc; ++ind) { 00074 00076 string parameter = argv[ind]; 00077 string suffix = parameter.substr(parameter.size()-5,5); 00078 if( suffix != ".data" && suffix != ".list") { 00079 string msg = "Error: File extension \"" +suffix+ "\" not recognized."; 00080 return usage(1,msg); 00081 } 00082 00084 if( suffix == ".data" ) { 00085 filenames.push_back(parameter.c_str()); 00086 continue; 00087 } 00088 00090 if( suffix == ".list" ) { 00091 ifstream filelist; 00092 filelist.open(parameter.c_str(), ios::in); 00093 00095 string aLine; 00096 while(filelist >> aLine) { 00097 filenames.push_back(aLine); 00098 } 00099 00100 filelist.close(); 00101 } 00102 } 00103 00104 00106 for(unsigned int ci=0; ci<filenames.size(); ci++) { 00107 cout<<"RRaw::Processing "<<filenames[ci]<<endl; 00108 00110 DayaBay::RawDataReader rr; 00111 00113 bool ok = rr.open( filenames[ci].c_str() ); 00114 if(!ok){ 00115 cerr << "Failed to open " << filenames[ci] << endl; 00116 string msg = "Failed to open: \"" + filenames[ci] + "\""; 00117 return usage(1, msg); 00118 } 00119 00121 RRawTree rrtree; 00122 00124 string newfile = filenames[ci]; 00125 newfile.replace(newfile.size()-4,4,"rraw"); 00126 00127 // But, if user wants output to go to some specific directory, 00128 // munge the filename to match 00129 if (outdir) { 00130 string::size_type ind = newfile.rfind("/"); 00131 if (ind != string::npos) { 00132 newfile = newfile.substr(ind); 00133 } 00134 else { 00135 newfile = "/" + newfile; 00136 } 00137 newfile = outdir + newfile; 00138 } 00139 00140 // Do not modify this line, scripts rely on it! 00141 cout << "RRaw::Processing to output file: " << newfile<< endl; 00142 00143 int status = rrtree.open(newfile.c_str()); 00144 if (!status) { 00145 cout <<"failed to open file: " << newfile << endl; 00146 return 2; 00147 } 00148 00150 DayaBay::RawRecord* record; 00151 unsigned int nRecord; 00152 for( nRecord=1; /*empty field*/ ;nRecord++ ) { 00153 record = rr.nextRecord(); 00154 00156 if(!record) { 00157 return usage(2,"Error: Failed to load one record in raw data file."); 00158 } 00159 //cout<<record->size()<<endl; 00160 //record->dump( cout ); 00161 00163 unsigned int bufferSize = record->size(); 00164 00167 if( record->type() == RecordFormat::DataSeparator::type ) { 00168 DayaBay::RawDataSeparator* pSeparator 00169 = dynamic_cast<DayaBay::RawDataSeparator*> (record); 00170 unsigned int bytes = pSeparator->blockSize(); 00171 unsigned int lines = (bytes+sizeof(unsigned int)-1)/sizeof(unsigned int); 00172 bufferSize = bufferSize + lines; 00173 } 00174 00176 rrtree.fill( (Int32*)(record->buffer()), (Int32)bufferSize ); 00177 00179 if( record->type() == RecordFormat::FileEnd::type ) break; 00180 } // end of each record 00181 00182 rrtree.close(); 00183 00184 cout<<"Read in "<<nRecord<<" records"<<endl; 00185 00186 } // end of every file 00187 00188 00189 return 0; // 0 is unix standard for successful 00190 } // end of main
const char* usage_string |
Initial value:
"\n\ Usage: \n\ RootRawWriter.exe [options] [aRawData.data|aRawData.list] ...\n\ In the \"aRawData.list\" each line is a \".data\" file name.\n\ By default the \".rraw\" file is made next to the \".data\" file.\n\ \n\ options:\n\ -d outdir: specify an output directory\n\ \n\ return codes:\n\ 0: standard unix code for success\n\ 1: error, no output produced\n\ 2: error, partial output may have been produced\n\ "
Definition at line 5 of file RootRawWriter.cc.
char* optarg |
Version dependent.
int optind |
int opterr |
int optopt |