LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
evdb::EventDisplay Class Reference

ART event display service. More...

#include "EventDisplay.h"

Public Member Functions

 EventDisplay (fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
 
void reconfigure (fhicl::ParameterSet const &pset)
 

Public Attributes

unsigned int fAutoAdvanceInterval
 Wait time in milliseconds. More...
 
int fAutoPrintCount
 Number of events printed so far. More...
 
int fAutoPrintMax
 How many events to print (zero = disable printing). More...
 
std::string fAutoPrintPattern
 Pattern for printing output filenames. Must contain "%s" and "%d", in that order. More...
 
bool fEchoPrint
 Copy what you see in X to a .gif for each event. More...
 
std::string fEchoPrintFile
 The file to dump that .gif to. Only one file, if you want a different file for each event, use AutoPrint instead. More...
 
std::string fEchoPrintTempFile
 a temporary file to enable atomic writes More...
 

Private Member Functions

void postBeginJob ()
 
void postBeginJobWorkers (art::InputSource *inputs, std::vector< art::Worker * > const &workers)
 
void preProcessEvent (art::Event const &)
 
void postProcessEvent (art::Event const &)
 

Private Attributes

art::InputSourcefInputSource
 Input source of events. More...
 

Detailed Description

ART event display service.

Definition at line 24 of file EventDisplay.h.

Constructor & Destructor Documentation

evdb::EventDisplay::EventDisplay ( fhicl::ParameterSet const &  pset,
art::ActivityRegistry reg 
)

Definition at line 71 of file EventDisplay_service.cc.

References postBeginJob(), postBeginJobWorkers(), postProcessEvent(), preProcessEvent(), reconfigure(), art::ActivityRegistry::sPostBeginJob, art::ActivityRegistry::sPostBeginJobWorkers, art::ActivityRegistry::sPostProcessEvent, and art::ActivityRegistry::sPreProcessEvent.

72  :
74  {
75  // evdb::DisplayWindow::Register("Test1","Test display #1",600,900,mk_canvas1);
76  // evdb::DisplayWindow::OpenWindow(0);
77 
78  this->reconfigure(pset);
79 
80  reg.sPostBeginJob.watch (this, &EventDisplay::postBeginJob);
84  }
GlobalSignal< detail::SignalResponseType::FIFO, void()> sPostBeginJob
void postBeginJobWorkers(art::InputSource *inputs, std::vector< art::Worker * > const &workers)
GlobalSignal< detail::SignalResponseType::LIFO, void(InputSource *, std::vector< Worker * > const &)> sPostBeginJobWorkers
void preProcessEvent(art::Event const &)
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
GlobalSignal< detail::SignalResponseType::LIFO, void(Event const &)> sPostProcessEvent
void reconfigure(fhicl::ParameterSet const &pset)
void postProcessEvent(art::Event const &)
int fAutoPrintCount
Number of events printed so far.
Definition: EventDisplay.h:44

Member Function Documentation

void evdb::EventDisplay::postBeginJob ( )
private

Definition at line 140 of file EventDisplay_service.cc.

References evdb::DisplayWindow::SetServicesAll().

Referenced by EventDisplay().

141  {
143  }
static void SetServicesAll()
void evdb::EventDisplay::postBeginJobWorkers ( art::InputSource inputs,
std::vector< art::Worker * > const &  workers 
)
private

Definition at line 132 of file EventDisplay_service.cc.

References fInputSource.

Referenced by EventDisplay().

134  {
135  fInputSource = input_source;
136  }
art::InputSource * fInputSource
Input source of events.
Definition: EventDisplay.h:40
void evdb::EventDisplay::postProcessEvent ( art::Event const &  evt)
private

Definition at line 154 of file EventDisplay_service.cc.

References evdb::ServiceTable::ApplyEdits(), DEFINE_ART_SERVICE, evdb::DisplayWindow::DrawAll(), art::Event::event(), fAutoPrintCount, fAutoPrintMax, fAutoPrintPattern, fEchoPrint, fEchoPrintFile, fEchoPrintTempFile, fInputSource, evdb::Printable::GetPrintables(), art::Event::id(), evdb::EventHolder::Instance(), evdb::ServiceTable::Instance(), art::SubRunID::invalidSubRun(), evdb::kGOTO_EVENT, evdb::kNEXT_EVENT, evdb::kPREV_EVENT, evdb::kRELOAD_EVENT, evdb::kSEQUENTIAL_ONLY, LOG_DEBUG, art::errors::LogicError, evdb::Printable::Print(), evdb::Printable::PrintTag(), art::RootInput::seekToEvent(), evdb::NavState::Set(), evdb::EventHolder::SetEvent(), evdb::NavState::TargetEvent(), evdb::NavState::TargetRun(), and evdb::NavState::Which().

Referenced by EventDisplay().

155  {
156  // stuff the event into the holder
158  holder->SetEvent(&evt);
159 
161 
162  if(fAutoPrintMax == 0){
163  TApplication* app = gROOT->GetApplication();
164 
165  // Hold here for user input from the GUI...
166  app->Run(kTRUE);
167  }
168 
169  //
170  // Apply edits to any services that may have been reconfigured
171  //
173 
174  if(fAutoPrintMax > 0){
175  ++fAutoPrintCount;
176  std::map<std::string, Printable*>& ps = Printable::GetPrintables();
177  for(std::map<std::string,Printable*>::iterator it = ps.begin(); it != ps.end(); ++it){
178  Printable* p = it->second;
179  // Ensure the format string is well-formed
180  if(fAutoPrintPattern.find("%s") == std::string::npos)
181  throw cet::exception("EventDisplay") << "Cannot find AutoPrintPattern"
182  << " format for %s";
183  if(fAutoPrintPattern.find("%d") == std::string::npos)
184  throw cet::exception("EventDisplay") << "Cannot find AutoPrintPattern"
185  << " format for %d";
186  // png doesn't seem to work for some reason
187  p->Print(TString::Format(fAutoPrintPattern.c_str(), p->PrintTag(), evt.event()));
188  }
189  if(fAutoPrintCount >= fAutoPrintMax) exit(0);
190  }
191 
192  // if fEchoPrint is set, do so
193  if (fEchoPrint){
194  std::map<std::string, Printable*>& ps = Printable::GetPrintables();
195  for(std::map<std::string,Printable*>::iterator it = ps.begin(); it != ps.end(); ++it){
196  Printable* p = it->second;
197  // lack of more parameters to Print() call means use the file format
198  // that's specified by the file name extension
199  p->Print(fEchoPrintTempFile.c_str());
200  }
201  // move temporary file to final file. This makes the creation of the
202  // newly printed file close to atomic
203  int result;
204  result=rename(fEchoPrintTempFile.c_str(),fEchoPrintFile.c_str());
205  if (result==0)
206  LOG_DEBUG("EventDisplayBase") << fEchoPrintTempFile
207  << " tempfile successfully renamed to "
208  << fEchoPrintFile;
209  else
210  mf::LogWarning("EventDisplayBase") << "Error renaming file "
212  << " to " << fEchoPrintFile
213  << " " << strerror(errno) <<"\n";
214  }
215 
216  art::RootInput* rootInput = dynamic_cast<art::RootInput*>(fInputSource);
217 
218  if(!rootInput && NavState::Which() != kSEQUENTIAL_ONLY){
220  mf::LogWarning("EventDisplayBase")
221  << "Random access for the EventDisplay requires a RootInput source for proper operation.\n"
222  << "You do not have a RootInput source so only sequential access works.\n";
223  }
224 
225 
226  // Figure out where to go in the input stream from here
227  switch (NavState::Which()) {
228  case kSEQUENTIAL_ONLY: break;
229  case kNEXT_EVENT: {
230  // Contrary to appearances, this is *not* a NOP: it ensures run and
231  // subRun are (re-)read as necessary if we've been doing random
232  // access. Come the revolution ...
233  //
234  // 2011/04/10 CG.
235  if(rootInput) rootInput->seekToEvent(0);
236  break;
237  }
238  case kPREV_EVENT: {
239  if(rootInput) rootInput->seekToEvent(-2);
240  break;
241  }
242  case kRELOAD_EVENT: {
243  if(rootInput) rootInput->seekToEvent(evt.id());
244  break;
245  }
246  case kGOTO_EVENT: {
248  if(rootInput){
249  if (!rootInput->seekToEvent(id)) { // Couldn't find event
250  mf::LogWarning("EventDisplayBase") << "Unable to find "
251  << id
252  << " -- reloading current event.";
253  // Reload current event.
254  rootInput->seekToEvent(evt.id());
255  }
256  }// end if not a RootInput
257  break;
258  }
259  default: {
261  << "EvengtDisplay in unhandled state "
262  << NavState::Which()
263  << ".\n";
264  }
265  } // end switch statement
266 
267  }
static void Set(int which)
Definition: NavState.cxx:24
static int TargetEvent()
Definition: NavState.cxx:51
int fAutoPrintMax
How many events to print (zero = disable printing).
Definition: EventDisplay.h:45
static ServiceTable & Instance()
intermediate_table::iterator iterator
std::string fEchoPrintFile
The file to dump that .gif to. Only one file, if you want a different file for each event...
Definition: EventDisplay.h:48
bool fEchoPrint
Copy what you see in X to a .gif for each event.
Definition: EventDisplay.h:47
std::string fEchoPrintTempFile
a temporary file to enable atomic writes
Definition: EventDisplay.h:49
static int TargetRun()
Definition: NavState.cxx:47
static std::map< std::string, evdb::Printable * > & GetPrintables()
Definition: Printable.cxx:61
static EventHolder * Instance()
Definition: EventHolder.cxx:15
bool seekToEvent(T eventSpec, bool exact=false)
Definition: RootInput.h:145
static void DrawAll(const char *opt=0)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
static int Which()
Definition: NavState.cxx:20
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:164
#define LOG_DEBUG(id)
int fAutoPrintCount
Number of events printed so far.
Definition: EventDisplay.h:44
std::string fAutoPrintPattern
Pattern for printing output filenames. Must contain "%s" and "%d", in that order. ...
Definition: EventDisplay.h:46
void SetEvent(art::Event const *evt)
Definition: EventHolder.cxx:32
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
art::InputSource * fInputSource
Input source of events.
Definition: EventDisplay.h:40
void evdb::EventDisplay::preProcessEvent ( art::Event const &  evt)
private

Definition at line 147 of file EventDisplay_service.cc.

References art::EventID::event(), art::Event::id(), art::EventID::run(), and evdb::DisplayWindow::SetRunEventAll().

Referenced by EventDisplay().

148  {
149  evdb::DisplayWindow::SetRunEventAll(evt.id().run(), evt.id().event());
150  }
static void SetRunEventAll(int run, int event)
void evdb::EventDisplay::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 88 of file EventDisplay_service.cc.

References fAutoAdvanceInterval, fAutoPrintMax, fAutoPrintPattern, fEchoPrint, fEchoPrintFile, fEchoPrintTempFile, fhicl::ParameterSet::get(), and w.

Referenced by EventDisplay().

89  {
90  fAutoAdvanceInterval = pset.get<unsigned int>("AutoAdvanceInterval" );
91  fAutoPrintMax = pset.get<int >("AutoPrintMax", 0 );
92  fAutoPrintPattern = pset.get<std::string >("AutoPrintPattern", "");
93  fEchoPrint = pset.get<bool >("EchoPrint", false);
94  fEchoPrintFile = pset.get<std::string >("EchoPrintFile", "$HOME/evt_echo.gif");
95  // Sanitize filename: root's OK with env variables, straight system
96  // calls are not. So, force a substitution of env. variables in the
97  // filename so we can do atomic-write "renames" later using a tmp file
98  if (fEchoPrint) {
99  wordexp_t p;
100  char** w;
101  wordexp( fEchoPrintFile.c_str(), &p, 0 );
102  w = p.we_wordv;
103  fEchoPrintFile = std::string(*w);
104  // the tempfile has to end with the same extension (eg, ".gif") as
105  // the specified filename. root's printing takes the format of the file
106  // from that extension. So, we have to construct a name with the same
107  // path, and extension: need to insert a "tmp" before the final .gif
108  // Sp, simply grab the file extension and stick it back on the end
109  std::string::size_type idx;
110  std::string extension;
111  idx = fEchoPrintFile.rfind('.');
112  if(idx != std::string::npos) {
113  extension = fEchoPrintFile.substr(idx);
114  fEchoPrintTempFile = std::string(*w) + ".tmp" + extension;
115  } else {
116  // No extension found, can't do this
117  fEchoPrint = false;
118  fEchoPrintTempFile = "";
119  mf::LogWarning("EventDisplayBase")
120  << "No file extension given to EchoPrintFile "
121  << fEchoPrintFile
122  << " so cannot determine file format, disabling EchoPrint\n";
123  }
124  wordfree(&p);
125  } else {
126  fEchoPrintTempFile = "";
127  }
128  }
int fAutoPrintMax
How many events to print (zero = disable printing).
Definition: EventDisplay.h:45
std::string fEchoPrintFile
The file to dump that .gif to. Only one file, if you want a different file for each event...
Definition: EventDisplay.h:48
unsigned int fAutoAdvanceInterval
Wait time in milliseconds.
Definition: EventDisplay.h:43
bool fEchoPrint
Copy what you see in X to a .gif for each event.
Definition: EventDisplay.h:47
std::string fEchoPrintTempFile
a temporary file to enable atomic writes
Definition: EventDisplay.h:49
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string fAutoPrintPattern
Pattern for printing output filenames. Must contain "%s" and "%d", in that order. ...
Definition: EventDisplay.h:46
Float_t w
Definition: plot.C:23

Member Data Documentation

unsigned int evdb::EventDisplay::fAutoAdvanceInterval

Wait time in milliseconds.

Definition at line 43 of file EventDisplay.h.

Referenced by evdb::ButtonBar::AutoAdvance(), evdb::ButtonBar::HandleTimer(), and reconfigure().

int evdb::EventDisplay::fAutoPrintCount

Number of events printed so far.

Definition at line 44 of file EventDisplay.h.

Referenced by postProcessEvent().

int evdb::EventDisplay::fAutoPrintMax

How many events to print (zero = disable printing).

Definition at line 45 of file EventDisplay.h.

Referenced by postProcessEvent(), and reconfigure().

std::string evdb::EventDisplay::fAutoPrintPattern

Pattern for printing output filenames. Must contain "%s" and "%d", in that order.

Definition at line 46 of file EventDisplay.h.

Referenced by postProcessEvent(), and reconfigure().

bool evdb::EventDisplay::fEchoPrint

Copy what you see in X to a .gif for each event.

Definition at line 47 of file EventDisplay.h.

Referenced by postProcessEvent(), and reconfigure().

std::string evdb::EventDisplay::fEchoPrintFile

The file to dump that .gif to. Only one file, if you want a different file for each event, use AutoPrint instead.

Definition at line 48 of file EventDisplay.h.

Referenced by postProcessEvent(), and reconfigure().

std::string evdb::EventDisplay::fEchoPrintTempFile

a temporary file to enable atomic writes

Definition at line 49 of file EventDisplay.h.

Referenced by postProcessEvent(), and reconfigure().

art::InputSource* evdb::EventDisplay::fInputSource
private

Input source of events.

Definition at line 40 of file EventDisplay.h.

Referenced by postBeginJobWorkers(), and postProcessEvent().


The documentation for this class was generated from the following files: