28 using namespace DD4hep;
37 GenericEventHandler::~GenericEventHandler() {
38 m_subscriptions.clear();
46 throw runtime_error(
"Invalid event handler");
51 for(Subscriptions::iterator i=m_subscriptions.begin(); i!=m_subscriptions.end();++i)
57 m_subscriptions.insert(consumer);
62 Subscriptions::iterator i=m_subscriptions.find(consumer);
63 if ( i != m_subscriptions.end() ) m_subscriptions.erase(i);
67 long GenericEventHandler::numEvents()
const {
68 return current()->numEvents();
72 string GenericEventHandler::datasourceName()
const {
73 return current()->datasourceName();
78 if ( m_current && m_current->hasEvent() ) {
79 return m_current->collectionType(collection);
85 size_t GenericEventHandler::collectionLoop(
const string& collection,
DDEveHitActor& actor) {
86 if ( m_current && m_current->hasEvent() ) {
87 return m_current->collectionLoop(collection,actor);
93 size_t GenericEventHandler::collectionLoop(
const string& collection,
DDEveParticleActor& actor) {
94 if ( m_current && m_current->hasEvent() ) {
95 return m_current->collectionLoop(collection,actor);
101 bool GenericEventHandler::Open(
const string& file_type,
const string& file_name) {
102 size_t idx = file_name.find(
"lcio");
103 size_t idr = file_name.find(
"root");
110 if ( file_type.find(
"FCC") != string::npos ) {
111 m_current = (
EventHandler*)PluginService::Create<void*>(
"DDEve_FCCEventHandler",(
const char*)0);
114 else if ( idx != string::npos ) {
115 m_current = (
EventHandler*)PluginService::Create<void*>(
"DDEve_LCIOEventHandler",(
const char*)0);
117 else if ( idr != string::npos ) {
118 m_current = (
EventHandler*)PluginService::Create<void*>(
"DDEve_DDG4EventHandler",(
const char*)0);
121 throw runtime_error(
"Attempt to open file:"+file_name+
" of unknown type:"+file_type);
124 if ( m_current->Open(file_type, file_name) ) {
126 NotifySubscribers(&EventConsumer::OnFileOpen);
129 err =
"+++ Failed to open the data file:"+file_name;
133 err =
"+++ Failed to create fikle reader for file '"+file_name+
"' of type '"+file_type+
"'";
136 catch(
const exception&
e) {
137 err =
"\nAn exception occurred \n"
138 "while opening event data:\n" + string(e.what()) +
"\n\n";
140 string path = TString::Format(
"%s/icons/stop_t.xpm", gSystem->Getenv(
"ROOTSYS")).Data();
141 const TGPicture* pic = gClient->GetPicture(path.c_str());
142 new TGMsgBox(gClient->GetRoot(),0,
"Failed to open event data",err.c_str(),pic,
143 kMBDismiss,0,kVerticalFrame,kTextLeft|kTextCenterY);
148 bool GenericEventHandler::NextEvent() {
152 if ( current()->NextEvent() > 0 ) {
154 NotifySubscribers(&EventConsumer::OnNewEvent);
158 throw runtime_error(
"+++ EventHandler::readEvent: No file open!");
160 catch(
const exception&
e) {
161 string path = TString::Format(
"%s/icons/stop_t.xpm", gSystem->Getenv(
"ROOTSYS")).Data();
162 string err =
"\nAn exception occurred \n"
163 "while reading a new event:\n" + string(e.what()) +
"\n\n";
164 const TGPicture* pic = gClient->GetPicture(path.c_str());
165 new TGMsgBox(gClient->GetRoot(),0,
"Failed to read event", err.c_str(),pic,
166 kMBDismiss,0,kVerticalFrame,kTextLeft|kTextCenterY);
172 bool GenericEventHandler::PreviousEvent() {
174 if ( m_hasFile && current()->PreviousEvent() > 0 ) {
176 NotifySubscribers(&EventConsumer::OnNewEvent);
183 bool GenericEventHandler::GotoEvent(
long event_number) {
185 if ( m_hasFile && current()->GotoEvent(event_number) > 0 ) {
187 NotifySubscribers(&EventConsumer::OnNewEvent);
Event data actor base class for hits. Used to extract data from concrete classes. ...
void deletePtr(T *&p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Event handler base class. Interface to all DDEve I/O actions.
Event handler base class. Interface to all DDEve I/O actions.
Event data actor base class for particles. Used to extract data from concrete classes.
ClassImp(GenericEventHandler) GenericEventHandler
Standard constructor.