CoilTools Class Reference

#include <CoilTools.h>

List of all members.

Classes

struct  Cleaner

Public Member Functions

const BfldDbiCoilStateGetCoilState (const VldContext &vldc, int ism=1)
const Dcs_Mag_NearGetMagNear (const VldContext &vldc)
void SetWindow (Int_t wsec)
void SetTask (Int_t task)
void ClearCaches ()

Static Public Member Functions

static CoilToolsInstance ()
static void Distill (VldTimeStamp start, VldTimeStamp end, Int_t sm, Float_t curr, Detector::Detector_t NearOrFar)
static Int_t GetLast (VldTimeStamp start, Int_t sm, VldTimeStamp *LastTime, Float_t *LastCurr, Detector::Detector_t NearOrFar)
static void FixFormat ()
static Bool_t IsOK (const VldContext &vldc)
static Bool_t IsOK (VldTimeStamp now, Detector::Detector_t det)
static Bool_t IsReverse (const VldContext &vldc)
static Bool_t IsReverse (VldTimeStamp now, Detector::Detector_t det)
static std::pair< Float_t,
Float_t > 
CoilCurrent (const VldContext &vldc)
static std::pair< Float_t,
Float_t > 
CoilCurrentLimits (const VldContext &vldc)
static void Write (VldTimeStamp start, VldTimeStamp end, Int_t sm, Float_t curr, UInt_t status, Detector::Detector_t det)
static int GetNCoils (const VldContext &vldc)

Private Member Functions

Bool_t IsCoilStateOK (const VldContext &vldc)
Bool_t IsCoilStateReverse (const VldContext &vldc)
Bool_t IsMagNearOK (const VldContext &vldc)
Bool_t IsMagNearReverse (const VldContext &vldc)
 CoilTools ()
virtual ~CoilTools ()
template<class T >
void ExtendedQuery (const VldContext &vldc, DbiResultPtr< T > &resultPtr, VldRange &resultRange)
template<class T >
void LocalQuery (const VldContext &vldc, DbiResultPtr< T > &extResPtr, std::map< int, const T * > &resultAggMap, VldRange &resultRange)

Static Private Member Functions

static void WriteRow (VldTimeStamp start, VldTimeStamp end, Int_t sm, Float_t curr, Detector::Detector_t NearOrFar)
static void CheckNearOrFar (Detector::Detector_t NearOrFar)

Private Attributes

Int_t fWindow
Int_t fTask
DbiResultPtr< BfldDbiCoilStatefDRPCoilState
VldRange fExtendedRangeCoilState
VldRange fLocalRangeCoilState
std::map< int, const
BfldDbiCoilState * > 
fCoilStateSet
DbiResultPtr< Dcs_Mag_NearfDRPMagNear
VldRange fExtendedRangeMagNear
VldRange fLocalRangeMagNear
std::map< int, const
Dcs_Mag_Near * > 
fMagNearSet

Static Private Attributes

static CoilToolsfgInstance = 0

Friends

struct Cleaner

Detailed Description

Definition at line 17 of file CoilTools.h.


Constructor & Destructor Documentation

CoilTools::CoilTools (  )  [private]

Definition at line 248 of file CoilTools.cxx.

References fCoilStateSet, and fMagNearSet.

Referenced by Instance().

00249   : fWindow(2*24*60*60)   // by default 48hr window in local cache
00250   , fTask(0)
00251 {
00252   // default ctor
00253   fCoilStateSet.clear();
00254   fMagNearSet.clear();
00255 }

virtual CoilTools::~CoilTools (  )  [inline, private, virtual]

Definition at line 99 of file CoilTools.h.

00099 { }; 


Member Function Documentation

void CoilTools::CheckNearOrFar ( Detector::Detector_t  NearOrFar  )  [static, private]

Definition at line 679 of file CoilTools.cxx.

References bfld::AsString(), exit(), Msg::kError, Detector::kFar, Detector::kNear, and MSG.

Referenced by Distill(), GetLast(), and WriteRow().

00679                                                            {
00680   if (!((NearOrFar == Detector::kNear) || (NearOrFar == Detector::kFar))) {
00681     MSG("Dcs", Msg::kError) << "HOWL!  Bad Detector Type " 
00682                             << Detector::AsString(NearOrFar) << endl;
00683     exit(-1);
00684   }
00685 }

void CoilTools::ClearCaches (  )  [inline]
std::pair< Float_t, Float_t > CoilTools::CoilCurrent ( const VldContext vldc  )  [static]

Definition at line 725 of file CoilTools.cxx.

References GetCoilState(), BfldDbiCoilState::GetCurrent(), Dcs_Mag_Near::GetCurrent(), VldContext::GetDetector(), GetMagNear(), Instance(), Detector::kFar, and Detector::kNear.

Referenced by ANtpEventInfoAna::Analyze(), MadTVAnalysis::CreatePAN(), and BField::ResetVldContext().

00726 { 
00727   // Switch behavior by detector 
00728   std::pair<Float_t,Float_t> coil_currents(0,0);
00729 
00730   const BfldDbiCoilState* farsm1;
00731   const BfldDbiCoilState* farsm2;
00732   const Dcs_Mag_Near *nearstate;
00733   switch ( vldc.GetDetector() ) {
00734   case Detector::kFar:
00735     farsm1 = CoilTools::Instance().GetCoilState(vldc,1);
00736     farsm2 = CoilTools::Instance().GetCoilState(vldc,2);
00737     if (farsm1) coil_currents.first  = farsm1->GetCurrent();
00738     if (farsm2) coil_currents.second = farsm2->GetCurrent();
00739     break;
00740   case Detector::kNear:
00741     nearstate = CoilTools::Instance().GetMagNear(vldc);
00742     if (nearstate) {
00743       // just one coil, but set both to be same for convenience
00744       coil_currents.first = coil_currents.second = nearstate->GetCurrent();
00745     }
00746     break;
00747   default:
00748     break;
00749   }
00750   return coil_currents;
00751 }

std::pair< Float_t, Float_t > CoilTools::CoilCurrentLimits ( const VldContext vldc  )  [static]

Definition at line 770 of file CoilTools.cxx.

References bfld::AsString(), VldRange::AsString(), VldContext::GetDetector(), BfldDbiCoilLimits::GetLimits(), DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), DbiValidityRec::GetSeqNo(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), Dbi::kDefaultTask, Dbi::kDisabled, Detector::kFar, Msg::kInfo, Detector::kNear, Msg::kSynopsis, Msg::kWarning, MAXMSG, and MSG.

Referenced by IsMagNearOK(), and WriteRow().

