SCC/TFndSCCMan.h

00001 // @(#)fROOT/SCC:$Name:  $:$Id: TFndSCCMan.h,v 1.33 2007/09/05 10:34:58 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2006/02/07
00003 
00004 #ifndef FROOT_TFndSCCMan
00005 #define FROOT_TFndSCCMan
00006 
00008 //                                                      //
00009 //  Control class for the FINUDA Slow Control Manager   //
00010 //                                                      //
00012 // the following lines are required in order to compile under Mac-OS
00013 //#ifdef __CINT__
00014 #if !defined(linux) && !defined(__linux) && !defined(__linux__)
00015 #undef __GNUC__
00016 #endif
00017 
00018 #if !defined(__CINT__)
00019 #include <netinet/in.h>
00020 #else
00021 struct sockaddr_in;
00022 #endif
00023 
00024 #include <Riostream.h>
00025 #include "TTimer.h"
00026 
00027 #include "TThread.h"
00028 #include "TFndSCCRaw.h"
00029 
00030 #include "FROOT.h"
00031 
00032 class TFndSCCMan: public TFndSCCRaw
00033 {
00034 
00035  protected:  
00036   enum E_SCC_LogType{
00037     E_SCC_Log_Status = 0, // information about all detectors
00038     E_SCC_Log_Store = 1,  // log of every stored (sent) event
00039     E_SCC_Log_End = 2  // used for arrays
00040   };
00041 
00042 
00043   TThread *fReceiveThread[K_N_SOCKS_IN];
00044 
00045   Int_t fSockDescr[K_N_SOCKS_IN]; // socket descriptors
00046   struct sockaddr_in fLocSockAddr[K_N_SOCKS_IN];
00047 
00048   Int_t fCurReceivedEv[K_N_SOCKS_IN]; // SIL will be incremented at every completed event
00049 
00050   // complete data send management
00051   TThread *fSendThread;
00052   Int_t fCurSent;
00053   TTimer *fTimer;
00054   Int_t fUpdateInterval; // time interval for update (seconds)
00055   Int_t fCounterUpdate; // used to count updates
00056   Int_t fRatioUpdate; // text-log/raw-store interval ratio
00057 
00058   Bool_t fMustSendToDAQ;
00059   Bool_t fMustSaveLocalRaw;
00060 
00061   // --- logging support (Feb, 2007)
00062   ofstream *fCurLogFile[(Int_t)E_SCC_Log_End]; 
00063   ofstream *fCurOutRawFile; 
00064 
00065   TString fLogFilesPath[(Int_t)E_SCC_Log_End];
00066   TString fRawFilesPath;
00067 
00068 
00069   FILE *fRawFile; // used for reading raw-files
00070 
00071  private:
00072   void Init();
00073   Int_t IsSingleReceiveThreadRunning(Int_t sock_idx); // return value: -1: Thread not found ; != -1: Thread state
00074 
00075   Int_t StartSingleReceiveThread(Int_t sock_idx);
00076   Int_t StopSingleReceiveThread(Int_t sock_idx);
00077   
00078 
00079  public:
00080   TFndSCCMan();
00081   ~TFndSCCMan();
00082 
00083   Bool_t fSendingData;
00084   
00085   enum E_SCC_MAN_GuiComm_t{
00086     E_SCC_MAN_GuiComm_Idle = 0,
00087     E_SCC_MAN_GuiComm_Building = 1,
00088     E_SCC_MAN_GuiComm_Sent = 2,
00089     E_SCC_MAN_GuiComm_Stored = 3,
00090   };
00091   /*   E_SCC_MAN_GuiComm_t fSend_GUI_comm; // used for GUI updates */
00092   
00093   Int_t SockId2SlowId(Int_t sock_idx);
00094   Int_t SlowId2SockId(Int_t slow_det,Int_t part = 1); // part is used by SIL only
00095   void StopAllThreads();
00096 
00097   static void *Receiver(void *arg); // Receive raw-events from SlowControls
00098   /*   static void *Sender(void *arg); // Send the complete event to DAQ */
00099   
00100   Int_t IsReceiveThreadRunning(Int_t slow_det);
00101   Int_t StartReceiveThread(Int_t slow_det);
00102   Int_t StopReceiveThread(Int_t slow_det);
00103   Int_t GetSocketDescriptor(Int_t sock_idx) { return fSockDescr[sock_idx]; }
00104 
00105   // --- print methods
00106   // print header is supported by the base class "TFndSCCRaw"
00107   void PrintSlowDetDataValues(Int_t slow_det);
00108   void PrintSlowDetMessage(Int_t slow_det);
00109   void PrintSlowDetMiscValues(Int_t slow_det);
00110   Int_t PrintSlowDetInfo(Int_t slow_det, Bool_t check_receive_thread = kFALSE);
00111   Int_t PrintAllInfo(Bool_t check_receive_thread=kFALSE);
00112 
00113   // methods used within Receiver threads
00114   struct sockaddr_in GetLocSockAddr(Int_t sock_idx) { return fLocSockAddr[sock_idx]; }
00115   Int_t GetReceivedEv(Int_t sock_idx) { return fCurReceivedEv[sock_idx]; }
00116   void IncrReceivedEv(Int_t sock_idx) { fCurReceivedEv[sock_idx]++; }
00117 
00118   // the "ReceivedEvent" method will be connected to the application class
00119   virtual void ReceivedEvent(Int_t slow_det,Int_t part) = 0; // Automatically called by receiver threads
00120   //  virtual void PerformingScheduledOperation() = 0; // Automatically called by receiver threads
00121   virtual void ScheduledOperationPerformed(E_SCC_MAN_GuiComm_t oper,Bool_t UpdateTime = kFALSE) = 0; // Automatically called by receiver threads
00122 
00123   TThread *GetReceiveThread(Int_t slow_det) { return fReceiveThread[slow_det]; }
00124   
00125   // complete data send management
00126   Int_t StartSendThread(); // used also for saving local raw-data
00127   Int_t StopSendThread(); // used also for saving local raw-data
00128   Int_t IsSendThreadThreadRunning(); // return value: -1: Thread not found ; != -1: Thread state
00129 
00130   void SetMustSendToDAQ(const Bool_t &val) { fMustSendToDAQ = val; }
00131   void SetMustSaveLocalRaw(const Bool_t &val) { fMustSaveLocalRaw = val; }
00132   
00133   Bool_t GetMustSendToDAQ() { return fMustSendToDAQ; }
00134   Bool_t GetMustSaveLocalRaw() { return fMustSaveLocalRaw; }
00135   
00136   Int_t ScheduledOperation();
00137   
00138   // --- logging support (Feb, 2007)
00139   virtual void OpenLogFile(E_SCC_LogType log_type,const TString &fdir, const TString &fnam,const Bool_t &reset_old);
00140   virtual void CloseLogFile(E_SCC_LogType log_type);
00141   virtual void WriteLogFile(E_SCC_LogType log_type,const TString &line);
00142   virtual void UpdateCurrentLogFile(); // used for status log-file
00143 
00144   // --- raw-saving support (Feb, 2007)
00145  private:
00146   // writing raw-file is handled apart
00147   virtual void OpenOutRawFile(const Bool_t &reset_old);
00148   virtual void WriteOutRawFile(UInt_t *data);
00149   virtual void UpdateCurrentOutRawFile();
00150   virtual void CloseOutRawFile();
00151  public:
00152   // support for several open-sintaxes
00153   virtual Int_t OpenRawFile(const TString &fpath);
00154   virtual Int_t CloseRawFile();
00155   virtual UInt_t *GetNextRawEvent(Int_t &exit_val);
00156   virtual Int_t GlobalEventToGlobalHeader();
00157   virtual Int_t GlobalEventToDetEvents();
00158   virtual Int_t DetEventToMsgPart(const Int_t &slow_det);
00159 
00160   virtual Int_t OpenRawFile(const TString &fdir,const TString &fnam)
00161     {
00162       TString pth; pth.Form("%s/%s",gSystem->ExpandPathName(fdir),fnam.Data());
00163       return OpenRawFile(pth);
00164     }
00165   
00166   virtual Int_t OpenRawFile(const TString &fdir,const UInt_t &day,const UInt_t &month,const UInt_t &year)
00167     {
00168       TString fnam;
00169       fnam.Form("%u_%u_%u.scc.raw",day,month,year);
00170       
00171       TString path_str = "";
00172       path_str.Form("%s/%s",gSystem->ExpandPathName(fdir.Data()),fnam.Data());
00173       return OpenRawFile(path_str);      
00174     }
00175   
00176   virtual Int_t OpenRawFile(const TString &fdir,const TDatime &date_time)
00177     {   
00178       TString fnam;
00179       fnam.Form("%d_%d_%d.scc.raw",
00180                 date_time.GetDay(),
00181                 date_time.GetMonth(),
00182                 date_time.GetYear()
00183                 );
00184       
00185       TString path_str = "";
00186       path_str.Form("%s/%s",gSystem->ExpandPathName(fdir.Data()),fnam.Data());
00187       return OpenRawFile(path_str);
00188     }
00189   
00190 
00191   // ---
00192   ClassDef(TFndSCCMan,0) // Manager of the Slow-Control-Manager
00193 };
00194     
00195 //R__EXTERN TFndSCCMan *gSCCManager;
00196 
00197 #endif // FROOT_TFndSCCMan

Generated on Tue Oct 16 15:40:48 2007 by  doxygen 1.5.2