SctApiHisto.h

00001 #ifndef SCTROD_SCTAPI_HISTO_H
00002 #define SCTROD_SCTAPI_HISTO_H
00003 
00004 // Make sure USE_IS etc. are defined 
00005 #include "config.h"
00006 
00007 #include <map.h>
00008 
00009 #include <boost/date_time/posix_time/posix_time.hpp>
00010 
00011 #include "ScanMonitor.h"
00012 
00013 #include "utility.h"
00014 #include "Sct/Addressing.h"
00015 
00016 #include "SctApiFwd.h"
00017 
00018 struct scan_result_ptrs;
00019 
00020 namespace SctApi {
00021 
00023   void saveHistogramToFile(scan_result_ptrs histo, std::string filename);
00024 
00026   void readHistogramToFile(const Sct::UCID & ucid, const Scan &scan, const ScanEx &ex, UINT32 mid, std::string sn, 
00027                            scan_result_ptrs scanData, time_t saveTime, int frame = 0);
00028 
00029 #ifdef USE_IS
00030 
00031   void readHistogramToIS(const Sct::UCID & ucid, const Scan &scan, const ScanEx &ex,
00032                          UINT32 mid, scan_result_ptrs scanData);
00033 #endif
00034 
00035 struct ModuleMask {
00036   UINT32 mask0;
00037   UINT32 mask1;
00038 };
00039 
00043 class RodScanEx {
00044  public:
00045   // Module slots in use
00046   ModuleMask channels;
00047 
00048   // Module slots per Group
00049   ModuleMask groupChannels[8];
00050 
00051   // Module slots for each slave
00052   ModuleMask slaveChannels[4];
00053 
00055   int slaves;
00056 
00058   char bitFieldDSP;
00059 
00061   int firstSlave;
00062 };
00063 
00070 class ScanEx {
00071  public:
00072   ScanEx() 
00073 #if USE_CONST_SCAN
00074     : startTime(boost::posix_time::second_clock::universal_time()),
00075     endTime(boost::posix_time::second_clock::universal_time())
00076 #endif
00077     {}
00078 
00080   std::map<RodLabel, RodScanEx> rodInfo;
00081 
00082   typedef std::map<RodLabel, RodScanEx> RodInfoMap;
00083 
00084   RodScanEx &getOrNewRod(const RodLabel &l, RodScanEx defaultEx);
00085   const RodScanEx &getRodScanInfo(const RodLabel &l) const;
00086   RodScanEx &getRodScanInfo(const RodLabel &l);
00087 
00089   std::vector<std::list<std::string> > groupLists;
00090 
00091 #if USE_CONST_SCAN
00092   // These are moved from Scan...
00093   ModuleList getModuleList(unsigned int group) const;
00094   void setModuleList(unsigned int group, const ModuleList & newList);
00095   unsigned int getNGroups() const;
00096   void setNGroups(unsigned int val);
00097   
00098   boost::posix_time::ptime getStartTime() const;
00099   void setStartTime(boost::posix_time::ptime t);
00100   
00101   boost::posix_time::ptime getEndTime() const;
00102   void setEndTime(boost::posix_time::ptime t);
00103 
00104   // And need some place to store stuff
00105   unsigned int m_maxGroup;
00106   boost::posix_time::ptime startTime, endTime;
00107 #endif
00108 
00110   unsigned int diagnosticReg;
00111 
00112   std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> histoMap;
00113 
00114   std::map<std::pair<RodLabel, int>, Utility::MemoryBlock> evCountMap;
00115 
00117   int trimScan;
00118 
00119   // Maps
00120 
00121   UINT8 groupDspMap[4];
00122   UINT8 groupSpMap[2];
00123   UINT8 groupRangeMap[2];
00124 };
00125 
00143 class ScanControl {
00144  protected:
00145   SctApi &api;
00146 
00147   ScanControl(SctApi &api, int bin, int event);
00148   ScanControl(SctApi &api);
00149 
00150   virtual ~ScanControl() {}
00151  public:
00153   virtual void startHistogramming() = 0;
00154 
00156   virtual void initialisePolling() = 0;
00157 
00159   virtual void reportEventErrors() = 0;
00160 
00162   virtual void reportTimeout() = 0;
00163 
00165   virtual void nextBin() = 0;
00166 
00172   virtual bool checkScanComplete(bool &progressMade, bool &newBin) = 0;
00173 
00177   virtual void abort() = 0;
00178 
00179 /*   /\** Poll *\/ */
00180 /*   virtual void pollHistogramming(ScanEx &ex, int bins, int events, int timeout = 5) = 0; */
00181 
00186   virtual void finishHistogram(bool success) = 0;
00187 
00188 #if USE_CONST_SCAN
00189   static void setModuleScanCacheToLastPointInScan(SctApi &api, boost::shared_ptr<const Scan> aScan, 
00190                           boost::shared_ptr<const ScanEx> scanEx);
00191 #else
00192   static void setModuleScanCacheToLastPointInScan(SctApi &api, boost::shared_ptr<const Scan> aScan);
00193 #endif
00194 
00195   void printVetoStatus();
00196 };
00197 
00201 class ScanControlRODHisto : public ScanControl {
00202  protected:
00203   std::map<RodLabel, int> lastBin;
00204   std::map<RodLabel, int> lastEvent;
00205   std::map<RodLabel, bool> reportedFinished;
00206   
00207 #warning "This should be const"
00208   boost::shared_ptr<Scan> scan;
00209   boost::shared_ptr<ScanEx> scanEx;
00210 
00211   int finalBin;
00212   int finalTrigger;
00213 
00214   int sectionStartBin;
00215   int sectionEndBin;
00216   int sectionEndTrigger;
00217 
00218   // Store for internal timing
00219   time_t scanStart;
00220 
00221   bool aborting;
00222 
00230   unsigned int getEventCounter(const RodLabel &rodLabel, int slave, bool fromMaster);
00231 
00233   void readHistograms();
00234 
00236   scan_result_ptrs readHistogramData(UINT32 mid, int frame = 0);
00237 
00238   char* readHistogramRawData(UINT32 mid, int frame = 0);
00239 
00241   void postScanModuleSetup();
00242 
00244 
00247   unsigned long *getHistogramChunk(RodLabel label, int slave, unsigned long offset, unsigned long size);
00248 
00250 
00253   unsigned long *getEventCountChunk(RodLabel label, int slave);
00254 
00255   bool checkDebugOption(int opt);
00256 
00257   bool findNextSection();
00258  public:
00259   ScanControlRODHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00260 
00261   virtual ~ScanControlRODHisto() {};
00262 
00264   void startHistogramming();
00265 
00267   void initialisePolling();
00268 
00270   void reportEventErrors();
00271 
00272   typedef std::pair<std::pair<int, int>, std::pair<int, int> > TrapBuffers;
00273 
00275   TrapBuffers getTrapBuffers(const RodLabel rlabel, int dsp);
00276 
00278   unsigned int getProcTime(const RodLabel rlabel, int dsp);
00279 
00281   void dumpHistoStatus(const RodLabel label, int dsp);
00282 
00284   void reportTimeout();
00285 
00287   void nextBin();
00288 
00290   bool checkScanComplete(bool &progressMade, bool &newBin);
00291 
00295   void abort();
00296 
00298   virtual bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00299 
00301   void finishHistogram(bool success);
00302 
00303   std::pair<RodLabel, unsigned int> findModuleSlave(unsigned int mid);
00304 };
00305 
00309 class ScanControlTIMHisto : public ScanControlRODHisto {
00310   int binCount;
00311 
00312  public:
00313 #warning "Constify scan"
00314   ScanControlTIMHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00315 
00317   void startHistogramming();
00318 
00320   void nextBin();
00321 
00323   void finishHistogram(bool success);
00324 
00326   bool checkScanCompleteROD(const RodLabel &rodLabel, bool &progressMade, bool &newBin, int &totalBin);
00327 
00328   // Same as RODHisto
00329 /*   /\** Tidy up, read out and save histogram *\/ */
00330 /*   void finishHistogram(); */
00331 };
00332 
00336 class ScanControlAsyncHisto : public ScanControlRODHisto {
00337   int binCount;
00338 
00339  public:
00340 #warning "Constify scan"
00341   ScanControlAsyncHisto(SctApi &api, boost::shared_ptr<Scan> aScan, boost::shared_ptr<ScanEx> aScanEx);
00342 
00344   void startHistogramming();
00345 
00347   void nextBin();
00348 
00350   void finishHistogram(bool success);
00351 
00352   // checkScanCompleteROD is not called as polling not done
00353 };
00354 
00355 } // Close SctApi namespace
00356 
00357 #endif

Generated on Mon Feb 6 14:01:28 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6