00771 { 
00772   std::pair<Float_t,Float_t> limits(0,0);
00773 
00774   // try the DB, don't abort if table is missing or no results
00775   Dbi::Task task = Dbi::kDefaultTask;
00776   DbiResultPtr<BfldDbiCoilLimits> rsptr_limits(vldc,task,Dbi::kDisabled);
00777   Int_t numrows = rsptr_limits.GetNumRows();
00778   if ( numrows > 0 ) {
00779     if ( numrows > 1 ) {
00780       MAXMSG("Dcs",Msg::kWarning,4)
00781         << "More than one BfldDbiCoilLimits entry for VLD " << vldc << endl;
00782     }
00783     const BfldDbiCoilLimits* limits_row = rsptr_limits.GetRow(0);
00784     limits = limits_row->GetLimits();
00785 
00786     // for test purposes
00787     static int lastSeqNo = 0;
00788     const DbiValidityRec* vldrec = rsptr_limits.GetValidityRec(limits_row);
00789     int currSeqNo = vldrec->GetSeqNo();
00790     if ( currSeqNo != lastSeqNo ) {
00791       MSG("Dcs",Msg::kSynopsis)
00792         << "BfldDbiCoilLimits: "
00793         << limits.first << " to " << limits.second
00794         << ", using SEQNO " << currSeqNo 
00795         << endl
00796         << " for " 
00797         << vldrec->GetVldRange().AsString("acs-") 
00798         << endl;
00799       lastSeqNo = currSeqNo;
00800     }
00801   } else {
00802     // set some defaults in case no DB entry
00803     switch ( vldc.GetDetector() ) {
00804     case Detector::kNear:
00805       // pre April 2007
00806       //limits.first  = 4955.0;
00807       //limits.second = 5005.0;
00808       // post April 2007 through mid Dec 2007
00809       //limits.first  = 4940.0;
00810       //limits.second = 4990.0;
00811       // post Dec 2007 - very wide, to account for noise in readback
00812       limits.first  = 4800.0;  // low limit
00813       limits.second = 5100.0;  // high limit
00814       break;
00815     case Detector::kFar:
00816       limits.first   = 79.0;   // low limit
00817       limits.second  = 81.0;   // high limit 
00818       break;
00819     default:
00820       MAXMSG("Dcs",Msg::kInfo,4) 
00821         << "Calling CoilCurrentLimits() on Detector::k"
00822         << Detector::AsString(vldc.GetDetector())
00823         << " is non-sensical" << endl;
00824       break;
00825     }
00826     MAXMSG("Dcs",Msg::kInfo,1) 
00827       << "No DBI entry for BfldDbiCoilLimits for " << endl
00828       << "   VldContext = " << vldc << endl
00829       << "   use: " << limits.first << " to " << limits.second << endl;
00830   }
00831 
00832   // return best limits
00833   return limits;
00834 }

void CoilTools::Distill ( VldTimeStamp  start,
VldTimeStamp  end,
Int_t  sm,
Float_t  curr,
Detector::Detector_t  NearOrFar 
) [static]

Definition at line 289 of file CoilTools.cxx.

References VldTimeStamp::AsString(), CheckNearOrFar(), exit(), VldTimeStamp::GetBOT(), VldTimeStamp::GetEOT(), GetLast(), Msg::kDebug, Msg::kError, Detector::kFar, Msg::kInfo, Msg::kSynopsis, Msg::kWarning, MaxTime, MSG, and WriteRow().

Referenced by DcsWriter::EndJob(), and DcsWriter::ProcessRawRecord().

