// JEventProcessor_danahddm.cc // // // JANA event processor plugin writes out hddm event to file // // // David Lawrence, 7-May-2010 #include #include #include #include "JEventProcessor_danahddm.h" // hddm output file name, use hddm:FILENAME configuration parameter to override static string hddmFileName = "dana_events.hddm"; // mutex for serializing writing to file static pthread_mutex_t hddmMutex = PTHREAD_MUTEX_INITIALIZER; // Make us a plugin // for initializing plugins extern "C" { void InitPlugin(JApplication *app) { InitJANAPlugin(app); app->AddProcessor(new JEventProcessor_danahddm(), true); } } // "extern C" //------------------------------- // Constructor //------------------------------- JEventProcessor_danahddm::JEventProcessor_danahddm() { jout << endl << " Default JEventProcessor_danahddm invoked" << endl << endl; // Check for hddm:FILENAME output file name parameter gPARMS->SetDefaultParameter("hddm:FILENAME",hddmFileName); jout << endl << " hddm output file name is " << hddmFileName << endl << endl; file = NULL; Nevents_written = 0; } //------------------------------- // Destructor //------------------------------- JEventProcessor_danahddm::~JEventProcessor_danahddm() { } //------------------------------- // init //------------------------------- jerror_t JEventProcessor_danahddm::init(void) { return NOERROR; } //------------------------------- // brun //------------------------------- jerror_t JEventProcessor_danahddm::brun(JEventLoop *loop, int runnumber) { // If file is already open, don't reopen it. Just keep adding to it. if(file)return NOERROR; // We wait until here to open the output so that we can check if the // input is hddm. If it's not, tell the user and exit immediately JEvent& event = loop->GetJEvent(); JEventSource *source = event.GetJEventSource(); DEventSourceHDDM *hddm_source = dynamic_cast(source); if(!hddm_source){ cerr<<" This program MUST be used with an HDDM file as input!"<GetJEvent(); JEventSource *source = event.GetJEventSource(); DEventSourceHDDM *hddm_source = dynamic_cast(source); if(!hddm_source){ cerr<<" This program MUST be used only with HDDM files as inputs!"<physicsEvents; if(PE){ for(unsigned int i=0; imult; i++){ s_ReconView_t *my_recon = PE->in[i].reconView; if(my_recon != HDDM_NULL){ // Create a new, temporary event s_HDDM_t *tmp_hddm = make_s_HDDM(); s_PhysicsEvents_t *tmp_PE = make_s_PhysicsEvents(1); // Move recon branch over to temporary tree tmp_PE->mult=1; tmp_PE->in[0].reconView = my_recon; tmp_PE->in[0].reactions = (s_Reactions_t*)HDDM_NULL; tmp_PE->in[0].hitView = (s_HitView_t*)HDDM_NULL; PE->in[i].reconView = (s_ReconView_t*)HDDM_NULL; // Delete temporary tree and any memory in the recon branch along with it flush_s_HDDM(tmp_hddm, NULL); } // Create a new reconView branch to hang our data from (only for // first physics event). if(recon==HDDM_NULL)recon = PE->in[i].reconView = make_s_ReconView(); } } // In order to do anything worthwhile here, we need to have a valid recon // pointer. if(recon==NULL || recon==HDDM_NULL)return NOERROR; // Fill in reconstructed banks, replacing any that are already there Add_DTrackTimeBased(loop, recon); // get write lock pthread_mutex_lock(&hddmMutex); // Write event to file and update counter flush_s_HDDM(hddm, file); Nevents_written++; // unlock pthread_mutex_unlock(&hddmMutex); // Tell the JEventSourceHDDM object not to free this event a second time hddm_source->flush_on_free = false; return NOERROR; } //------------------------------- // erun //------------------------------- jerror_t JEventProcessor_danahddm::erun(void) { return NOERROR; } //------------------------------- // fini //------------------------------- jerror_t JEventProcessor_danahddm::fini(void) { if(file){ close_s_HDDM(file); cout< tracktimebaseds; loop->Get(tracktimebaseds); if(tracktimebaseds.size()==0)return; // Allocate memory for all time based tracks s_Tracktimebaseds_t *tbt = recon->tracktimebaseds = make_s_Tracktimebaseds(tracktimebaseds.size()); tbt->mult = 0; for(unsigned int i=0; imult++){ const DTrackTimeBased *tbt_dana = tracktimebaseds[i]; s_Tracktimebased_t *tbt_hddm = &(tbt->in[tbt->mult]); DVector3 pos = tbt_dana->position(); DVector3 mom = tbt_dana->momentum(); tbt_hddm->FOM = tbt_dana->FOM; tbt_hddm->candidateid = tbt_dana->candidateid; tbt_hddm->trackid = tbt_dana->trackid; tbt_hddm->id = tbt_dana->id; tbt_hddm->chisq = tbt_dana->chisq; tbt_hddm->Ndof = tbt_dana->Ndof; tbt_hddm->momentum = make_s_Momentum(); tbt_hddm->properties = make_s_Properties(); tbt_hddm->origin = make_s_Origin(); tbt_hddm->momentum->E = tbt_dana->energy(); tbt_hddm->momentum->px = mom.x(); tbt_hddm->momentum->py = mom.y(); tbt_hddm->momentum->pz = mom.z(); tbt_hddm->properties->charge = tbt_dana->charge(); tbt_hddm->properties->mass = tbt_dana->mass(); tbt_hddm->origin->t = 0.0; tbt_hddm->origin->vx = pos.x(); tbt_hddm->origin->vy = pos.y(); tbt_hddm->origin->vz = pos.z(); } }