BDCheckDB Class Reference

Check contents of DB against raw files. More...

#include <BDCheckDB.h>

List of all members.

Public Member Functions

 BDCheckDB ()
 Create a checker.
 ~BDCheckDB ()
bool SpinFile (const char *filename)
 Process one file.
void SpinDir (const char *dirname)
bool CheckSpill (const RawBeamMonBlock &rbmb, const RawBeamMonHeaderBlock &rbmhb)
 Check one spill against the DB.

Detailed Description

Check contents of DB against raw files.

Author:
(last to touch it)
Author
bv
Version:
Revision
1.2
Date:
Date
2005/08/05 14:42:08

Contact: bv@bnl.gov

Created on: Fri Jul 8 10:24:57 2005

Id
BDCheckDB.h,v 1.2 2005/08/05 14:42:08 bv Exp

Definition at line 29 of file BDCheckDB.h.


Constructor & Destructor Documentation

BDCheckDB::BDCheckDB (  ) 

Create a checker.

Definition at line 34 of file BDCheckDB.cxx.

References HistMan::Book(), Form(), toroids, and TOROIDS.

00035 {
00036     HistMan hm("bd_check_db");
00037 
00038     hm.Book<TH1F>("dt","Time from file VldContext to spill time, less delay",
00039             1000,-0.1,0.1);
00040     hm.Book<TH1F>("dtnd","Time from file VldContext to SpillTimeND",
00041             1000,-0.1,0.1);
00042     hm.Book<TH1F>("dh","File-DB horn diff (kAmp)",
00043             200,-0.001,0.001);
00044 
00045     for (int ind=0; toroids[ind]; ++ind) {
00046         hm.Book<TH1F>(toroids[ind],Form("File-DB for %s",TOROIDS[ind]),
00047                       200,-0.0001,0.0001);
00048     }
00049 }

BDCheckDB::~BDCheckDB (  ) 

Definition at line 51 of file BDCheckDB.cxx.

References HistMan::WriteOut().

00052 {
00053     HistMan hm("");
00054     hm.WriteOut("bd_check_db.root");
00055 }


Member Function Documentation

bool BDCheckDB::CheckSpill ( const RawBeamMonBlock rbmb,
const RawBeamMonHeaderBlock rbmhb 
)

Check one spill against the DB.

Definition at line 153 of file BDCheckDB.cxx.

References det, MuELoss::e, BeamMonSpill::fHornCur, HistMan::Fill1d(), BeamMonSpill::fTor101, BeamMonSpill::fTortgt, BeamMonSpill::fTr101d, BeamMonSpill::fTrtgtd, BDSpillAccessor::Get(), get_timestamp(), RawBeamData::GetData(), RawBeamData::GetDataLength(), SpillTimeFinder::GetTimeOfNearestSpill(), SpillTimeFinder::Instance(), SimFlag::kData, Detector::kNear, BDSpillAccessor::LoadSpill(), UtilMath::sameValue(), BeamMonSpill::SpillTime(), toroids, and TOROIDS.

Referenced by SpinFile().

00155 {
00156     HistMan hm("bd_check_db");
00157 
00158     VldTimeStamp file_vts = get_timestamp(rbmb);
00159     const BeamMonSpill* spill = BDSpillAccessor::Get().LoadSpill(file_vts);
00160     if (!spill) {
00161         cerr << file_vts << " no DB entry\n";
00162         return false;
00163     }
00164     Detector::Detector_t det = Detector::kNear;
00165     SimFlag::SimFlag_t simflag = SimFlag::kData;
00166     VldContext file_vc(det,simflag,file_vts);
00167     VldTimeStamp spilltimend = SpillTimeFinder::Instance().GetTimeOfNearestSpill(file_vc);
00168 
00169     double nd_file_diff_time = (double)(file_vts - spilltimend);
00170     hm.Fill1d("dtnd",nd_file_diff_time);
00171 
00172     if (fabs(nd_file_diff_time) > 0.5) {
00173         cerr << "spilltimend: "
00174              << file_vts << " " << spilltimend << " " << nd_file_diff_time << endl;
00175     }
00176 
00177     VldTimeStamp db_vts = spill->SpillTime();
00178     double diff_time = file_vts - db_vts;
00179     hm.Fill1d("dt",diff_time);
00180     if (fabs(diff_time) > 0.5) {
00181         cerr << "timing: "
00182              << file_vts << " " << db_vts << " " << diff_time << endl;
00183         return false;
00184     }
00185 
00186 
00187     int errors=0;
00188 
00189     double db_toroids[4] = {
00190         spill->fTor101, spill->fTr101d, spill->fTortgt, spill->fTrtgtd
00191     };
00192 
00193     for (int ind=0; TOROIDS[ind]; ++ind) {
00194         double file_tor = 0;
00195         const RawBeamData* data = rbmb[TOROIDS[ind]];
00196         if (data && data->GetDataLength()) file_tor = data->GetData()[0];
00197         if (UtilMath::sameValue(file_tor, db_toroids[ind],true)) continue;
00198         double dt = file_tor - db_toroids[ind];
00199         hm.Fill1d(toroids[ind],dt);
00200         if (fabs(dt/(file_tor+db_toroids[ind])) > 1e-5) {
00201             cerr << "toroids: "
00202                  << db_vts << " " << TOROIDS[ind] << " "
00203                  << file_tor << " - " << db_toroids[ind] << " = "
00204                  << dt << " rel = " << dt/(file_tor+db_toroids[ind])
00205                  << endl;
00206             ++errors;
00207         }
00208     }
00209 
00210     double file_horn = 0;
00211     const char* horns[] = { "E:NSLINA","E:NSLINB","E:NSLINC","E:NSLIND",0 };
00212     for (int ind=0; horns[ind]; ++ind) {
00213         const RawBeamData* data = rbmb[horns[ind]];
00214         if (data && data->GetDataLength()) file_horn += data->GetData()[0];
00215     }
00216     double dh = file_horn-spill->fHornCur;
00217     hm.Fill1d("dh",dh);
00218     if (fabs(dh) > 0.01) {
00219         cerr << "horn: file=" << file_horn << " db="<<spill->fHornCur 
00220              << " dh=" << dh << endl;
00221         ++errors;
00222     }
00223 
00224     return !errors;
00225 }