00293                                                       {
00294 
00295   // Bail on bad SM or detector flag
00296   if ((sm > 2) || (sm < 1)) {
00297     MSG("Dcs", Msg::kError) << "HOWL!  Bad SM " << sm << endl;
00298     exit(-1);
00299   }
00300   CoilTools::CheckNearOrFar(NearOrFar);
00301 
00302   // Set up distillation parameters
00303   // On first pass, select Near or Far.  We will never mix the two in one job
00304   static Bool_t first = true;
00305   static Double_t MaxTime;
00306   static Double_t MaxDelay;
00307   static Double_t MaxSmallGap;
00308   static Float_t  MaxDeltaCurrent;
00309   if (first) {
00310     first = false;
00311     if (NearOrFar == Detector::kFar) { // Set parameters for Far Det
00312       MSG("Dcs", Msg::kInfo) << "Distilling the Far Detector Coil" << endl;
00313       MaxTime     = 3600.0; // 1 Hour, longest time to 
00314                                                   // wait between distilled
00315                                                   // rows
00316 
00317       MaxDelay    = 900.0;  // 15 Minutes, longest time
00318                                                   // of a gap in which the 
00319                                                   // magnet must have been up 
00320                                                   // the whole time if it's 
00321                                                   // at 80A afterwards, since 
00322                                                   // it takes 15 minutes to 
00323                                                   // ramp up the magnet 
00324                                                   // completely
00325 
00326       MaxSmallGap = 150.0;  // 2.5 Minutes, there are 
00327                                                   // often individual data 
00328                                                   // points dropped.  Given a 
00329                                                   // readout cycle of a bit 
00330                                                   // more than a minute, this 
00331                                                   // delta-t catches these 
00332                                                   // small gaps
00333 
00334       MaxDeltaCurrent = 0.015; // How big a current jump 
00335                                                      // can we tolerate before
00336                                                      // writing out a data 
00337                                                      // point? This is more 
00338                                                      // than 2 ADC ticks, I 
00339                                                      // think
00340     } else { // Set parameters for Near Det
00341       MSG("Dcs", Msg::kInfo) << "Distilling the Near Detector Coil" << endl;
00342       MaxTime     = 3600.0; // 1 Hour, longest time to 
00343                                                   // wait between distilled
00344                                                   // rows
00345 
00346       MaxDelay    = 2700.0; // 45 Minutes, longest time
00347                                                   // of a gap in which the 
00348                                                   // magnet must have been up 
00349                                                   // the whole time.  The ND 
00350                                                   // magnet ramps up much 
00351                                                   // faster than the ACNET 
00352                                                   // readout, so this 
00353                                                   // parameter is useless for 
00354                                                   // ND
00355 
00356       MaxSmallGap = 2700.0; // 45 Minutes, to allow us 
00357                                                   // to miss one readout cycle
00358                                                   // (20min) without freaking 
00359                                                   // out
00360 
00361       MaxDeltaCurrent = 5.1; // How big a current jump 
00362                                                    // can we tolerate before
00363                                                    // writing out a data 
00364                                                    // point?  2.5A seems to be one ADC tick at ND
00365     }
00366   } // end of if (first)
00367 
00368   // Static stuff to remember between calls
00369   static const VldTimeStamp BOT = VldTimeStamp::GetBOT();
00370   static const VldTimeStamp EOT = VldTimeStamp::GetEOT();
00371 
00372   // The last row written out:
00373   static VldTimeStamp LastDistillTime[2]    = {BOT, BOT};
00374   static Float_t      LastDistillCurrent[2] = {0.0, 0.0};
00375 
00376   // The last row read:
00377   static VldTimeStamp LastReadTime[2]       = {BOT, BOT};
00378   static Float_t      LastReadCurrent[2]    = {0.0, 0.0};
00379 
00380   // The row which will next be written out:
00381   static VldTimeStamp SaveReadTime[2]       = {BOT, BOT};
00382   static Float_t      SaveReadCurrent[2]    = {0.0, 0.0};
00383 
00384   // Index for the above arrays
00385   Int_t smindex = sm - 1;
00386 
00387   // If start==EOT, that's the signal to dump the last row saved through
00388   // last row seen unless it happened to have already been dumped, or the last 
00389   // saved value is bogus
00390   if ((start == EOT) && 
00391       (SaveReadTime[smindex] != BOT) &&
00392       (SaveReadTime[smindex] != EOT) &&
00393 // ATH 12/28/07 - trap on EOT/BOT bogosity which slips into the DB for some reason
00394       (LastReadTime[smindex] != BOT) &&
00395       (LastReadTime[smindex] != EOT)
00396       ) {
00397     MSG("Dcs", Msg::kInfo) << "SM" << sm << " Forced dump of this row "<< endl;
00398     // If row was just dumped, don't do it again
00399     if (SaveReadTime[smindex] == LastReadTime[smindex]) {
00400       MSG("Dcs", Msg::kInfo) << " Row already just dumped "<< endl;
00401     } else {
00402       CoilTools::WriteRow(SaveReadTime[smindex],LastReadTime[smindex],sm,
00403                           SaveReadCurrent[smindex],NearOrFar);
00404     }
00405     // reset saved values to defaults just in case
00406     SaveReadTime[smindex] = BOT;
00407     SaveReadCurrent[smindex] = 0.0;
00408     return;
00409   }
00410 
00411   // Comment out if you want to backfill early stuff
00412   // If LastReadTime is BOT then this is the first call - go to the DB 
00413   // and get the last previous entry as a starting point
00414   if (LastReadTime[smindex] == BOT) {
00415     if (!CoilTools::GetLast(start,sm,&LastReadTime[smindex],
00416                             &LastReadCurrent[smindex],NearOrFar)) {
00417       SaveReadTime[smindex] = LastReadTime[smindex];
00418       SaveReadCurrent[smindex] = LastReadCurrent[smindex];
00419     } else {
00420       MSG("Dcs", Msg::kError) << "HOWL!  Can't get initial conditions from DB" << endl;
00421       //      exit(-1);
00422       // For initial run, of course we can't, so comment out this exit
00423     }
00424   }
00425 
00426   // Spew this one
00427   MSG("Dcs", Msg::kDebug) << "SM" << sm << " Start: " << start.AsString("s") 
00428                           << " End: " << end.AsString("s") << "\tCurr: " 
00429                           << curr << endl;
00430 
00431   // Decide if we need to write a distilled entry.
00432   // 1) More than MaxTime time has elapsed since last one;
00433   // 2) Current has changed by more than MaxDeltaCurrent
00434   // 3) This reading is beyond the last entry + MaxDelay
00435   // 4) If start == EOT write out the last row (unless that row 
00436   //    happened to already have been written out, see above)
00437   // Need to be smarter about this - how long a gap do we really care
00438   // about?  Also need to be able to go back and overide earlier
00439   // validity if a long gap turns out to really be a problem.  Say, a gap
00440   // then a bad current should disqualify the whole gap.
00441 
00442   Float_t DeltaTime    = (Double_t)start - (Double_t)SaveReadTime[smindex];
00443   Float_t DeltaDelay   = (Double_t)start - (Double_t)LastReadTime[smindex];
00444   Float_t DeltaCurrent = curr - SaveReadCurrent[smindex];
00445 
00446   // Check to see if gap in time exists more than MaxSmallGap but less
00447   // than MaxDelay.  If so there may be a problem, but probably not if
00448   // the next data point is at full voltage (as was the last), since
00449   // ramping up that far takes MaxDelay to happen.  Otherwise, dump the row.
00450   // Gap will need to be set manually as with all gaps - but be sure
00451   // to flag this one as bad when you do!
00452   if ((DeltaDelay > MaxSmallGap) && (DeltaDelay < MaxDelay)) {
00453     if ((fabs(curr) < 79.0) || (fabs(LastReadCurrent[smindex]) < 79.0)) {
00454       // Uh-oh, magnet has crashed, dump saved stuff
00455       MSG("Dcs", Msg::kSynopsis) << "SM" << sm << " SAVED: DeltaTime = " 
00456                                  << DeltaTime << " DeltaDelay " 
00457                                  << DeltaDelay << " DeltaCurrent = " 
00458                                  << DeltaCurrent << endl;
00459       MSG("Dcs", Msg::kWarning) << "SM" << sm << " GAP from " 
00460                                 << LastReadTime[smindex].AsString("s") 
00461                                 << " to " 
00462                                 << start.AsString("s") 
00463                                 << " with low current " << curr << endl;
00464       CoilTools::WriteRow(SaveReadTime[smindex],LastReadTime[smindex],sm,
00465                           SaveReadCurrent[smindex],NearOrFar);
00466       // Save this info for next loop
00467       LastDistillTime[smindex] = SaveReadTime[smindex];
00468       LastDistillCurrent[smindex] = SaveReadCurrent[smindex];
00469       SaveReadTime[smindex] = start;
00470       SaveReadCurrent[smindex] = curr;
00471     } else {
00472       // Otherwise just keep on truckin'
00473       MSG("Dcs", Msg::kWarning) << "SM" << sm << " GAP of " << DeltaDelay 
00474                                 << " skipped since current is " << curr 
00475                                 << endl;
00476     }
00477   }
00478 
00479   if ((DeltaTime >= MaxTime) || 
00480       (fabs(DeltaCurrent) >= MaxDeltaCurrent) ||
00481       (DeltaDelay >= MaxDelay)) {
00482     MSG("Dcs", Msg::kSynopsis) << "SM" << sm << " SAVED: DeltaTime = " 
00483                                << DeltaTime << " DeltaDelay " 
00484                                << DeltaDelay << " DeltaCurrent = " 
00485                                << DeltaCurrent << endl;
00486     // If this is not the first row we want to save, we now know the 
00487     // validity of the last one, either:
00488     //   a) if not too big a gap, it stops now
00489     //   b) if too big a gap, take the last known readout as a stop point
00490     //      This leaves a validity gap which corresponds to the unknown
00491     //      time period, needs manually filled in the DB
00492     // don't write an empty row at the start though
00493     if ((SaveReadTime[smindex] != BOT) &&
00494 // ATH 12/28/07 - trap on EOT/BOT bogosity which slips into the DB for some reason
00495         (SaveReadTime[smindex] != EOT) &&
00496 // ATH 12/28/07 - trap on EOT/BOT bogosity which slips into the DB for some reason
00497         (LastReadTime[smindex] != BOT) &&
00498         (LastReadTime[smindex] != EOT)
00499         ) { 
00500       if (DeltaDelay < MaxDelay) {
00501         CoilTools::WriteRow(SaveReadTime[smindex],start,sm,
00502                             SaveReadCurrent[smindex],NearOrFar);
00503       } else {
00504         MSG("Dcs", Msg::kWarning) << "SM" << sm << " GAP from " 
00505                                   << LastReadTime[smindex].AsString("s") 
00506                                   << " to " << start.AsString("s") << endl;
00507         CoilTools::WriteRow(SaveReadTime[smindex],
00508                             LastReadTime[smindex],sm,SaveReadCurrent[smindex],
00509                             NearOrFar);
00510       }
00511       LastDistillTime[smindex] = SaveReadTime[smindex];
00512       LastDistillCurrent[smindex] = SaveReadCurrent[smindex];
00513     }
00514     // Save current info to be start of next distillation
00515     SaveReadTime[smindex] = start;
00516     SaveReadCurrent[smindex] = curr;
00517   }
00518 
00519   // Record this row for future reference
00520   LastReadTime[smindex] = start;
00521   LastReadCurrent[smindex] = curr;
00522 }

template<class T >
void CoilTools::ExtendedQuery ( const VldContext vldc,
DbiResultPtr< T > &  resultPtr,
VldRange resultRange 
) [inline, private]

Definition at line 31 of file CoilTools.cxx.

