// $Id$ // // File: MyProcessor.cc // Created: Mon Aug 28 EDT 2006 // Creator: davidl (on Darwin swire-b241.jlab.org 8.7.0 powerpc) // #include #include #include using namespace std; #include "DEventSourceET/DTrigger.h" #include "DEventSourceET/DEPICS.h" #include "BCAL/DBCAL_ADCHit.h" #include "BCAL/DBCAL_TDCHit.h" #include "TAGGER/DTAGGER_ETCoinc_factory.h" #include "TRIGGER/DTRIGGER_TDCHit.h" #include "MyProcessor.h" extern int NARG; extern char **ARGV; // This program is used to create ROOT Tree DSTs of the // bcal06 data. // Sorting functions used to put TDC hits in order bool TrigTDCsort(const DTRIGGER_TDCHit* const &t1, const DTRIGGER_TDCHit* const &t2) { if(t1->t != t2->t)return fabs(t1->t) < fabs(t2->t); return t1->tid < t1->tid; } // Sorting functions used to put TDC hits in order bool TAGGERTDCsort(const DTAGGER_ETCoinc* const &t1, const DTAGGER_ETCoinc* const &t2) { if(t1->time != t2->time)return fabs(t1->time-593.0) < fabs(t2->time-593.0); return t1->T_id < t1->T_id; } //------------------ // init //------------------ MyProcessor::MyProcessor(void) { // File is opened in brun so we can use runnumber // in the filename. If you want one file for several // runs (e.g. multiple files from different runs are // specified on the command line) then open the file // here. runnumber = 0; pthread_mutex_init(&file_mutex,NULL); } //------------------ // brun //------------------ jerror_t MyProcessor::brun(JEventLoop *eventLoop, int runnumber) { // Special events (like prestart and go) will not have run number // info in them. Ignore these. if(runnumber==0 || runnumber==this->runnumber)return NOERROR; // Lock access to ROOT pthread_mutex_lock(&file_mutex); // Create output file char fname[256]; sprintf(fname,"bcal%05d.ascii", runnumber); fout.open(fname); if(!fout.is_open()){ cerr<<__FILE__<<":"<<__LINE__<<" Unable to open file \""<runnumber = runnumber; time_t t = time(NULL); fout<<"# ASCII formatted BCAL06 data file produced on "< triggers; vector adchits; vector tdchits; vector ethits; vector trigtdcs; loop->Get(triggers); loop->Get(adchits); loop->Get(tdchits); loop->Get(ethits); loop->Get(trigtdcs); // Initialize variables b.adcsumN = b.adcsumS = 0; b.trig=0; for(int i=0; i<18; i++)b.adcN[i] = b.adcS[i] = 0; for(int i=0; i<18; i++)b.tdcN[i] = b.tdcS[i] = -10000; // Trigger if(triggers.size()>0)b.trig=triggers[0]->latch; sort(trigtdcs.begin(), trigtdcs.end(), TrigTDCsort); b.Ntdctrig=0; for(unsigned int i=0; it)>300.0)continue; // cut out obviously out-of-time hits b.tdctrig[b.Ntdctrig] = tdc->t; b.tdctrigid[b.Ntdctrig++] = tdc->tid; if(i>=MAX_TRIGTDCS)break; } // BCAL ADC for(unsigned int i=0; icid<1 || adchit->cid>18)continue; if(adchit->end==0){ b.adcN[adchit->cid - 1] = adchit->adc-adchit->ped; b.adcsumN += adchit->adc-adchit->ped; }else{ b.adcS[adchit->cid - 1] = adchit->adc-adchit->ped; b.adcsumS += adchit->adc-adchit->ped; } } // BCAL TDC for(unsigned int i=0; icid<1 || tdchit->cid>18)continue; if(tdchit->end==0){ b.tdcN[tdchit->cid - 1] = tdchit->t; }else{ b.tdcS[tdchit->cid - 1] = tdchit->t; } } // Tagger sort(ethits.begin(), ethits.end(), TAGGERTDCsort); b.Nphotons = 0; for(unsigned int i=0; ienergy==0.0)continue; b.tphoton[b.Nphotons] = ethits[i]->time; b.Ephoton[b.Nphotons] = ethits[i]->energy; b.Nphotons++; if(b.Nphotons>=MAX_PHOTONS)break; } // Fill bcal tree if(adchits.size()>0){ // 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 // pretty much just the output written // while the mutex is locked. pthread_mutex_lock(&file_mutex); fout<<"EVENT: "< epics; loop->Get(epics); if(epics.size() == 0)return; // Initialize values beam.I2c24 = beam.x2c24 = beam.y2c24 = 0.0; beam.I2c21 = beam.x2c21 = beam.y2c21 = 0.0; env.templ1 = env.templ2 = env.templ3 = 0.0; env.humidityl1 = env.humidityl2 = env.humidityl3 = 0.0; // Loop over EPICS variables, copying the interesting ones for(unsigned int i=0; itime; if(e->name == "hallb_IPM2C21A_CUR")beam.I2c21 = atof(e->value.c_str()); if(e->name == "hallb_IPM2C21A_XPOS")beam.x2c21 = atof(e->value.c_str()); if(e->name == "hallb_IPM2C21A_YPOS")beam.y2c21 = atof(e->value.c_str()); if(e->name == "hallb_IPM2C24A_CUR")beam.I2c24 = atof(e->value.c_str()); if(e->name == "hallb_IPM2C24A_XPOS")beam.x2c24 = atof(e->value.c_str()); if(e->name == "hallb_IPM2C24A_YPOS")beam.y2c24 = atof(e->value.c_str()); if(e->name == "hallb_l1_temp")env.templ1 = atof(e->value.c_str()); if(e->name == "hallb_l2_temp")env.templ2 = atof(e->value.c_str()); if(e->name == "hallb_l3_temp")env.templ3 = atof(e->value.c_str()); if(e->name == "hallb_l1_hum")env.humidityl1 = atof(e->value.c_str()); if(e->name == "hallb_l2_hum")env.humidityl2 = atof(e->value.c_str()); if(e->name == "hallb_l3_hum")env.humidityl3 = atof(e->value.c_str()); } // Check if there was beam current info if(beam.I2c21!=0.0 || beam.x2c21!=0.0 || beam.y2c21!=0.0){ pthread_mutex_lock(&file_mutex); // do nothing for now pthread_mutex_unlock(&file_mutex); } // Check if there was environment info if(env.templ1!=0.0 || env.templ2!=0.0 || env.templ3!=0.0){ pthread_mutex_lock(&file_mutex); // do nothing for now pthread_mutex_unlock(&file_mutex); } }