BRAT 2.4.5
Class index
Full class index
brahmlib
BRAHMS
ROOT page
//____________________________________________________________________
// 
// A 'main 'module container to manage a full job, be it digitization
// of GEANT data, analysis of raw data, or some later step in the
// analysis chain, such as user analysis.   
// 
// It basically works like a module container (BrModuleContainer) but
// is a singleton i.e., only one instance can exist. 
//
// This class is used in the bratmain program to communicate the user
// defined setup of a job.  This is possible because the class is a
// singleton, and that the static pointer to that singleton is
// accesible from both the interpretor and the program (it is both
// name spaces) 
//
// An example of a setup could be: 
// 
//    BrMainModule* mainModule = 
//      new BrMainModule("GlbRdoConfig", "Global Reconstruction",
//                       "Christian Holm Christensen", 0, 1, 0);
//    mainModule->SetMaxEvents(eventsOption->GetValue());
//    mainModule->SetMaxRuns(maxrunsOption->GetValue());
// 
//    BrIOModule* inputModule =
//      new BrRawDataInput("rawInput", "Raw Data Input");
//    inputModule->SetIOMode(BrIOModule::kBrJobFile|
//                           BrRawDataInput::kBrRawDiskFile);
//    inputModule->AddFile(inputOption->GetValue());
//    mainModule->AddModule(inputModule);
//
//    BrHistIOModule* histModule = 
//        new BrHistIOModule("histograms", "Some histograms"); 
//    histModule->AddFile(histogramOption->GetValue());
//    mainModule->AddModule(histModule);
//    mainModule->SetHistOn();
//
//    BrTriggerFilter* triggerFilter = 
//      new BrTriggerFilter("trigFilter", "Trigger filter");
//    mainModule->AddModule(triggerFilter);
//    triggerFilter->AddTrigger(1);
//    triggerFilter->AddTrigger(4);
//    triggerFilter->AddTrigger(5);
//    triggerFilter->AddTrigger(6);
//
//    BrHeaderModule* headerModule = 
//      new BrHeaderModule("header", "Copy the event header");
//    mainModule->AddModule(headerModule);
//
//    BrGlbPackage* glbPackage = 
//      new BrGlbPackage("glbPackage", "Global detector reconstrucction");
//    mainModule->AddModule(glbPackage);
//
//    BrIOModule* outputModule = 
//      new BrEventIO("ouputModule", "Output module");
//    outputModule->SetIOMode(BrIOModule::kBrJobFile|
//                            BrIOModule::kBrRecreateFile);
//    outputModule->AddFile(outputOption->GetValue());
//    mainModule->AddModule(outputModule);
//
//    mainModule->SetVerbose(verboseOption->GetValue());
//    mainModule->SetDebugLevel(debugOption->GetValue());
//
// Here 
//
//      eventsOption
//      maxrunsOption
//      inputOption
//      histogramOption
//      outputOption
//
// are assumed to be pointers to BrAppOption objects.  Alternatively
// one can use variables. 
//  
// For more on Job-levels, please refer to BrModule class description.   
// 
// Below 'analysis module' is taken to mean program/derived class,
// etc. 
// 
//

//____________________________________________________________________
// 
// $Id: BrMainModule.cxx,v 1.9 2002/04/22 17:00:14 cholm Exp $
// $Author: cholm $
// $Date: 2002/04/22 17:00:14 $
//
#ifndef BRAT_BrMainModule
#include "BrMainModule.h"
#endif 
#ifndef ROOT_TFile
#include "TFile.h"
#endif
#ifndef BRAT_BrEvent
#include "BrEvent.h"
#endif
#ifndef ROOT_TObjectTable
#include "TObjectTable.h"
#endif
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <limits.h>

//____________________________________________________________________
ClassImp(BrMainModule); 

//____________________________________________________________________
BrMainModule* BrMainModule::fgInstance   = 0;
Bool_t        BrMainModule::fgMoreRuns   = kTRUE;
Bool_t        BrMainModule::fgMoreEvents = kTRUE;

//____________________________________________________________________
 BrMainModule::BrMainModule() 
  : BrModuleContainer()
{
  // Default CTOR - DO NOT USE - required for ROOT I/O
  if (fgInstance) 
    Error("BrMainModule", 
	  "Can not have more then one instance"); 
  fgInstance     = this;
  fMajorVersion  = 0;
  fMinorVersion  = 0;
  fRevision      = 0;    
  fAuthor        = "";      
  fNumberRun     = 0;
  fNumberEvent   = 0;
  fMaxRuns       = INT_MAX;
  fMaxEvents     = INT_MAX;
}

