00001 #include "ScanResultWriter.h"
00002 #include "dataTypes.h"
00003 #include "ipc/core.h"
00004
00005 #include <CommonWithDsp/processor.h>
00006 #include <Sct/AbcdModule.h>
00007 #include <Sct/AbcdScans.h>
00008
00009 #include <cstdio>
00010 #include <sstream>
00011 #include <cstring>
00012 #include <ctime>
00013
00014 using namespace std;
00015 using namespace SctData;
00016
00017
00018 scan_result_ptrs* readFile(const char* name);
00019 void help();
00020 void publish(scan_result_ptrs& scanResult, unsigned int i);
00021
00022
00023
00024 int main(int argc, char** argv) {
00025 if (argc != 3) help();
00026
00027 Sct::setExceptionHandlers(argv[0]);
00028 IPCCore::init(argc, argv);
00029
00030 scan_result_ptrs* scanResult = readFile(argv[1]);
00031 if (!scanResult) {
00032 cout << "Failed to read in file: " << argv[1] << endl;
00033 return -1;
00034 }
00035
00036 unsigned int publishCount = 0;
00037 string pCountStr(argv[2]);
00038 istringstream iss(pCountStr);
00039 iss >> publishCount;
00040
00041 cout << "Going to publish file: " << argv[1] << " " << publishCount << " times" << endl;
00042 cout << "RunNumber: " << scanResult->header.runNumber << " Module: " << scanResult->header.moduleName << endl;
00043 cout << "ScanNumbers will start from 0" << endl;
00044
00045 time_t start = time(0);
00046 time_t last10 = start;
00047 cout << "Start time: " << start << endl;
00048
00049 for (unsigned int i=0; i<publishCount; ++i) {
00050 if (i%10 == 0 && i>0) {
00051 time_t now = time(0);
00052 cout << "Published scan: " << i-1 << endl;
00053 cout << "Time now: " << now << " Time to do last 10: " << difftime(now, last10) << " seconds. Average: " << difftime(now, last10)/10 << " s" << endl;
00054 last10 = now;
00055 }
00056 if (i%100 == 0 && i>0) cout << endl;
00057 publish(*scanResult, i);
00058 }
00059
00060 cout << endl << "Finished" << endl << endl;
00061 time_t now = time(0);
00062 cout << "Time now: " << now << " Total Time: " << difftime(now, start) << " seconds. Average: " << flush << difftime(now, start)/publishCount << " s" << endl;
00063
00064 delete [] scanResult->points;
00065 delete [] scanResult->nEvents;
00066 delete [] scanResult->nErrorEvents;
00067 delete [] (short*)scanResult->data;
00068
00069 return 0;
00070 }
00071
00072 void help() {
00073 cout << "StressFilePublisher <FileName> <PublishCount>" << endl;
00074 cout << endl << "StessFilePublisher stress the IS/FittingService side of things by " << endl;
00075 cout << "publishing the raw data in the binary file <FileName> <PublishCount> times." << endl;
00076 exit(0);
00077 }
00078
00079 void publish(scan_result_ptrs& scanResult, unsigned int i) {
00080 scanResult.header.scanNumber = i;
00081 ScanResultWriter::publish(scanResult);
00082 }
00083
00084
00085
00086
00087
00088 scan_result_ptrs* readFile(const char* name) {
00089 FILE * pFile;
00090 long lSize;
00091
00092 pFile = fopen (name, "rb" );
00093 if (pFile==NULL)
00094 return 0;
00095
00096
00097 fseek (pFile , 0 , SEEK_END);
00098 lSize = ftell (pFile);
00099 rewind (pFile);
00100
00101
00102 scan_result_ptrs& scanResult = *new scan_result_ptrs();
00103
00104
00105 int n = fread(&scanResult.header, sizeof(ScanHeader), 1, pFile);
00106
00107
00108 scanResult.points = new FLOAT32[scanResult.header.npoints];
00109 scanResult.nEvents = new UINT32[scanResult.header.npoints];
00110 scanResult.nErrorEvents = new UINT32[scanResult.header.npoints];
00111
00112 fseek(pFile, scanResult.header.pntPoints, SEEK_SET);
00113 n = fread(scanResult.points, sizeof(FLOAT32), scanResult.header.npoints, pFile);
00114
00115 fseek(pFile, scanResult.header.pntEvents, SEEK_SET);
00116 n = fread(scanResult.nEvents, sizeof(UINT32), scanResult.header.npoints, pFile);
00117
00118 fseek(pFile, scanResult.header.pntErrors, SEEK_SET);
00119 n = fread(scanResult.nErrorEvents, sizeof(UINT32), scanResult.header.npoints, pFile);
00120
00121
00122
00123 scanResult.data = new short[scanResult.header.size];
00124 cout << scanResult.header.size << endl;
00125 fseek(pFile, scanResult.header.pntData, SEEK_SET);
00126 n = fread(scanResult.data, sizeof(UINT16), scanResult.header.size, pFile);
00127
00128
00129 fclose (pFile);
00130
00131 return &scanResult;
00132 }