LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 &, art::ScheduleContext)
 
void postProcessEvent (art::Event const &, art::ScheduleContext)
 

Private Attributes

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

Detailed Description

ART event display service.

Definition at line 26 of file EventDisplay.h.

Constructor & Destructor Documentation

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

Definition at line 72 of file EventDisplay.cc.

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

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

Member Function Documentation

void evdb::EventDisplay::postBeginJob ( )
private

Definition at line 141 of file EventDisplay.cc.

References evdb::DisplayWindow::SetServicesAll().

Referenced by EventDisplay().

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

Definition at line 133 of file EventDisplay.cc.

References fInputSource.

Referenced by EventDisplay().

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

Definition at line 155 of file EventDisplay.cc.

References evdb::ServiceTable::ApplyEdits(), 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, art::errors::LogicError, MF_LOG_DEBUG, evdb::Printable::Print(), evdb::Printable::PrintTag(), evdb::NavState::Set(), evdb::EventHolder::SetEvent(), evdb::NavState::TargetEvent(), evdb::NavState::TargetRun(), and evdb::NavState::Which().

Referenced by EventDisplay().

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

Definition at line 148 of file EventDisplay.cc.

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

Referenced by EventDisplay().

149  {
151  }
unsigned int event
Definition: DataStructs.h:627
unsigned int run
Definition: DataStructs.h:628
static void SetRunEventAll(int run, int event)
TCEvent evt
Definition: DataStructs.cxx:8
void evdb::EventDisplay::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 89 of file EventDisplay.cc.

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

Referenced by EventDisplay().

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

Member Data Documentation

unsigned int evdb::EventDisplay::fAutoAdvanceInterval

Wait time in milliseconds.

Definition at line 45 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 46 of file EventDisplay.h.

Referenced by postProcessEvent().

int evdb::EventDisplay::fAutoPrintMax

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

Definition at line 47 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 48 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 49 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 50 of file EventDisplay.h.

Referenced by postProcessEvent(), and reconfigure().

std::string evdb::EventDisplay::fEchoPrintTempFile

a temporary file to enable atomic writes

Definition at line 51 of file EventDisplay.h.

Referenced by postProcessEvent(), and reconfigure().

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

Input source of events.

Definition at line 42 of file EventDisplay.h.

Referenced by postBeginJobWorkers(), and postProcessEvent().


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