Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

StressFilePublisher.cpp

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

Generated on Thu Jul 15 09:50:53 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5