//____________________________________________________________________
 BrMainModule::BrMainModule(Char_t* name, 
			   Char_t* title, 
			   Char_t* author,
			   Int_t   major, 
			   Int_t   minor, 
			   Int_t   revision) 
  : BrModuleContainer(name,title)
{
  // Named CTOR - The arguments are:
  // 
  //   name              name of this job.  Set this to be the
  //                     basename of your configuration script.
  //   title             title of ths job (be descriptive)
  //   author            name of the person that started this job
  //   major             major version number for this job
  //                     it's recommended that this starts at zero
  //                     (0), and as the job is well tested, bumped to
  //                     one (1).  If major changes are made to the
  //                     job, this should be bumped again. 
  //   minor             Minor version number.  Should start at one
  //                     (1), and be incremented for each change, such
  //                     as new option, a new module, and so on.  At
  //                     major changes, zero it. 
  //   revision          revision number. Should start at zero,
  //                     increment for each, like spelling, value of
  //                     default arguments, and so on.  Should be
  //                     zeroed at minor bumps. 
  // 
  // The version number <major>.<minor>.<revision> is a good way to
  // identify the history of a configuration script.  Please use it. 
  //
  if (fgInstance) 
    Error("BrMainModule", 
	  "Can not have more then one instance"); 
  fgInstance     = this;
  fMajorVersion  = major;
  fMinorVersion  = minor;
  fRevision      = revision;    
  fAuthor        = author;      
  fNumberRun     = 0;
  fNumberEvent   = 0;
  fMaxRuns       = INT_MAX;
  fMaxEvents     = INT_MAX;
}

//____________________________________________________________________
 BrMainModule::~BrMainModule() 
{
  // Default DTOR.  Does nothing
}

//____________________________________________________________________
 BrMainModule* BrMainModule::Instance(void) 
{
  // Get a pointer to the singleton object. If no BrMainModule is
  // initialized a fatal error is produced. 
  if (!fgInstance) {
    ::Fatal("BrMainModule::Instance()", 
	    "BrMainModule not instantized yet");
    return 0;
  }
  return fgInstance;
}

//____________________________________________________________________
 Int_t BrMainModule::Main() 
{
  // Do a full job 

  // Reset status
  Reset();

  // Start by initialising 
  Init();
  if (fStatus >= kFailure) {
    Error("Main", "Init failed");
    return fStatus;
  }
  
  // Define histograms 
  if (HistOn()) {
    Book();
    if (fStatus >= kFailure) {
      Error("Main", "Book failed");      
      return fStatus;
    }
  }
  
  // If verbose is greater then 2, show information on modules 
  if (Verbose() > 2) 
    Print();

  // Next we start the run loop 
  while(kTRUE) {
    // Check if we have reached user limit  
    if (fNumberRun >= fMaxRuns || !fgMoreRuns) {
      Info(3, "Main", "Max events reached");
      break;
    }
    
    // Reset status
    Reset();
    
    // Let the modules do their stuff 
    Begin();
    if (fStatus > kFailure) {
      Error("Main", "Begin Failed");
      return fStatus;
    }
    if (fStatus > kStop)
      break;
    
    // Event loop
    while (kTRUE) {
      // Reset modules 
      Reset();
      
      // Check if we've reached user limit 
      if (fNumberEvent >= fMaxEvents || !fgMoreEvents) {
	Info(3, "Main", "Max events reached");
	fgMoreRuns = kFALSE;
	break;
      }
      
      // Make Event objects 
      BrEvent* inEvent  = new BrEvent("inEvent", 0, 0); 
      BrEvent* outEvent = new BrEvent("outEvent", 0, 0); 
      
      // Execute event method of all modules 
      Event(inEvent, outEvent); 
      if (fStatus > kFailure) 
	return fStatus; 
      
      // Clean up
      delete inEvent;
      delete outEvent;
      
      if (fStatus > kStop) 
	break; 
      
    }
    
    // Reset status
    Reset();
    
    // Finish of this run level 
    End();
    if (fStatus > kFailure) {
      Error("Main", "End failed");
      return fStatus;
    }
    if (fStatus >  kStop)
      break;
    
  }
  
  // Reset status
  Reset();
  
  // Finish this job 
  Finish();

  if (fStatus == kOk) 
    return 0;

  Error("Main", "Finish failed");
  return fStatus;
}