References VldTimeStamp::Add(), det, DbiValidityRec::IsGap(), Msg::kDebug, Msg::kInfo, DbiSqlContext::kOverlaps, MAXMSG, and MSG.

00034 {
00035   MSG("Dcs",Msg::kDebug)
00036     << " CoilTools::ExtendedQuery<" << typeid(T).name() 
00037     << "> looking for " << vldc.AsString("sql") << endl;
00038 
00039   // make an extended query on the DB for the Dcs_Mag_Near table
00040   Detector::Detector_t det = vldc.GetDetector();
00041   SimFlag::SimFlag_t  sflg = vldc.GetSimFlag();
00042   VldTimeStamp minTime = vldc.GetTimeStamp();
00043   VldTimeStamp maxTime = vldc.GetTimeStamp();
00044   minTime.Add(-60*60); // only 60 min in reverse direction
00045   maxTime.Add(+fWindow);
00046   // create an extended context
00047   DbiSqlContext econtext(DbiSqlContext::kOverlaps,
00048                          minTime,maxTime,det,sflg);
00049   // update the table with new context
00050   resultPtr.NewQuery(econtext,fTask);
00051   // record what range we requested
00052   resultRange = VldRange(det,sflg,minTime,maxTime,"econtext");
00053   // the DBI range might be bigger as it slops over the ends
00054   const DbiValidityRec* dbiVldRec = resultPtr.GetValidityRec();
00055 
00056   //resultRange = dbiVldRec->GetVldRange();
00057 
00058   if ( dbiVldRec->IsGap() ) {
00059     MAXMSG("Dcs",Msg::kInfo,10)  
00060       << " CoilTools::ExtendedQuery<" << typeid(T).name()
00061       << "> saw a gap for " << vldc.AsString("c")
00062       // << dbiVldRec->GetVldRange().AsString("acs-") // ==> (0,0,now,now,"unknown")
00063       << endl;
00064   }
00065 
00066   MSG("Dcs",Msg::kDebug) 
00067     << "CoilTools::ExtendedQuery<" << typeid(T).name() << "> narrow "
00068     << resultRange.AsString("acs-") 
00069     //<< " dbi " << dbiVldRec->GetVldRange().AsString("acs-")
00070     << " found " << resultPtr.GetNumRows() << " rows " << endl;
00071 
00072 }

void CoilTools::FixFormat (  )  [static]

Definition at line 648 of file CoilTools.cxx.

References MsgStream::AttachOStream(), MsgService::GetStream(), Instance(), Msg::kCVSId, Msg::kDebug, Msg::kError, Msg::kFile, Msg::kInfo, Msg::kLine, Msg::kName, Msg::kPriority, Msg::kSynopsis, Msg::kTime, Msg::kWarning, MsgStream::RemoveFormat(), and MsgStream::SetLogLevel().

Referenced by DcsWriter::BeginJob().

00648                           {
00649   // Get pointers to the message service and to the stream I want ("Dcs")
00650   MsgService* msvc = MsgService::Instance();
00651   MsgStream*  mstr = msvc->GetStream("Dcs");
00652   
00653   // Set the log level for the stream. If you just want the default
00654   // (kInfo) this line is not needed
00655   mstr->SetLogLevel(Msg::kDebug);
00656   
00657   // Send GAP-related messages off to a file instead of just stdout
00658   // so humans can be notified
00659   // kWarning should be the minimal level the cron job needs to work.  For 
00660   // more, it seems we have to list each level not just a threshold, that's 
00661   // a pain.
00662   mstr->AttachOStream(Msg::kWarning,"distill-gaps.log");
00663   mstr->AttachOStream(Msg::kError,"distill-gaps.log");
00664   mstr->AttachOStream(Msg::kInfo,"distill-gaps.log");
00665   mstr->AttachOStream(Msg::kDebug,"distill-gaps.log");
00666   mstr->AttachOStream(Msg::kSynopsis,"distill-gaps.log");
00667   
00668   // Clean up format flags for warning messages
00669   mstr->RemoveFormat(Msg::kWarning, 
00670                 Msg::kPriority+Msg::kName+Msg::kTime+Msg::kFile+Msg::kCVSId+Msg::kLine);
00671   // Clean up format flags for debug messages
00672   mstr->RemoveFormat(Msg::kDebug, 
00673                 Msg::kPriority+Msg::kName+Msg::kTime+Msg::kFile+Msg::kLine);
00674 }

const BfldDbiCoilState * CoilTools::GetCoilState ( const VldContext vldc,
int  ism = 1 
)

Definition at line 837 of file CoilTools.cxx.

References fCoilStateSet, fDRPCoilState, fExtendedRangeCoilState, fLocalRangeCoilState, GetNCoils(), and VldRange::IsCompatible().

Referenced by CoilCurrent(), NuExtraction::ExtractCoilCurrent(), ANtpInfoObjectFiller::FillHeaderInformation(), IsCoilStateOK(), IsCoilStateReverse(), and Anp::FillHeader::Run().

00838 {
00839   // make sure extended query fCoilState covers requested validity
00840   if ( ! fExtendedRangeCoilState.IsCompatible(vldc) ) {
00841     ExtendedQuery<BfldDbiCoilState>(vldc,fDRPCoilState,fExtendedRangeCoilState);
00842     fLocalRangeCoilState = VldRange();  // invalidate local range
00843   }
00844   // if necessary, find correct row in extended query
00845   if ( ! fLocalRangeCoilState.IsCompatible(vldc) )
00846     LocalQuery<BfldDbiCoilState>(vldc,fDRPCoilState,
00847                                  fCoilStateSet,fLocalRangeCoilState);
00848 
00849   // assume NearDet has sm=1 and FarDet has sm=1,2
00850   if ( ism < 0 || ism > GetNCoils(vldc) ) return 0;
00851   return fCoilStateSet[ism];  // index into array by SM
00852 }

Int_t CoilTools::GetLast ( VldTimeStamp  start,
Int_t  sm,
VldTimeStamp LastTime,
Float_t *  LastCurr,
Detector::Detector_t  NearOrFar 
) [static]

Definition at line 580 of file CoilTools.cxx.

References VldTimeStamp::AsString(), CheckNearOrFar(), BfldDbiCoilState::GetCurrent(), DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), DbiString::GetString(), BfldDbiCoilState::GetSupermodule(), VldRange::GetTimeEnd(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), Msg::kDebug, Msg::kError, Msg::kInfo, Detector::kNear, and MSG.

Referenced by Distill().

