ODBCheck Class Reference
[Odbcheck]

Provides corrected ODB files for alcapana production. More...

#include <ODBCheck.hh>

List of all members.

Public Member Functions

 ODBCheck ()
 ~ODBCheck ()
void SetDirs (const std::string &raw, const std::string &odb, const std::string &hist, const std::string &corr)
void Check (int run)

Private Member Functions

void OutputCorrections ()

Private Attributes

int fRun
 Run number.
WireMap fODB
 Original ODB.
WireMap fCorrections
 Corrected ODB; produced in the course of running Check().
DataDir fDataDirs
 Location of necessary files.
PulseEstimate fEstimate
 Estimates based off of data quality histograms for corrected ODB.
std::ofstream fCorrectionsFile
 The corrected ODB file.

Detailed Description

Provides corrected ODB files for alcapana production.

ODBCheck looks simply for inconsistencies between the alcapana data quality output histograms and the original ODB files, then outputs a corrected ODB file for the run to be loaded on the next alcapana production.

Definition at line 23 of file ODBCheck.hh.


Constructor & Destructor Documentation

ODBCheck::ODBCheck (  ) 

Definition at line 10 of file ODBCheck.cc.

00010                    : fRun(0), fODB(), fCorrections(), fDataDirs(),
00011                        fEstimate(), fCorrectionsFile() {
00012 }

ODBCheck::~ODBCheck (  ) 

Definition at line 14 of file ODBCheck.cc.

00014                     {
00015 }


Member Function Documentation

void ODBCheck::Check ( int  run  ) 

Correct a run.

Using the histogram output from alcapana, make estimates as to the correct values of some ODB keys. Outputs a corrections file when done.

Parameters:
[in] run Run number to process.

Definition at line 122 of file ODBCheck.cc.

References WireMap::Add(), WireMap::Clear(), WireMap::ClearDisabledDuplicateDetectors(), WireMap::Default(), WireMap::Disable(), PulseEstimate::Estimate(), fCorrections, fDataDirs, fEstimate, fODB, fRun, WireMap::GetBanks(), WireMap::GetDets(), WireMap::GetFrequencies(), DataDir::GetHistFileName(), WireMap::GetNDets(), DataDir::GetODBFileName(), PulseEstimate::GetOffset(), PulseEstimate::GetPedestal(), PulseEstimate::GetPolarity(), WireMap::LoadOver(), OutputCorrections(), WireMap::SetRun(), and WireMap::UniqueFixes().

Referenced by main().

00122                             {
00123   TFile hist_file(fDataDirs.GetHistFileName(run).c_str(), "READ");
00124 
00125   if (!hist_file.IsOpen()) {
00126     std::cout <<
00127       "ODBCheck ERROR: Cannot open histogram file! (" <<
00128       fDataDirs.GetHistFileName(run).c_str() << ")" <<
00129       std::endl;
00130     return;
00131   }
00132 
00133   fRun = run;
00134   std::string fname(fDataDirs.GetODBFileName(fRun));
00135   WireMap run_odb(fRun, fname);
00136   fODB = WireMap::Default();
00137   fODB.LoadOver(run_odb);
00138   fCorrections.Clear();
00139   fCorrections.SetRun(fRun);
00140 
00141   // The value we're looping over is the bank names in the ODB.
00142   // Some corresponding detector names are not real,
00143   // such as "blank". We hope these histograms do not exist so
00144   // that we don't process them unnecessarily.
00145   for (unsigned int i = 0; i < fODB.GetNDets(); ++i) {
00146     // If channel is implicitly disabled (named blank or ZZZZ),
00147     // simply copy values from file ODB and disable.
00148     if (fODB.GetBanks()[i] == "ZZZZ" || fODB.GetDets()[i] == "blank") {
00149       fCorrections.Add(fODB, i);
00150       fCorrections.Disable();
00151       continue;
00152     }
00153     // We look for the shapes and timing histograms
00154     TH2* shapes;
00155     TH1* timing;
00156     hist_file.GetObject(("DataQuality_LowLevel/hDQ_PulseShapes_" + fODB.GetDets()[i] + "_" + fODB.GetBanks()[i]).c_str(), shapes);
00157     hist_file.GetObject(("DataQuality_LowLevel/hDQ_muScTDiff_" + fODB.GetDets()[i] + "_" + fODB.GetBanks()[i]).c_str(), timing);
00158 
00159     // Only if both histograms are present and filled are corrections estimated
00160     // Mark all other channels as disabled.
00161     // Detector muSc is the exception, which is expected to have an empty
00162     // timing correlation histogram.
00163     if (!shapes) {
00164       fCorrections.Add(fODB, i);
00165       std::cout <<
00166         "ODBCheck WARNING: Shapes histogram not found! Corrections not included for " <<
00167         fODB.GetDets()[i] << "_" << fODB.GetBanks()[i] << " and the channel has been marked as disabled..." <<
00168         std::endl;
00169       fCorrections.Disable();
00170     } else if (!timing) {
00171       fCorrections.Add(fODB, i);
00172       std::cout <<
00173         "ODBCheck WARNING: Timing histogram not found! Corrections not included for " <<
00174         fODB.GetDets()[i] << "_" << fODB.GetBanks()[i] << " and the channel has been marked as disabled..." <<
00175         std::endl;
00176       fCorrections.Disable();
00177     } else if (!shapes->GetEntries()) {
00178       fCorrections.Add(fODB, i);
00179       std::cout <<
00180         "ODBCheck WARNING: Shapes histogram empty! Corrections not included for " <<
00181         fODB.GetDets()[i] << "_" << fODB.GetBanks()[i] << " and the channel has been marked as disabled..." <<
00182         std::endl;
00183       fCorrections.Disable();
00184     } else if (!timing->GetEntries() && fODB.GetDets()[i] != std::string("muSc")) { // muSc has empty timing histogram, but still good
00185       fCorrections.Add(fODB, i);
00186         std::cout <<
00187           "ODBCheck WARNING: Timing histogram empty! Corrections not included for " <<
00188           fODB.GetDets()[i] << "_" << fODB.GetBanks()[i] << " and the channel has been marked as disabled..." <<
00189           std::endl;
00190         fCorrections.Disable();
00191     } else {
00192       fEstimate.Estimate(shapes, timing);
00193       fCorrections.Add(fODB.GetBanks()[i], fODB.GetDets()[i],
00194                        true, fEstimate.GetPedestal(),
00195                        fEstimate.GetPolarity(), fEstimate.GetOffset(),
00196                        fODB.GetFrequencies()[i]);
00197     }
00198 
00199     delete shapes;
00200     delete timing;
00201     shapes = NULL;
00202     timing = NULL;
00203   }
00204   hist_file.Close();
00205 
00206   fCorrections.ClearDisabledDuplicateDetectors();
00207   fCorrections.UniqueFixes();
00208 
00209   OutputCorrections();
00210 }