//____________________________________________________________________
 void BrMainModule::Init() 
{
  // Initialize all modules and module containers this job
  // Sends message BrModule::Init recursively
  Info(3, "Init", "Initialising all modules");
  fgMoreRuns   = kTRUE;
  fgMoreEvents = kTRUE;
  fNumberRun   = 0;
  fNumberEvent = 0;
  BrModuleContainer::Init();
}

//____________________________________________________________________
 void BrMainModule::Begin() 
{
  // Initialize all modules and module containers for this run
  // Sends message BrModule::Begin recursively

  ++fNumberRun;
  Info(3, "Begin", "Starting loop over the %d'%s run", 
       fNumberRun, (fNumberRun % 10 == 1 ? "st" : 
		    (fNumberRun % 10 == 2 ? "nd" : 
		     (fNumberRun % 10 == 3 ? "rd" : "th"))));
  fNumberEvent = 0;
  fgMoreEvents = kTRUE;
  BrModuleContainer::Begin();
}

//____________________________________________________________________
 void BrMainModule::Event() 
{
  // Process this event by all modules and module containers
  // Sends message Calls BrModule::Event recursively
  ++fNumberEvent;
  if (Verbose() > 0 && Verbose() < 3 && fNumberEvent % 5000 == 0)
    cout << "Event # " << fNumberEvent << endl;
  else if (Verbose() > 2 && Verbose() < 20 && fNumberEvent % 1000 == 0)
    cout << "Event # " << fNumberEvent << endl;

  if (DebugLevel() > 20)
    gObjectTable->Print();
  else if (DebugLevel() > 2 && fNumberEvent % 1000 == 0)
    gObjectTable->Print();
  
  BrModuleContainer::Event();
}

//____________________________________________________________________
 void BrMainModule::Event(BrEventNode* in, BrEventNode* out) 
{
  // Process this event by all modules and module containers
  // Sends message Calls BrModule::Event recursively
  ++fNumberEvent;
  if (Verbose() > 6)
    cout << "Event # " << fNumberEvent << endl;
  else if (Verbose() > 3 && fNumberEvent % 100 == 0)
    cout << "Event # " << fNumberEvent << endl;
  else if (Verbose() > 2 && fNumberEvent % 1000 == 0)
    cout << "Event # " << fNumberEvent << endl;

  if (DebugLevel() > 20)
    gObjectTable->Print();
  else if (DebugLevel() > 2 && fNumberEvent % 1000 == 0)
    gObjectTable->Print();

  BrModuleContainer::Event(in,out);
}

//____________________________________________________________________
 void BrMainModule::Print(Option_t* option)
{
  // Print information to terminal 
  // 
  // Options: See BrModuleContainer::Print()
  //
  // This non-const version is only kept for backward compatibility
  // with ROOT pre3. Will soon disappear!
  TString opt(option);
  opt.ToLower();

  if (opt.Contains("b")) {
    cout << "*************************************************" << endl
	 << endl
	 << "  " << ClassName() << ": " << GetName() << endl
	 << "  " << GetTitle() << endl
	 << "  Version " << fMajorVersion << "." << fMinorVersion 
	 << "/" << fRevision << endl
	 << "  by " << fAuthor.Data() << endl
	 << endl
	 << "-------------------------------------------------  " << endl;
  }
  
  if (opt.Contains("d")) {
    BrModule::Print("D"); 
    cout << endl
	 << "  Max runs:   " << setw(20) << fMaxRuns   << endl
	 << "  Max events: " << setw(20) << fMaxEvents << endl
	 << endl
	 << "-------------------------------------------------" << endl;
  }
  
  if (opt.Contains("r")) {
    TIter    next(fModuleList);
    TObject *object;
    while((object = next()))
      object->Print(option);
  }
}

