STEER/TFndRun.h

00001 // @(#)fROOT/STEER:$Name:  $:$Id: TFndRun.h,v 1.50 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 // Original Author: P. Cerello <mailto:cerello@to.infn.it>, 2000
00004 
00005 #ifndef FROOT_TFndRun
00006 #define FROOT_TFndRun
00007 
00009 //                                                               //
00010 //  Control class for FINUDA C++ run processing                  //
00011 //  Only one single instance of this class exists.               //
00012 //  The object is pointed by the global fndrun.                  //
00013 //                                                               //
00014 //   -Supports the list of all FINUDA Detectors (fDetectors).    //
00015 //                                                               //
00017 
00018 
00019 #include <TFile.h>
00020 
00021 #include "TFndGtsMonFrame.h"
00022 #include "TFndTofMonFrame.h"
00023 #include "TFndSilMonFrame.h"
00024 #include "TFndLmdMonFrame.h"
00025 #include "TFndStbMonFrame.h"
00026 
00027 #include "TFndRunConfiguration.h"
00028 #include "TFndGenInfo.h"
00029 #include "TFndFeeMap.h"
00030 #include "TFndHdt.h"
00031 
00032 #include "TFndProcessRec.h"
00033 #include "TFndRdt.h"
00034 
00035 class TFndGtsMon;
00036 class TFndTofMon;
00037 class TFndSilMon;
00038 class TFndLmdMon;
00039 class TFndStbMon;
00040 
00041 #include "FROOT.h"
00042 using namespace FROOT;
00043 
00044 // be careful with the following lines:
00045 // - <netinet>/CINT is handled in FROOT.h
00046 // - check TFndRun.cxx for other inclusions reguarding "socket"
00047 
00048 #if defined(__CINT__)
00049 struct sockaddr_in; // needed since netinet causes problems with CINT
00050 #endif
00051 
00052 
00053 class TFndRun : public TNamed {
00054  protected:
00055   enum { k_MinRawFileSize = 1024 }; // minimum file size requested (bytes)
00056 
00057 
00058   Int_t         fDebug;        // Debug flag
00059   UInt_t        fDebugRawEv;   // Debug flag [hex coding] ( dedicated to the raw-event decoding)
00060 
00061   TFndRunConfiguration *fRunConfiguration; // Configuration of the run
00062 
00063   TString     fDBHost; // Database host
00064   TFndFeeMap *fFeeMap; //-> Database information
00065 
00066   TString fDataPath;    // path to raw data (default is "$RDT")
00067   TString fRunType;      // Run Type
00068   Int_t   fRunTypeID;    // Run Type ID (see FROOT.h)
00069   Int_t   fRunNumber;     // Run Number
00070   TString fRunFilename;    // Complete run-filename (no extension)
00071   TString fMonHisFilename; // Complete run-filename (with path to mon-histos) (no ext.)
00072   // --- socket management
00073   Int_t         fGebIp;        // DAQ process IP number
00074 
00075   Int_t   fOnlineFlag;       //Online-Detector Flag ... could become EFndOnlineFlags
00076 
00077   TString fCurRunType; // used in online mode to check if the run has changed
00078   UInt_t  fCurRunNum;  // used in online mode to check if the run has changed
00079   Bool_t fIsNewRun; // True for one event when the run number changes
00080 
00081   Bool_t fProcessing; // true if processing (either online or offline)
00082   Int_t fNumOfProcessedRuns;     // Total number of processed events
00083   Int_t fNumOfProcessedEvents;   // Total number of processed events
00084 
00085   Int_t fMaxNofEvents; // Maximum number of events to be processed (considering all requested runs)
00086   Int_t fMaxNofRuns;   // Maximum number of runs to be processed
00087 
00089   // SOCKET/RAW-FILE MANAGEMENT //
00090   Int_t fSockLength; // length used by the socket-to-DAQ
00091   struct sockaddr_in fLocSockAddr; // used to create and bind the socket.
00092   Int_t fUdpSd; // socket descriptor
00093   struct sockaddr_in fShrSockAddr; // used to send share data via socket
00094   Int_t   fShrSockAddr_size;
00095   Int_t request_counter;
00096   // ---
00097   FILE   *fRawFile;      
00098 
00099 
00100   UInt_t fRawEvent[FIN_RAW_DATA_BUF_SIZE];     // Pointer to the current raw event
00101   UInt_t fRunTime;      // Run Time
00102 
00103   /*   TFile   *fHdtRootFile;  // // TO BE MOVED IN TFndGeb2hdtMan */
00104 
00105   TFndGenInfo *fGenInfo; //-> Run Header information
00106 
00107   TFndGtsMonFrame   *fGtsMonFrame;     //Pointer GTS Monitor Frame
00108   TFndTofMonFrame   *fTofMonFrame;     //Pointer TOF Monitor Frame
00109   TFndSilMonFrame   *fSilMonFrame;     //Pointer SIL Monitor Frame
00110   TFndLmdMonFrame   *fLmdMonFrame;     //Pointer LMD Monitor Frame
00111   TFndStbMonFrame   *fStbMonFrame;     //Pointer STB Monitor Frame
00112 
00113   Bool_t fMustFillMonitor[D_STB+1];
00114   TFndGtsMon        *fGtsMon;     //Pointer GTS Monitor 
00115   TFndTofMon        *fTofMon;     //Pointer TOF Monitor 
00116   TFndSilMon        *fIsmMon;     //Pointer ISM Monitor 
00117   TFndSilMon        *fOsmMon;     //Pointer OSM Monitor 
00118   TFndLmdMon        *fLmdMon;     //Pointer LMD Monitor 
00119   TFndStbMon        *fStbMon;     //Pointer STB Monitor   
00120 
00121   TFndRdt       *fFinRdt;       //Pointer to the structure of the current raw event
00122   TFndHdt       *fFinHdt;       //Pointer to current hitevent
00123 
00124   // --- fidarc wrapper and pre-analysis data members
00125   TFndProcessRec *fProcessRec; //new ZEBRA Interface 
00126   
00127   ofstream *fCurLogFile; 
00128 
00129  protected:
00130   virtual Long_t OpenRawFile(TString fdir, TString fnam,Bool_t check_only=kFALSE);
00131   Int_t Init(); // private method called by ctors
00132   virtual void CheckRawSwapping();
00133   void  CleanEvent(); // clear and delete event
00134   
00135   // public is used for testin purposes only
00136   // public: 
00137   virtual Int_t CreateSocketToDAQ(E_Fnd_DaqRaw_Udp_Ports det_port);
00138   virtual Int_t ShutdownSocketToDAQ();
00139 
00140   virtual Int_t CheckSocketToDAQ();
00141   virtual Int_t RecreateSocketToDAQ(E_Fnd_DaqRaw_Udp_Ports det_port=FIN_DAQ_RAW_UDP_PORT){
00142     // return value:
00143     //              0: socket closed and recreated
00144     //              1: no previous socket: creating a new one
00145     if(fUdpSd != -1) shutdown(fUdpSd,2);
00146     CreateSocketToDAQ(det_port);
00147     return 0;
00148   }
00149   virtual UInt_t *GetNextRawEventFromSocket(int &exit_val); // get the next raw-event (from socket)
00150   virtual UInt_t *GetNextRawEventFromFile(int &exit_val); // get the next raw-event (from file)
00151 
00152  public:
00153   static TFndHdt *fgFinHdt;
00154 
00155   TFndRun(const TString &name="FINUDA_run_processor", const TString &title="The FINUDA run processor");
00156   /*    TFndRun(const char *run_type, Int_t run_num, Int_t NofEvents = 1000000, const char *data_path = "$RDT", const char *msql_host = "$MSQL_DB_HOST"); //root<->fidarc */
00157 
00158   ~TFndRun();
00159   
00160   Int_t InitNewRun(TString runtype="ONLM",const Int_t &runnum=-1,const Bool_t &UsedByPrean=kFALSE);// initialize new run (default: online)
00161   Bool_t IsProcessing() {return fProcessing;}
00162   Bool_t IsNewRun(); // used in online-mode to check for new run (event by event)
00163 
00164   TFndFeeMap    *GetFeeMap() { return fFeeMap; } // will be removed soon
00165   Int_t CheckMsqlConnection();
00166   Int_t ConnectToDB(); // support for mysql is coming soon...
00167   Int_t FetchDBinfo(Int_t source,Bool_t verbose=kFALSE); // support for mysql is coming soon...
00168   Int_t DisconnectFromDB(); // support for mysql is coming soon...
00169   Int_t FinishRun(Bool_t last=kFALSE,const Bool_t &UsedByPrean=kFALSE); // reset interface and data members
00170    
00171   void  ClearEvent(); // clear event without deleteing it
00172    
00173   Int_t  GetNofProcessedRuns() { return fNumOfProcessedRuns; } // Total number processed events
00174   Int_t  GetNofProcessedEvents() { return fNumOfProcessedEvents; } // Total number processed events
00175   /*   Int_t  GetNofHdtEvents() { return fHdtt ? fHdtt->GetEntries() : 0; } //Number of events in current Hdt */
00176   UInt_t GetEvNum_Raw() { return fRawEvent ? fRawEvent[2] : 0; } // directly read from current raw event (sftw ev-num)
00177   // ---
00178   Int_t GetDebug() { return fDebug; }
00179   UInt_t GetDebugRawEv() { return fDebugRawEv; }
00180    
00181   void ReadConfigFile(TString ConfFileName = "RunConfig.C"); // may become private
00182   TFndRunConfiguration *RunConfiguration() { return fRunConfiguration; } // Get current configuration
00183    
00184   void SetDBHost(const TString &dbhost)
00185     {
00186       if(!dbhost.IsNull()) fDBHost = ExpandPathName(dbhost).Data(); 
00187       else Warning("SetDBHost","empty string received: using default value");
00188     }
00189   TString GetDBHost() { return fDBHost; }
00190    
00191   TString GetDataPath() { return fDataPath; }
00192   void SetDataPath(const TString &data_path)
00193     {
00194       if(!data_path.IsNull()) fDataPath = data_path;
00195       else Warning("SetData_Path","empty string received: using default value");
00196     }
00197    
00198   TString GetRunType(Int_t &run_type_id) { run_type_id = fRunTypeID; return fRunType;}
00199   TString GetRunType() { return fRunType;}
00200   Int_t SetRunType(TString runtype);
00201   void SetRunType(Int_t runtype); // may become private
00202 
00203   UInt_t GetCurOnlineRunNmber() { return fCurRunNum; }
00204   Int_t GetRunNumber() { return fRunNumber; }
00205   void SetRunNumber(Int_t run_num){ fRunNumber = run_num; } // may become private
00206 
00207   Int_t GetMaxNumberOfEvents() { return fMaxNofEvents; }
00208   void SetMaxNumberOfEvents(Int_t max_evts){ fMaxNofEvents = max_evts; } // may become private
00209 
00210   Int_t GetGebIP()  { return fGebIp; }
00211   void  SetGebIP(Int_t geb_ip)  { fGebIp = geb_ip; } // may become private
00212 
00213   void  SetDebugLevel(Int_t level) {fDebug = level;}
00214   void  SetDebugRawEv(UInt_t levels) { fDebugRawEv = levels; }
00215 
00216 
00219 
00220   virtual Int_t  GetNextEvent(Bool_t fill_hdt=kTRUE);
00221   virtual UInt_t *GetNextRawEvent(Int_t &exit_value); // read the next raw-event (from socket or from file)
00222   Int_t  ReadRawEvent(Bool_t using_db=kTRUE); // read and unpack current raw event filling the HDT structure
00223   UInt_t *GetCurrentRawEvent() { return fRawEvent; } // may be used to access directly the raw-event
00224   virtual Int_t ReconstructEvent(); // Reconstruction of the current raw event (not implemented yet)
00225 
00226   //  TFndHdt       *GetHdtEvent(Int_t n);
00227 
00228   UInt_t GetRunTime() { return fRunTime;}
00229   void SetRunTime(const UInt_t &rtim) 
00230     { // debugging purposes only
00231       Warning("SetRunTime","Use this method for debug only...");
00232       Printf("TFndRun::SetRunTime ---> Use this method for debug only...");
00233       fRunTime = rtim;
00234     } 
00235 
00236   Int_t Onlflg() { return fOnlineFlag; }
00237   //   void SetOnlflg(Int_t onl=ONL_ALL) { fOnlineFlag = onl;} // this method should never be needed...
00238 
00241    
00242   TFndGtsMonFrame   *GtsMonFrame() { return fGtsMonFrame; }
00243   TFndTofMonFrame   *TofMonFrame() { return fTofMonFrame; }
00244   TFndSilMonFrame   *SilMonFrame() { return fSilMonFrame; }
00245   TFndLmdMonFrame   *LmdMonFrame() { return fLmdMonFrame; }
00246   TFndStbMonFrame   *StbMonFrame() { return fStbMonFrame; }
00247   TFndGtsMon   *GtsMon() { return fGtsMon; }
00248   TFndTofMon   *TofMon() { return fTofMon; }
00249   TFndSilMon   *IsmMon() { return fIsmMon; }
00250   TFndSilMon   *OsmMon() { return fOsmMon; }
00251   TFndLmdMon   *LmdMon() { return fLmdMon; }
00252   TFndStbMon   *StbMon() { return fStbMon; }
00253 
00254   TFndGenInfo    *GetGenInfo() {return fGenInfo;}
00255 
00256   // ---
00257   void SetMustFillMonitor(EFndMonDetectors det_id,const Bool_t &val) { fMustFillMonitor[(Int_t)det_id] = val; }
00258   void  FillMonitors();
00259   void  WriteMonitors(Bool_t close = kFALSE); // default is update only
00260   //
00261   void  StartMonitors();
00262   void  StartGtsMonitor();
00263   void  StartGtsMonitor(TString *); // fill producer histograms from saved file
00264   //
00265   void  StartTofMonitor(Int_t adc_bins = -1,Float_t adc_min = -1.,Float_t adc_max = -1.,Int_t tdc_bins = -1,Float_t tdc_min = -1.,Float_t tdc_max = -1.);
00266   void  StartTofMonitor(TString *); // fill producer histograms from saved file
00267   //
00268   void  StartIsmMonitor();
00269   void  StartOsmMonitor();
00270   void  StartIsmMonitor(TString *); // fill producer histograms from saved file
00271   void  StartOsmMonitor(TString *); // fill producer histograms from saved file
00272   //
00273   void  StartLmdMonitor(Int_t adc_bins = -1,Float_t adc_min = -1.,Float_t adc_max = -1.,Int_t tdc_bins = -1,Float_t tdc_min = -1.,Float_t tdc_max = -1.);
00274   void  StartLmdMonitor(TString *); // fill producer histograms from saved file
00275   //
00276   void  StartStbMonitor(Int_t tdc_bins=-1,Float_t tdc_min=-1.,Float_t tdc_max=-1.);
00277   void  StartStbMonitor(TString *); // fill producer histograms from saved file
00278 
00279   TFndHdt       *GetCurrentHdt() { return fFinHdt; }
00280   TFndRdt       *GetCurrentRdt() { return fFinRdt; }
00281    
00282   Int_t StartMonFrame(Int_t det,TString RootFileName=0, TString RootFileName2=0); // Start monitor-frame (consumer-GUI) for the selected detector (det)
00283   TFndMonFrame *GetMonFrame(Int_t det); // Get current monitor-frame (consumer-GUI) for the selected detector (det)
00284   Int_t DeleteMonFrame(Int_t det); // delete current monitor-frame (consumer-GUI) for the selected detector (det)
00285 
00286   // --- fidarc wrapper and pre-analysis data members
00287   // to be removed from here: preanalysis has its own environment
00288   //                          and DST generation/management processes need a (new) dedicated class
00289   void SetProcessRec(TFndProcessRec *proc) {fProcessRec = proc;}// maybe better in TFndPreanMan (more meaningful)
00290   TFndProcessRec *GetProcessRec() {return fProcessRec;}// maybe better in TFndPreanMan (more meaningful)
00291   Int_t *Zebra_LQ()  {return fProcessRec->GetLQ();}// maybe better in TFndPreanMan (more meaningful)
00292   Int_t *Zebra_IQ()  {return fProcessRec->GetIQ();}// maybe better in TFndPreanMan (more meaningful)
00293   Float_t *Zebra_Q() {return fProcessRec->GetQ();}// maybe better in TFndPreanMan (more meaningful)
00294 
00295   // --- support for log files
00296   virtual void OpenLogFile(const TString &fdir, const TString &fnam);
00297   void CloseLogFile();
00298   void WriteLogFile(const TString &line);
00299 
00300 
00301   // use the following methods only if you really know what you are doing!
00302   void  SetHdt(TFndHdt *hdt) {fFinHdt = hdt;}
00303   void SetfProcessing(const Bool_t &flg) { fProcessing = flg; }
00304   void SetfOnlineFlag(const Int_t &flg) { fOnlineFlag = flg; }
00305   void SetfRunFileName(const TString &nam) { fRunFilename = nam; }
00306    
00307   ClassDef(TFndRun,1) // Main class for the FINUDA ONLINE MONITORING software structure (pointed by fndrun)
00308 };
00309  
00310 R__EXTERN  TFndRun *fndrun;
00311 
00312 #endif // FROOT_TFndRun
00313 
00315     // keeping memory of some removed parts
00316     //   void  SetEvent(TFndEvent *evt) {fndevt = evt;}

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