void BDCheckDB::SpinDir ( const char *  dirname  ) 

Process a directory of files, file namess must be in canonical raw form.

Definition at line 99 of file BDCheckDB.cxx.

References done(), gSystem(), it, and SpinFile().

00100 {
00101     void* dir = gSystem->OpenDirectory(dirname);
00102     if (!dir) {
00103         cerr << "Failed to open directory \"" << dirname << "\"\n";
00104         return;
00105     }
00106     list<string> file_names;
00107     const char* cptr=0;
00108     while ( (cptr = gSystem->GetDirEntry(dir)) )
00109         if (cptr) file_names.push_back(cptr);
00110     if (!file_names.size()) return;
00111     file_names.sort();
00112     list<string>::iterator it, done = file_names.end();
00113 
00114     int bad_files = 0;
00115 
00116     for (it=file_names.begin(); it != done; ++it) {
00117         string file = *it;
00118         if (string::npos == file.find(".mbeam.root") || file[0] != 'B') {
00119             cerr << "Skipping unmatched file \"" << file << "\"\n";
00120             continue;
00121         }
00122         
00123         string path = dirname;
00124         path += "/" + file;
00125         cerr << "Processing " << path << endl;
00126         
00127         bool good = this->SpinFile(path.c_str());
00128         if (!good) {
00129             ++bad_files;
00130             cerr << path << " is bad\n";
00131         }
00132     }
00133     
00134     cerr << bad_files << " bad files\n";
00135 }

bool BDCheckDB::SpinFile ( const char *  filename  ) 

Process one file.

Definition at line 57 of file BDCheckDB.cxx.

References CheckSpill(), count, RawRecord::GetRawBlockIter(), infile, and nentries.

Referenced by SpinDir().

00058 {
00059     TFile infile(filename,"READ");
00060     TTree* intree=(TTree*)(infile.Get("BeamMon"));
00061 
00062     int bad_spills = 0, count=0;
00063 
00064     RawRecord* record = 0;
00065     int nentries = intree->GetEntries();
00066     for ( Int_t ient = 0; ient < nentries; ient++ ) {
00067         intree -> SetBranchAddress("RawRecord",&record);
00068         intree->GetEntry(ient);
00069 
00070         const RawBeamMonBlock* rbmb = 0;
00071         const RawBeamMonHeaderBlock* rbmhb = 0;
00072         TObject *obj = 0;
00073         TIter itr = record->GetRawBlockIter();
00074         while ((obj = itr())) {
00075             const RawBeamMonBlock* b =
00076                 dynamic_cast<const RawBeamMonBlock*>(obj);
00077             if (b) rbmb = b;
00078             const RawBeamMonHeaderBlock* h =
00079                 dynamic_cast<const RawBeamMonHeaderBlock*>(obj);
00080             if (h) rbmhb = h;
00081         }
00082 
00083         if (!(rbmb && rbmhb)) continue;
00084 
00085         ++count;
00086         bool good = this->CheckSpill(*rbmb,*rbmhb);
00087         if (!good) ++bad_spills;
00088 
00089     }
00090 
00091     if (bad_spills)
00092         cerr << filename << " " << bad_spills << " bad spills out of "
00093              << count << endl;
00094 
00095     infile.Close();
00096     return !bad_spills;
00097 }


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1