//____________________________________________________________________
 void BrMainModule::Print(Option_t* option) const
{
  // Print information to terminal 
  // 
  // Options: See BrModuleContainer::Print()
  //
  TString opt(option);
  opt.ToLower();

  if (opt.Contains("b")) {
    cout << "**************************************************" << endl
	 << endl
	 << "  " << ClassName() << ": " << GetName() << endl
	 << "  " << GetTitle() << endl
	 << "  Version " << fMajorVersion << "." << fMinorVersion 
	 << "/" << fRevision << endl
	 << "  by " << fAuthor.Data() << endl
	 << endl
	 << "  ----------------------------------------------  " << endl
	 << "  Max runs:   " << setw(20) << fMaxRuns   << endl
	 << "  Max events: " << setw(20) << fMaxEvents << endl
	 << endl
	 << "--------------------------------------------------" << endl;
  }

  if (opt.Contains("r")) {
    TIter    next(fModuleList);
    TObject *object;
    while((object = next()))
      object->Print(option);
  }
  if (opt.Contains("d")) {  
    BrModule::Print("D"); 
    cout << "  Original author: Christian Holm Christensen" << endl
	 << "    $Author: cholm $" << endl
	 << "    $Date: 2002/04/22 17:00:14 $"   << endl
	 << "    $Revision: 1.9 $ " << endl
	 << endl
	 << "*************************************************" << endl;
  }  
}

//____________________________________________________________________
 Bool_t BrMainModule::NextEvent() 
{ 
  // Test if we have more events to do. Can be used in BrModules to
  // react on previous module settting this flag
  return fgMoreEvents; 
}

//____________________________________________________________________
 Bool_t BrMainModule::NextRun() 
{
  // Test if we have more runs to do. Can be used in BrModules to
  // react on previous module settting this flag
  return fgMoreRuns; 
}

//____________________________________________________________________
 void BrMainModule::StopJob() 
{
  // Stop the current run level. This is a static method, so that
  // BrModules may send this message with:
  //
  //    BrMainModule::StopJob()
  //
  // The effect is to stop the current run loop i.e., the loop over
  // runs that trigger the call of BrModule::Begin(), event loop 
  // (see BrMainModule::StopRun()) and BrModule::End(). After this 
  // BrModule::Finish() is called on all modules, and the job
  // terminates 
  fgMoreRuns = kFALSE;
}

//____________________________________________________________________
 void BrMainModule::StopRun() 
{
  // Stop the current event level. This is a static method, so that
  // BrModules may send this message with:
  //
  //    BrMainModule::StopRun()
  //
  // The effect is to stop the current event loop i.e., the loop over
  // events that trigger the call of BrModule::Event(). After this
  // message is send, BrModule::End() on all modules is called, and
  // the run level loop is resumed. To stop both the job from the
  // event loop, the message BrMainModule::StopJob() should be called
  // as well.  
  fgMoreEvents = kFALSE;
}

//____________________________________________________________________
 void BrMainModule::TagFile(void) 
{
  // Tag a ROOT file with the information from this job. That includes
  // all sub modules, etc. 
  // I'm not quite sure how to do this yet, but I'll think of
  // something soon 
}

// 
// $Log: BrMainModule.cxx,v $
// Revision 1.9  2002/04/22 17:00:14  cholm
// Now, if fVerbose > 3, write event progress every 100'th event, and if
// fVerbose > 5 every event.  For really slow jobs, it's nice to get a bit more
// output.
//
// Revision 1.8  2002/03/20 19:16:11  videbaek
// Fix a tiny error in not used Event() method.
//
// Revision 1.7  2001/12/14 15:41:17  cholm
// Updated for new BrModule::Info method
//
// Revision 1.6  2001/11/03 09:07:21  ouerdane
// removed the return statement for a continue statement in case of kStop in begin loop
//
// Revision 1.5  2001/11/02 15:22:27  cholm
// Cosmetic changes
//
// Revision 1.4  2001/10/25 16:08:28  videbaek
// Added a new calss BrAppendContainer to deal with modules that use both
// inNode and outNode as requeired input.
//
// Revision 1.3  2001/08/21 15:59:27  cholm
// Added print-out from gObjectTable depending on the debug level.  Note
// you can always turn that feature of completly in your .rootrc file.
// Also, added some documentation.
//
// Revision 1.2  2001/08/10 14:29:43  cholm
// Main Will return 0 on success (as it should)
//
// Revision 1.1.1.1  2001/06/21 14:55:14  hagel
// Initial revision of brat2
//
// Revision 1.6  2001/06/05 20:19:05  videbaek
// If num events limit hit - do not read more runs (files) even
// if more files in list. This is presumably want we want not reading the first
// numevents in each file !
//
// Revision 1.5  2001/03/20 16:59:04  videbaek
// fixed log type
//
// 

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