BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
//
//

// $Id: BrRunInfo.cxx,v 1.3 2002/03/21 23:42:08 cholm Exp $
// $Author: cholm $
// $Date: 2002/03/21 23:42:08 $
// $Copyright: 2001 BRAHMS Collaboration <brahmlib@rhic.bnl.gov>
#include "BrRunInfo.h"
#include "BrException.h"
#include <iostream.h>
#include <time.h>

//____________________________________________________________________
ClassImp(BrRunInfo);

//____________________________________________________________________
 BrRunInfo::BrRunInfo() 
{
  fSequences   = new TObjArray;
  fSeqIter     = 0;
  fCurrentSeq  = 0;
  fRun         = 0;

  try {
    fRunDb          = BrRunsDb::Instance();
  }
  catch (BrException* e) {
    cout << "BrRunInfo() " << *e << endl;
    e->Execute();  
  }

  fInitialized = kFALSE;
}

//____________________________________________________________________
 BrRunInfo::~BrRunInfo() 
{
  
  if (fSequences) {
    if (fSeqIter) 
      delete fSeqIter; 
    fSequences->SetOwner(kTRUE);
    delete fSequences;
  }
  if (fRun) 
    delete fRun;
}

//____________________________________________________________________
 void BrRunInfo::Init() 
{
  // Nothing
  fInitialized = kTRUE;
}

  
//____________________________________________________________________
 void BrRunInfo::SetDatabase(BrRunsDb* db)
{
  //
  // This MUST be done before Init()
  //
  if(fInitialized)
    throw new BrWarning("SetDatabase","Not allowed after Init()");
  fRunDb = db;
}

//____________________________________________________________________
 void BrRunInfo::Update(Int_t runNo) 
{
  // Update structure for run given by run number
  if(!fInitialized) {
    Warning("Update","Not allowed before Init()");
    throw new BrWarning("Update","Not allowed before Init()");
  }
  
  fSequences->SetOwner(kTRUE);
  fSequences->Delete();

  // Check that we're connected 
  if (!fRunDb->IsConnected()) {
    // try to connect to the run database
    if (!fRunDb->Connect()) {
      Warning("Update", "couldn't connect to run database");
      return;
    }
  }

  fRun            = fRunDb->GetRun(runNo);
  fSequences      = fRunDb->GetXFile(runNo);
  // Next isn't implemented
  // fD1             = runDb->GetMagnet(1,runNo); 
  // fD2             = runDb->GetMagnet(2,runNo);
  // fD3             = runDb->GetMagnet(3,runNo);
  // fD4             = runDb->GetMagnet(4,runNo);
  // fD5             = runDb->GetMagnet(5,runNo);

  // Close the connection so that we free the slot in server. 
#ifdef BR_USE_DISCONNECT
  fRunDb->Close();
#endif

  // Next isn't used 
  // fShiftReport    = runDb->GetShiftReport(runNo); // Needed?        
  if (fSeqIter)
    delete fSeqIter;
  fSeqIter = new TIter(fSequences);
  fCurrentSeq = 0;
}

//____________________________________________________________________
 Bool_t BrRunInfo::NextSequence() 
{ 
  // Make internal iterator point to next sequnce information 
  if (!fSeqIter) {
    if (!fSequences) 
      return kFALSE; 
    fSeqIter = new TIter(fSequences);
  }
  fCurrentSeq = (BrDbFile*)fSeqIter->Next();
  if (!fCurrentSeq) 
    return kFALSE;
  return kTRUE;
}

