00001 #ifndef SCTROD_SCTAPI_HISTO_H
00002 #define SCTROD_SCTAPI_HISTO_H
00003
00004
00005 #include "config.h"
00006
00007 #include <map.h>
00008
00009 #include "utility.h"
00010
00011 namespace SctApi {
00012
00014 void saveHistogramToFile(scan_result_ptrs histo, std::string filename);
00015
00017 void readHistogramToFile(const Scan &scan, const ScanEx &ex, UINT32 mid, std::string sn,
00018 scan_result_ptrs scanData, time_t saveTime, int frame = 0);
00019
00020 #ifdef USE_IS
00021
00022 void readHistogramToIS(const Scan &scan, const ScanEx &ex,
00023 UINT32 mid, scan_result_ptrs scanData);
00024 #endif
00025
00026 struct ModuleMask {
00027 UINT32 mask0;
00028 UINT32 mask1;
00029 };
00030
00032
00035 class RodScanEx {
00036 public:
00037
00038 ModuleMask channels;
00039
00040
00041 ModuleMask groupChannels[8];
00042
00043
00044 ModuleMask slaveChannels[4];
00045
00047 int slaves;
00048
00050 char bitFieldDSP;
00051 };
00052
00053 class ScanEx {
00054 public:
00056 std::map<RodLabel, RodScanEx> rodInfo;
00057
00058 typedef std::map<RodLabel, RodScanEx> RodInfoMap;
00059
00060 RodScanEx &getOrNewRod(const RodLabel &l, RodScanEx defaultEx);
00061 const RodScanEx &getRodScanInfo(const RodLabel &l) const;
00062 RodScanEx &getRodScanInfo(const RodLabel &l);
00063
00065 std::vector<std::list<std::string> > groupLists;
00066
00068 unsigned int diagnosticReg;
00069
00070 std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> histoMap;
00071
00072 std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> evCountMap;
00073
00075 int trimScan;
00076
00077
00078
00079 UINT8 groupDspMap[4];
00080 UINT8 groupSpMap[2];
00081 UINT8 groupRangeMap[2];
00082 };
00083
00084 class ScanControl {
00085 protected:
00086 SctApi &api;
00087
00088 ScanControl(SctApi &api, int bin, int event);
00089 ScanControl(SctApi &api);
00090
00091 virtual ~ScanControl() {}
00092 public:
00094 virtual void startHistogramming() = 0;
00095
00097 virtual void initialisePolling() = 0;
00098
00100 virtual void reportEventErrors() = 0;
00101
00103 virtual void reportTimeout() = 0;
00104
00106 virtual void nextBin() = 0;
00107
00113 virtual bool checkScanComplete(bool &progressMade, bool &newBin) = 0;
00114
00115
00116
00117
00122 virtual void finishHistogram(bool success) = 0;
00123 };
00124
00125 class ScanControlRODHisto : public ScanControl {
00126 protected:
00127 std::map<RodLabel, int> lastBin;
00128 std::map<RodLabel, int> lastEvent;
00129
00130 boost::shared_ptr<Scan> scan;
00131 boost::shared_ptr<ScanEx> scanEx;
00132
00133 int finalBin;
00134 int finalTrigger;
00135
00136 int sectionStartBin;
00137 int sectionEndBin;
00138 int sectionEndTrigger;
00139
00140
00141 time_t scanStart;
00142
00144 void readHistograms();
00145
00147 scan_result_ptrs readHistogramData(UINT32 mid, int frame = 0);
00148
00149 char* readHistogramRawData(UINT32 mid, int frame = 0);
00150
00152 void postScanModuleSetup();
00153
00155
00158 unsigned long *getHistogramChunk(RodLabel label, int slave, unsigned long offset, unsigned long size);
00159
00161
00164 unsigned long *getEventCountChunk(RodLabel label, int slave);
00165
00166 bool checkDebugOption(int opt);
00167
00168 bool findNextSection();
00169 public:
00170 ScanControlRODHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00171
00172 virtual ~ScanControlRODHisto() {};
00173
00175 void startHistogramming();
00176
00178 void initialisePolling();
00179
00181 void reportEventErrors();
00182
00183 typedef std::pair<std::pair<int, int>, std::pair<int, int> > TrapBuffers;
00184
00186 TrapBuffers getTrapBuffers(const RodLabel rlabel, int dsp);
00187
00189 unsigned int getProcTime(const RodLabel rlabel, int dsp);
00190
00192 void reportTimeout();
00193
00195 void nextBin();
00196
00198 bool checkScanComplete(bool &progressMade, bool &newBin);
00199
00201 virtual bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00202
00204 void finishHistogram(bool success);
00205
00206 std::pair<RodLabel, unsigned int> findModuleSlave(unsigned int mid);
00207 };
00208
00209 class ScanControlTIMHisto : public ScanControlRODHisto {
00210 int binCount;
00211
00212 public:
00213 ScanControlTIMHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00214
00216 void startHistogramming();
00217
00219 void nextBin();
00220
00222 bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00223
00224
00225
00226
00227 };
00228
00229 }
00230
00231 #endif