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 int lastBin;
00078 int lastTrigger;
00079
00080
00081
00082 UINT8 groupDspMap[4];
00083 UINT8 groupSpMap[2];
00084 UINT8 groupRangeMap[2];
00085 };
00086
00087 class ScanControl {
00088 protected:
00089 SctApi &api;
00090
00091 ScanControl(SctApi &api, int bin, int event);
00092 ScanControl(SctApi &api);
00093
00094 virtual ~ScanControl() {}
00095 public:
00097 virtual void startHistogramming() = 0;
00098
00100 virtual void initialisePolling() = 0;
00101
00103 virtual void reportEventErrors() = 0;
00104
00106 virtual void reportTimeout() = 0;
00107
00109 virtual void nextBin() = 0;
00110
00116 virtual bool checkScanComplete(bool &progressMade, bool &newBin) = 0;
00117
00118
00119
00120
00125 virtual void finishHistogram(bool success) = 0;
00126 };
00127
00128 class ScanControlRODHisto : public ScanControl {
00129 protected:
00130 std::map<RodLabel, int> lastBin;
00131 std::map<RodLabel, int> lastEvent;
00132
00133 boost::shared_ptr<Scan> scan;
00134 boost::shared_ptr<ScanEx> scanEx;
00135
00136 int finalBin;
00137 int finalTrigger;
00138
00139 int sectionStartBin;
00140 int sectionEndBin;
00141 int sectionEndTrigger;
00142
00143
00144 time_t scanStart;
00145
00147 void readHistograms();
00148
00150 scan_result_ptrs readHistogramData(UINT32 mid, int frame = 0);
00151
00152 char* readHistogramRawData(UINT32 mid, int frame = 0);
00153
00155 void postScanModuleSetup();
00156
00158
00161 unsigned long *getHistogramChunk(RodLabel label, int slave, unsigned long offset, unsigned long size);
00162
00164
00167 unsigned long *getEventCountChunk(RodLabel label, int slave);
00168
00169 bool checkDebugOption(int opt);
00170
00171 bool findNextSection();
00172 public:
00173 ScanControlRODHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00174
00175 virtual ~ScanControlRODHisto() {};
00176
00178 void startHistogramming();
00179
00181 void initialisePolling();
00182
00184 void reportEventErrors();
00185
00186 typedef std::pair<std::pair<int, int>, std::pair<int, int> > TrapBuffers;
00187
00189 TrapBuffers getTrapBuffers(const RodLabel rlabel, int dsp);
00190
00192 unsigned int getProcTime(const RodLabel rlabel, int dsp);
00193
00195 void reportTimeout();
00196
00198 void nextBin();
00199
00201 bool checkScanComplete(bool &progressMade, bool &newBin);
00202
00204 virtual bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00205
00207 void finishHistogram(bool success);
00208 };
00209
00210 class ScanControlTIMHisto : public ScanControlRODHisto {
00211 int binCount;
00212
00213 public:
00214 ScanControlTIMHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00215
00217 void startHistogramming();
00218
00220 void nextBin();
00221
00223 bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00224
00225
00226
00227
00228 };
00229
00230 }
00231
00232 #endif