////////////////////////////////////////////////////////////////////
//  PDecayManager
//
//  Author:   Volker Hejny
//  Written:  Sep. 99
//  Revised:  21.03.05 RH (writing parent indices to ascii file implemented)
//  Revised:  10.12.04 RH (beam smearing/skewing implemented)
//  Revised:  28.08.03 RH (random decays implemented)
//  Revised:  04.07.03 RH (adjusted for multiple Root files: 1.9Gb limit!)
//  Revised:  15.12.00 RH (adjustments for Pythia decay routines)
//  Revised:  26.09.00 R. Holzmann (adjusted to gcc 2.95.2 20000220)
//  Revised:  08.08.00 R. Holzmann (weight treatment fixed)
//  Revised:  21.06.00 MK (adjustments for decay modes from PData)
//  Revised:  14.04.00 R. Holzmann (minor adjustments for 
//                                  PFireball and HGeant operation)
//  Revised:  27.07.07 IF: Changes for the new framework,
//                         Removed beam smearing as covered by the Distr.Manager
// 
//  The purpose of PDecayManager is to produce a set of possible
//  decay branches of a initial particle using a list of particle
//  decay modes. The list of decay modes is empty by default. The 
//  user has to take care about the filling of this list. This can
//  be done using the defaults supplied by this file (at end) or
//  by hand.
//
//  ----
//
//  The following templates and the class PReactionList are
//  private members of PDecayManager, but I due to problems using
//  ClassImp() and ClassDef() with nested classes, they are not
//  derived from TObject and not known inside ROOT. The members are 
//  all public for better use inside PDecayManager.
//  
//  template<class T> class PNextList
//    It implements a linked list of pointers to object T. All elements
//    of this templates are public. The destructor does not imply a
//    delete of the object T itself. If this is wanted -> use member
//    function Delete().
//
//    T 	 *Curr;		// pointer to object T
//    PNextList  *Next;		// pointer to next list node
//
//    PNextList();		// standard constructor
//    PNextList(T*);		// initalized with object T
//    ~PNextList();		// standard destructor
//				
//    void Add(T*);		// add object T to list
//    void Delete();            // delete the objects T in the list
//
//
//  template<class T> class PStack
//    It implements a last-in-first-out standard stack via a single linked
//    list. Additionally the number of objects is counted. All elements
//    are public.
//
//    PNextList<T>	*top;	// pointer to top node
//    Int_t		Count;	// number of elements in the stack
//
//    PStack();			// standarad constructor
//    ~PStack();		// the destructor deletes the nodes
//				// starting at top node, but not the
//				// objects T itself.
//
//    void Push(T*);
//    T *Pop();			// standard stack operators
//
//    PStack<T> *Clone(PStack<T> *UseThis);
//				// returns a pointer to a clone of the stack.
// 				// either an existing, empty stack is used 
//				// (giving UseThis as an optional argument)
//				// or a new stack is constructed internally.
//
//
//  class PReactionList
//    It implements two connected stacks of PChannel objects to organize 
//    the already processed decay channels and the work to do.
//    'Processed' means that all possible decay channels of the daughter
//    particles have been put on the ToDo stack.  
//    The variable ReactionWeight contains the overall weight of
//    this specific channel. All elements of this class are public.
//
//    PStack<PChannel> 	*Finished;	// channels already looked at
//    PStack<PChannel> 	*ToDo;		// decays to be done
//    Double_t		ReactionWeight;	// overall branching ratio
//    Int_t		ID;		// serial number of this object
//    static Int_t	maxID;		// maximum serial number
//  
//    PReactionList(); 
//    ~PReactionList(); 		// again: deletes only the stacks,
//					// not the objects in it.
//    PReactionList *Clone(); 		// doubles the whole PReactionList
//					// returning a pointer to the 
//					// new one.
//
// 
////////////////////////////////////////////////////////////////////
using namespace std;
//#include <strstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "TClonesArray.h"
#include "PData.h"
#include "PUtils.h"
#include "PReaction.h"
#include "PDecayChannel.h"
#include "PDecayManager.h"
#include "TStopwatch.h"

ClassImp(PDecayManager)

static char ret[200];
Int_t PReactionList::maxID = 0;