//____________________________________________________________________
 void BrRunInfo::Print(Option_t* option) const 
{
  // Print the current information 
  // Options:
  //    B           Basic information (default)
  //    A           Angle settings 
  //    F           Field settings 
  //    H           HPSS and date/time information 
  //    L           Trigger (latch) counts 
  //    D           Diagnostics/Debug information
  //    C           Comments and supervisor information 
  //    S           Current sequence information 
  //
  if (!fRun) 
    return;
  TString opt(option);
  opt.ToLower();
  cout << "Run information for run # " << GetRunNo() << endl
       << "-------------------------------------" << endl;

  if (opt.Contains("b")) 
    cout << " Run Type:         " << GetRunType() << endl
	 << " Events:           " << GetEvents() << endl;
  if (opt.Contains("h"))
    cout << " HPSS:             " << GetHPSS() << endl
	 << " Partitions:       " << GetPartitions() << endl
	 << " End State:        " << GetEndState() << endl
	 << " Start Time:       " << GetStartTime() << endl
	 << " End Time:         " << GetEndTime() << endl;
  if (opt.Contains("a")) 
    cout << " MRS Angle:        " << GetMRSAngle() << endl
	 << " FFS Angle:        " << GetFFSAngle() << endl
	 << " BFS Angle:        " << GetBFSAngle() << endl;
  if (opt.Contains("f")) 
    cout << " D1 Pol:           " << GetD1Pol() << endl
	 << " D1 Set:           " << GetD1Set() << endl
	 << " D2 Pol:           " << GetD2Pol() << endl
	 << " D2 Set:           " << GetD2Set() << endl
	 << " D3 Pol:           " << GetD3Pol() << endl
	 << " D3 Set:           " << GetD3Set() << endl
	 << " D4 Pol:           " << GetD4Pol() << endl
	 << " D4 Set:           " << GetD4Set() << endl
	 << " D5 Pol:           " << GetD5Pol() << endl
	 << " D5 Set:           " << GetD5Set() << endl;
  if (opt.Contains("L")) 
    cout << " Trigger 1:        " << GetTrigger1() << endl
	 << " Trigger 2:        " << GetTrigger2() << endl
	 << " Trigger 3:        " << GetTrigger3() << endl
	 << " Trigger 4:        " << GetTrigger4() << endl
	 << " Trigger 5:        " << GetTrigger5() << endl
	 << " Trigger 6:        " << GetTrigger6() << endl
	 << " Trigger 7:        " << GetTrigger7() << endl
	 << " Trigger 8:        " << GetTrigger8() << endl
	 << " Trigger Summary:  " << GetTriggerSummary() << endl
	 << " Scale 1:          " << GetScale1() << endl
	 << " Scale 2:          " << GetScale2() << endl
	 << " Scale 3:          " << GetScale3() << endl
	 << " Scale 4:          " << GetScale4() << endl
	 << " Scale 5:          " << GetScale5() << endl
	 << " Scale 6:          " << GetScale6() << endl
	 << " Scale 7:          " << GetScale7() << endl
	 << " Scale 8:          " << GetScale8() << endl;
  if (opt.Contains("d")) 
    cout << " Debug:            " << GetDebug() << endl
	 << " Errors:           " << GetErrors() << endl
         << " Max Events:       " << GetMaxEvents() << endl
	 << " Errors Front End: " << GetErrorsFrontEnd() << endl
	 << " Errors Sync:      " << GetErrorsSync() << endl
	 << " Errors Unpack:    " << GetErrorsUnpack() << endl;
  if (opt.Contains("c")) 
    cout << " Supervisor:       " << GetSupervisor() << endl
	 << " Start Comment:    " << GetStartComment() << endl
	 << " Comments:         " << GetComments() << endl;
  
  if (!fCurrentSeq) 
    return;
  if (opt.Contains("s"))
    cout << "Currrent Sequence information:" << endl
	 << "-------------------------------------" << endl
	 << " SpoolFile:        " << GetSpoolFile() << endl
	 << " Run No:           " << GetSequenceRunNo() << endl
	 << " Sequence No:      " << GetSeqNo() << endl
	 << " File Start Time:  " << GetFileStartTime() << endl
	 << " File End Time:    " << GetFileEndTime() << endl
	 << " Size Bytes:       " << GetSizeBytes() << endl
	 << " First Event No:   " << GetFirstEventNo() << endl
	 << " Last Event No:    " << GetLastEventNo() << endl
	 << " Event Count:      " << GetEventCount() << endl
	 << " HPSS Start Time:  " << GetHPSSStartTime() << endl
	 << " HPSS End Time:    " << GetHPSSEndTime() << endl
	 << " HPSS File:        " << GetHPSSFile() << endl
	 << " Trigger Summary:  " << GetSequenceTriggerSummary() <<  endl;
}

