Skip to content

Commit

Permalink
Merge pull request #842 from JeffersonLab/nsj_fix_locks
Browse files Browse the repository at this point in the history
Nsj fix locks
  • Loading branch information
aaust authored Sep 26, 2024
2 parents d709d4f + 9c7e531 commit b5ab7e8
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ using namespace jana;
// Routine used to create our JEventProcessor
#include <JANA/JApplication.h>
#include <JANA/JFactory.h>
#include "HistogramTools.h"
#include "PID/DVertex.h"
#include "PID/DChargedTrack.h"
#include "TRACKING/DTrackTimeBased.h"
Expand Down Expand Up @@ -173,21 +172,23 @@ jerror_t JEventProcessor_CDC_TimeToDistance::brun(JEventLoop *eventLoop, int32_t
sprintf(ccdbTable,"CDC/cdc_drift_table%s",dIsNoFieldFlag?"::NoBField":"");

if (jcalib->Get(ccdbTable, tvals)==false){
japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
japp->RootFillLock(this); //ACQUIRE ROOT LOCK!!
for(unsigned int i=0; i<tvals.size(); i++){
map<string, double> &row = tvals[i];
HistCurrentConstants->Fill(i+1,1000.*row["t"]);
}
japp->RootUnLock(); //RELEASE ROOT LOCK
japp->RootFillUnLock(this); //RELEASE ROOT LOCK
}
else{
jerr << " CDC time-to-distance table not available... bailing..." << endl;
exit(0);
}

japp->RootFillLock(this); //ACQUIRE ROOT LOCK!!

sprintf(ccdbTable,"CDC/drift_parameters%s",dIsNoFieldFlag?"::NoBField":"");
if (jcalib->Get(ccdbTable, tvals)==false){
japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!

map<string, double> &row = tvals[0]; // long drift side
HistCurrentConstants->Fill(101,row["a1"]);
HistCurrentConstants->Fill(102,row["a2"]);
Expand All @@ -213,12 +214,14 @@ jerror_t JEventProcessor_CDC_TimeToDistance::brun(JEventLoop *eventLoop, int32_t
HistCurrentConstants->Fill(120,row["c3"]);
HistCurrentConstants->Fill(121,row["B1"]);
HistCurrentConstants->Fill(122,row["B2"]);
japp->RootUnLock(); //RELEASE ROOT LOCK

}

// Save run number
HistCurrentConstants->Fill(125,runnumber);


japp->RootFillUnLock(this); //RELEASE ROOT LOCK

return NOERROR;
}

Expand Down Expand Up @@ -268,11 +271,11 @@ jerror_t JEventProcessor_CDC_TimeToDistance::evnt(JEventLoop *loop, uint64_t eve
}
}

japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
japp->RootFillLock(this); //ACQUIRE ROOT LOCK!!
if (least_fom >= 0.001) dHistZ2tracks0001->Fill(z);
if (least_fom >= 0.01) dHistZ2tracks001->Fill(z);
if (least_fom >= 0.1) dHistZ2tracks01->Fill(z);
japp->RootUnLock(); //RELEASE ROOT LOCK
japp->RootFillUnLock(this); //RELEASE ROOT LOCK

} // end if 2 tracks