// --------------------------------------------------------------------------
PDecayManager::PDecayManager() {

    makeStaticData();

    makeDistributionManager()->ExecAll("init"); //init physics, if not yet done, and allow for didx-plugins

    Int_t key = makeDataBase()->GetEntry("std_set");
    if (key<0) 
	Warning("PDecayManager()", "std_set not found");
    Int_t listkey = -1;
    while (makeDataBase()->MakeListIterator(key, "snpart", "slink" ,&listkey)) {
	PDecayChannel *ch = new PDecayChannel();
	//loop over all particles
	makeDataBase()->SetParamTObj(listkey, "decaychannel", ch);   
    }
    decaychannel_param = makeDataBase()->GetParamTObj("decaychannel");

    UsedParticles 	= new PNextList<PParticle>;
    UsedParticleArrays 	= new PNextList<PParticle*>;
    UsedChannels 	= new PNextList<PChannel>;
    ReactionList	= new PNextList<PReactionList>;
    CurrentReactionListPointer = NULL;
    verbose             = 0;
    userSelection       = NULL;
    nTrigCond           = 0;
    fHGeant             = kFALSE;
    fWriteIndex         = kFALSE;
    fPythia             = NULL;
    maxFileSize         = 0;
    tauMax              = -1.;

    pdist = makeDistributionManager(); //create static object, if not yet done

    Info("PDecayManager()", "(%s)", PRINT_CTOR);

    fileoutput_pos = 0;
    bulkdecay_pos  = pro_bulkdecay_pos = 0;

}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
PDecayManager::~PDecayManager() {
    printf("decay manager destructor ok\n");

    UsedParticles->Delete(); 	delete UsedParticles;
    UsedParticleArrays->Delete(); delete UsedParticleArrays;
    UsedChannels->Delete(); 	delete UsedChannels;
    ReactionList->Delete();	delete ReactionList;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::SetVerbose(Int_t v) {
    // Setting verbose flag to optional parameter v. Omitting 'v' switches
    // on verbose option.
    verbose = v;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::AddChannel(Int_t id, PDecayChannel *n) {
    // Adds a specific PDecayChannel 'n' to the particle with ID 'id'. 
    if (!makeStaticData()->IsParticleValid(id)) { 
	Warning("AddChannel", "id %i s unvalid", id);
	return;
    } else {
	Int_t key = makeDataBase()->GetEntryInt("pid", id);
	PDecayChannel *ch;
	TObject       *o;
	if (key < 0) return;
	if (!makeDataBase()->GetParamTObj(key, "decaychannel", &o)) return;
	ch = (PDecayChannel*)o;
	if (ch == NULL) {
	    makeDataBase()->SetParamTObj(key, "decaychannel", ch);   
	} else
	    ch->AddChannel(n);
    }
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::AddChannel(PParticle *p, PDecayChannel *n) {
    // Adds a specific PDecayChannel 'n' to the particle represented by a
    // pointer to a PParticle object. 
    if (p) AddChannel(p->ID(), n);  
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::AddChannel(const char *p, PDecayChannel *n) {
    // Adds a specific PDecayChannel 'n' to the particle represented just
    // by its name. 
    AddChannel(makeStaticData()->GetParticleID(p), n);  
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
PDecayChannel *PDecayManager::GetChannel(Int_t id) const {
    // Returns a pointer to PDecayChannel for the particle with the ID 'id.'

    Int_t key = makeStaticData()->GetParticleKey(id); 
    if (key < 0) {
	Warning("GetChannel", "id %i not found in data base", id);
	return NULL;
    }
    TObject *ch;
    if (!makeDataBase()->GetParamTObj(key, decaychannel_param, &ch)) {
	Warning("GetChannel", "no decaychannel found for ID: %i", id);
	return NULL;
    }
    return (PDecayChannel*) ch;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
PDecayChannel *PDecayManager::GetChannel(PParticle *p) const {
    // Returns a pointer to PDecayChannel for the particle represented by a
    // pointer to a PParticle object.

    if (p) return GetChannel(p->ID()); //TODO: This would be much faster if PParticles would know their key
    return NULL;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
PDecayChannel *PDecayManager::GetChannel(char *p) const {
    // Returns a pointer to PDecayChannel for the particle represented
    // by its name.

    if (p) return GetChannel(makeStaticData()->GetParticleID(p));
    return NULL;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::SetDefault(Int_t id, Int_t recursive) {
    // Sets the default decay branches for the particle with ID 'id'.
    if (!makeStaticData()->IsParticleValid(id)) return;
    
    Clear(id);
    PDecayChannel *c = GetChannel(id);
    if (!c) {
	Warning("SetDefault", "Channel not present");
    }

    const char *name = GetName(id);
    if (verbose) cout << endl << "Setting defaults for particle #" << id << ", " 
		      << name << endl;
    
    if (verbose) {
	cout << "Information found:" << endl;
	makeStaticData()->PrintParticle(id); 
    }
  
    //now loop over decay modes
    Int_t key = makeDataBase()->GetEntryInt("pid", id);
    Int_t listkey = -1;
    Int_t tid[11];
    while (makeDataBase()->MakeListIterator(key, "pnmodes", "link", &listkey)) {
	tid[0] = 10; 
	makeStaticData()->GetDecayModeByKey(listkey, tid); // retrieve current mode info
	
	int *pos;
	makeDataBase()->GetParamInt(listkey, "didx", &pos); //small workaround
	Double_t weight = makeStaticData()->GetDecayBR(*pos);        // static branching ratio
	c->AddChannel(weight, tid[0], &tid[1]);    // constructor by product pid-array pointer
	if (recursive) {
	    for (int i=0; i<tid[0]; i++)
		SetDefault(tid[i+1]);
	}
    }
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::SetDefault(PParticle *p,Int_t recursive) {
    // Sets the default decay branches for the particle represented by a
    // a pointer to a PParticle object.
    if (p) SetDefault(p->ID(), recursive);  
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::SetDefault(const char *p,Int_t recursive) {
    // Sets the default decay branches for the particle represented by its
    // name.
    SetDefault(makeStaticData()->GetParticleID(p), recursive);  
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::Clear(Int_t id) {
    // Deletes the current list of decay branches for the particle with the
    // ID 'id'. This is necessary when one wants to introduce a new set
    // of branches to a particle. The SetDefault() functions are calling
    // this function automatically.
    
    Int_t key = makeDataBase()->GetEntryInt("pid", id); //TODO: make this faster
    /* if (key < 0); */
    TObject *ch;
    if (!makeDataBase()->GetParamTObj(key, "decaychannel", &ch)) return;
    if (ch == NULL) return;
    PDecayChannel *ch2 = new PDecayChannel();
    if (!makeDataBase()->SetParamTObj(key, "decaychannel", ch2)) return;
    delete (PDecayChannel*) ch;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::Clear(PParticle *p) {
    // Deletes the current list of decay branches for the particle represented
    // by a pointer to a PParticle object.
    Clear(p->ID());  
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::MyClear(char *p) {
    // Deletes the current list of decay branches for the particle represented
    // by its name.
    Clear(makeStaticData()->GetParticleID(p));  
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::InitReaction(PParticle *start, PDecayChannel *CurrentChannel) {
    // This function calculates the whole tree of decay branches of particle
    // 'start'. If there is a 'CurrentChannel' given, the initial branches
    // are fetched from this PDecayChannel. Otherwise the information is
    // used, which has been added by AddChannel() or SetDefault() calls.
    // Calling this function is mandatory as an initialization step
    // before producing any data.

    if (UsedParticles) {  
	UsedParticles->Delete();
	delete UsedParticles;
	UsedParticles = new PNextList<PParticle>;
    }
    if (UsedParticleArrays) { 
	UsedParticleArrays->Delete();  
	delete UsedParticleArrays;
	UsedParticleArrays = new PNextList<PParticle*>;
    }
    if (UsedChannels) {   
	UsedChannels->Delete();
	delete UsedChannels;
	UsedChannels = new PNextList<PChannel>;
    }
    if (ReactionList) {   
	ReactionList->Delete();
	delete ReactionList;
	ReactionList = new PNextList<PReactionList>;
    }
    CurrentReactionNumber = 0;
    CurrentReactionListPointer = NULL;
  

    // build the initial channels to start with
  
    if (verbose) cout << endl << "processing decay:" << endl; 
  
    // if no channel given use the standard one.
    if (!CurrentChannel) CurrentChannel = GetChannel(start);
    
    Int_t copyFlag = ( start->IsFireball() || start->IsFileInput() )
	? 0 : 1; // don't want to make clones
    Int_t nReac1 = 0, nReac2 = 0;
    while (CurrentChannel) {
	//CurrentChannel->Print();
	//start->Print();
	PReactionList *tempRL = new PReactionList; 
	ConstructPChannel(start, CurrentChannel, tempRL, copyFlag);
	ReactionList->Add(tempRL);
	nReac1++;
	CurrentChannel = CurrentChannel->GetNext();
    }

    // ok, now we are processing ReactionList as long as there are some
    // channels to process
   
    Int_t MoreToDo = 1;
    while (MoreToDo) {
	MoreToDo = 0;
	PNextList<PReactionList> *x = ReactionList;
	// process the whole reaction list
	while (x) {	 
	    PReactionList* tempRL = x->Curr;
	    PChannel* tempPC = tempRL->ToDo->Pop();
	    // process the whole ToDo stack
	    while (tempPC) {
		MoreToDo = 1;
		tempRL->Finished->Push(tempPC);
 
		Int_t           i, loop;
		Int_t           NOP = tempPC->GetNumPar();	// number of products
		PParticle     **LOP = tempPC->GetParticles();   // list of products
		PDecayChannel **pdc = new PDecayChannel*[NOP];  // array of decay channels
		// one for each product
      

		for(i=0; i<NOP; i++) 
		    pdc[i] = GetChannel(LOP[i+1]);
      
		// like a multi digit counter, the decay channels for one particle
		// are processed via the Next entry one by one. If the last has been
		// processed, it is restored and loop is set to 1. Then the channels
		// of the next particle will be switched. The decay channel of the
		// first particle will always change. The loop has finished when the
		// decay channel of the last particle reaches its last entry.
		loop = 0;
		while (pdc[NOP-1]) {
		    // first lets clone the current reaction list
		    PReactionList *newRL = tempRL->Clone();
		    // collect the current decay channels
		    for (i=0; i<NOP; i++) {
			ConstructPChannel(LOP[i+1], pdc[i], tempRL);
			// if it is the first one or loop has been set -> Get the next entry
			if ( (!i) || (loop) ) {
			    loop = 0;
			    pdc[i] = pdc[i]->GetNext();
			    // if it is not the last one and there is no next channel -> reset
			    // and set loop to increment the next channel
			    if ( (i<(NOP-1)) && !pdc[i] ) {
				pdc[i] =  GetChannel(LOP[i+1]);
				loop = 1;
			    }
			}
		    } // end of collecting channels
		    // if the last channel has not reached the end, store the newly
		    // created reaction list and switch to it, otherwise delete it.
		    if (pdc[NOP-1]) { 
			ReactionList->Add(newRL);
			nReac2++;
			tempRL = newRL; 
		    } else 
			delete newRL;
		} // end of loop over all channel combinations
     
		// Get the next parent channel from the ToDo stack
		tempPC = tempRL->ToDo->Pop();

	    } // end of ToDo stack.
      
	    // Get next entry in reaction list.
	    x = x->Next;
	} // end of ReactionList    
    } // there is nothing left to do
    NumberOfReactions = nReac1 + nReac2;  // number of reactions in ReactionList 
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::ConstructPChannel(PParticle *p, PDecayChannel *c1,
				      PReactionList *RL, Int_t CopyFlag) {
    // This function is used internally inside InitReaction(). For one
    // given parent particle 'p' and PDecayChannel 'c1' it constructs
    // a PChannel and puts it in the ToDo stack of the PReactionList *RL.    

    //    cout << "***enter for  " << p->ID() << endl;

    // multiplying all the channel weights
    Double_t CurrentWeight = c1->GetWeight();
    if (CurrentWeight<1.0e-20) return;  
    RL->ReactionWeight *= CurrentWeight;
  
    // Get daughter particles, create a new array (for PChannel) and store
    // the original particle in it.
    Int_t  NumOfProducts;
    Int_t* ListOfProducts = c1->GetDaughters(NumOfProducts);
    PParticle** array = new PParticle*[NumOfProducts+1];
    UsedParticleArrays->Add(array);
    if (CopyFlag)     
	array[0] = p->Clone();
    else 		    
	array[0] = p;
//   if (verbose) {
//     cout << "(" << setw(2) << RL->ID << ", " << setw(8) << setprecision(2);
//     cout.setf(ios::scientific);
//     cout << RL->ReactionWeight << setprecision(0) << ") ";
// #warning: cout.setf(0, ios::scientific) commented for the moment!
//     cout.setf(ios::left, ios::scientific);
//     cout << GetName(array[0]->ID()) << " --> ";
//   }
  
    // Process the daughter particles.
    for (Int_t i=0; i<NumOfProducts; i++) {
	Int_t id = ListOfProducts[i];
	// Store this particle as a new one in the array
	array[i+1] = new PParticle(id);
	UsedParticles->Add(array[i+1]);
	//    if (verbose) cout << GetName(id) << " ";
    } // out of daughter particles

    // again, create new channel with array and put in on the stack
    PChannel *tempPC = new PChannel(array, NumOfProducts);
    UsedChannels->Add(tempPC);
    RL->ToDo->Push(tempPC);
    //  if (verbose) cout << endl;

    if (verbose) {
	cout << "Next channel for " << p->Name() << ", weight: " << setw(8) << setprecision(2);
	cout.setf(ios::scientific);
	cout << RL->ReactionWeight << setprecision(0) << endl;
	//cout << " is: " << tempPC->GetName() 
	//   << endl;
	tempPC->Print();
    }

    pdist->from_pdecaymanager = 1;
    pdist->Attach(tempPC); //Attach this channel to the known physics
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
PReaction *PDecayManager::GetNextReaction(int wf, const char *name, int f0,
					  int f1, int f2, int f3,
					  TTree *tt) {
    // GetNextReaction() looks for the next decay tree in 'ReactionList'
    // and constructs a new PReaction. If the weight flag 'wf' is set, 
    // the channel weight is copied to the parent particle of the first
    // PChannel. This results in equal statistics of all channels. 
    // The options are passed to the appropriate PReaction constructor.
    //
    // Normally this routine is called internally from the loop() function.
  
    char *filename;
  
    if (verbose) cout << "Selecting next reaction:" << endl;
    if (ListForReaction) delete [] ListForReaction;
  
    if (CurrentReaction) delete CurrentReaction;
  
    if (!ReactionList) {
	if (verbose) cout << " No initialization done." << endl;
	return NULL;
    }

    if (!CurrentReactionListPointer) CurrentReactionListPointer = ReactionList;
    else CurrentReactionListPointer = CurrentReactionListPointer->Next;
  
    if (!CurrentReactionListPointer) {
	if (verbose) cout << " No reaction left." << endl;
	return NULL;
    }
    
    CurrentReactionNumber++;
    if (verbose) cout << endl << "This is reaction #" << CurrentReactionNumber << endl;

    filename = new char[1024];
    if (f3 == 2) sprintf(filename,"%s",name);  // all in 1 file 
    else sprintf(filename, "%s_%03d", name, CurrentReactionNumber);
  
    PReactionList *tempRL = CurrentReactionListPointer->Curr->Clone();
    Int_t NumOfChannels = tempRL->Finished->Count;
    ListForReaction = new PChannel*[NumOfChannels];
    for (Int_t i=NumOfChannels-1; i>=0; i--) {
	ListForReaction[i] = tempRL->Finished->Pop();
    }
    CurrentWeight = tempRL->ReactionWeight;
    if (verbose) cout << " Weight of reaction is " << CurrentWeight << endl;
    if (wf)
	(ListForReaction[0]->GetParticles())[0]->SetW(CurrentWeight);
    CurrentReaction = new PReaction(ListForReaction, filename, NumOfChannels,
				    f0, f1, f2, f3, tt);
    CurrentReaction->SetHGeant(fHGeant);
    CurrentReaction->SetWriteIndex(fWriteIndex);
    if (maxFileSize > 0) CurrentReaction->SetMaxFileSize(maxFileSize);
    if (fPythia) CurrentReaction->SetPythia(fPythia);
    if (userSelection) {
	CurrentReaction->SetUserSelection(userSelection);
	CurrentReaction->SetTrigCond(nTrigCond);
    }
    if (tauMax >= 0.) {
	CurrentReaction->SetDecayAll(tauMax);
    }

    //Copy bulk pointers to the PReaction
    for (int i=0; i<bulkdecay_pos; i++)
	CurrentReaction->AddBulk(bulk[i]);
    for (int i=0; i<pro_bulkdecay_pos; i++)
	CurrentReaction->AddPrologueBulk(pro_bulk[i]);

    delete tempRL;

    return CurrentReaction;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
PReaction *PDecayManager::GetNextReaction(const char *name, int f0,
					  int f1, int f2, int f3,
					  TTree *tt) {
    // This call sets the weight flag to zero and is obsolete.
    return GetNextReaction(0, name, f0, f1, f2, f3, tt);
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
Int_t PDecayManager::Loop(int num, int wf, const char *name, int f0,
			  int f1, int f2, int f3, int rf) {
    // This is the standard call to process all possible reaction channels
    // of the reaction set up before.
    // The total number of events given as the first argument are used
    // as a 'equivalent number'. It reflects the sum of weights to
    // get a proper normalization between the single channels. If the
    // weight flag 'wf' is set, the channel probability is also put
    // into this weight. This results in equal statistics for each channel.
    // The other parameters are the same as for the PReaction::loop() call.
    // The real number of events is returned.
  
    if (rf==1 && f3==1) f3 = 2;   // for random decays, we want common ascii file

    Int_t rStart, rStop, rEntries;
    char* rDescription = new char[1024];
    Double_t rWeight = 0.;

    Int_t  SumOfEvents = 0;
    Double_t WeightSum = 0;
    char* filename = new char[1024];
    sprintf(filename, "%s.root", name);
    TFile *f  = NULL;
    TTree *td = NULL, *ti = NULL;  
    CurrentReaction = NULL;
    ListForReaction = NULL;

    if(!fHGeant) { // do not open Root output if run from HGeant
	f  = new TFile(filename,"RECREATE");
	f->SetCompressionLevel(1);
    }

    td = new TTree("data", "Event data");

    sprintf(filename, "%s.evt", name);
    if (f3 == 2) PReaction::asciif = fopen(filename, "w");   // common ascii file
    PReaction::globalEventCounter = 0;

    if (rf == 1) { // random decay mix of all reactions
	PReaction *pReactionArray[NumberOfReactions];
	double     rWeights[NumberOfReactions];  

	Double_t wsave[NumberOfReactions];
	for (int i=0; i<NumberOfReactions; i++) {
	    CurrentReaction = NULL;
	    ListForReaction = NULL;
	    pReactionArray[i] = GetNextReaction(wf, name, f0, f1, f2, f3, td);
	    wsave[i] = GetCurrentWeight();
	    WeightSum += wsave[i];
	    rWeights[i] = WeightSum;    // cumulative weigth
	}

	for (int i=0; i<NumberOfReactions; i++) {
	    cout << endl << "Reaction " << i+1 << " -------------- with weight: "
		 << wsave[i] << endl;
	    pReactionArray[i]->Print();
	}

	for (int i=0; i<NumberOfReactions; i++) rWeights[i]/=WeightSum; // normalize

	cout << endl << "Do " << num << " events now..." << endl;

	TStopwatch timer;                        // time loop
	timer.Start();
	int percentevents = (num/100) * (*makeStaticData()->GetBatchValue("_system_printout_percent")), 
	    cpc = 1, ipc = cpc*percentevents;
	double t0 = timer.RealTime();
	timer.Continue();

	double *events = makeStaticData()->GetBatchValue("_system_total_event_number");
	(*makeStaticData()->GetBatchValue("_system_total_events_to_sample")) = num;
	int system_printout_percent = int(*makeStaticData()->GetBatchValue("_system_printout_percent"));

	for (int i=0; i<num; i++) { // do now num events randomly from reaction list

	    double rand = PUtils::sampleFlat();
	    int    ind  = PUtils::FindIndex(NumberOfReactions, rWeights, rand);
	    pReactionArray[ind]->InitChannels();
//      pReactionArray[ind]->Print();
	    pReactionArray[ind]->DisableWeightReset();
	    pReactionArray[ind]->loop(1, 0, 0); //BUGBUG: global weight has to be set

	    // (*events)++; -> done in PReaction
	    if ((*events) == ipc) {
		printf(" %i%c done in %f sec\n", cpc*system_printout_percent,
		       '%', timer.RealTime()-t0);
		cpc++;
		ipc = cpc*percentevents;
		timer.Continue();
	    }
	}
	SumOfEvents = num;
    } else {  // sequential treatment of reactions
	ti = new TTree("info", "Run information");
	ti->Branch("rStart",   &rStart,   "rStart/I");
	ti->Branch("rStop",    &rStop,    "rStop/I");
	ti->Branch("rEntries", &rEntries, "rEntries/I");
	ti->Branch("rWeight",  &rWeight,  "rWeight/D");
	ti->Branch("rDescription", (void*)rDescription, "rDescription/C");

	PReaction *r = GetNextReaction(wf, name, f0, f1, f2, f3, td);
	while (r) {
//	std::ostringstream os(rDescription); //BUGBUG: Is this length-save?
//	std::ostringstream os(rDescription,1024);
//      ostrstream os(rDescription,1024);
//      PReactionList* RL = CurrentReactionListPointer->Curr->Clone();
//      PrintReactionListEntry(RL,os);
//      os << ends; //do not use it at the moment!!!
	    rStart = SumOfEvents + 1;  
	    if (verbose) r->Print();
	    rWeight = GetCurrentWeight();
	    WeightSum += rWeight;
	    if (verbose) cout << " Weight of this channel is " << rWeight << endl;
	    if (f3 == 1) PReaction::globalEventCounter = 0;
	    if (wf) rEntries = r->loop(num,1);
	    else rEntries = r->loop((Int_t)(num*rWeight + 0.5), 0);
	    SumOfEvents += rEntries;
	    rStop = SumOfEvents;
	    CurrentReaction = NULL; //DONEv6
            //...cannot delete CurrentReaction -> CRASH
	    r = GetNextReaction(wf, name, f0, f1, f2, f3, td);
	    if (ti) ti->Fill();
	}
    }
    if (f) {
	f = td->GetCurrentFile();
	f->Write();
	f->Close();
	delete f;
    }
    if (f3 == 2) fclose(PReaction::asciif);
    delete [] filename;
    delete [] rDescription;
    if (verbose) cout << "Sum of weights is " << WeightSum << endl;
    return SumOfEvents;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
Double_t PDecayManager::GetCurrentWeight() {
    // Returns the weight of the current reaction channel.
    return CurrentWeight;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::MyPrint() const {
    // Prints the particle decay list.
    cout << "Particle Decay List:" << endl;
    cout << "--------------------" << endl;
//  for (Int_t i=0;i<PData::maxnumpar;Print(i++)); 
  
    Int_t key = makeDataBase()->GetEntry("std_set");
    if (key < 0)
	Warning("MyPrint", "std_set not found");
    Int_t listkey = -1;
    while (makeDataBase()->MakeListIterator(key, "snpart", "slink", &listkey)) {
	//loop over all particles
	int id = makeStaticData()->GetParticleIDByKey(listkey);
	if (id < 1000) Print(id); //Skip Quasi-Particles
    }
    PrintReactionList();
} 
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::Print(Int_t id) const  {
    // Prints the decay channels of the given particle (specified by its id).
    if (!makeStaticData()->IsParticleValid(id)) return;
    PDecayChannel *DC = GetChannel(id);
    if (!DC) return;
    
    if (DC->GetWeight()) {

	cout.setf(ios::left);
	cout.width(20);
	cout << GetName(id);
	DC->Print();
	cout << endl;
    }
    return;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::Print(PParticle *p) const  {
    // Prints the decay channels of the given particle (specified by a pointer
    // to a PParticle).
    if (p) Print(p->ID());
    return;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::MyPrint(char *p) const  {
    // Prints the decay channels of the given particle (specified by its name).
    if (p) Print(makeStaticData()->GetParticleID(p));
    return;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::PrintReactionList() const {
    // Prints the current reaction list
    PNextList<PReactionList> *x = ReactionList;
    Int_t Entry = 0;

    while(x) {
	if ( x->Curr ) {
	    PReactionList *RL = x->Curr->Clone();
	    Entry++;
	    cout << "-----" << endl;
	    cout << "Decay chain #" << Entry << ", probability " 
		 << RL->ReactionWeight << endl;
	    PrintReactionListEntry(RL,cout);
	    delete RL;
	}
	x = x->Next;
    }
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::PrintReactionListEntry(PReactionList *RL, 
					   ostream &os) const{
    // Prints one entry of the reaction list (used internally).
    Int_t count = RL->Finished->Count;
    PChannel **temp = new PChannel*[count];
    for (Int_t i=count-1; i>=0; i--) {
	temp[i] = RL->Finished->Pop();
    }
    PrintChain((temp[0]->GetParticles())[0], temp, count, os);  
    delete [] temp; 
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
void PDecayManager::PrintChain(PParticle *p, PChannel **l, Int_t c, 
			       ostream &os) const {
    // Prints one reaction chain (used internally).
    static Int_t indent = 0;
    indent += 2;
    for (Int_t i=0; i<c; i++) {
	Int_t       pcount = l[i]->GetNumPar();
	PParticle **plist  = l[i]->GetParticles();
	if (p == plist[0]) {
	    if (i == 0) indent = 2;
	    os.width(indent) ; 
	    os << " ";
	    os.setf(ios::left);
	    os << setw(12) << GetName(p->ID()) 
	       << setw(0) << " --> ";
	    for (Int_t k=1; k<=pcount; k++) {
		os << GetName((plist[k])->ID()) << " ";
	    }
	    os << endl;
	    for (Int_t k=1; k<=pcount; k++) {
		PrintChain(plist[k], l, c, os);
	    }
	}
    }
    indent -= 2;
}
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
const char *PDecayManager::GetName(Int_t id) const {
    // Returns the name of a particle (specified by its id).
    if (id <=0 ) 	
	return "???";
    if (id < 1000)
	return (char*)makeStaticData()->GetParticleName(id);
    char  temp[200];
    Int_t Upper = id/1000;
    Int_t Lower = id - 1000*Upper;
    sprintf(ret, "%s ", makeStaticData()->GetParticleName(Lower));
    id = Upper;
    while (id) {
	Upper = id/1000;
	Lower = id - 1000*Upper;
	sprintf(temp, "%s + %s", makeStaticData()->GetParticleName(Lower),ret);
	strcpy(ret, temp);
	id = Upper;
    }
    return ret;
}
// --------------------------------------------------------------------------


Bool_t PDecayManager::AddBulk(PBulkInterface *mybulk) {
    //Add a bulk interface to the list
    //Each bulk object will be executed during the event loop
    //after the normal decay
  
    if (bulkdecay_pos == MAX_BULKDECAY ) {
	Error("AddBulk", "MAX_BULKDECAY reached");
	return kFALSE;
    }
    if (bulkdecay_pos && (bulk[bulkdecay_pos-1]->GetPriority() > mybulk->GetPriority())) {
	bulk[bulkdecay_pos]   = bulk[bulkdecay_pos-1];
	bulk[bulkdecay_pos-1] = mybulk;
	bulkdecay_pos++;
    } else
	bulk[bulkdecay_pos++] = mybulk;

    return kTRUE;
}

Bool_t PDecayManager::AddPrologueBulk(PBulkInterface *mybulk) {
    //Add a bulk interface to the list
    //Each bulk object will be executed during the event loop
    //before the normal decay

    if (pro_bulkdecay_pos == MAX_BULKDECAY ) {
	Error("AddPrologueBulk", "MAX_BULKDECAY reached");
	return kFALSE;
    }
    if (pro_bulkdecay_pos && (pro_bulk[pro_bulkdecay_pos-1]->GetPriority() > mybulk->GetPriority())) {
	pro_bulk[pro_bulkdecay_pos]   = pro_bulk[pro_bulkdecay_pos-1];
	pro_bulk[pro_bulkdecay_pos-1] = mybulk;
	pro_bulkdecay_pos++;
    } else
	pro_bulk[pro_bulkdecay_pos++] = mybulk;

    return kTRUE;
}


 PDecayManager.cc:1
 PDecayManager.cc:2
 PDecayManager.cc:3
 PDecayManager.cc:4
 PDecayManager.cc:5
 PDecayManager.cc:6
 PDecayManager.cc:7
 PDecayManager.cc:8
 PDecayManager.cc:9
 PDecayManager.cc:10
 PDecayManager.cc:11
 PDecayManager.cc:12
 PDecayManager.cc:13
 PDecayManager.cc:14
 PDecayManager.cc:15
 PDecayManager.cc:16
 PDecayManager.cc:17
 PDecayManager.cc:18
 PDecayManager.cc:19
 PDecayManager.cc:20
 PDecayManager.cc:21
 PDecayManager.cc:22
 PDecayManager.cc:23
 PDecayManager.cc:24
 PDecayManager.cc:25
 PDecayManager.cc:26
 PDecayManager.cc:27
 PDecayManager.cc:28
 PDecayManager.cc:29
 PDecayManager.cc:30
 PDecayManager.cc:31
 PDecayManager.cc:32
 PDecayManager.cc:33
 PDecayManager.cc:34
 PDecayManager.cc:35
 PDecayManager.cc:36
 PDecayManager.cc:37
 PDecayManager.cc:38
 PDecayManager.cc:39
 PDecayManager.cc:40
 PDecayManager.cc:41
 PDecayManager.cc:42
 PDecayManager.cc:43
 PDecayManager.cc:44
 PDecayManager.cc:45
 PDecayManager.cc:46
 PDecayManager.cc:47
 PDecayManager.cc:48
 PDecayManager.cc:49
 PDecayManager.cc:50
 PDecayManager.cc:51
 PDecayManager.cc:52
 PDecayManager.cc:53
 PDecayManager.cc:54
 PDecayManager.cc:55
 PDecayManager.cc:56
 PDecayManager.cc:57
 PDecayManager.cc:58
 PDecayManager.cc:59
 PDecayManager.cc:60
 PDecayManager.cc:61
 PDecayManager.cc:62
 PDecayManager.cc:63
 PDecayManager.cc:64
 PDecayManager.cc:65
 PDecayManager.cc:66
 PDecayManager.cc:67
 PDecayManager.cc:68
 PDecayManager.cc:69
 PDecayManager.cc:70
 PDecayManager.cc:71
 PDecayManager.cc:72
 PDecayManager.cc:73
 PDecayManager.cc:74
 PDecayManager.cc:75
 PDecayManager.cc:76
 PDecayManager.cc:77
 PDecayManager.cc:78
 PDecayManager.cc:79
 PDecayManager.cc:80
 PDecayManager.cc:81
 PDecayManager.cc:82
 PDecayManager.cc:83
 PDecayManager.cc:84
 PDecayManager.cc:85
 PDecayManager.cc:86
 PDecayManager.cc:87
 PDecayManager.cc:88
 PDecayManager.cc:89
 PDecayManager.cc:90
 PDecayManager.cc:91
 PDecayManager.cc:92
 PDecayManager.cc:93
 PDecayManager.cc:94
 PDecayManager.cc:95
 PDecayManager.cc:96
 PDecayManager.cc:97
 PDecayManager.cc:98
 PDecayManager.cc:99
 PDecayManager.cc:100
 PDecayManager.cc:101
 PDecayManager.cc:102
 PDecayManager.cc:103
 PDecayManager.cc:104
 PDecayManager.cc:105
 PDecayManager.cc:106
 PDecayManager.cc:107
 PDecayManager.cc:108
 PDecayManager.cc:109
 PDecayManager.cc:110
 PDecayManager.cc:111
 PDecayManager.cc:112
 PDecayManager.cc:113
 PDecayManager.cc:114
 PDecayManager.cc:115
 PDecayManager.cc:116
 PDecayManager.cc:117
 PDecayManager.cc:118
 PDecayManager.cc:119
 PDecayManager.cc:120
 PDecayManager.cc:121
 PDecayManager.cc:122
 PDecayManager.cc:123
 PDecayManager.cc:124
 PDecayManager.cc:125
 PDecayManager.cc:126
 PDecayManager.cc:127
 PDecayManager.cc:128
 PDecayManager.cc:129
 PDecayManager.cc:130
 PDecayManager.cc:131
 PDecayManager.cc:132
 PDecayManager.cc:133
 PDecayManager.cc:134
 PDecayManager.cc:135
 PDecayManager.cc:136
 PDecayManager.cc:137
 PDecayManager.cc:138
 PDecayManager.cc:139
 PDecayManager.cc:140
 PDecayManager.cc:141
 PDecayManager.cc:142
 PDecayManager.cc:143
 PDecayManager.cc:144
 PDecayManager.cc:145
 PDecayManager.cc:146
 PDecayManager.cc:147
 PDecayManager.cc:148
 PDecayManager.cc:149
 PDecayManager.cc:150
 PDecayManager.cc:151
 PDecayManager.cc:152
 PDecayManager.cc:153
 PDecayManager.cc:154
 PDecayManager.cc:155
 PDecayManager.cc:156
 PDecayManager.cc:157
 PDecayManager.cc:158
 PDecayManager.cc:159
 PDecayManager.cc:160
 PDecayManager.cc:161
 PDecayManager.cc:162
 PDecayManager.cc:163
 PDecayManager.cc:164
 PDecayManager.cc:165
 PDecayManager.cc:166
 PDecayManager.cc:167
 PDecayManager.cc:168
 PDecayManager.cc:169
 PDecayManager.cc:170
 PDecayManager.cc:171
 PDecayManager.cc:172
 PDecayManager.cc:173
 PDecayManager.cc:174
 PDecayManager.cc:175
 PDecayManager.cc:176
 PDecayManager.cc:177
 PDecayManager.cc:178
 PDecayManager.cc:179
 PDecayManager.cc:180
 PDecayManager.cc:181
 PDecayManager.cc:182
 PDecayManager.cc:183
 PDecayManager.cc:184
 PDecayManager.cc:185
 PDecayManager.cc:186
 PDecayManager.cc:187
 PDecayManager.cc:188
 PDecayManager.cc:189
 PDecayManager.cc:190
 PDecayManager.cc:191
 PDecayManager.cc:192
 PDecayManager.cc:193
 PDecayManager.cc:194
 PDecayManager.cc:195
 PDecayManager.cc:196
 PDecayManager.cc:197
 PDecayManager.cc:198
 PDecayManager.cc:199
 PDecayManager.cc:200
 PDecayManager.cc:201
 PDecayManager.cc:202
 PDecayManager.cc:203
 PDecayManager.cc:204
 PDecayManager.cc:205
 PDecayManager.cc:206
 PDecayManager.cc:207
 PDecayManager.cc:208
 PDecayManager.cc:209
 PDecayManager.cc:210
 PDecayManager.cc:211
 PDecayManager.cc:212
 PDecayManager.cc:213
 PDecayManager.cc:214
 PDecayManager.cc:215
 PDecayManager.cc:216
 PDecayManager.cc:217
 PDecayManager.cc:218
 PDecayManager.cc:219
 PDecayManager.cc:220
 PDecayManager.cc:221
 PDecayManager.cc:222
 PDecayManager.cc:223
 PDecayManager.cc:224
 PDecayManager.cc:225
 PDecayManager.cc:226
 PDecayManager.cc:227
 PDecayManager.cc:228
 PDecayManager.cc:229
 PDecayManager.cc:230
 PDecayManager.cc:231
 PDecayManager.cc:232
 PDecayManager.cc:233
 PDecayManager.cc:234
 PDecayManager.cc:235
 PDecayManager.cc:236
 PDecayManager.cc:237
 PDecayManager.cc:238
 PDecayManager.cc:239
 PDecayManager.cc:240
 PDecayManager.cc:241
 PDecayManager.cc:242
 PDecayManager.cc:243
 PDecayManager.cc:244
 PDecayManager.cc:245
 PDecayManager.cc:246
 PDecayManager.cc:247
 PDecayManager.cc:248
 PDecayManager.cc:249
 PDecayManager.cc:250
 PDecayManager.cc:251
 PDecayManager.cc:252
 PDecayManager.cc:253
 PDecayManager.cc:254
 PDecayManager.cc:255
 PDecayManager.cc:256
 PDecayManager.cc:257
 PDecayManager.cc:258
 PDecayManager.cc:259
 PDecayManager.cc:260
 PDecayManager.cc:261
 PDecayManager.cc:262
 PDecayManager.cc:263
 PDecayManager.cc:264
 PDecayManager.cc:265
 PDecayManager.cc:266
 PDecayManager.cc:267
 PDecayManager.cc:268
 PDecayManager.cc:269
 PDecayManager.cc:270
 PDecayManager.cc:271
 PDecayManager.cc:272
 PDecayManager.cc:273
 PDecayManager.cc:274
 PDecayManager.cc:275
 PDecayManager.cc:276
 PDecayManager.cc:277
 PDecayManager.cc:278
 PDecayManager.cc:279
 PDecayManager.cc:280
 PDecayManager.cc:281
 PDecayManager.cc:282
 PDecayManager.cc:283
 PDecayManager.cc:284
 PDecayManager.cc:285
 PDecayManager.cc:286
 PDecayManager.cc:287
 PDecayManager.cc:288
 PDecayManager.cc:289
 PDecayManager.cc:290
 PDecayManager.cc:291
 PDecayManager.cc:292
 PDecayManager.cc:293
 PDecayManager.cc:294
 PDecayManager.cc:295
 PDecayManager.cc:296
 PDecayManager.cc:297
 PDecayManager.cc:298
 PDecayManager.cc:299
 PDecayManager.cc:300
 PDecayManager.cc:301
 PDecayManager.cc:302
 PDecayManager.cc:303
 PDecayManager.cc:304
 PDecayManager.cc:305
 PDecayManager.cc:306
 PDecayManager.cc:307
 PDecayManager.cc:308
 PDecayManager.cc:309
 PDecayManager.cc:310
 PDecayManager.cc:311
 PDecayManager.cc:312
 PDecayManager.cc:313
 PDecayManager.cc:314
 PDecayManager.cc:315
 PDecayManager.cc:316
 PDecayManager.cc:317
 PDecayManager.cc:318
 PDecayManager.cc:319
 PDecayManager.cc:320
 PDecayManager.cc:321
 PDecayManager.cc:322
 PDecayManager.cc:323
 PDecayManager.cc:324
 PDecayManager.cc:325
 PDecayManager.cc:326
 PDecayManager.cc:327
 PDecayManager.cc:328
 PDecayManager.cc:329
 PDecayManager.cc:330
 PDecayManager.cc:331
 PDecayManager.cc:332
 PDecayManager.cc:333
 PDecayManager.cc:334
 PDecayManager.cc:335
 PDecayManager.cc:336
 PDecayManager.cc:337
 PDecayManager.cc:338
 PDecayManager.cc:339
 PDecayManager.cc:340
 PDecayManager.cc:341
 PDecayManager.cc:342
 PDecayManager.cc:343
 PDecayManager.cc:344
 PDecayManager.cc:345
 PDecayManager.cc:346
 PDecayManager.cc:347
 PDecayManager.cc:348
 PDecayManager.cc:349
 PDecayManager.cc:350
 PDecayManager.cc:351
 PDecayManager.cc:352
 PDecayManager.cc:353
 PDecayManager.cc:354
 PDecayManager.cc:355
 PDecayManager.cc:356
 PDecayManager.cc:357
 PDecayManager.cc:358
 PDecayManager.cc:359
 PDecayManager.cc:360
 PDecayManager.cc:361
 PDecayManager.cc:362
 PDecayManager.cc:363
 PDecayManager.cc:364
 PDecayManager.cc:365
 PDecayManager.cc:366
 PDecayManager.cc:367
 PDecayManager.cc:368
 PDecayManager.cc:369
 PDecayManager.cc:370
 PDecayManager.cc:371
 PDecayManager.cc:372
 PDecayManager.cc:373
 PDecayManager.cc:374
 PDecayManager.cc:375
 PDecayManager.cc:376
 PDecayManager.cc:377
 PDecayManager.cc:378
 PDecayManager.cc:379
 PDecayManager.cc:380
 PDecayManager.cc:381
 PDecayManager.cc:382
 PDecayManager.cc:383
 PDecayManager.cc:384
 PDecayManager.cc:385
 PDecayManager.cc:386
 PDecayManager.cc:387
 PDecayManager.cc:388
 PDecayManager.cc:389
 PDecayManager.cc:390
 PDecayManager.cc:391
 PDecayManager.cc:392
 PDecayManager.cc:393
 PDecayManager.cc:394
 PDecayManager.cc:395
 PDecayManager.cc:396
 PDecayManager.cc:397
 PDecayManager.cc:398
 PDecayManager.cc:399
 PDecayManager.cc:400
 PDecayManager.cc:401
 PDecayManager.cc:402
 PDecayManager.cc:403
 PDecayManager.cc:404
 PDecayManager.cc:405
 PDecayManager.cc:406
 PDecayManager.cc:407
 PDecayManager.cc:408
 PDecayManager.cc:409
 PDecayManager.cc:410
 PDecayManager.cc:411
 PDecayManager.cc:412
 PDecayManager.cc:413
 PDecayManager.cc:414
 PDecayManager.cc:415
 PDecayManager.cc:416
 PDecayManager.cc:417
 PDecayManager.cc:418
 PDecayManager.cc:419
 PDecayManager.cc:420
 PDecayManager.cc:421
 PDecayManager.cc:422
 PDecayManager.cc:423
 PDecayManager.cc:424
 PDecayManager.cc:425
 PDecayManager.cc:426
 PDecayManager.cc:427
 PDecayManager.cc:428
 PDecayManager.cc:429
 PDecayManager.cc:430
 PDecayManager.cc:431
 PDecayManager.cc:432
 PDecayManager.cc:433
 PDecayManager.cc:434
 PDecayManager.cc:435
 PDecayManager.cc:436
 PDecayManager.cc:437
 PDecayManager.cc:438
 PDecayManager.cc:439
 PDecayManager.cc:440
 PDecayManager.cc:441
 PDecayManager.cc:442
 PDecayManager.cc:443
 PDecayManager.cc:444
 PDecayManager.cc:445
 PDecayManager.cc:446
 PDecayManager.cc:447
 PDecayManager.cc:448
 PDecayManager.cc:449
 PDecayManager.cc:450
 PDecayManager.cc:451
 PDecayManager.cc:452
 PDecayManager.cc:453
 PDecayManager.cc:454
 PDecayManager.cc:455
 PDecayManager.cc:456
 PDecayManager.cc:457
 PDecayManager.cc:458
 PDecayManager.cc:459
 PDecayManager.cc:460
 PDecayManager.cc:461
 PDecayManager.cc:462
 PDecayManager.cc:463
 PDecayManager.cc:464
 PDecayManager.cc:465
 PDecayManager.cc:466
 PDecayManager.cc:467
 PDecayManager.cc:468
 PDecayManager.cc:469
 PDecayManager.cc:470
 PDecayManager.cc:471
 PDecayManager.cc:472
 PDecayManager.cc:473
 PDecayManager.cc:474
 PDecayManager.cc:475
 PDecayManager.cc:476
 PDecayManager.cc:477
 PDecayManager.cc:478
 PDecayManager.cc:479
 PDecayManager.cc:480
 PDecayManager.cc:481
 PDecayManager.cc:482
 PDecayManager.cc:483
 PDecayManager.cc:484
 PDecayManager.cc:485
 PDecayManager.cc:486
 PDecayManager.cc:487
 PDecayManager.cc:488
 PDecayManager.cc:489
 PDecayManager.cc:490
 PDecayManager.cc:491
 PDecayManager.cc:492
 PDecayManager.cc:493
 PDecayManager.cc:494
 PDecayManager.cc:495
 PDecayManager.cc:496
 PDecayManager.cc:497
 PDecayManager.cc:498
 PDecayManager.cc:499
 PDecayManager.cc:500
 PDecayManager.cc:501
 PDecayManager.cc:502
 PDecayManager.cc:503
 PDecayManager.cc:504
 PDecayManager.cc:505
 PDecayManager.cc:506
 PDecayManager.cc:507
 PDecayManager.cc:508
 PDecayManager.cc:509
 PDecayManager.cc:510
 PDecayManager.cc:511
 PDecayManager.cc:512
 PDecayManager.cc:513
 PDecayManager.cc:514
 PDecayManager.cc:515
 PDecayManager.cc:516
 PDecayManager.cc:517
 PDecayManager.cc:518
 PDecayManager.cc:519
 PDecayManager.cc:520
 PDecayManager.cc:521
 PDecayManager.cc:522
 PDecayManager.cc:523
 PDecayManager.cc:524
 PDecayManager.cc:525
 PDecayManager.cc:526
 PDecayManager.cc:527
 PDecayManager.cc:528
 PDecayManager.cc:529
 PDecayManager.cc:530
 PDecayManager.cc:531
 PDecayManager.cc:532
 PDecayManager.cc:533
 PDecayManager.cc:534
 PDecayManager.cc:535
 PDecayManager.cc:536
 PDecayManager.cc:537
 PDecayManager.cc:538
 PDecayManager.cc:539
 PDecayManager.cc:540
 PDecayManager.cc:541
 PDecayManager.cc:542
 PDecayManager.cc:543
 PDecayManager.cc:544
 PDecayManager.cc:545
 PDecayManager.cc:546
 PDecayManager.cc:547
 PDecayManager.cc:548
 PDecayManager.cc:549
 PDecayManager.cc:550
 PDecayManager.cc:551
 PDecayManager.cc:552
 PDecayManager.cc:553
 PDecayManager.cc:554
 PDecayManager.cc:555
 PDecayManager.cc:556
 PDecayManager.cc:557
 PDecayManager.cc:558
 PDecayManager.cc:559
 PDecayManager.cc:560
 PDecayManager.cc:561
 PDecayManager.cc:562
 PDecayManager.cc:563
 PDecayManager.cc:564
 PDecayManager.cc:565
 PDecayManager.cc:566
 PDecayManager.cc:567
 PDecayManager.cc:568
 PDecayManager.cc:569
 PDecayManager.cc:570
 PDecayManager.cc:571
 PDecayManager.cc:572
 PDecayManager.cc:573
 PDecayManager.cc:574
 PDecayManager.cc:575
 PDecayManager.cc:576
 PDecayManager.cc:577
 PDecayManager.cc:578
 PDecayManager.cc:579
 PDecayManager.cc:580
 PDecayManager.cc:581
 PDecayManager.cc:582
 PDecayManager.cc:583
 PDecayManager.cc:584
 PDecayManager.cc:585
 PDecayManager.cc:586
 PDecayManager.cc:587
 PDecayManager.cc:588
 PDecayManager.cc:589
 PDecayManager.cc:590
 PDecayManager.cc:591
 PDecayManager.cc:592
 PDecayManager.cc:593
 PDecayManager.cc:594
 PDecayManager.cc:595
 PDecayManager.cc:596
 PDecayManager.cc:597
 PDecayManager.cc:598
 PDecayManager.cc:599
 PDecayManager.cc:600
 PDecayManager.cc:601
 PDecayManager.cc:602
 PDecayManager.cc:603
 PDecayManager.cc:604
 PDecayManager.cc:605
 PDecayManager.cc:606
 PDecayManager.cc:607
 PDecayManager.cc:608
 PDecayManager.cc:609
 PDecayManager.cc:610
 PDecayManager.cc:611
 PDecayManager.cc:612
 PDecayManager.cc:613
 PDecayManager.cc:614
 PDecayManager.cc:615
 PDecayManager.cc:616
 PDecayManager.cc:617
 PDecayManager.cc:618
 PDecayManager.cc:619
 PDecayManager.cc:620
 PDecayManager.cc:621
 PDecayManager.cc:622
 PDecayManager.cc:623
 PDecayManager.cc:624
 PDecayManager.cc:625
 PDecayManager.cc:626
 PDecayManager.cc:627
 PDecayManager.cc:628
 PDecayManager.cc:629
 PDecayManager.cc:630
 PDecayManager.cc:631
 PDecayManager.cc:632
 PDecayManager.cc:633
 PDecayManager.cc:634
 PDecayManager.cc:635
 PDecayManager.cc:636
 PDecayManager.cc:637
 PDecayManager.cc:638
 PDecayManager.cc:639
 PDecayManager.cc:640
 PDecayManager.cc:641
 PDecayManager.cc:642
 PDecayManager.cc:643
 PDecayManager.cc:644
 PDecayManager.cc:645
 PDecayManager.cc:646
 PDecayManager.cc:647
 PDecayManager.cc:648
 PDecayManager.cc:649
 PDecayManager.cc:650
 PDecayManager.cc:651
 PDecayManager.cc:652
 PDecayManager.cc:653
 PDecayManager.cc:654
 PDecayManager.cc:655
 PDecayManager.cc:656
 PDecayManager.cc:657
 PDecayManager.cc:658
 PDecayManager.cc:659
 PDecayManager.cc:660
 PDecayManager.cc:661
 PDecayManager.cc:662
 PDecayManager.cc:663
 PDecayManager.cc:664
 PDecayManager.cc:665
 PDecayManager.cc:666
 PDecayManager.cc:667
 PDecayManager.cc:668
 PDecayManager.cc:669
 PDecayManager.cc:670
 PDecayManager.cc:671
 PDecayManager.cc:672
 PDecayManager.cc:673
 PDecayManager.cc:674
 PDecayManager.cc:675
 PDecayManager.cc:676
 PDecayManager.cc:677
 PDecayManager.cc:678
 PDecayManager.cc:679
 PDecayManager.cc:680
 PDecayManager.cc:681
 PDecayManager.cc:682
 PDecayManager.cc:683
 PDecayManager.cc:684
 PDecayManager.cc:685
 PDecayManager.cc:686
 PDecayManager.cc:687
 PDecayManager.cc:688
 PDecayManager.cc:689
 PDecayManager.cc:690
 PDecayManager.cc:691
 PDecayManager.cc:692
 PDecayManager.cc:693
 PDecayManager.cc:694
 PDecayManager.cc:695
 PDecayManager.cc:696
 PDecayManager.cc:697
 PDecayManager.cc:698
 PDecayManager.cc:699
 PDecayManager.cc:700
 PDecayManager.cc:701
 PDecayManager.cc:702
 PDecayManager.cc:703
 PDecayManager.cc:704
 PDecayManager.cc:705
 PDecayManager.cc:706
 PDecayManager.cc:707
 PDecayManager.cc:708
 PDecayManager.cc:709
 PDecayManager.cc:710
 PDecayManager.cc:711
 PDecayManager.cc:712
 PDecayManager.cc:713
 PDecayManager.cc:714
 PDecayManager.cc:715
 PDecayManager.cc:716
 PDecayManager.cc:717
 PDecayManager.cc:718
 PDecayManager.cc:719
 PDecayManager.cc:720
 PDecayManager.cc:721
 PDecayManager.cc:722
 PDecayManager.cc:723
 PDecayManager.cc:724
 PDecayManager.cc:725
 PDecayManager.cc:726
 PDecayManager.cc:727
 PDecayManager.cc:728
 PDecayManager.cc:729
 PDecayManager.cc:730
 PDecayManager.cc:731
 PDecayManager.cc:732
 PDecayManager.cc:733
 PDecayManager.cc:734
 PDecayManager.cc:735
 PDecayManager.cc:736
 PDecayManager.cc:737
 PDecayManager.cc:738
 PDecayManager.cc:739
 PDecayManager.cc:740
 PDecayManager.cc:741
 PDecayManager.cc:742
 PDecayManager.cc:743
 PDecayManager.cc:744
 PDecayManager.cc:745
 PDecayManager.cc:746
 PDecayManager.cc:747
 PDecayManager.cc:748
 PDecayManager.cc:749
 PDecayManager.cc:750
 PDecayManager.cc:751
 PDecayManager.cc:752
 PDecayManager.cc:753
 PDecayManager.cc:754
 PDecayManager.cc:755
 PDecayManager.cc:756
 PDecayManager.cc:757
 PDecayManager.cc:758
 PDecayManager.cc:759
 PDecayManager.cc:760
 PDecayManager.cc:761
 PDecayManager.cc:762
 PDecayManager.cc:763
 PDecayManager.cc:764
 PDecayManager.cc:765
 PDecayManager.cc:766
 PDecayManager.cc:767
 PDecayManager.cc:768
 PDecayManager.cc:769
 PDecayManager.cc:770
 PDecayManager.cc:771
 PDecayManager.cc:772
 PDecayManager.cc:773
 PDecayManager.cc:774
 PDecayManager.cc:775
 PDecayManager.cc:776
 PDecayManager.cc:777
 PDecayManager.cc:778
 PDecayManager.cc:779
 PDecayManager.cc:780
 PDecayManager.cc:781
 PDecayManager.cc:782
 PDecayManager.cc:783
 PDecayManager.cc:784
 PDecayManager.cc:785
 PDecayManager.cc:786
 PDecayManager.cc:787
 PDecayManager.cc:788
 PDecayManager.cc:789
 PDecayManager.cc:790
 PDecayManager.cc:791
 PDecayManager.cc:792
 PDecayManager.cc:793
 PDecayManager.cc:794
 PDecayManager.cc:795
 PDecayManager.cc:796
 PDecayManager.cc:797
 PDecayManager.cc:798
 PDecayManager.cc:799
 PDecayManager.cc:800
 PDecayManager.cc:801
 PDecayManager.cc:802
 PDecayManager.cc:803
 PDecayManager.cc:804
 PDecayManager.cc:805
 PDecayManager.cc:806
 PDecayManager.cc:807
 PDecayManager.cc:808
 PDecayManager.cc:809
 PDecayManager.cc:810
 PDecayManager.cc:811
 PDecayManager.cc:812
 PDecayManager.cc:813
 PDecayManager.cc:814
 PDecayManager.cc:815
 PDecayManager.cc:816
 PDecayManager.cc:817
 PDecayManager.cc:818
 PDecayManager.cc:819
 PDecayManager.cc:820
 PDecayManager.cc:821
 PDecayManager.cc:822
 PDecayManager.cc:823
 PDecayManager.cc:824
 PDecayManager.cc:825
 PDecayManager.cc:826
 PDecayManager.cc:827
 PDecayManager.cc:828
 PDecayManager.cc:829
 PDecayManager.cc:830
 PDecayManager.cc:831
 PDecayManager.cc:832
 PDecayManager.cc:833
 PDecayManager.cc:834
 PDecayManager.cc:835
 PDecayManager.cc:836
 PDecayManager.cc:837
 PDecayManager.cc:838
 PDecayManager.cc:839
 PDecayManager.cc:840
 PDecayManager.cc:841
 PDecayManager.cc:842
 PDecayManager.cc:843
 PDecayManager.cc:844
 PDecayManager.cc:845
 PDecayManager.cc:846
 PDecayManager.cc:847
 PDecayManager.cc:848
 PDecayManager.cc:849
 PDecayManager.cc:850
 PDecayManager.cc:851
 PDecayManager.cc:852
 PDecayManager.cc:853
 PDecayManager.cc:854
 PDecayManager.cc:855
 PDecayManager.cc:856
 PDecayManager.cc:857
 PDecayManager.cc:858
 PDecayManager.cc:859
 PDecayManager.cc:860
 PDecayManager.cc:861
 PDecayManager.cc:862
 PDecayManager.cc:863
 PDecayManager.cc:864
 PDecayManager.cc:865
 PDecayManager.cc:866
 PDecayManager.cc:867
 PDecayManager.cc:868
 PDecayManager.cc:869
 PDecayManager.cc:870
 PDecayManager.cc:871
 PDecayManager.cc:872
 PDecayManager.cc:873
 PDecayManager.cc:874
 PDecayManager.cc:875
 PDecayManager.cc:876
 PDecayManager.cc:877
 PDecayManager.cc:878
 PDecayManager.cc:879
 PDecayManager.cc:880
 PDecayManager.cc:881
 PDecayManager.cc:882
 PDecayManager.cc:883
 PDecayManager.cc:884
 PDecayManager.cc:885
 PDecayManager.cc:886
 PDecayManager.cc:887
 PDecayManager.cc:888
 PDecayManager.cc:889
 PDecayManager.cc:890
 PDecayManager.cc:891
 PDecayManager.cc:892
 PDecayManager.cc:893
 PDecayManager.cc:894
 PDecayManager.cc:895
 PDecayManager.cc:896
 PDecayManager.cc:897
 PDecayManager.cc:898
 PDecayManager.cc:899
 PDecayManager.cc:900
 PDecayManager.cc:901
 PDecayManager.cc:902
 PDecayManager.cc:903
 PDecayManager.cc:904
 PDecayManager.cc:905
 PDecayManager.cc:906
 PDecayManager.cc:907
 PDecayManager.cc:908
 PDecayManager.cc:909
 PDecayManager.cc:910
 PDecayManager.cc:911
 PDecayManager.cc:912
 PDecayManager.cc:913
 PDecayManager.cc:914
 PDecayManager.cc:915
 PDecayManager.cc:916
 PDecayManager.cc:917
 PDecayManager.cc:918
 PDecayManager.cc:919
 PDecayManager.cc:920
 PDecayManager.cc:921
 PDecayManager.cc:922
 PDecayManager.cc:923
 PDecayManager.cc:924
 PDecayManager.cc:925
 PDecayManager.cc:926
 PDecayManager.cc:927
 PDecayManager.cc:928
 PDecayManager.cc:929
 PDecayManager.cc:930
 PDecayManager.cc:931
 PDecayManager.cc:932
 PDecayManager.cc:933
 PDecayManager.cc:934
 PDecayManager.cc:935
 PDecayManager.cc:936
 PDecayManager.cc:937
 PDecayManager.cc:938
 PDecayManager.cc:939
 PDecayManager.cc:940
 PDecayManager.cc:941
 PDecayManager.cc:942
 PDecayManager.cc:943
 PDecayManager.cc:944
 PDecayManager.cc:945