void ODBCheck::OutputCorrections (  )  [private]

Calls the function to output the corrections file. All the corrections should be done by this point.

Definition at line 24 of file ODBCheck.cc.

References fCorrections, fCorrectionsFile, fDataDirs, fRun, DataDir::GetCorrFileName(), WireMap::GetDets(), WireMap::GetEnableds(), WireMap::GetFrequencies(), WireMap::GetNDets(), WireMap::GetOffsets(), WireMap::GetPedestals(), WireMap::GetPolarities(), and WireMap::GetRun().

Referenced by Check().

00024                                  {
00025   // Some constants used in this function
00026   static const std::string header("[/Analyzer/Wiremap]");
00027   static const std::string det_key("DetectorName = STRING");
00028   static const std::string en_key("Enabled = BOOL");
00029   static const std::string pol_key("TriggerPolarity = INT");
00030   static const std::string ped_key("Pedestal = INT");
00031   static const std::string time_key("TimeShift = FLOAT");
00032   static const std::string freq_key("SamplingFrequency = FLOAT");
00033 
00034   static const std::string key_tail_sm("[48] :"); // < Run 2173
00035   static const std::string key_tail_lg("[52] :"); // >= Run 2173
00036   static std::string key_tail;
00037 
00038   // Open the file
00039   if (fCorrectionsFile.is_open()) {
00040     std::cout << "ODBCheck WARNING: Corrections file already open. Closing old file..." << std::endl;
00041     fCorrectionsFile.close();
00042   }
00043   fCorrectionsFile.open(fDataDirs.GetCorrFileName(fRun).c_str());
00044   if (!fCorrectionsFile.is_open()) {
00045     std::cout <<
00046       "ODBCheck ERROR: Cannot open correction file (" <<
00047       fDataDirs.GetCorrFileName(fRun) << ")!" <<
00048       std::endl <<
00049       "                Corrections file not written!" <<
00050       std::endl;
00051     return;
00052   }
00053   
00054   // Resize corrected wiremap for consistency
00055   //fCorrections.ResizeToBanks();
00056 
00057   // Sanity check
00058   // If the number of detectors is 52, the run number must be greater than 2173
00059   // If it is 48, the run must have been before then
00060   // Otherwise, there's an error
00061   unsigned int ndets = fCorrections.GetNDets();
00062   if ((ndets == 48 && fCorrections.GetRun() >= 2173) ||
00063       (ndets == 52 && fCorrections.GetRun() < 2173)) {
00064     std::cout << "ODBCheck ERROR: Corrected wiremap has run (" << fCorrections.GetRun() <<
00065       ") and number of detectors (" << ndets << ") that disagree with how the run went!" <<
00066       std::endl << "                Not outputting corrections." << std::endl;
00067     return;
00068   }
00069     
00070   // The tail of the keys depends on the size
00071   if (ndets == 48) {
00072     key_tail = key_tail_sm;
00073   } else if (ndets == 52) {
00074     key_tail = key_tail_lg;
00075   } else {
00076     std::cout <<
00077       "ODBCheck ERROR: Corrected WireMap has detector count not 48 or 52! (" <<
00078       fCorrections.GetNDets() << ")" << std::endl <<
00079       "                Corrected ODB not written." << std::endl;
00080     return;
00081   }
00082 
00083   // Write the file
00084   // The lines must be of the form
00085   // [INDEX] VALUE
00086   fCorrectionsFile << header << std::endl;
00087   fCorrectionsFile << det_key << key_tail << std::endl;
00088   for (unsigned int idet = 0; idet < ndets; ++idet)
00089     fCorrectionsFile << "[80] " <<
00090       fCorrections.GetDets()[idet] <<
00091       std::endl;
00092   fCorrectionsFile << en_key << key_tail << std::endl;
00093   for (unsigned int idet = 0; idet < ndets; ++idet)
00094     fCorrectionsFile << "[" << idet << "] " <<
00095       (fCorrections.GetEnableds()[idet] ? 'y' : 'n') << // Print y if enabled, n if disabled
00096       std::endl;
00097   fCorrectionsFile << pol_key << key_tail << std::endl;
00098   for (unsigned int idet = 0; idet < ndets; ++idet)
00099     fCorrectionsFile << "[" << idet << "] " <<
00100       fCorrections.GetPolarities()[idet] <<
00101       std::endl; 
00102   fCorrectionsFile << ped_key << key_tail << std::endl;
00103   for (unsigned int idet = 0; idet < ndets; ++idet)
00104     fCorrectionsFile << "[" << idet << "] " <<
00105       fCorrections.GetPedestals()[idet] <<
00106       std::endl; 
00107   fCorrectionsFile << time_key << key_tail << std::endl;
00108   for (unsigned int idet = 0; idet < ndets; ++idet)
00109     fCorrectionsFile << "[" << idet << "] " <<
00110       -fCorrections.GetOffsets()[idet] <<
00111       std::endl;
00112   fCorrectionsFile << freq_key << key_tail << std::endl;
00113   for (unsigned int idet = 0; idet < ndets; ++idet)
00114     fCorrectionsFile << "[" << idet << "] " <<
00115       fCorrections.GetFrequencies()[idet] <<
00116       std::endl;
00117   fCorrectionsFile << std::endl;
00118 
00119   fCorrectionsFile.close();
00120 }

