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
00034 class RodScanEx {
00035 public:
00036
00037 ModuleMask channels;
00038
00039
00040 ModuleMask groupChannels[8];
00041
00042
00043 ModuleMask slaveChannels[4];
00044
00046 int slaves;
00047
00049 char bitFieldDSP;
00050
00052 int firstSlave;
00053 };
00054
00061 class ScanEx {
00062 public:
00064 std::map<RodLabel, RodScanEx> rodInfo;
00065
00066 typedef std::map<RodLabel, RodScanEx> RodInfoMap;
00067
00068 RodScanEx &getOrNewRod(const RodLabel &l, RodScanEx defaultEx);
00069 const RodScanEx &getRodScanInfo(const RodLabel &l) const;
00070 RodScanEx &getRodScanInfo(const RodLabel &l);
00071
00073 std::vector<std::list<std::string> > groupLists;
00074
00076 unsigned int diagnosticReg;
00077
00078 std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> histoMap;
00079
00080 std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> evCountMap;
00081
00083 int trimScan;
00084
00085
00086
00087 UINT8 groupDspMap[4];
00088 UINT8 groupSpMap[2];
00089 UINT8 groupRangeMap[2];
00090 };
00091
00109 class ScanControl {
00110 protected:
00111 SctApi &api;
00112
00113 ScanControl(SctApi &api, int bin, int event);
00114 ScanControl(SctApi &api);
00115
00116 virtual ~ScanControl() {}
00117 public:
00119 virtual void startHistogramming() = 0;
00120
00122 virtual void initialisePolling() = 0;
00123
00125 virtual void reportEventErrors() = 0;
00126
00128 virtual void reportTimeout() = 0;
00129
00131 virtual void nextBin() = 0;
00132
00138 virtual bool checkScanComplete(bool &progressMade, bool &newBin) = 0;
00139
00143 virtual void abort() = 0;
00144
00145
00146
00147
00152 virtual void finishHistogram(bool success) = 0;
00153 };
00154
00158 class ScanControlRODHisto : public ScanControl {
00159 protected:
00160 std::map<RodLabel, int> lastBin;
00161 std::map<RodLabel, int> lastEvent;
00162
00163 boost::shared_ptr<Scan> scan;
00164 boost::shared_ptr<ScanEx> scanEx;
00165
00166 int finalBin;
00167 int finalTrigger;
00168
00169 int sectionStartBin;
00170 int sectionEndBin;
00171 int sectionEndTrigger;
00172
00173
00174 time_t scanStart;
00175
00176 bool aborting;
00177
00185 unsigned int getEventCounter(const RodLabel &rodLabel, int slave, bool fromMaster);
00186
00188 void readHistograms();
00189
00191 scan_result_ptrs readHistogramData(UINT32 mid, int frame = 0);
00192
00193 char* readHistogramRawData(UINT32 mid, int frame = 0);
00194
00196 void postScanModuleSetup();
00197
00199
00202 unsigned long *getHistogramChunk(RodLabel label, int slave, unsigned long offset, unsigned long size);
00203
00205
00208 unsigned long *getEventCountChunk(RodLabel label, int slave);
00209
00210 bool checkDebugOption(int opt);
00211
00212 bool findNextSection();
00213 public:
00214 ScanControlRODHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00215
00216 virtual ~ScanControlRODHisto() {};
00217
00219 void startHistogramming();
00220
00222 void initialisePolling();
00223
00225 void reportEventErrors();
00226
00227 typedef std::pair<std::pair<int, int>, std::pair<int, int> > TrapBuffers;
00228
00230 TrapBuffers getTrapBuffers(const RodLabel rlabel, int dsp);
00231
00233 unsigned int getProcTime(const RodLabel rlabel, int dsp);
00234
00236 void dumpHistoStatus(const RodLabel label, int dsp);
00237
00239 void reportTimeout();
00240
00242 void nextBin();
00243
00245 bool checkScanComplete(bool &progressMade, bool &newBin);
00246
00250 void abort();
00251
00253 virtual bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00254
00256 void finishHistogram(bool success);
00257
00258 std::pair<RodLabel, unsigned int> findModuleSlave(unsigned int mid);
00259 };
00260
00264 class ScanControlTIMHisto : public ScanControlRODHisto {
00265 int binCount;
00266
00267 public:
00268 ScanControlTIMHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00269
00271 void startHistogramming();
00272
00274 void nextBin();
00275
00277 bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00278
00279
00280
00281
00282 };
00283
00284 }
00285
00286 #endif