//____________________________________________________________________
 const Char_t *BrRunInfo::FormatDate(const Int_t time) const 
{
  // Return formatted start date-time
  // Input is the fDatim from the TDatime
  // This is done in later versions of root using
  // TDatime::AsSQLString() but that is not yet in root that is being
  // used at the time of this writing.  So we do it by hand for
  // compatibility. 

  static Char_t formattedDate[32];

  time_t itime = time;
  struct tm *tp = localtime(&itime);
  strftime(formattedDate,32,"%d-%b-%Y %H:%M:%S",tp);

  return formattedDate;
}


//____________________________________________________________________
ostream& operator<< (ostream & os,BrRunInfo *run) 
{
  os<< *run;
  return os;
}

//____________________________________________________________________
ostream& operator<< (ostream & os,BrRunInfo &run) 
{
  Int_t i,numfiles;
  
  os<< "Run Number: "<< run.GetRunNo();
  os<< "  Start: " << run.GetStartTime();
  os<< "  End: " << run.GetEndTime();
  os<< endl;
  
  os << "Supervisor: " << run.GetSupervisor();
  os << endl;
  
  os << "Number of events: " << run.GetEvents();
  if(run.GetMaxEvents() == 0) {
    os << "   (Max events = unlimited)";
  }
  else {
    os << "   (Max events = " << run.GetMaxEvents() << ")";
  }
  os << endl;
  
  os << "Start Comment:" << endl;
  os << run.GetStartComment();
  os << endl;
  os << endl;
  
  os << "Modes: ";
  if(run.GetDebug()) os << " Debug ";
  if(run.GetHPSS()) os << " HPSS ";
  os << endl;
  
  os << "Partitions: " << run.GetPartitions() << endl;
  
  os << "Triggers:" << endl;
  os << "Trigger 1 " << run.GetTrigger1() << endl;
  os << "Trigger 2 " << run.GetTrigger2() << endl;
  os << "Trigger 3 " << run.GetTrigger3() << endl;
  os << "Trigger 4 " << run.GetTrigger4() << endl;
  os << "Trigger 5 " << run.GetTrigger5() << endl;
  os << "Trigger 6 " << run.GetTrigger6() << endl;
  os << "Trigger 7 " << run.GetTrigger7() << endl;
  os << endl;
  os << endl;
  
  os << "Errors:" << endl;
  os << "Total Errors: " << run.GetErrors();
  os << "  Frontend: " << run.GetErrorsFrontEnd();
  os << "  Unpacking: " << run.GetErrorsUnpack();
  os << "  Synch: " << run.GetErrorsSync();
  os << endl;
  os << endl;
  
  os << "Trigger Summary:" << endl;
  os << run.GetTriggerSummary();
  os << endl;
  os << endl;
  
 /*
   os << "Files information:" << endl;
   
   numfiles = run.GetNumSeq();
   for(i=0;i<numfiles;i++) {
   BrRunFile *file = run.GetFileSeq(i);
   cout << file;
   }
 */
  
  return os;
}




// 
// $Log: BrRunInfo.cxx,v $
// Revision 1.3  2002/03/21 23:42:08  cholm
// Added code in Update, so that as soon as the connection to the
// DB server isn't needed anymore from this Update step, we
// disconnect our clients.  This is done, so we may keep as many free
// slots on the server as possible.  MySQL, in it's current setup has a
// limit of 1000 simultaneous connections, and so disconnecting from the
// server may allow more jobs to run.  This `Disconnect ASAP' policy is
// conditional on the preprocessor flag BRAT_USE_DISCONNECT, defined in
// `db/abc/BrDb.h'.
//
// Revision 1.2  2001/09/12 15:09:48  cholm
// Better pritn method.  Stuff is only printed if option is given.  See
// method doc.
//
// Revision 1.1.1.1  2001/06/21 14:55:18  hagel
// Initial revision of brat2
//
// Revision 1.6  2001/04/20 16:13:52  hagel
// Rework MySQL mode of BrMagnetVolume
//
// Revision 1.5  2001/03/22 20:45:48  cholm
// Added protection for NULL TSqlRow in SingleInstance methods, and cleaned
// up a bit of the stuff.
//
//

This page automatically generated by script docBrat by Christian Holm

Copyright ; 2002 BRAHMS Collaboration <brahmlib@rcf.rhic.bnl.gov>
Last Update on by

Validate HTML
Validate CSS