void ODBCheck::SetDirs ( const std::string &  raw,
const std::string &  odb,
const std::string &  hist,
const std::string &  corr 
)

Set the directories to look for the different files we might need. The information is stored in a DataDir object.

Parameters:
[in] raw Raw data directory (MIDAS files)
[in] odb ODB data directory (ODB files)
[in] hist Histograms directory (hist?????.root files)
[in] corr Corrections directory (correction*.dat files for rootana)

Definition at line 17 of file ODBCheck.cc.

References fDataDirs, DataDir::SetCorrDir(), DataDir::SetHistDir(), DataDir::SetODBDir(), and DataDir::SetRawDir().

Referenced by main().

00017                                                                                                                {
00018   fDataDirs.SetRawDir(raw);
00019   fDataDirs.SetODBDir(odb);
00020   fDataDirs.SetHistDir(hist);
00021   fDataDirs.SetCorrDir(corr);
00022 }


Member Data Documentation

Corrected ODB; produced in the course of running Check().

Definition at line 27 of file ODBCheck.hh.

Referenced by Check(), and OutputCorrections().

std::ofstream ODBCheck::fCorrectionsFile [private]

The corrected ODB file.

Definition at line 30 of file ODBCheck.hh.

Referenced by OutputCorrections().

Location of necessary files.

Definition at line 28 of file ODBCheck.hh.

Referenced by Check(), OutputCorrections(), and SetDirs().

Estimates based off of data quality histograms for corrected ODB.

Definition at line 29 of file ODBCheck.hh.

Referenced by Check().

Original ODB.

Definition at line 26 of file ODBCheck.hh.

Referenced by Check().

int ODBCheck::fRun [private]

Run number.

Definition at line 25 of file ODBCheck.hh.

Referenced by Check(), and OutputCorrections().


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

Generated on 15 Jun 2016 for AlcapDAQ by  doxygen 1.6.1