00584                                                        {
00585 
00586   CoilTools::CheckNearOrFar(NearOrFar);
00587 
00588   // Ask for last time before the start of the current record.
00589   // Originally this code section did not exist, but just asked for the
00590   // last record period.  However, it we are re-running data and trying
00591   // to overlay validities with new, better stuff we need the last entry
00592   // _before_ the current record.
00593   DbiSqlContext myContext = DbiSqlContext("TIMEEND <= \'");
00594   myContext << start.AsString("s")  << '\'';
00595 
00596   // Setup query for detector and SM
00597   if (NearOrFar == Detector::kNear) {
00598     myContext << " AND AGGREGATENO = 1 AND DETECTORMASK & 1 ORDER BY TIMEEND DESC LIMIT 1";
00599   } else {
00600     if (sm==1) 
00601       myContext << " AND AGGREGATENO = 1 AND DETECTORMASK & 2 ORDER BY TIMEEND DESC LIMIT 1";
00602     else
00603       myContext << " AND AGGREGATENO = 2 AND DETECTORMASK & 2 ORDER BY TIMEEND DESC LIMIT 1";
00604   }
00605 
00606   // Actually make the query
00607   DbiResultPtr<BfldDbiCoilState> rsPtr1("BFLDDBICOILSTATE",myContext);
00608 
00609   Int_t numRows = rsPtr1.GetNumRows();
00610   MSG("Dcs", Msg::kDebug) << "The context: " << myContext.GetString() 
00611                           << " selected " << numRows 
00612                           << " rows from the BFLDDBICOILSTATE table" << endl;
00613 
00614   Bool_t FoundIt = false;
00615   // Loop over the entries
00616   for (int i = 0; i < numRows; ++i) {
00617     // Grab the row
00618     const BfldDbiCoilState* mag = rsPtr1.GetRow(i);
00619 
00620     if (mag->GetSupermodule() == sm) {
00621       // Grab that row's validity
00622       const DbiValidityRec* v_rec = rsPtr1.GetValidityRec(mag);
00623       const VldRange&  v_range = v_rec->GetVldRange();
00624       *LastTime = v_range.GetTimeEnd();
00625       // Extract some magnet data
00626       *LastCurr=mag->GetCurrent();
00627       FoundIt = true;
00628       break;
00629     }
00630   }
00631   if (FoundIt) {
00632     MSG("Dcs", Msg::kInfo) << "SM" << sm << " Got last time in DB as " 
00633                             << LastTime->AsString("s")
00634                             << " with current " << *LastCurr << " given " 
00635                             << start.AsString("s") << endl;
00636     return(0);
00637   } else {
00638     MSG("Dcs", Msg::kError) << "SM" << sm << " No last time in DB given " 
00639                             << start.AsString("s") << endl;
00640     return(-1);
00641   }
00642 }

const Dcs_Mag_Near * CoilTools::GetMagNear ( const VldContext vldc  ) 

Definition at line 939 of file CoilTools.cxx.

References fDRPMagNear, fExtendedRangeMagNear, fLocalRangeMagNear, fMagNearSet, and VldRange::IsCompatible().

Referenced by CoilCurrent(), MadPIDAnalysis::CreatePAN(), NuExtraction::ExtractCoilCurrent(), ANtpInfoObjectFiller::FillHeaderInformation(), ANtpEventInfoAna::GetNDCoilCurrent(), IsMagNearOK(), IsMagNearReverse(), and Anp::FillHeader::Run().

00940 {
00941   // make sure extended query fMagNear covers requested validity
00942   if ( ! fExtendedRangeMagNear.IsCompatible(vldc) ) {
00943     ExtendedQuery<Dcs_Mag_Near>(vldc,fDRPMagNear,fExtendedRangeMagNear);
00944     fLocalRangeMagNear = VldRange();  // invalidate local range
00945   }
00946   // if necessary, find correct row in extended query
00947   if ( ! fLocalRangeMagNear.IsCompatible(vldc) )
00948     LocalQuery<Dcs_Mag_Near>(vldc,fDRPMagNear,fMagNearSet,fLocalRangeMagNear);
00949 
00950   // sets are index by aggregate # ... NearDet should be either 1 or -1
00951   //    1 if was lying w/ Dcs_Mag_Near::GetAggregateNo() const { return 1; }
00952   //    data is actually unaggregated (ie. AggNo = -1)
00953   // either is acceptable (it will be one or the other)
00954   const Dcs_Mag_Near* entry = fMagNearSet[1];
00955   if ( entry ) return entry;
00956   return fMagNearSet[-1];
00957 
00958 }

int CoilTools::GetNCoils ( const VldContext vldc  )  [static]

Definition at line 236 of file CoilTools.cxx.

References VldContext::GetDetector(), Detector::kFar, and Detector::kNear.

Referenced by GetCoilState(), IsCoilStateOK(), IsCoilStateReverse(), and LocalQuery().

00237 {
00238   // number of coils
00239   switch (vldc.GetDetector()) {
00240   case Detector::kNear:  return 1;
00241   case Detector::kFar:   return 2;
00242   default:               return 0;
00243   }
00244 }

CoilTools & CoilTools::Instance (  )  [static]

Definition at line 259 of file CoilTools.cxx.

References CoilTools(), fgInstance, Msg::kDebug, Msg::kFatal, MSG, and CoilTools::Cleaner::UseMe().

Referenced by CoilCurrent(), MadPIDAnalysis::CreatePAN(), NuExtraction::ExtractCoilCurrent(), ANtpInfoObjectFiller::FillHeaderInformation(), FixFormat(), ANtpEventInfoAna::GetNDCoilCurrent(), IsOK(), IsReverse(), and Anp::FillHeader::Run().

00260 {
00261   //MSG("Dcs",Msg::kDebug) << " CoilTools::Instance() " << endl;
00262 
00263   // Cleaner destructor calls CoilTools dtor
00264   static Cleaner cleaner;
00265   
00266   // create singleton instance of CoilTools
00267   if ( ! fgInstance ) {
00268     MSG("Dcs",Msg::kDebug) << "create CoilTools::fgInstance " << endl;
00269     cleaner.UseMe();
00270     fgInstance = new CoilTools();
00271   }
00272   
00273   // die if we couldn't actually create an instance
00274   if ( ! fgInstance ) {
00275     MSG("Dcs",Msg::kFatal) 
00276       << "Could not create CoilTools::fgInstance !!" << endl;
00277     assert(fgInstance);
00278   }
00279 
00280   // return reference to the one-and-only
00281   return *fgInstance;
00282 
00283 }

Bool_t CoilTools::IsCoilStateOK ( const VldContext vldc  )  [private]

Definition at line 856 of file CoilTools.cxx.

References VldContext::AsString(), VldTimeStamp::GetBOT(), GetCoilState(), GetNCoils(), VldTimeStamp::GetSec(), VldContext::GetSimFlag(), VldContext::GetTimeStamp(), BfldDbiCoilState::IsOK(), SimFlag::kData, Msg::kWarning, and MSG.

Referenced by IsOK().

00857 { 
00858 
00859   int nOK=0, nBad=0;
00860 
00861   int ncoils = GetNCoils(vldc);
00862   for (int icoil = 1; icoil <= ncoils ; ++icoil ) {
00863     const BfldDbiCoilState* coilState = GetCoilState(vldc,icoil);
00864     if ( ! coilState ) {
00865       // coilState should now be set.  If it isn't for Data it
00866       // is a problem, but for non-Data (i.e. MC)
00867       // assume it is simply "missing" (and OK).
00868       if (vldc.GetSimFlag() != SimFlag::kData) ++nOK; 
00869     } else {
00870       if ( coilState->IsOK() ) ++nOK;
00871       else                     ++nBad;
00872     }
00873   }
00874 
00875   if ( nOK  == ncoils ) return true;
00876   if ( nBad == ncoils ) return false;
00877 
00878   // inconsistent state
00879   static VldTimeStamp lastWarning = VldTimeStamp::GetBOT();
00880   VldTimeStamp thisTime = vldc.GetTimeStamp();
00881   // don't warn but every timeDelta seconds
00882   const int timeDelta = 60*20;  // 20 min
00883   if ( TMath::Abs(lastWarning.GetSec()-thisTime.GetSec()) > timeDelta ) {
00884       MSG("Dcs",Msg::kWarning)
00885         << "CoilTools saw inconsistent OK state " << endl
00886         << "  nOK=" << nOK << " nBad=" << nBad << " of " << ncoils << " coils "
00887         << " for " << vldc.AsString("c") << endl
00888         << "  suppress further warnings in the next " << timeDelta
00889         << " seconds." << endl;
00890       lastWarning = thisTime;
00891     }
00892   return false;  // what to choose, what to choose?  Anything bad ==> not OK
00893 
00894 }