Expand All @@ -290,6 +293,9 @@ jerror_t JEventProcessor_CDC_TimeToDistance::evnt(JEventLoop *loop, uint64_t eve

if (thisTimeBasedTrack->FOM < MIN_FOM) continue; // was 1e-10
vector<DTrackFitter::pull_t> pulls = thisTimeBasedTrack->pulls;

japp->RootFillLock(this); //ACQUIRE ROOT LOCK!!

// Loop over the pulls to get the appropriate information for our ring
for (unsigned int i = 0; i < pulls.size(); i++){
DTrackFitter::pull_t thisPull = pulls[i];
Expand All @@ -311,10 +317,10 @@ jerror_t JEventProcessor_CDC_TimeToDistance::evnt(JEventLoop *loop, uint64_t eve
int ring = thisCDCHit->wire->ring;
int straw = thisCDCHit->wire->straw;

japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!


dHistResidualVsFOM->Fill(thisTimeBasedTrack->FOM, thisPull.resi);
dHistResidualVslogFOM->Fill(log10(thisTimeBasedTrack->FOM), thisPull.resi);
dHistResidualVsFOM->Fill(thisTimeBasedTrack->FOM, thisPull.resi);
dHistResidualVslogFOM->Fill(log10(thisTimeBasedTrack->FOM), thisPull.resi);

// Fill Histogram with the drift times near t0 (+-50 ns)
dHistEarlyDriftTimesPerChannel->Fill(time,straw_offset[ring]+straw);
Expand Down Expand Up @@ -347,10 +353,10 @@ jerror_t JEventProcessor_CDC_TimeToDistance::evnt(JEventLoop *loop, uint64_t eve
// We only really need one histogram here
dHistPredictedDistanceVsDeltaVsDrift->Fill(time, delta, predictedDistance);

if (thisTimeBasedTrack->FOM >= 0.9) dHistPredictedDistanceVsDeltaVsDriftFOM09->Fill(time, delta, predictedDistance);
if (thisTimeBasedTrack->FOM >= 0.6) dHistPredictedDistanceVsDeltaVsDriftFOM06->Fill(time, delta, predictedDistance);
if (thisTimeBasedTrack->FOM >= 0.1) dHistPredictedDistanceVsDeltaVsDriftFOM01->Fill(time, delta, predictedDistance);
if (thisTimeBasedTrack->FOM >= 0.01) dHistPredictedDistanceVsDeltaVsDriftFOM001->Fill(time, delta, predictedDistance);
if (thisTimeBasedTrack->FOM >= 0.9) dHistPredictedDistanceVsDeltaVsDriftFOM09->Fill(time, delta, predictedDistance);
if (thisTimeBasedTrack->FOM >= 0.6) dHistPredictedDistanceVsDeltaVsDriftFOM06->Fill(time, delta, predictedDistance);
if (thisTimeBasedTrack->FOM >= 0.1) dHistPredictedDistanceVsDeltaVsDriftFOM01->Fill(time, delta, predictedDistance);
if (thisTimeBasedTrack->FOM >= 0.01) dHistPredictedDistanceVsDeltaVsDriftFOM001->Fill(time, delta, predictedDistance);


// To investigate some features, also do this in bins of Max sag
Expand All @@ -373,8 +379,10 @@ jerror_t JEventProcessor_CDC_TimeToDistance::evnt(JEventLoop *loop, uint64_t eve
// histo for hits in 1.8T region
if (Bz > 1.75 && Bz < 1.85) dHistPredictedDistanceVsDeltaVsDriftBz18->Fill(time, delta, predictedDistance);

japp->RootUnLock(); //RELEASE ROOT LOCK

}

japp->RootFillUnLock(this); //RELEASE ROOT LOCK
}
return NOERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/Utilities/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ SConscript(dirs=subdirs, exports='env osname', duplicate=0)
# Optional targets
optdirs = ['danahddm', 'dumpcandidates', 'dumpthrowns', 'l3bdt']
optdirs.extend(['merge_rawevents', 'syncskim', 'DAQ', 'TTab', 'rawevent'])
optdirs.extend(['cdc_amp_t','cdc_echo','cdc_emu', 'fmwpc_scan', 'epem_ml_skim'])
optdirs.extend(['cdc_amp_t','cdc_echo','cdc_emu','cdc_scan', 'fmwpc_scan', 'epem_ml_skim'])
sbms.OptionallyBuild(env, optdirs)
5 changes: 5 additions & 0 deletions src/plugins/Utilities/cdc_amp_t/JEventProcessor_cdc_amp_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ jerror_t JEventProcessor_cdc_amp_t::init(void)
{
// This is called once at program startup.

TDirectory *main = gDirectory;
gDirectory->mkdir("cdc_amp_t")->cd();

amp_t = new TH2I("amp_t","Digihit pulse height - pedestal vs sample number;sample number;pulse height-pedestal", 200,0,200,205,0,4100);
amp_tt = new TH2I("amp_tt","Digihit pulse height - pedestal vs sample number, hits on tracks;sample number; pulse height-pedestal", 200,0,200,205,0,4100);

hitamp_t = new TH2I("hitamp_t","Hit amplitude vs time;time (ns);hit amplitude", 125,0,1000,205,0,4100);
hitamp_tt = new TH2I("hitamp_tt","Tracked hit amplitude vs time;time (ns);hit amplitude", 125,0,1000,205,0,4100);

main->cd();

return NOERROR;
}

Expand Down
16 changes: 8 additions & 8 deletions src/plugins/Utilities/cdc_echo/JEventProcessor_cdc_echo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ jerror_t JEventProcessor_cdc_echo::evnt(JEventLoop *loop, uint64_t eventnumber)

if (locCDCHits.size() > 0) {

japp->RootWriteLock();
japp->RootFillLock(this);
counts->Fill(0);
japp->RootUnLock();
japp->RootFillUnLock(this);
}

vector<DTrackFitter::pull_t> pulls = track->pulls;
Expand Down Expand Up @@ -441,7 +441,7 @@ jerror_t JEventProcessor_cdc_echo::evnt(JEventLoop *loop, uint64_t eventnumber)

ULong64_t eventnum = (ULong64_t)eventnumber;

japp->RootWriteLock();
japp->RootFillLock(this);

TT->SetBranchAddress("eventnum",&eventnum);
TT->SetBranchAddress("ntrackhits",&ntrackhits);
Expand All @@ -454,7 +454,7 @@ jerror_t JEventProcessor_cdc_echo::evnt(JEventLoop *loop, uint64_t eventnumber)

TT->Fill();

japp->RootUnLock();
japp->RootFillUnLock(this);

}

Expand All @@ -481,7 +481,7 @@ jerror_t JEventProcessor_cdc_echo::evnt(JEventLoop *loop, uint64_t eventnumber)

// increment counts histo 0: tracks 1:all pulses 2:hits 3:hits on tracks 4: echo pulses 5: echo hits 6: echoes on tracks 7: saturated pulses 8:saturated hits 9:saturated hits on tracks

japp->RootWriteLock();
japp->RootFillLock(this);

counts->Fill(1);

Expand All @@ -508,7 +508,7 @@ jerror_t JEventProcessor_cdc_echo::evnt(JEventLoop *loop, uint64_t eventnumber)
if ( ontrack[rocid-25][slot-3][channel] >0 ) counts->Fill(9);
}

japp->RootUnLock();
japp->RootFillUnLock(this);


if (parent[rocid-25][slot-3][channel] == 0 ) continue; // not a parent or an echo
Expand Down Expand Up @@ -578,7 +578,7 @@ jerror_t JEventProcessor_cdc_echo::evnt(JEventLoop *loop, uint64_t eventnumber)

ULong64_t eventnum = (ULong64_t)eventnumber;

japp->RootWriteLock();
japp->RootFillLock(this);

if ( parentamp[rocid-25][slot-3][channel] >0 && timeovert < 8 ) { // probable echoes
counts->Fill(4);
Expand Down Expand Up @@ -626,7 +626,7 @@ jerror_t JEventProcessor_cdc_echo::evnt(JEventLoop *loop, uint64_t eventnumber)

T->Fill();

japp->RootUnLock();
japp->RootFillUnLock(this);

}

Expand Down
12 changes: 6 additions & 6 deletions src/plugins/Utilities/cdc_scan/JEventProcessor_cdc_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ jerror_t JEventProcessor_cdc_scan::evnt(JEventLoop *loop, uint64_t eventnumber)
ULong64_t eventnum = (ULong64_t)eventnumber;


japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
japp->RootFillLock(this); //ACQUIRE ROOT LOCK!!

t->SetBranchAddress("eventnum",&eventnum);
t->SetBranchAddress("CDCPulsecount",&nc);
Expand All @@ -304,15 +304,15 @@ jerror_t JEventProcessor_cdc_scan::evnt(JEventLoop *loop, uint64_t eventnumber)

t->Fill();

japp->RootUnLock();
japp->RootFillUnLock(this);





if (ntt > 0) { // Df125TriggerTime

japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
japp->RootFillLock(this); //ACQUIRE ROOT LOCK!!

tt->SetBranchAddress("eventnum",&eventnum);

Expand Down Expand Up @@ -340,7 +340,7 @@ jerror_t JEventProcessor_cdc_scan::evnt(JEventLoop *loop, uint64_t eventnumber)
tt->Fill();
}

japp->RootUnLock();
japp->RootFillUnLock(this);

}

