// $Id$ // // File: MyProcessor.cc // Created: Mon Aug 28 EDT 2006 // Creator: davidl (on Darwin swire-b241.jlab.org 8.7.0 powerpc) // #include "BCAL/DBCAL_ADCHit.h" #include "BCAL/DBCAL_TDCHit.h" #include "DEventSourceET/DADC.h" #include "MyProcessor.h" // This is an example program that shows how to access the BCAL06 // beam test data and create an ASCII file from it. // It uses a mutex for serializing access to the // file so this should be thread safe. To run it with // multiple processing threads, run the program with the // --nthreads=XXX option where XXX is the number of threads. //------------------ // init //------------------ jerror_t MyProcessor::init(void) { // Initialize file pointer file = NULL; // Initialize mutex pthread_mutex_init(&mutex, NULL); return NOERROR; } //------------------ // brun //------------------ jerror_t MyProcessor::brun(JEventLoop *eventLoop, int runnumber) { if(file==NULL && runnumber>0){ // Open output file char fname[256]; sprintf(fname,"gluex%05d.ascii", runnumber); file = fopen(fname, "w"); if(file){ cout<<"Opened file \""< adchits; vector tdchits; vector adcs; loop->Get(adchits); loop->Get(tdchits); loop->Get(adcs); // Skip uninteresting events if(adchits.size()==0)return NOERROR; // When we run with multiple threads, we should lock // a mutex so that only a single thread is accessing // the file at a time. To make threading // efficient, we need to minimize the amount of time // spent with the mutex locked. Thus, all of the // loop-Get(...) calls should be done first and // only file access done while the mutex is locked. pthread_mutex_lock(&mutex); // Write a header line for the event with how many hits there are fprintf(file,"EVENT: %d %d\n", (int)adchits.size()+2, (int)tdchits.size()); // Loop over hits vector::iterator hit; for(hit = adchits.begin(); hit != adchits.end(); hit++){ // Add this hit as a row to the file fprintf(file,"%d %d %d %d\n", (*hit)->layer, (*hit)->sector, (*hit)->end, (*hit)->adc + ((*hit)->overflow ? 4096:0)); } // Grab COSMIC paddle ADCs int cosmic1 = 0; int cosmic2 = 0; for(unsigned int i=0; icrate!=1)continue; if(adc->slot!=19)continue; if(adc->channel == 30)cosmic1=adc->adc + (adc->overflow ? 4096:0); if(adc->channel == 31)cosmic2=adc->adc + (adc->overflow ? 4096:0); } fprintf(file,"0 0 0 %d\n",cosmic1); fprintf(file,"0 0 0 %d\n",cosmic2); // Loop over TDC hits vector::iterator thit; for(thit = tdchits.begin(); thit != tdchits.end(); thit++){ // Add this hit as a row to the file fprintf(file,"%d %d %d %3.3f\n", (*thit)->layer, (*thit)->sector, (*thit)->end, (*thit)->t); } // Release the lock on the mutex pthread_mutex_unlock(&mutex); return NOERROR; } //------------------ // erun //------------------ jerror_t MyProcessor::erun(void) { // Don't need to do anything here. return NOERROR; } //------------------ // fini //------------------ jerror_t MyProcessor::fini(void) { // Close output file if(file)fclose(file); file=NULL; return NOERROR; }