Bool_t CoilTools::IsCoilStateReverse ( const VldContext vldc  )  [private]

Definition at line 898 of file CoilTools.cxx.

References VldContext::AsString(), VldTimeStamp::GetBOT(), GetCoilState(), GetNCoils(), VldTimeStamp::GetSec(), VldContext::GetSimFlag(), BfldDbiCoilState::GetStatus(), VldContext::GetTimeStamp(), SimFlag::kData, CoilStatus::kReverse, Msg::kWarning, and MSG.

Referenced by IsReverse().

00899 {
00900 
00901   int nfwd=0, nrev=0;
00902 
00903   int ncoils = GetNCoils(vldc);
00904   for (int icoil = 1; icoil <= ncoils ; ++icoil ) {
00905     const BfldDbiCoilState* coilState = GetCoilState(vldc,icoil);
00906     if ( ! coilState ) {
00907       // coilState should now be set.  If it isn't for Data it
00908       // is a problem, but for non-Data (i.e. MC)
00909       // assume it is simply "missing" (and 'forward').
00910       if (vldc.GetSimFlag() != SimFlag::kData) ++nfwd; 
00911     } else {
00912       if ( coilState->GetStatus() & CoilStatus::kReverse ) ++nrev;
00913       else                                                 ++nfwd;
00914     }
00915   }
00916 
00917   if ( nfwd == ncoils ) return false;
00918   if ( nrev == ncoils ) return true;
00919 
00920   static VldTimeStamp lastWarning = VldTimeStamp::GetBOT();
00921   VldTimeStamp thisTime = vldc.GetTimeStamp();
00922   // don't warn but every timeDelta seconds
00923   const int timeDelta = 60*20;  // 20 min
00924   if ( TMath::Abs(lastWarning.GetSec()-thisTime.GetSec()) > timeDelta ) {
00925       MSG("Dcs",Msg::kWarning)
00926         << "CoilTools saw inconsistent polarities " << endl
00927         << "  nforward=" << nfwd << " nreverse=" << nrev
00928         << " for " << vldc.AsString("c") << endl
00929         << "  suppress further warnings in the next " << timeDelta
00930         << " seconds." << endl;
00931       lastWarning = thisTime;
00932     }
00933   return true;  // what to choose, what to choose?  either reverse ==> report reversed
00934 
00935 }

Bool_t CoilTools::IsMagNearOK ( const VldContext vldc  )  [private]

Definition at line 962 of file CoilTools.cxx.

References CoilCurrentLimits(), Dcs_Mag_Near::GetCurrent(), Dcs_Mag_Near::GetGroundFault(), Dcs_Mag_Near::GetInterLocksComplete(), GetMagNear(), Dcs_Mag_Near::GetOverCurrentDC(), Dcs_Mag_Near::GetOverTemperature(), Dcs_Mag_Near::GetPowerSupplyOn(), VldContext::GetSimFlag(), and SimFlag::kData.

Referenced by IsOK().

00963 {
00964 
00965   const Dcs_Mag_Near* magNear = GetMagNear(vldc);
00966 
00967   if ( ! magNear ) {
00968     // fMagNear should now be set.  If it isn't then assume it's bad
00969     // for data, but simply "missing" for MC.
00970     if (vldc.GetSimFlag() == SimFlag::kData) return false; 
00971     else                                     return true;
00972   }
00973 
00974   std::pair<Float_t,Float_t> limits = CoilCurrentLimits(vldc);
00975   Float_t curr = magNear->GetCurrent();
00976   // Changed from 4955 and 5005, April 2007, ATH
00977   // Changed from 4940 and 4990, December 2007, RWH
00978   if (((fabs(curr) < fabs(limits.first)) || 
00979         fabs(curr) > fabs(limits.second)) ||
00980       (magNear->GetInterLocksComplete() == 0) ||
00981       (magNear->GetPowerSupplyOn() == 0) ||
00982       (magNear->GetGroundFault() == 1) || 
00983       (magNear->GetOverCurrentDC() == 1) || 
00984       (magNear->GetOverTemperature() == 1) ) {
00985     return false;
00986   } else {
00987     return true;
00988   }
00989 
00990 }

Bool_t CoilTools::IsMagNearReverse ( const VldContext vldc  )  [private]

Definition at line 994 of file CoilTools.cxx.

References GetMagNear(), Dcs_Mag_Near::GetPolarity(), VldContext::GetSimFlag(), and SimFlag::kData.

Referenced by IsReverse().

00995 {
00996 
00997   const Dcs_Mag_Near* magNear = GetMagNear(vldc);
00998 
00999   if ( ! magNear ) {
01000     // fMagNear should now be set.  If it isn't then assume it's bad
01001     // for data, but simply "missing" (and forward) for MC.
01002     if (vldc.GetSimFlag() == SimFlag::kData) return true; 
01003     else                                     return false;
01004   }
01005 
01006   return magNear->GetPolarity();
01007 }

Bool_t CoilTools::IsOK ( VldTimeStamp  now,
Detector::Detector_t  det 
) [static]

Definition at line 755 of file CoilTools.cxx.

References IsOK(), and SimFlag::kData.

00756 {
00757   // Go get the data at time "now" for detector det
00758   VldContext vldc(det,SimFlag::kData,now);
00759   return CoilTools::IsOK(vldc);
00760 }

Bool_t CoilTools::IsOK ( const VldContext vldc  )  [static]

Definition at line 695 of file CoilTools.cxx.

References VldContext::GetDetector(), Instance(), IsCoilStateOK(), IsMagNearOK(), Detector::kFar, and Detector::kNear.

Referenced by ANtpEventInfoAna::Analyze(), ANtpInfoObjectFiller::FillHeaderInformation(), NtpSRModule::FillNtpDetStatus(), IsOK(), DataQualityInterface::ProcessDetectorStatus(), BField::ResetVldContext(), and Anp::FillHeader::Run().

00696 { 
00697   // Switch behavior by detector
00698   switch ( vldc.GetDetector() ) {
00699   case Detector::kFar:   
00700     return CoilTools::Instance().IsCoilStateOK(vldc);
00701     break;
00702   case Detector::kNear:  
00703     return CoilTools::Instance().IsMagNearOK(vldc);
00704     break;
00705   default:
00706     return false;
00707   }
00708 }

Bool_t CoilTools::IsReverse ( VldTimeStamp  now,
Detector::Detector_t  det 
) [static]

Definition at line 762 of file CoilTools.cxx.

References IsReverse(), and SimFlag::kData.

00763 {
00764   // Go get the data at time "now" for detector det
00765   VldContext vldc(det,SimFlag::kData,now);
00766   return CoilTools::IsReverse(vldc);
00767 }

Bool_t CoilTools::IsReverse ( const VldContext vldc  )  [static]
template<class T >
void CoilTools::LocalQuery ( const VldContext vldc,
DbiResultPtr< T > &  extResPtr,
std::map< int, const T * > &  resultAggMap,
VldRange resultRange 
) [inline, private]

