source: trunk/MagicSoft/Mars/mtemp/mifae/library/MDisplay.cc@ 6977

Last change on this file since 6977 was 4761, checked in by rico, 20 years ago
Changelog
File size: 4.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17! Author(s): Javier Rico 05/2004 <mailto:jrico@ifae.es>
18!
19! Copyright: MAGIC Software Development, 2000-2004
20!
21!
22\* ======================================================================== */
23
24//////////////////////////////////////////////////////////////////////////////
25//
26// MDisplay
27//
28// Class to display camera events (MCamEvent)
29// You can set an event-by-event display with pause between two consecutive
30// events. You can set an output PS file.
31//
32// Input containers (to be provided to the constructor):
33//
34// MCamEvent
35// MGeomCam
36//
37// Output containers:
38//
39//
40//////////////////////////////////////////////////////////////////////////////
41
42#include <fstream>
43#include <math.h>
44
45#include "TCanvas.h"
46#include "TPostScript.h"
47
48#include "MParList.h"
49#include "MDisplay.h"
50#include "MCamEvent.h"
51#include "MGeomCam.h"
52#include "MHCamera.h"
53#include "MRawRunHeader.h"
54#include "MRawEvtHeader.h"
55
56#include "MLog.h"
57#include "MLogManip.h"
58
59ClassImp(MDisplay);
60
61using namespace std;
62
63static const TString gsDefName = "MDisplay";
64static const TString gsDefTitle = "Camera display task";
65static const TString gsDefPSFileName = "display.ps";
66
67// -------------------------------------------------------------------------
68//
69// Constructor. Need to provide the MCamEvent container to be displayed <event>
70// and camera geometry <geom>. Also the display type <type> can be specified
71// (see the MHCamera documentation for more details)
72//
73MDisplay::MDisplay(MCamEvent* event, MGeomCam* geom, Int_t type, const char* name, const char* title)
74 : fGeomCam(geom), fCamEvent(event), fCanvas(NULL), fPSFile(NULL), fDisplayType(type), fCreatePSFile(kFALSE), fPause(kTRUE)
75{
76 fName = name ? name : gsDefName.Data();
77 fTitle = title ? title : gsDefTitle.Data();
78
79 fDisplay = new MHCamera(*geom);
80 fDisplay->SetPrettyPalette();
81
82 fPSFileName = gsDefPSFileName;
83}
84// -------------------------------------------------------------------------
85//
86// Destructor
87//
88MDisplay::~MDisplay()
89{
90 delete fDisplay;
91 if(fCanvas)
92 delete fCanvas;
93 if(fPSFile)
94 delete fPSFile;
95}
96
97// -------------------------------------------------------------------------
98//
99// Create the canvas, eventually set the batch mode and open ps file
100//
101Int_t MDisplay::PreProcess(MParList* pList)
102{
103 fCanvas = new TCanvas("myCanvas","Event Display",600,600);
104 if(fCreatePSFile)
105 fPSFile = new TPostScript(fPSFileName,111);
106 if(!fPause)
107 fCanvas->SetBatch();
108 fCanvas->cd(1);
109 fDisplay->Draw();
110
111 //look for the run and event headers
112 fEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
113 if (!fEvtHeader)
114 {
115 *fLog << err << "MRawEvtHeader not found... aborting." << endl;
116 return kFALSE;
117 }
118
119 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
120 if (!fRunHeader)
121 {
122 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
123 return kFALSE;
124 }
125
126 return kTRUE;
127}
128
129// -------------------------------------------------------------------------
130//
131// Set the new containt of the camera event and update the display.
132// Set new page if ps file is requested
133// Pause execution if event-by-event display is chosen
134//
135Int_t MDisplay::Process()
136{
137 // new page in ps file
138 if(fPSFile)
139 fPSFile->NewPage();
140
141 // update the display contents
142 fDisplay->SetCamContent(*fCamEvent,fDisplayType);
143 fCanvas->GetPad(1)->Modified();
144 fCanvas->GetPad(1)->Update();
145
146 *fLog << all << "Run: " << fRunHeader->GetRunNumber() << ", Event: " << fEvtHeader->GetDAQEvtNumber() << endl;
147
148 // pause execution
149 if(fPause)
150 {
151 cout << "Type 'q' to exit, 'p' to print event into ps file, <return> to go on: ";
152 TString input;
153 input =cin.get();
154
155 if (input=='q')
156 return kFALSE;
157 if(input=='p')
158 {
159 Char_t psfile[200];
160 sprintf(psfile,"Run%06dEvent%07d.ps", fRunHeader->GetRunNumber(), fEvtHeader->GetDAQEvtNumber());
161 fCanvas->Print(psfile);
162 }
163 }
164
165 return kTRUE;
166}
167
168// -------------------------------------------------------------------------
169//
170// Close ps file if it was open
171//
172Int_t MDisplay::PostProcess()
173{
174 if(fPSFile) fPSFile->Close();
175 return kTRUE;
176}
Note: See TracBrowser for help on using the repository browser.