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 };
00051
00058 class ScanEx {
00059 public:
00061 std::map<RodLabel, RodScanEx> rodInfo;
00062
00063 typedef std::map<RodLabel, RodScanEx> RodInfoMap;
00064
00065 RodScanEx &getOrNewRod(const RodLabel &l, RodScanEx defaultEx);
00066 const RodScanEx &getRodScanInfo(const RodLabel &l) const;
00067 RodScanEx &getRodScanInfo(const RodLabel &l);
00068
00070 std::vector<std::list<std::string> > groupLists;
00071
00073 unsigned int diagnosticReg;
00074
00075 std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> histoMap;
00076
00077 std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> evCountMap;
00078
00080 int trimScan;
00081
00082
00083
00084 UINT8 groupDspMap[4];
00085 UINT8 groupSpMap[2];
00086 UINT8 groupRangeMap[2];
00087 };
00088
00106 class ScanControl {
00107 protected:
00108 SctApi &api;
00109
00110 ScanControl(SctApi &api, int bin, int event);
00111 ScanControl(SctApi &api);
00112
00113 virtual ~ScanControl() {}
00114 public:
00116 virtual void startHistogramming() = 0;
00117
00119 virtual void initialisePolling() = 0;
00120
00122 virtual void reportEventErrors() = 0;
00123
00125 virtual void reportTimeout() = 0;
00126
00128 virtual void nextBin() = 0;
00129
00135 virtual bool checkScanComplete(bool &progressMade, bool &newBin) = 0;
00136
00137
00138
00139
00144 virtual void finishHistogram(bool success) = 0;
00145 };
00146
00150 class ScanControlRODHisto : public ScanControl {
00151 protected:
00152 std::map<RodLabel, int> lastBin;
00153 std::map<RodLabel, int> lastEvent;
00154
00155 boost::shared_ptr<Scan> scan;
00156 boost::shared_ptr<ScanEx> scanEx;
00157
00158 int finalBin;
00159 int finalTrigger;
00160
00161 int sectionStartBin;
00162 int sectionEndBin;
00163 int sectionEndTrigger;
00164
00165
00166 time_t scanStart;
00167
00169 void readHistograms();
00170
00172 scan_result_ptrs readHistogramData(UINT32 mid, int frame = 0);
00173
00174 char* readHistogramRawData(UINT32 mid, int frame = 0);
00175
00177 void postScanModuleSetup();
00178
00180
00183 unsigned long *getHistogramChunk(RodLabel label, int slave, unsigned long offset, unsigned long size);
00184
00186
00189 unsigned long *getEventCountChunk(RodLabel label, int slave);
00190
00191 bool checkDebugOption(int opt);
00192
00193 bool findNextSection();
00194 public:
00195 ScanControlRODHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00196
00197 virtual ~ScanControlRODHisto() {};
00198
00200 void startHistogramming();
00201
00203 void initialisePolling();
00204
00206 void reportEventErrors();
00207
00208 typedef std::pair<std::pair<int, int>, std::pair<int, int> > TrapBuffers;
00209
00211 TrapBuffers getTrapBuffers(const RodLabel rlabel, int dsp);
00212
00214 unsigned int getProcTime(const RodLabel rlabel, int dsp);
00215
00217 void dumpHistoStatus(const RodLabel label, int dsp);
00218
00220 void reportTimeout();
00221
00223 void nextBin();
00224
00226 bool checkScanComplete(bool &progressMade, bool &newBin);
00227
00229 virtual bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00230
00232 void finishHistogram(bool success);
00233
00234 std::pair<RodLabel, unsigned int> findModuleSlave(unsigned int mid);
00235 };
00236
00240 class ScanControlTIMHisto : public ScanControlRODHisto {
00241 int binCount;
00242
00243 public:
00244 ScanControlTIMHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00245
00247 void startHistogramming();
00248
00250 void nextBin();
00251
00253 bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00254
00255
00256
00257
00258 };
00259
00260 }
00261
00262 #endif