Definition at line 77 of file CoilTools.cxx.

References VldContext::AsString(), VldTimeStamp::AsString(), VldRange::AsString(), VldTimeStamp::GetBOT(), DbiValidityRec::GetCreationDate(), VldTimeStamp::GetEOT(), GetNCoils(), DbiResultPtr< T >::GetNumRows(), DbiResultPtr< T >::GetRow(), DbiValidityRec::GetSeqNo(), VldRange::GetTimeEnd(), VldContext::GetTimeStamp(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), VldRange::IsCompatible(), Msg::kDebug, Msg::kVerbose, MSG, and VldRange::TrimTo().

00081 {
00082 // Rummage through the DbiResultPtr set (holding an extended query results)
00083 // to find an appropriate entries (for each aggregate #), put them into the 
00084 // map and return the overall trimmed range.
00085 // Assume that the one with the latest CREATIONDATE is "best" for the
00086 // passed VldContext but we must also trim down the VldRange based on
00087 // other later CREATIONDATE entries for the aggregate.
00088   
00089   MSG("Dcs",Msg::kDebug)
00090     << " Local looking for " << vldc.AsString("sql") << endl;
00091 
00092   // invalidate what we are going to fill
00093   resultAggMap.clear();
00094   resultRange = VldRange();
00095 
00096   // some temporaries
00097   std::map<int, VldTimeStamp> lastCreationDateMap; // = VldTimeStamp::GetBOT();
00098   std::map<int, VldRange>     aggRangeMap;
00099   std::map<int, UInt_t>       iSeqNoUsed; 
00100   typedef std::map<int, const T*>  resMap_t;
00101   typedef typename resMap_t::iterator resItr_t;
00102   resItr_t resItr;
00103 
00104   VldTimeStamp tsVldc = vldc.GetTimeStamp();
00105 
00106   // find the compatible row with latest CREATIONDATE
00107   for ( UInt_t irow = 0; irow < extResPtr.GetNumRows(); ++irow ) {
00108     const T* ptrRow = extResPtr.GetRow(irow);
00109     int aggNo = ptrRow->GetAggregateNo();
00110     const DbiValidityRec* dbiVldRec = extResPtr.GetValidityRec(ptrRow);
00111     const VldRange& rowRange = dbiVldRec->GetVldRange();
00112     if ( rowRange.IsCompatible(vldc) ) {
00113       VldTimeStamp foundCreationDate = dbiVldRec->GetCreationDate();
00114       MSG("Dcs",Msg::kVerbose)
00115         << " row " << irow 
00116         << " SEQNO " << dbiVldRec->GetSeqNo()
00117         << " created " << foundCreationDate.AsString("sql")
00118         << " vld " << rowRange.AsString("acs-")
00119         << endl;
00120 
00121       const T* oldRow = resultAggMap[aggNo];
00122       if ( ! oldRow ) lastCreationDateMap[aggNo] = VldTimeStamp::GetBOT();
00123 
00124       // take the last creation date that satisfies
00125       if ( foundCreationDate > lastCreationDateMap[aggNo] ) {
00126         lastCreationDateMap[aggNo] = foundCreationDate;
00127         resultAggMap[aggNo]        = ptrRow;
00128         aggRangeMap[aggNo]         = rowRange;
00129         iSeqNoUsed[aggNo]          = dbiVldRec->GetSeqNo();
00130       }
00131     }
00132   }
00133 
00134   // prepare to trim the range 
00135   std::map<int, VldTimeStamp> maxStart;
00136   std::map<int, VldTimeStamp> minEnd;
00137   for ( resItr=resultAggMap.begin() ; resItr!=resultAggMap.end() ; ++resItr) {
00138     int aggNo = resItr->first;
00139     maxStart[aggNo] = aggRangeMap[aggNo].GetTimeStart();
00140     minEnd[aggNo]   = aggRangeMap[aggNo].GetTimeEnd();
00141     MSG("Dcs",Msg::kVerbose)
00142       << " aggNo " << aggNo
00143       << " iSeqNoUsed " << iSeqNoUsed[aggNo] << " " 
00144       << aggRangeMap[aggNo].AsString("acs-") << endl;
00145   }
00146 
00147   // trim the ranges
00148   for ( UInt_t irow = 0; irow < extResPtr.GetNumRows(); ++irow ) {
00149     const T* ptrRow = extResPtr.GetRow(irow);
00150     int aggNo = ptrRow->GetAggregateNo();
00151     if ( ptrRow == resultAggMap[aggNo] ) continue;  // don't trim against self
00152     const DbiValidityRec* dbiVldRec = extResPtr.GetValidityRec(ptrRow);
00153     const VldRange& rowRange = dbiVldRec->GetVldRange();
00154     VldTimeStamp foundCreationDate = dbiVldRec->GetCreationDate();
00155 
00156     // skip entries created before the chosen one are not relevant
00157     if ( foundCreationDate < lastCreationDateMap[aggNo] ) continue;
00158 
00159     // Rows that overlap the chosen row but were created after it was
00160     // can trim its range.
00161     VldTimeStamp thisStart = rowRange.GetTimeStart();
00162     VldTimeStamp thisEnd   = rowRange.GetTimeEnd();
00163     //
00164     // start time is inclusive, end time is exclusive
00165     //
00166     // find overlaps
00167     if ( thisEnd   < maxStart[aggNo] ) continue;  // too low  for aggregate
00168     if ( thisStart > minEnd[aggNo]   ) continue;  // too high for aggregate
00169 
00170     //MSG("Dcs",Msg::kVerbose)
00171     //  << " row " << irow << " trim aggno=" << aggNo 
00172     //  << " SEQNO " << dbiVldRec->GetSeqNo()
00173     //  << " thisRnage " << rowRange.AsString("acs-")
00174     //  << endl;
00175 
00176     // trim low end of aggregate's range
00177     if ( thisEnd  < tsVldc && thisEnd > maxStart[aggNo] ) {  
00178       MSG("Dcs",Msg::kVerbose)
00179         << " row " << irow << " trim aggno=" << aggNo 
00180         << " low  " << maxStart[aggNo].AsString("sql")
00181         << " SEQNO " << dbiVldRec->GetSeqNo()
00182         << " created " << foundCreationDate.AsString("sql")
00183         << " vld " << aggRangeMap[aggNo].AsString("acs-")
00184         << endl;
00185       maxStart[aggNo] = thisEnd;
00186     }
00187     // trim high end of aggregate's range
00188     if ( thisStart > tsVldc && thisStart < minEnd[aggNo] ) { 
00189       MSG("Dcs",Msg::kVerbose)
00190         << " row " << irow << " trim aggno=" << aggNo
00191         << " high " << minEnd[aggNo].AsString("sql")
00192         << " SEQNO " << dbiVldRec->GetSeqNo()
00193         << " created " << foundCreationDate.AsString("sql")
00194         << " vld " << aggRangeMap[aggNo].AsString("acs-")
00195         << endl;
00196       minEnd[aggNo] = thisStart;
00197     }
00198   }
00199 
00200   resultRange = VldRange(0xFFFF,0xFFFF,
00201                          VldTimeStamp::GetBOT(),VldTimeStamp::GetEOT(),
00202                          "CoilTools::LocalQuery");
00203   for ( resItr=resultAggMap.begin() ; resItr!=resultAggMap.end() ; ++resItr) {
00204     int aggNo = resItr->first;
00205     // trim aggregate's range
00206     aggRangeMap[aggNo].SetTimeStart(maxStart[aggNo]);
00207     aggRangeMap[aggNo].SetTimeEnd(minEnd[aggNo]);
00208     // trim overall range base on this aggregate
00209     resultRange.TrimTo(aggRangeMap[aggNo]);
00210     MSG("Dcs",Msg::kDebug)
00211       << " trimmed aggNo " << aggNo << " SEQNO "
00212       << extResPtr.GetValidityRec(resultAggMap[aggNo])->GetSeqNo()
00213       << " VldRange " << aggRangeMap[aggNo].AsString("acs-") << endl;
00214   }
00215   MSG("Dcs",Msg::kDebug)
00216     << " overall final VldRange " << resultRange.AsString("acs-") << endl;
00217 
00218   int nfound = resultAggMap.size();
00219   if ( nfound == 0 ) {
00220     MSG("Dcs",Msg::kDebug) 
00221       << "LocalQuery<" << typeid(T).name() 
00222       << " saw no appropriate rows" << endl;
00223   } else if ( nfound != GetNCoils(vldc) ) {
00224     MSG("Dcs",Msg::kDebug) 
00225       << "LocalQuery<" << typeid(T).name() << " saw " << nfound 
00226       << " matching rows (expected " << GetNCoils(vldc) << " for " 
00227       << vldc << " in " 
00228       << extResPtr.GetValidityRec()->GetVldRange().AsString("acs-")
00229       << endl;
00230   }
00231 
00232 }

