Changeset 2490


Ignore:
Timestamp:
11/10/03 11:14:35 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r2489 r2490  
    11                                                 -*-*- END OF LINE -*-*-
     2
     3  2003/11/10: Nicola Galante
     4 
     5   * macros/dohtml.C:
     6     - added mreflector
     7     
     8   * mbase/MEvtLoop.[h,cc]:
     9     - removed instantiation of gListOfPrimitives
     10     
     11   * mbase/MGGroupFrame.h:
     12     - minor change
     13     
     14   * mbase/MLog.cc:
     15     - added a comment
     16     
     17   * mbase/MParContainer.[h,cc]:
     18     - removed include MEvtLoop.h
     19     - added instantiation of gListOfPrimitves
     20     
     21   * mbase/MReadSocket.[h,cc]:
     22     - added more functionality
     23     - added comments
     24     - added Open() Close()
     25     
     26   * mbase/MTask.cc:
     27     - removed obsolete include for MGGroupFrame
     28
     29   * mfilter/MFRealTimePeriod.h:
     30     - initialize fTime with 0
     31     
     32   * mhist/MHCamEvent.cc, mhist/MHEvent.cc, mhist/MHTriggerLvl0.cc:
     33     - removed creation of additional pad in Draw
     34     
     35   * mhist/MHCamera.cc:
     36     - added creating of additional pad in Draw
     37     - added some comments
     38     
     39   * mraw/MRawSocketRead.[h,cc]:
     40     - added comments
     41     - added fPort data member
     42     - take MStatusDisplay status into account
     43     - SetStausLine2 added
     44     - SetProgressBarPosition added
     45     - removed obsolete include of iosfwd
     46
    247
    348 
     
    1560     - Added some instruction to write all the MMcTriggerLvl2 histograms into
    1661       a TFile
     62
    1763
    1864
  • trunk/MagicSoft/Mars/macros/dohtml.C

    r2080 r2490  
    5151    sourcedir += "mmc:";
    5252    sourcedir += "mmontecarlo:";
     53    sourcedir += "mranforest:";
    5354    sourcedir += "mraw:";
    54     sourcedir += "mranforest:";
     55    sourcedir += "mreflector:";
    5556    sourcedir += "mtools:";
    5657    sourcedir += ".:";
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.cc

    r2459 r2490  
    9696using namespace std;
    9797
    98 
    99 //!
    100 //! Maybe we can add a static parameter list to MEvtLoop
    101 //! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too
    102 //!
    103 
    104 TList *gListOfPrimitives; // forward declaration in MParContainer.h
    105 
    10698// --------------------------------------------------------------------------
    10799//
     
    372364    if (fProgress && fNumEvents>0)
    373365        fProgress->SetPosition((Double_t)num/fNumEvents);
    374 
    375366
    376367    // FIXME: This is a workaround, because TApplication::Run is not
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.h

    r2438 r2490  
    8585};
    8686
    87 // FIXME: Move as (persistent) static data member to MParContainer
    88 R__EXTERN TList *gListOfPrimitives; // instantiation in MEvtLoop
    89 
    9087#endif
  • trunk/MagicSoft/Mars/mbase/MGGroupFrame.h

    r2015 r2490  
    1414class MGGroupFrame : public TGGroupFrame, public TGWidget
    1515{
    16     MGTask  *fTask;
     16    MGTask *fTask;
    1717    MGList *fList;
    1818
  • trunk/MagicSoft/Mars/mbase/MParContainer.cc

    r2470 r2490  
    5151#include "MLogManip.h"
    5252
    53 #ifndef __COSY__
    54 #include "MEvtLoop.h"     // gListOfPrimitives
    55 #else
    5653TList *gListOfPrimitives; // forard declaration in MParContainer.h
    57 #endif
    5854
    5955#undef DEBUG
  • trunk/MagicSoft/Mars/mbase/MParContainer.h

    r2470 r2490  
    132132};
    133133
     134//!
     135//! Maybe we can add a static parameter list to MEvtLoop
     136//! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too
     137//!
     138
     139// FIXME: Move as (persistent) static data member to MParContainer
     140R__EXTERN TList *gListOfPrimitives; // instantiation in MEvtLoop
     141
    134142/*
    135143class MParContainer : public TNamed
  • trunk/MagicSoft/Mars/mbase/MReadSocket.cc

    r2438 r2490  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2001
     18!   Author(s): Thomas Bretz, 10/2003 <mailto:tbretz@astro.uni.wuerzburg.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2003
    2121!
    2222!
     
    2727//
    2828// MReadSocket
     29//
     30// This class acts like a standard C++ istream, but read from a socket
     31// (ifstream works similar)
     32//
     33// ios::io_state:
     34// --------------
     35// eof()  or ios::eofbit:  Connection closed or not established
     36// fail() or ios::failbit: Error trying to establish connection or
     37//                         waiting for data in underflow() timed out
     38// good() tells you that everything is ok and we can read from the stream
     39//
     40// Example:
     41// --------
     42//
     43//    Double_t d;
     44//
     45//    MReadSocket sin(1024); // open port 1024
     46//
     47//    sin >> d;
     48//    sin.read((char*)&d, sizeof(Double_t));
     49//
    2950//
    3051//////////////////////////////////////////////////////////////////////////////
     
    4465using namespace std;
    4566
     67// --------------------------------------------------------------------------
     68//
     69// You can use the constructor in two ways:
     70//
     71//    MReadSocket read(7000);
     72// This opens the socket and blocks until the connection has been
     73// established.
     74//
     75//    MReadSocket read;
     76// Returns immidiatly. The connection will be opend by calling
     77//    read.Open(7000);
     78//
    4679MReadSocket::MReadSocket(int port, int mtu) : istream(this), fMtu(mtu), fTimeout(2500), fServSock(NULL), fRxSocket(NULL)
    4780{
     
    5083    setg(fBuffer, fBuffer, fBuffer+1);
    5184
    52     cout << "Starting server socket on port 7000..." << endl;
    53 
    54     while (1)
     85    clear(ios::eofbit);
     86
     87    if (port>0)
     88        Open(port);
     89}
     90
     91// --------------------------------------------------------------------------
     92//
     93//  Destructor. Close an possible open connection and delete the fBuffer
     94//
     95MReadSocket::~MReadSocket()
     96{
     97    Close();
     98    delete fBuffer;
     99}
     100
     101void MReadSocket::OpenServerSocket(int port)
     102{
     103    if (fServSock)
     104        return;
     105
     106    cout << "Starting server socket on port #" << port << "..." << endl;
     107
     108    while (!fServSock)
    55109    {
    56110        fServSock=new TServerSocket(port, kTRUE);
    57111        if (fServSock->IsValid())
    58             break;
     112            continue;
    59113
    60114        cout << "ServerSocket not valid: ";
    61115        switch (fServSock->GetErrorCode())
    62116        {
    63         case 0: cout << "No error." << endl; break;
     117        case  0: cout << "No error." << endl; break;
    64118        case -1: cout << "low level socket() call failed." << endl; break;
    65119        case -2: cout << "low level bind() call failed." << endl; break;
     
    68122        }
    69123
    70         delete fServSock;
    71         fServSock=NULL;
    72         break;
    73     }
    74     if (!fServSock)
    75     {
    76         cout << "MReadSocket: TServerSocket - Connection timed out." << endl;
    77         setstate(ios::failbit);
     124        Close();
     125        clear(ios::failbit);
    78126        return;
    79127    }
    80128
    81129    fServSock->SetOption(kNoBlock, 1);
    82 
    83     while (1)
     130}
     131
     132void MReadSocket::OpenConnection(Bool_t block)
     133{
     134    do
    84135    {
    85136        const TTime timeout = gSystem->Now() + TTime(5000);
    86137
    87138        TDatime now;
    88         cout << now.AsString() << ": Waiting for conntection on port 7000..." << endl;
    89         fRxSocket = NULL;
    90         while ((Long_t)fRxSocket<=0 && gSystem->Now()<timeout)
     139        cout << now.AsString() << ": Waiting for connection..." << endl;
     140
     141        //
     142        // fRxSocket<0  means: No connection,non-blocking mode
     143        // fRxSocket==0 means: Error
     144        // This is only done until timeout is reached
     145        //
     146        while (fRxSocket==0 && gSystem->Now()<timeout)
    91147        {
    92148            fRxSocket = fServSock->Accept();
    93149            if (fRxSocket==0)
    94                 cout << "Error: TServerSock::Accept" << endl;
    95             usleep(1);
     150            {
     151                cout << "MReadSocket::OpenConnection: ERROR - TServerSock::Accept()" << endl;
     152                setstate(ios::failbit);
     153                return;
     154            }
     155            if ((Long_t)fRxSocket<0)
     156                fRxSocket=NULL;
     157
     158            usleep(10);
    96159        }
    97160
    98         if ((Long_t)fRxSocket<=0)
     161        //
     162        // No connection has been established. Restart waiting for
     163        // connection except we are in non-blocking mode.
     164        //
     165        if (fRxSocket==0)
    99166            continue;
    100167
     168        //
     169        // Check if the established connection is valid
     170        //
    101171        if (fRxSocket->IsValid())
    102             break;
     172        {
     173            cout << "Connection established..." << endl;
     174            fRxSocket->SetOption(kNoBlock, 1);
     175            clear();
     176            return;
     177        }
    103178
    104179        cout << "TSocket: Connection not valid..." << endl;
    105180        delete fRxSocket;
    106     }
    107 
    108     if ((Long_t)fRxSocket<=0)
    109     {
    110         cout << "MReadSocket: TServerSocket::Accept - Connection timed out." << endl;
    111181        fRxSocket=NULL;
    112182        setstate(ios::failbit);
    113183        return;
    114     }
    115 
    116     cout << "Connection established..." << endl;
    117 
    118     fRxSocket->SetOption(kNoBlock, 1);
     184
     185    } while (block);
     186}
     187
     188// --------------------------------------------------------------------------
     189//
     190//  Open the connectionj on port port. Wait until the connection has
     191//  been established. If an error occures and the connection cannot
     192//  be established return kFALSE. To check whether an error occured
     193//  use operator!() or operator void*() or fail()
     194//
     195Bool_t MReadSocket::Open(int port, Bool_t block=kFALSE)
     196{
     197    //
     198    // If no port is given use the port given in the constructor
     199    //
     200    if (port<=0)
     201        port = fPort;
     202
     203    //
     204    // Remember port for later uses
     205    //
     206    if (fPort<=0)
     207        fPort = port;
     208
     209    //
     210    // Check whether a connection has already been established
     211    //
     212    if (fServSock)
     213    {
     214        //
     215        // Check whether the connection has the right port
     216        //
     217        if (fServSock->GetLocalPort()!=port)
     218            Close();
     219    }
     220
     221    //
     222    // Check whether port is valid
     223    //
     224    if (port<=0)
     225    {
     226        cout << "Invalid port #" << port << "!" << endl;
     227        clear(ios::failbit);
     228        return kFALSE;
     229    }
     230
     231    //
     232    // Start server socket...
     233    //
     234    OpenServerSocket(port);
     235    if (!fServSock)
     236        return kFALSE;
     237
     238    OpenConnection(block);
     239    if (!fRxSocket)
     240        return kFALSE;
    119241
    120242    underflow();
    121 }
    122 
    123 // --------------------------------------------------------------------------
    124 //
    125 //  Destructor, destroying the gui mutex.
    126 //
    127 MReadSocket::~MReadSocket()
     243    return kTRUE;
     244}
     245
     246void MReadSocket::Close()
    128247{
    129248    if (fRxSocket)
     249    {
    130250        delete fRxSocket;
     251        fRxSocket=NULL;
     252    }
    131253    if (fServSock)
     254    {
     255        const Int_t port = fServSock->GetLocalPort();
     256
    132257        delete fServSock;
    133 
    134     delete fBuffer;
    135 
    136     cout << "Connection on Port 7000 closed." << endl;
     258        fServSock=NULL;
     259
     260        cout << "Connection on Port #" << port << " closed." << endl;
     261    }
     262
     263    clear(ios::eofbit);
    137264}
    138265
     
    149276int MReadSocket::underflow()
    150277{
    151     if (fail())
     278    // FIXME:     vvvvv is this correct?
     279    if (fail() || eof())
    152280    {
    153281        setg(fBuffer, fBuffer, fBuffer+fMtu);
     
    185313    return 0;
    186314}
    187 
  • trunk/MagicSoft/Mars/mbase/MReadSocket.h

    r2386 r2490  
    1919    char *fBuffer; //!
    2020
     21    int   fPort;
    2122    int   fMtu;
    2223    TTime fTimeout;
     
    2526    TSocket        *fRxSocket;
    2627
     28    void OpenServerSocket(int port);
     29    void OpenConnection(Bool_t block);
     30
    2731    int underflow();
    2832    int sync();
    2933
    3034public:
    31     MReadSocket(int port, int mtu=1500);
     35    MReadSocket(int port=-1, int mtu=1500);
    3236    MReadSocket(MReadSocket const& log) : istream((std::streambuf*)&log)
    3337    {
    3438    }
    3539    ~MReadSocket();
     40
     41    Bool_t Open(int port=-1, Bool_t block=kFALSE);
     42    void   Close();
    3643
    3744    void SetTimeout(UInt_t millisec) { fTimeout = millisec; }
  • trunk/MagicSoft/Mars/mbase/MTask.cc

    r2473 r2490  
    8383
    8484#include "MFilter.h"
    85 #include "MGGroupFrame.h"
    8685#include "MStatusDisplay.h"
    8786
  • trunk/MagicSoft/Mars/mfilter/MFRealTimePeriod.h

    r2408 r2490  
    1515
    1616public:
    17     MFRealTimePeriod(UInt_t millis=1000) : fMilliSec(millis)
     17    MFRealTimePeriod(UInt_t millis=1000) : fTime(0), fMilliSec(millis)
    1818    {
    1919        fName  = "MFRealTimePeriod";
  • trunk/MagicSoft/Mars/mhist/MHCamEvent.cc

    r2416 r2490  
    144144    *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
    145145
    146     for (unsigned int i=0; i<fSum->GetNumPixels(); i++)
     146    for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
    147147    {
    148148        if (!fSum->IsUsed(i))
     
    151151        if ((*fSum)[i+1]>mean+s*rms)
    152152            *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
    153         // if ((*fSum)[i+1]==0)
    154         //     *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " == 0" << endl;
    155         // if ((*fSum)[i+1]<fSum->GetMean()-s*fSum->GetRMS())
    156         //     *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " < " << s << "*rms" << endl;
    157153    }
    158154}
     
    175171
    176172    pad->cd(1);
    177     gPad->SetBorderMode(0);
    178     gPad->Divide(1,1);
    179     gPad->cd(1);
    180     gPad->SetBorderMode(0);
    181173    fSum->Draw();
    182174
  • trunk/MagicSoft/Mars/mhist/MHCamera.cc

    r2488 r2490  
    359359// To draw a camera into its own pad do something like:
    360360//
     361// MGeomCamMagic m;
     362// MHCamera *d=new MHCamera(m);
     363//
    361364// TCanvas *c = new TCanvas;
    362365// c->Divide(2,1);
    363 // MGeomCamMagic m;
    364 // MHCamera *d=new MHCamera(&m);
     366// c->cd(1);
     367//
    365368// d->FillRandom();
    366 // c->cd(1);
    367 // gPad->SetBorderMode(0);
    368 // gPad->Divide(1,1);
    369 // gPad->cd(1);
    370369// d->Draw();
    371370// d->SetBit(kCanDelete);
     
    375374    // root 3.02:
    376375    // gPad->SetFixedAspectRatio()
    377     Int_t col = 16;
    378 
    379     if (gPad)
    380         col = gPad->GetFillColor();
    381 
    382     TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
     376    const Color_t col = gPad ? gPad->GetFillColor() : 16;
     377    TVirtualPad  *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 656, 600);
    383378    pad->SetBorderMode(0);
    384379    pad->SetFillColor(col);
    385380
     381    //
     382    // Create an own pad for the MHCamera-Object which can be
     383    // resized in paint to keep the correct aspect ratio
     384    //
     385    pad->Divide(1, 1, 0, 0, col);
     386    pad->cd(1);
     387    gPad->SetBorderMode(0);
     388
    386389    AppendPad(option);
     390
     391    //
     392    // Do not change gPad. The user should not see, that Draw
     393    // changes gPad...
     394    //
     395    pad->cd();
    387396}
    388397
  • trunk/MagicSoft/Mars/mhist/MHEvent.cc

    r2488 r2490  
    256256    }
    257257
    258     TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
    259     pad->SetBorderMode(0);
    260 
    261     pad->Divide(1,1);
    262 
    263     pad->cd(1);
    264     gPad->SetBorderMode(0);
    265     gPad->Divide(1,1);
    266     gPad->cd(1);
    267     gPad->SetBorderMode(0);
     258    if (!gPad)
     259        MakeDefCanvas(this);
    268260    fHist->Draw();
    269261}
  • trunk/MagicSoft/Mars/mhist/MHTriggerLvl0.cc

    r2416 r2490  
    179179
    180180    pad->cd(1);
    181     gPad->SetBorderMode(0);
    182     gPad->Divide(1,1);
    183     gPad->cd(1);
    184     gPad->SetBorderMode(0);
     181    /*
     182     gPad->SetBorderMode(0);
     183     gPad->Divide(1,1);
     184     gPad->cd(1);
     185     gPad->SetBorderMode(0);
     186     */
    185187    fSum->Draw();
    186188
  • trunk/MagicSoft/Mars/mraw/MRawSocketRead.cc

    r2466 r2490  
    3535//
    3636//  Output Containers:
    37 //   MRawRunHeader, MRawEvtHeader, MRawEvtData, MRawCrateArray, MRawEvtTime
     37//   MRawRunHeader
     38//   MRawEvtHeader
     39//   MRawEvtData
     40//   MRawCrateArray
     41//   MRawEvtTime
    3842//
    3943//////////////////////////////////////////////////////////////////////////////
     
    5862#include "MRawCrateArray.h"
    5963
    60 //#include "../mmain/MStatusDisplay.h"
     64#include "MStatusDisplay.h"
    6165
    6266ClassImp(MRawSocketRead);
     
    6973//
    7074MRawSocketRead::MRawSocketRead(const char *name, const char *title)
    71     : fIn(NULL)
     75    : fIn(NULL), fPort(-1)
    7276{
    7377    fName  = name  ? name  : "MRawSocketRead";
    7478    fTitle = title ? title : "Task to read DAQ binary data from tcp/ip socket";
    7579
    76     fIn = new MReadSocket(7000);
     80    fIn = new MReadSocket;
    7781}
    7882
     
    8488{
    8589    delete fIn;
     90}
     91
     92// --------------------------------------------------------------------------
     93//
     94// Open the socket. This blocks until the connection has been established,
     95// an error occured opening the connection or the user requested to
     96// quit the application.
     97//
     98Bool_t MRawSocketRead::OpenSocket()
     99{
     100    if (fDisplay)
     101        fDisplay->SetStatusLine2(Form("Waiting for connection on port #%d...", fPort));
     102
     103    //
     104    // Open socket connection
     105    //
     106    while (1)
     107    {
     108        //
     109        // If port could be opened eveything is ok
     110        //
     111        if (fIn->Open(fPort))
     112            return kTRUE;
     113
     114        //
     115        // If a MStatusDisplay is attached the user might have
     116        // requested to quit the application
     117        //
     118        if (fDisplay)
     119            switch (fDisplay->CheckStatus())
     120            {
     121            case MStatusDisplay::kFileClose:
     122            case MStatusDisplay::kFileExit:
     123                *fLog << inf << "MRawSocketRead::PreProcess - MStatusDisplay triggered exit." << endl;
     124                return kFALSE;
     125            default:
     126                break;
     127            }
     128
     129        //
     130        // If an error occured during opening the socket stop
     131        //
     132        if (fIn->fail())
     133            break;
     134    }
     135
     136    *fLog << err << "ERROR - Cannot open port #" << fPort << endl;
     137    return kFALSE;
    86138}
    87139
     
    104156Int_t MRawSocketRead::PreProcess(MParList *pList)
    105157{
     158    if (!OpenSocket())
     159        return kFALSE;
     160
    106161    //
    107162    //  check if all necessary containers exist in the Parameter list.
     
    269324
    270325    fEvtNumber=fRawEvtHeader->GetDAQEvtNumber();
    271 /*
     326
    272327    if (fDisplay)
    273328        fDisplay->SetProgressBarPosition((Float_t)fEvtNumber/fRawRunHeader->GetNumEvents());
    274  */
     329
    275330    return kTRUE;
    276331}
    277332
    278333Int_t MRawSocketRead::PostProcess()
    279 {   /*
     334{
     335    //
     336    // Close Socket connection
     337    //
     338    fIn->Close();
     339
    280340    if (fDisplay)
    281341        fDisplay->SetProgressBarPosition(1);
    282      */
     342
    283343    return kTRUE;
    284344}
  • trunk/MagicSoft/Mars/mraw/MRawSocketRead.h

    r2466 r2490  
    44#ifndef MARS_MTask
    55#include "MTask.h"
    6 #endif
    7 
    8 #ifndef __IOSFWD__
    9 #include <iosfwd>
    106#endif
    117
     
    3329    UInt_t          fEvtNumber;     //!
    3430
    35     Int_t PreProcess(MParList *pList);
    36     Int_t Process();
    37     Int_t PostProcess();
     31    Int_t           fPort;          // Port on which we wait for the connection
     32
     33    Bool_t OpenSocket();
     34
     35    Int_t  PreProcess(MParList *pList);
     36    Int_t  Process();
     37    Int_t  PostProcess();
    3838
    3939public:
     
    4141    ~MRawSocketRead();
    4242
     43    void SetPort(int port) { fPort = port; }
     44
    4345    ClassDef(MRawSocketRead, 0) //Task to read DAQ binary data from tcp/ip socket
    4446};
Note: See TracChangeset for help on using the changeset viewer.