Expand All @@ -350,7 +350,7 @@ jerror_t JEventProcessor_cdc_scan::evnt(JEventLoop *loop, uint64_t eventnumber)

if (nc || (nf&&FDC)) { // branches are almost the same for CDC & FDC - only amp differs

japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
japp->RootFillLock(this); //ACQUIRE ROOT LOCK!!

p->SetBranchAddress("eventnum",&eventnum);

Expand Down Expand Up @@ -705,7 +705,7 @@ jerror_t JEventProcessor_cdc_scan::evnt(JEventLoop *loop, uint64_t eventnumber)

}

japp->RootUnLock();
japp->RootFillUnLock(this);
}

return NOERROR;
Expand Down
25 changes: 11 additions & 14 deletions src/plugins/Utilities/fmwpc_scan/JEventProcessor_fmwpc_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ jerror_t JEventProcessor_fmwpc_scan::init(void)
{
// This is called once at program startup.

const uint32_t NSAMPLES = 300;

japp->RootWriteLock();
const uint32_t NSAMPLES = 200;

t = new TTree("T","FWMPC events");

Expand Down Expand Up @@ -109,9 +107,6 @@ jerror_t JEventProcessor_fmwpc_scan::init(void)
uint16_t adc[NSAMPLES];
t->Branch("adc",&adc,Form("adc[%i]/s",NSAMPLES));

japp->RootUnLock();


return NOERROR;

}
Expand Down Expand Up @@ -154,7 +149,7 @@ jerror_t JEventProcessor_fmwpc_scan::evnt(JEventLoop *loop, uint64_t eventnumber
if (!nmp) return NOERROR;


const uint NSAMPLES=300;
const uint NSAMPLES=200;

for (uint32_t i=0; i<nmp; i++) {

Expand All @@ -165,13 +160,14 @@ jerror_t JEventProcessor_fmwpc_scan::evnt(JEventLoop *loop, uint64_t eventnumber

const Df125WindowRawData *wrd = NULL;
cp->GetSingle(wrd);

uint32_t eventnum = eventnumber&0xFFFFFFFF;
uint32_t rocid = cp->rocid;
uint32_t slot = cp->slot;
uint32_t channel = cp->channel;
uint32_t itrigger = cp->itrigger;


uint32_t word1 = cp->word1;
uint32_t word2 = cp->word2;
uint32_t time = cp->le_time;
Expand All @@ -180,17 +176,18 @@ jerror_t JEventProcessor_fmwpc_scan::evnt(JEventLoop *loop, uint64_t eventnumber
uint32_t q = cp->time_quality_bit;
uint32_t overflows = cp->overflow_count;
uint32_t amp = cp->first_max_amp;

bool emulated = cp->emulated;

uint16_t adc[NSAMPLES]= {0};

uint32_t ns = (uint32_t)wrd->samples.size();
uint32_t ns = 0;
if (wrd) ns = (uint32_t)wrd->samples.size();

for (uint j=0; j<ns; j++) {
adc[j] = wrd->samples[j];
}


japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!

Expand All @@ -201,7 +198,7 @@ jerror_t JEventProcessor_fmwpc_scan::evnt(JEventLoop *loop, uint64_t eventnumber
t->SetBranchAddress("itrigger",&itrigger);
t->SetBranchAddress("word1",&word1);
t->SetBranchAddress("word2",&word2);

t->SetBranchAddress("pedestal",&pedestal);
t->SetBranchAddress("integral",&integral);
t->SetBranchAddress("amp",&amp);
Expand All @@ -214,9 +211,9 @@ jerror_t JEventProcessor_fmwpc_scan::evnt(JEventLoop *loop, uint64_t eventnumber
t->SetBranchAddress("adc",&adc);

t->Fill();
japp->RootUnLock();
japp->RootUnLock();
}



return NOERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "JEventProcessor_CDC_PerStrawReco.h"
#include "PID/DChargedTrack.h"
#include "TRACKING/DTrackTimeBased.h"
#include "HistogramTools.h"

using namespace jana;

Expand Down Expand Up @@ -435,6 +434,8 @@ jerror_t JEventProcessor_CDC_PerStrawReco::evnt(JEventLoop *loop, uint64_t event
vector <const DChargedTrack *> chargedTrackVector;
loop->Get(chargedTrackVector);

japp->RootFillLock(this);

for (unsigned int iTrack = 0; iTrack < chargedTrackVector.size(); iTrack++){

const DChargedTrackHypothesis* bestHypothesis = chargedTrackVector[iTrack]->Get_BestTrackingFOM();
Expand Down Expand Up @@ -533,6 +534,8 @@ jerror_t JEventProcessor_CDC_PerStrawReco::evnt(JEventLoop *loop, uint64_t event

}
}

japp->RootFillUnLock(this);
return NOERROR;
}

Expand Down
Loading

0 comments on commit b5ab7e8

Please sign in to comment.