void CoilTools::SetTask ( Int_t  task  )  [inline]

Definition at line 68 of file CoilTools.h.

References ClearCaches(), and fTask.

00069   { fTask   = task; ClearCaches(); }

void CoilTools::SetWindow ( Int_t  wsec  )  [inline]

Definition at line 66 of file CoilTools.h.

References ClearCaches(), fWindow, and max.

00067   { fWindow = std::max(wsec,60); ClearCaches(); } // min 60 seconds

void CoilTools::Write ( VldTimeStamp  start,
VldTimeStamp  end,
Int_t  sm,
Float_t  curr,
UInt_t  status,
Detector::Detector_t  det 
) [static]

Definition at line 1011 of file CoilTools.cxx.

References DbiWriter< T >::Close(), and SimFlag::kData.

Referenced by WriteRow().

01016                                               {
01017   // Ripped from DcsWriter to dump the stuff
01018   Int_t aggNo = sm;
01019   Dbi::Task task = 0;
01020   VldRange OutputRange(det,SimFlag::kData,start,end,"BfldDbiCoilState");
01021   // No creationdate argument below means use overlay times
01022   DbiWriter<BfldDbiCoilState> writer(OutputRange,aggNo,task);
01023   // writer.SetLogComment("Manual Gap Set");  // not needed for this table
01024   BfldDbiCoilState row0(curr,status,(UInt_t)sm);
01025   writer << row0;
01026   writer.Close();
01027 }

void CoilTools::WriteRow ( VldTimeStamp  start,
VldTimeStamp  end,
Int_t  sm,
Float_t  curr,
Detector::Detector_t  NearOrFar 
) [static, private]

Definition at line 527 of file CoilTools.cxx.

References VldTimeStamp::AsString(), CheckNearOrFar(), CoilCurrentLimits(), CoilStatus::kBad, CoilStatus::kBadCurrent, SimFlag::kData, Detector::kFar, Msg::kInfo, CoilStatus::kReverse, Detector::MaskToString(), MSG, and Write().

Referenced by Distill().

00531                                                        {
00532 
00533   CoilTools::CheckNearOrFar(NearOrFar);
00534 
00535   // Figure out a status
00536   UInt_t status = 0;
00537 
00538   VldContext vldc(NearOrFar,SimFlag::kData,start);
00539   std::pair<Float_t,Float_t> limits = CoilCurrentLimits(vldc);
00540   // Switch on which detector
00541   if (NearOrFar == Detector::kFar) {
00542     // Check for reversed field
00543     if (curr < 0.0) status |= CoilStatus::kReverse;
00544     //if ((fabs(curr) < 79.0) || (fabs(curr) > 81.0)) {
00545     // RWH 2007.12 change to using CoilCurrentLimits()
00546     if (fabs(curr) < fabs(limits.first) || 
00547         fabs(curr) > fabs(limits.second)  ) { 
00548       status |= CoilStatus::kBad;
00549       status |= CoilStatus::kBadCurrent;
00550     }
00551   } else {
00552     // Check for reversed field.  Opposite sign convention for ND
00553     if (curr > 0.0) status |= CoilStatus::kReverse;
00554     // Changed from 4955 and 5005, April 2007, ATH
00555     //if ((fabs(curr) < 4940.0) || (fabs(curr) > 4990.0)) { 
00556     // RWH 2007.12 change to using CoilCurrentLimits()
00557     if (fabs(curr) < fabs(limits.first) || 
00558         fabs(curr) > fabs(limits.second)  ) { 
00559       status |= CoilStatus::kBad; 
00560       status |= CoilStatus::kBadCurrent; 
00561     } 
00562   }
00563   CoilTools::Write(start,end,sm,curr,status,NearOrFar);
00564 
00565   // Flagging gaps is done manually.  A tool to write the records after
00566   // a human reads the distiller logs and checks CRL is found in ManualGaps.C
00567 
00568   MSG("Dcs", Msg::kInfo) << "SM" << sm << " DISTILLED: Start: " 
00569                          << start.AsString("s") 
00570                          << " End: "  << end.AsString("s")<< "\tCurr: " 
00571                          << curr << " " << CoilStatus::MaskToString(status) 
00572                          << endl;
00573 }


Friends And Related Function Documentation

friend struct Cleaner [friend]

Definition at line 111 of file CoilTools.h.


Member Data Documentation

std::map<int, const BfldDbiCoilState*> CoilTools::fCoilStateSet [private]

Definition at line 131 of file CoilTools.h.

Referenced by CoilTools(), and GetCoilState().

Definition at line 128 of file CoilTools.h.

Referenced by GetCoilState().

Definition at line 133 of file CoilTools.h.

Referenced by GetMagNear().

Definition at line 129 of file CoilTools.h.

Referenced by ClearCaches(), and GetCoilState().

Definition at line 134 of file CoilTools.h.

Referenced by ClearCaches(), and GetMagNear().

CoilTools * CoilTools::fgInstance = 0 [static, private]

Definition at line 112 of file CoilTools.h.

Referenced by Instance(), and CoilTools::Cleaner::~Cleaner().

Definition at line 130 of file CoilTools.h.

Referenced by ClearCaches(), and GetCoilState().

Definition at line 135 of file CoilTools.h.

Referenced by ClearCaches(), and GetMagNear().

std::map<int, const Dcs_Mag_Near*> CoilTools::fMagNearSet [private]

Definition at line 136 of file CoilTools.h.

Referenced by CoilTools(), and GetMagNear().

Int_t CoilTools::fTask [private]

Definition at line 124 of file CoilTools.h.

Referenced by SetTask().

Int_t CoilTools::fWindow [private]

Definition at line 123 of file CoilTools.h.

Referenced by SetWindow().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1