///////////////////////////////////////////////////////////////////////////////
// Class StntupleMakerModule : fills Stntuple (P.Murat)
// ------------------------------------------
// order of the data blocks is essential - they are filled according to the
// order in which they are declared...
//
///////////////////////////////////////////////////////////////////////////////

#ifdef __GNUG__
#pragma implementation
#endif

#include <string>
#include <cstdio>

#include "evt/Event.hh"

#include <assert.h>
#include <iostream>
#include <iomanip>

#include "TH1.h"
#include "TString.h"
#include "TProfile.h"
#include "TFolder.h"
#include "TSystem.h"

#include "Calor/CprClusterMaker.hh"
#include "Calor/CprWireCollectionMaker.hh"
#include "HighLevelObjects/PhotonVariables.hh"
#include "HighLevelObjects/PhotonBackgroundComputer.hh"

#include <ElectronObjects/CdfEmObjectColl.hh>

#include <Stntuple/obj/TStnNode.hh>
#include <Stntuple/obj/TStnErrorLogger.hh>
#include <Stntuple/obj/TStnJetBlock.hh>
#include <Stntuple/obj/TCprDataBlock.hh>
#include <Stntuple/obj/TCp2DataBlock.hh>
#include <Stntuple/obj/TPesDataBlock.hh>
#include <Stntuple/obj/TPesCorrectedDataBlock.hh>
#include <Stntuple/obj/TGenpBlock.hh>
#include <Stntuple/obj/TXftBlock.hh>
#include <Stntuple/obj/TStnPhotonBlock.hh>
#include <Stntuple/obj/TStnElectronBlock.hh>
#include <Stntuple/obj/TPhoenixElectronBlock.hh>
#include <Stntuple/obj/TStnMuonBlock.hh>
#include <Stntuple/obj/TStnCosmicBlock.hh>
#include <Stntuple/obj/TStnMetBlock.hh>
#include <Stntuple/obj/TStnTrackBlock.hh>
#include <Stntuple/obj/TStnTriggerBlock.hh>
#include <Stntuple/obj/TSvxDataBlock.hh>
#include <Stntuple/obj/TSiStripBlock.hh>
#include <Stntuple/obj/TSvtDataBlock.hh>
#include <Stntuple/obj/TStnTrackLinkBlock.hh>
#include <Stntuple/obj/TStnVertexBlock.hh>
#include <Stntuple/obj/TStnEvent.hh>
#include <Stntuple/obj/TSiGeantIsectBlock.hh>
#include <Stntuple/obj/TSiIsectBlock.hh>
#include <Stntuple/obj/TDcasDataBlock.hh>
#include <Stntuple/obj/TStnTopSummaryBlock.hh>
#include <Stntuple/obj/TStnSecVtxTagBlock.hh>
#include <Stntuple/obj/TStnJetProbBlock.hh>
#include <Stntuple/obj/TStnConversionBlock.hh>

#include <Stntuple/mod/StntupleMakerModule.hh>

#include <Stntuple/mod/InitStntupleDataBlocks.hh>
#include <Stntuple/mod/StntupleUtilities.hh>

#include "TrackingObjects/Storable/CdfTrackColl.hh"
#include "TrackingObjects/Storable/CdfTrackView.hh"
#include "TrackingObjects/Tracks/CdfTrack.hh"
#include "TrackingObjects/Tracks/track_cut.hh"

#include "TrackingUserHL/Utility/CorrectedHitLocations.hh"

#include "Stntuple/alg/TStntuple.hh"

ClassImp(StntupleMakerModule)

static const char rcsid[] = "$Name: dev_242 $";

void stntuple_get_version(char*& ver, char*& test);
//------------------------------------------------------------------------------
// constructors
//------------------------------------------------------------------------------
StntupleMakerModule::StntupleMakerModule(const char* name, const char* desc): 
  StntupleModule   (name,desc)

  , fProcessName     ("processName"     ,this,"PROD")

  , fJetCollName     ("jetCollName"     ,this,1,100,"JetCluModule-cone0.4")
  , fTopTJetCollName ("TopTJetCollName" ,this     ,"TopTJetColl"     )
  , fTopLJetCollName ("TopLJetCollName" ,this     ,"TopLJetColl"     )

  , fMuonCollName    ("muonCollName"    ,this,"ProductionMuons")
  , fTopTMuonCollName("TopTmuonCollName",this,"TopTmuonColl"    )
  , fTopLMuonCollName("TopLmuonCollName",this,"TopLmuonColl"    )

  , fCosmicCollName  ("cosmicCollName"  ,this,"")

  , fElectronCollName    ("electronCollName"    ,this  ,"CalDriven")
  , fPhoenixElectronCollName("phoenixCollName",this,"Phoenix_Electrons") //Phoenix Stuff
  , fTopTElectronCollName("TopTElectronCollName",this  ,"TopTElectronColl")
  , fTopLElectronCollName("TopLElectronCollName",this  ,"TopLElectronColl")

  , fTrackCollName        ("trackCollName"       ,this,0,10,"default")
  , fVertexCollName       ("vertexCollName"      ,this,1,100,"DEFAULT_VXPRIM_VERTICES")
  , fPi0CollName          ("pi0CollName"         ,this,"Pi0CandidateCollection")
  , fTopSummaryName       ("TopSummaryName"      ,this     ,"GlobalSummary")
  , fMetCollName          ("metCollName"         ,this,1,5 ,"MetDefault"   )
  , fTopMetName           ("TopMetName"          ,this     ,"MetCorrected" )
  //  , fSecVtxCollName       ("SecVtxCollName"      ,this     ,"SecVtxColl")
  , fSecVtxCollName       ("SecVtxCollName"      ,this,1,20,"SecVtxColl")
 
  , fCmuInitMode          ("cmuInitMode"         ,this,0)
  , fGenpUseCuts          ("genpUseCuts"         ,this, 0)
  , fGenpEtaMin           ("genpEtaMin"          ,this,-100.)
  , fGenpEtaMax           ("genpEtaMax"          ,this, 100.)
  , fGenpPtMin            ("genpPtMin"           ,this, 0.)

  , fL3Source             ("l3Source"            ,this, 0)

  , fMakeCalData          ("makeCalData"         ,this,0)
  , fMakeCcrData          ("makeCcrData"         ,this,0)
  , fMakeCesData          ("makeCesData"         ,this,0)
  , fMakeClcData          ("makeClcData"         ,this,0)
  , fMakeClusters         ("makeClusters"        ,this,1)
  , fMakeCmpData          ("makeCmpData"         ,this,0)
  , fMakeCmuData          ("makeCmuData"         ,this,0)
  , fMakeCmxData          ("makeCmxData"         ,this,0)
  , fMakeConversions      ("makeConversions"     ,this,1)
  , fMakeCosmic           ("makeCosmic"          ,this,0)
  , fMakeCotData          ("makeCotData"         ,this,0)
  , fMakeCprData          ("makeCprData"         ,this,0)
  , fMakeCp2Data          ("makeCp2Data"         ,this,0)
  , fMakeDcasData         ("makeDcasData"        ,this,0)
  , fMakeEmtData          ("makeEmtData"         ,this,0)
  , fMakeEmTiming         ("makeEmTiming"        ,this,0)
  , fMakeElectrons        ("makeElectrons"       ,this,1)
  , fMakeFwdDetData       ("makeFwdDetData"      ,this,0)
  , fMakeGenp             ("makeGenp"            ,this,0)
  , fMakeHatData          ("makeHatData"         ,this,0)
  , fMakeJets             ("makeJets"            ,this,1)
  , fMakeJetProb          ("makeJetProb"         ,this,0)
  , fMakeL3Muons          ("makeL3Muons"         ,this,0)
  , fMakeL3Taus           ("makeL3Taus"          ,this,0)
  , fMakeL3Summary        ("makeL3Summary"       ,this,1)
  , fMakeMet              ("makeMet"             ,this,1)
  , fMakeMuons            ("makeMuons"           ,this,1)
  , fMakeObsp             ("makeObsp"            ,this,0)
  , fMakePesData          ("makePesData"         ,this,0)
  , fMakePesCorrectedData ("makePesCorrectedData",this,0)
  , fMakePhoenixElectrons ("makePhoenixElectrons",this,1)
  , fMakePhotons          ("makePhotons"         ,this,1)
  , fMakePi0s             ("makePi0s"            ,this,1)
  , fMakeSecVtxTag        ("makeSecVtxTag"       ,this,0)
  , fMakeSiGeantIsect     ("makeSiGeantIsect"    ,this,0)
  , fMakeSiIsect          ("makeSiIsect"         ,this,0)
  , fMakeSiStrips         ("makeSiStrips"        ,this,0)
  , fMakeSvt              ("makeSvt"		 ,this,1)
  , fMakeSvxData          ("makeSvxData"         ,this,0)

  , fMakeTaus             ("makeTaus"            ,this,1)
  , fMakeTofData          ("makeTofData"         ,this,0)

  , fMakeTopTElectrons    ("makeTopTElectrons"   ,this,0)
  , fMakeTopLElectrons    ("makeTopLElectrons"   ,this,0)
  , fMakeTopTJets         ("makeTopTJets"        ,this,0)
  , fMakeTopLJets         ("makeTopLJets"        ,this,0)
  , fMakeTopMet           ("makeTopMet"          ,this,0)
  , fMakeTopTMuons        ("makeTopTMuons"       ,this,0)
  , fMakeTopLMuons        ("makeTopLMuons"       ,this,0)
  , fMakeTopSummary       ("makeTopSummary"      ,this,0)

  , fMakeTracks           ("makeTracks"          ,this,1)
  , fMakeTrackLinks       ("makeTrackLinks"      ,this,0)
  , fMakeTrigger          ("makeTrigger"         ,this,1)
  , fMakeTrigSim          ("makeTrigSim"         ,this,1)
  , fMakeVertices         ("makeVertices"        ,this,1)
  , fMakeXft              ("makeXft"		 ,this,0)
  , fMakeZVertices        ("makeZVertices"       ,this,1)

  , fMetCorrectionMode    ("metCorrectionMode"   ,this, 0)
  , fPdgCode              ("pdgCode"             ,this, 0,100,0)

  , fStoreXftHits         ("storeXftHits"	 ,this,0)
  , fStoreXftPixels       ("storeXftPixels"	 ,this,0)
  , fStoreXftTracks       ("storeXftTrack"	 ,this,0)
{
  fProcessName.addDescription(" \t process name, default: PROD");
  commands()->append(&fProcessName);

  commands()->append(&fJetCollName);
  commands()->append(&fTopTJetCollName);
  commands()->append(&fTopLJetCollName);
  commands()->append(&fMuonCollName);
  commands()->append(&fCosmicCollName);
  commands()->append(&fTopTMuonCollName);
  commands()->append(&fTopLMuonCollName);
  commands()->append(&fElectronCollName);
  commands()->append(&fPhoenixElectronCollName); //Phoenix Stuff
  commands()->append(&fTopTElectronCollName);
  commands()->append(&fTopLElectronCollName);
  commands()->append(&fTrackCollName);
  commands()->append(&fVertexCollName);
  commands()->append(&fPi0CollName);
  commands()->append(&fTopSummaryName);
  commands()->append(&fMetCollName);
  commands()->append(&fTopMetName);
  commands()->append(&fSecVtxCollName);
  commands()->append(&fMakeCalData);
  commands()->append(&fMakeCcrData);
  commands()->append(&fMakeCesData);
  commands()->append(&fMakePesData);
  commands()->append(&fMakePesCorrectedData);
  commands()->append(&fMakeClcData);
  commands()->append(&fMakeClusters);
  commands()->append(&fMakeCmuData);
  commands()->append(&fCmuInitMode);
  commands()->append(&fMakeCmpData);
  commands()->append(&fMakeCmxData);
  commands()->append(&fMakeCosmic);
  commands()->append(&fMakeCotData);
  commands()->append(&fMakeCprData);
  commands()->append(&fMakeCp2Data);
  commands()->append(&fMakeDcasData);
  commands()->append(&fMakeEmtData);
  commands()->append(&fMakeEmTiming);
  commands()->append(&fMakeElectrons);
  commands()->append(&fMakeFwdDetData);
  commands()->append(&fMakeGenp);
  commands()->append(&fMakeHatData);
  commands()->append(&fMakeJets);
  commands()->append(&fMakeJetProb);
  commands()->append(&fMakeL3Muons);
  commands()->append(&fMakeL3Taus);
  commands()->append(&fMakeL3Summary);
  commands()->append(&fMakeMet);
  commands()->append(&fMakeMuons);
  commands()->append(&fMakeObsp);
  commands()->append(&fMakePhoenixElectrons);
  commands()->append(&fMakePhotons);
  commands()->append(&fMakePi0s);
  commands()->append(&fMakeSiGeantIsect);
  commands()->append(&fMakeSiIsect);
  commands()->append(&fMakeSecVtxTag);
  commands()->append(&fMakeSvt);

  commands()->append(&fGenpUseCuts);
  commands()->append(&fGenpEtaMin);
  commands()->append(&fGenpEtaMax);
  commands()->append(&fGenpPtMin);
  commands()->append(&fPdgCode);

  commands()->append(&fL3Source);

  commands()->append(&fMetCorrectionMode);

  commands()->append(&fMakeSvxData);
  commands()->append(&fMakeSiStrips);
  commands()->append(&fMakeTaus);
  commands()->append(&fMakeTofData);

  commands()->append(&fMakeTopMet);
  commands()->append(&fMakeTopTJets);
  commands()->append(&fMakeTopLJets);
  commands()->append(&fMakeTopTElectrons);
  commands()->append(&fMakeTopLElectrons);
  commands()->append(&fMakeTopTMuons);
  commands()->append(&fMakeTopLMuons);
  commands()->append(&fMakeTopSummary);

  commands()->append(&fMakeTracks);
  commands()->append(&fMakeTrackLinks);
  commands()->append(&fMakeTrigger);
  commands()->append(&fMakeTrigSim);
  commands()->append(&fMakeVertices);
  commands()->append(&fMakeXft);
  commands()->append(&fMakeZVertices);

  commands()->append(&fStoreXftHits);
  commands()->append(&fStoreXftPixels);
  commands()->append(&fStoreXftTracks);

  fPdgCode.setDefault();

  printf("Using %s tagged as %s\n", this->name(), rcsid);

  // setup for Cpr clustering in photons
  pCprCollMaker = new CprWireCollectionMaker();
  pCprClusMaker = new CprClusterMaker();

  char  *ver, *text;
  stntuple_get_version(ver,text);

  fVersion      = new TNamed(ver,text);
  TModule::fFolder->Add(fVersion);
}


//------------------------------------------------------------------------------
StntupleMakerModule::~StntupleMakerModule() {
  delete pCprCollMaker;
  delete pCprClusMaker;
  delete fVersion;
}


//------------------------------------------------------------------------------
AppResult StntupleMakerModule::beginRun( AbsEvent* aRun ) {

  static int first_begin_run = 1;

  if (first_begin_run) {
//-----------------------------------------------------------------------------
// if we runnning stnmaker_prod.exe, save revision of the TCL file in STNTUPLE
//-----------------------------------------------------------------------------
    first_begin_run = 0;
    const char* c = gSystem->Getenv("STNMAKER_PROD_TCL");
    if (c) TModule::fFolder->Add(new TNamed("STNMAKER_PROD_TCL",c));
    else   TModule::fFolder->Add(new TNamed("STNMAKER_PROD_TCL","unknown"));
  }

  pCprCollMaker->initRun(false); // false= do not print
  return AppResult::OK;
}

//------------------------------------------------------------------------------
AppResult StntupleMakerModule::endRun( AbsEvent* aRun ) {
  return AppResult::OK;
}


//------------------------------------------------------------------------------
AppResult StntupleMakerModule::endJob( AbsEvent* aRun ) {
  return AppResult::OK;
}


//------------------------------------------------------------------------------
AppResult StntupleMakerModule::beginJob(AbsEvent* event) {

  char    proc[20], desc[100], collOrView[20], coll_name[100], block_name[100];

  // create data blocks and branches

  fgStntupleFolder->Add(new TNamed("ProcessName"     ,fProcessName.value().c_str()));
  //  fgStntupleFolder->Add(new TNamed("JetCollName"     ,fJetCollName.value().c_str()));
  fgStntupleFolder->Add(new TNamed("TauCollName"     ,"CdfTauCollection"));
  fgStntupleFolder->Add(new TNamed("MuonCollName"    ,fMuonCollName.value().c_str()));
  fgStntupleFolder->Add(new TNamed("ElectronCollName",fElectronCollName.value().c_str()));

					// for the moment do it by hands...
					// create default branches to go into 
					// STNTUPLE

					// ****** RAW data branches
  if (fMakeCalData.value()) {
    AddDataBlock("CalDataBlock","TCalDataBlock",
		 StntupleInitCalDataBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
  }

  if (fMakeCcrData.value()) {
    AddDataBlock("CcrDataBlock","TCcrDataBlock",
		 StntupleInitCcrDataBlock,
		 fBufferSize.value(),
		 -1,
		 fCompressionLevel.value());
  }

  if (fMakeCesData.value()) {
    AddDataBlock("CesDataBlock","TCesDataBlock",
		 StntupleInitCesDataBlock,
		 fBufferSize.value(),
		 -1,			// don't split CES data
		 fCompressionLevel.value());
  }

  if (fMakeCprData.value()) {
    AddDataBlock("CprDataBlock","TCprDataBlock",
		 StntupleInitCprDataBlock,
		 fBufferSize.value(),
		 -1,               // raw data not split
		 fCompressionLevel.value());
  }

  if (fMakeCp2Data.value()) {
    AddDataBlock("Cp2DataBlock","TCp2DataBlock",
		 StntupleInitCp2DataBlock,
		 fBufferSize.value(),
		 -1,               // raw data not split
		 fCompressionLevel.value());
  }

  if (fMakePesData.value()) {
    AddDataBlock("PesDataBlock","TPesDataBlock",
		 StntupleInitPesDataBlock,
		 fBufferSize.value(),
		 -1,			// never split PES data
		 fCompressionLevel.value());
  }
  if (fMakePesCorrectedData.value()) {
    AddDataBlock("PesCorrectedDataBlock","TPesCorrectedDataBlock",
		 StntupleInitPesCorrectedDataBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),	      
		 fCompressionLevel.value());
  }
					// ****** CLC data: always non-split
  if (fMakeClcData.value()) {
    AddDataBlock("ClcDataBlock","TClcDataBlock",
		 StntupleInitClcDataBlock,
		 fBufferSize.value(),
		 -1,
		 fCompressionLevel.value());
  }

  if (fMakeCmpData.value()) {
    AddDataBlock("CmpDataBlock",
		 "TCmpDataBlock",
		 StntupleInitCmpDataBlock,
		 fBufferSize.value(),
		 -1,			     // CMP data not split
		 fCompressionLevel.value());
  }

  if (fMakeCmuData.value()) {
    TStnDataBlock* cmu_data;
    cmu_data = AddDataBlock("CmuDataBlock",
			    "TCmuDataBlock",
			    StntupleInitCmuDataBlock,
			    fBufferSize.value(),
			    fSplitMode.value(),
			    fCompressionLevel.value());
    
    cmu_data->SetInitMode(fCmuInitMode.value());
  }

  if (fMakeCmxData.value()) {
    AddDataBlock("CmxDataBlock","TCmxDataBlock",
		 StntupleInitCmxDataBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
  }

  if (fMakeCotData.value()) {
    AddDataBlock("CotDataBlock","TCotDataBlock",
		 StntupleInitCotDataBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
  }

  if (fMakeEmtData.value()) {
    AddDataBlock("EmtDataBlock","TEmtDataBlock",
		 StntupleInitEmtDataBlock,
		 fBufferSize.value(),
		 -1,			// don't split EMTD data
		 fCompressionLevel.value());
  }

  if (fMakeEmTiming.value()) {
    AddDataBlock("EmTimingBlock","TEmTimingBlock",
		 StntupleInitEmTimingBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
  }

  if (fMakeHatData.value()) {
    AddDataBlock("HatDataBlock","THatDataBlock",
		 StntupleInitHatDataBlock,
		 fBufferSize.value(),
		 -1,			// don't split HATD data
		 fCompressionLevel.value());
  }

  if (fMakeSvxData.value()) {
    AddDataBlock("SvxDataBlock","TSvxDataBlock",
		 StntupleInitSvxDataBlock,
		 fBufferSize.value(),
		 -1,
		 fCompressionLevel.value());
    SetResolveLinksMethod("SvxDataBlock",StntupleSvxDataBlockLinks);
  }

  if (fMakeSiStrips.value()) {
    TSiStripBlock *data;
    data = (TSiStripBlock *)AddDataBlock("SiStripsBlock","TSiStripBlock",
			StntupleInitSiStripBlock,
			fBufferSize.value(),
			std::min(fSplitMode.value(),1), // Don't
					 // split the TClonesArray
			3);

    if (data) {
      if (fMakeSiStrips.value() > 1) data->fStreamGeometryInfo=true;
      // Verbose strip set including global,local coords of each strip
    }
  }

  if (fMakeTofData.value()) {
    AddDataBlock("TofDataBlock","TTofDataBlock",
		 StntupleInitTofDataBlock,
		 fBufferSize.value(),
		 -1,               // raw data not split
		 fCompressionLevel.value());
  }
//-----------------------------------------------------------------------------
// 2 trigger data branches: one for the trigger data, 
// another one for the emulated trigger data
// always NON-SPLIT
//-----------------------------------------------------------------------------
  if (fMakeTrigger.value()) {
    TStnTriggerBlock *data;
    data = (TStnTriggerBlock*) AddDataBlock("TriggerBlock","TStnTriggerBlock",
					    StntupleInitTriggerBlock,
					    fBufferSize.value(),
					    -1,
					    fCompressionLevel.value());
    data->SetL3Source(fL3Source.value());
  }

  if (fMakeTrigSim.value()) {
    AddDataBlock("TrigSimBlock","TStnTriggerBlock",
		 StntupleInitTrigSimBlock,
		 fBufferSize.value(),
		 -1,
		 fCompressionLevel.value());
  }

  if (fMakeL3Summary.value()) {
    AddDataBlock("L3SummaryBlock","TL3SummaryBlock",
		 StntupleInitL3SummaryBlock,
		 fBufferSize.value(),
		 -1,
		 fCompressionLevel.value());
  }

  if (fMakeFwdDetData.value()) {
    AddDataBlock("FwdDetDataBlock","TFwdDetDataBlock",
		 StntupleInitFwdDetDataBlock,
		 fBufferSize.value(),
		 -1,			     // Forward Det data not split
		 fCompressionLevel.value());
  }

  if (fMakeDcasData.value()) {
    AddDataBlock("DcasDataBlock","TDcasDataBlock",
		 StntupleInitDcasDataBlock,
		 fBufferSize.value(),
		 -1,               // raw data not split
		 fCompressionLevel.value());
  }


					// ****** vertex data branch
  if (fMakeVertices.value()) {
    TStnDataBlock* vtx_data;
    
    for (AbsParmList<string>::ConstIterator name = fVertexCollName.begin();
         name != fVertexCollName.end(); ++name) {
      
      // parse collection name
      
      StntupleGetProcessName(name->data(),proc,desc);
      if (proc[0] == 0) {
	strcpy(proc,fProcessName.value().data());
      }

      // figure the block name - the default
      // collection goes to "VertexBlock", 
      // the rest - "PROC@desc"
      
      if (name == fVertexCollName.begin()) {
	strcpy(block_name,"VertexBlock");
      }
      else {
	strcpy(block_name,proc);
	strcat(block_name,"@");
	strcat(block_name,desc);
      }
      
      vtx_data = AddDataBlock(block_name,
			      "TStnVertexBlock",
			      StntupleInitVertexBlock,
			      fBufferSize.value(),
			      fSplitMode.value(),
			      fCompressionLevel.value());
      if (vtx_data) {
	vtx_data->SetCollName(proc,desc);
      }
    } // end loop for vertex collections
  } // end vertex


  // z vertices from ZVertexModule -> ZVertexColl
  if (fMakeZVertices.value()) {
    AddDataBlock("ZVertexBlock",
		 "TStnVertexBlock",
		 StntupleInitZVertexBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
  }

//-----------------------------------------------------------------------------
// track branches: for ROOT v3 to use streamers one has to specify split=-1
//-----------------------------------------------------------------------------

  if (fMakeTracks.value()) {
    TStnDataBlock* track_data;
					// always store defTracks for the 
					// default process in the "TrackBlock"

    track_data = AddDataBlock("TrackBlock",
			      "TStnTrackBlock",
			      StntupleInitTrackBlock,
			      fBufferSize.value(),
			      fSplitMode.value(),
			      fCompressionLevel.value());

    SetResolveLinksMethod("TrackBlock",StntupleTrackBlockLinks);

    if (track_data) {
      track_data->SetCollName(fProcessName.value().data(),"default");
    }
					// however there is only one track
					// link block for the moment
    if (fMakeTrackLinks.value()) {
      AddDataBlock("TrackLinkBlock","TStnTrackLinkBlock",
		   0,
		   fBufferSize.value(),
		   -1,
		   fCompressionLevel.value());
      SetResolveLinksMethod("TrackLinkBlock",StntupleTrackLinkBlockLinks);
    }
					// process additional collections

    for (AbsParmList<string>::ConstIterator name = fTrackCollName.begin();
         name != fTrackCollName.end(); ++name) {

					// parse collection name

      StntupleGetProcessName(name->data(),proc,desc);
      if (proc[0] == 0) {
					// set default process name

	strcpy(proc,fProcessName.value().data());
      }
					// figure the block name - the default
					// collection goes to "TrackBlock", 
					// the rest - to the block coll_name

      track_data = AddDataBlock(Form("%s@%s",proc,desc),
				"TStnTrackBlock",
				StntupleInitTrackBlock,
				fBufferSize.value(),
				fSplitMode.value(),
				fCompressionLevel.value());
      if (track_data) {
	track_data->SetCollName(proc,desc);
	track_data->SetResolveLinksMethod(StntupleTrackBlockLinks);
      }

    }
  }
//-----------------------------------------------------------------------------
// jet branches
//-----------------------------------------------------------------------------
  if (fMakeJets.value()) {
    TStnJetBlock* data;

    for (AbsParmList<string>::ConstIterator name = fJetCollName.begin();
         name != fJetCollName.end(); ++name) {

					// parse collection name

      StntupleGetProcessName(name->data(),proc,desc);
      if (proc[0] == 0) {
					// set default process name

	strcpy(proc,fProcessName.value().data());
      }
					// figure the block name - the default
					// collection goes to "JetBlock", 
					// the rest - "PROC@desc"

      if (name == fJetCollName.begin()) {
	strcpy(block_name,"JetBlock");
      }
      else {
	strcpy(block_name,proc);
	strcat(block_name,"@");
	strcat(block_name,desc);
      }


      data =  (TStnJetBlock*) AddDataBlock(block_name,
					   "TStnJetBlock",
					   StntupleInitJetBlock,
					   fBufferSize.value(),
					   fSplitMode.value(),
					   fCompressionLevel.value());
      if (data) {
	data->SetCollName(proc,desc);
	SetResolveLinksMethod(block_name,StntupleJetBlockLinks);
      }
    }
  }

// ==========================
//       Tight Top Jets 
// ==========================
  if (fMakeTopTJets.value()) {
    TStnJetBlock* data;
    data =  (TStnJetBlock*) AddDataBlock("TopTJetBlock",
					 "TStnJetBlock",
					 StntupleInitJetBlock,
					 fBufferSize.value(),
					 fSplitMode.value(),
					 fCompressionLevel.value());
    if (data) {
      data->SetCollName(fTopTJetCollName.value().data());
    }
  }

// ==========================
//       Loose Top Jets
// ==========================
  if (fMakeTopLJets.value()) {
    TStnJetBlock* data;
    data =  (TStnJetBlock*) AddDataBlock("TopLJetBlock",
					 "TStnJetBlock",
					 StntupleInitJetBlock,
					 fBufferSize.value(),
					 fSplitMode.value(),
					 fCompressionLevel.value());
    if (data) {
      data->SetCollName(fTopLJetCollName.value().data());
    }
  }


  if (fMakeGenp.value()) {
    TGenpBlock* genp;
    genp = (TGenpBlock*) AddDataBlock("GenpBlock",
				      "TGenpBlock",
				      StntupleInitGenpBlock,
				      fBufferSize.value(),
				      fSplitMode.value(),
				      fCompressionLevel.value());

    genp->SetUseCuts(fGenpUseCuts.value());
    genp->SetEtaMin (fGenpEtaMin.value());
    genp->SetEtaMax (fGenpEtaMax.value());
    genp->SetPtMin  (fGenpPtMin.value() );

    int ncodes = fPdgCode.size();

    for (AbsParmList<int>::ConstIterator code = fPdgCode.begin();
         code != fPdgCode.end(); ++code) {
      genp->AddPdgCode(*code);
    }
  }

  if (fMakeObsp.value()) {
    AddDataBlock("ObspBlock","TObspBlock",
		 StntupleInitObspBlock,
		 fBufferSize.value(),
		 -1,
		 fCompressionLevel.value());
  }

//=============================
//	Electrons
//=============================
  if (fMakeElectrons.value()) {
    TStnElectronBlock* data;
    data =  (TStnElectronBlock*) AddDataBlock("ElectronBlock",
					      "TStnElectronBlock",
					      StntupleInitElectronBlock,
					      fBufferSize.value(),
					      fSplitMode.value(),
					      fCompressionLevel.value());

    if (data) {
      StntupleGetProcessName(fElectronCollName.value().data(),
			     proc,desc,collOrView);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      data->SetCollName(proc,desc,collOrView);
      SetResolveLinksMethod("ElectronBlock",StntupleElectronBlockLinks);
    }
  }

  //Phoenix Stuff
  if (fMakePhoenixElectrons.value()) {
    TPhoenixElectronBlock* data;
    data = (TPhoenixElectronBlock*) AddDataBlock("Phoenix_Electrons",
						 "TPhoenixElectronBlock",
						 StntupleInitPhoenixElectronBlock,
						 fBufferSize.value(),
						 fSplitMode.value(),
						 fCompressionLevel.value());
    if (data) {
         StntupleGetProcessName(fPhoenixElectronCollName.value().data(),
                             proc,desc);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      data->SetCollName(proc,desc);
      SetResolveLinksMethod("Phoenix_Electrons",StntuplePhoenixElectronBlockLinks);
    }
  }
  //end of Phoenix Stuff

//=============================
//	Top Tight Electrons
//=============================
  if (fMakeTopTElectrons.value()) {
    TStnElectronBlock* data;
    data =  (TStnElectronBlock*) AddDataBlock("TopTElectronBlock",
					      "TStnElectronBlock",
		 StntupleInitElectronBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());

    if (data) {
      StntupleGetProcessName(fTopTElectronCollName.value().data(),
			     proc,desc,collOrView);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      data->SetCollName(proc,desc,collOrView);
      SetResolveLinksMethod("TopTElectronBlock",StntupleElectronBlockLinks);
    }
  }

//=============================
//	Top Loose Electrons
//=============================
  if (fMakeTopLElectrons.value()) {
    TStnElectronBlock* data;
    data =  (TStnElectronBlock*) AddDataBlock("TopLElectronBlock",
					      "TStnElectronBlock",
		 StntupleInitElectronBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());

    if (data) {
      StntupleGetProcessName(fTopLElectronCollName.value().data(),proc,desc,collOrView);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      data->SetCollName(proc,desc,collOrView);
      SetResolveLinksMethod("TopLElectronBlock",StntupleElectronBlockLinks);
    }
  }



//		Photons
//=============================
  if (fMakePhotons.value()) {
    AddDataBlock("PhotonBlock","TStnPhotonBlock",
		 StntupleInitPhotonBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
    SetResolveLinksMethod("PhotonBlock",StntuplePhotonBlockLinks);
  }

  if (fMakeClusters.value()) {
    AddDataBlock("ClusterBlock","TStnClusterBlock",
		 StntupleInitClusterBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
  }

//--------------------------------
//  L3Muons: do not resolve links to the tracks for the moment -
//  tracks may not exist... Even if they do, the name of the 
//  corresponding collection is yet to be figured
//--------------------------------
  if (fMakeL3Muons.value()) {
    TStnDataBlock* muon_block;
    muon_block = (TStnMuonBlock*) AddDataBlock("L3MuonBlock","TStnMuonBlock",
			      StntupleInitMuonBlock,
			      fBufferSize.value(),
			      fSplitMode.value(),
			      fCompressionLevel.value());
    if (muon_block) {
      muon_block->SetCollName("L3@ProductionMuons");
    }
  }

//--------------------------------
//  Muons
//--------------------------------
  if (fMakeMuons.value()) {
    TStnDataBlock* muon_block;
    muon_block = (TStnMuonBlock*) AddDataBlock("MuonBlock","TStnMuonBlock",
			      StntupleInitMuonBlock,
			      fBufferSize.value(),
			      fSplitMode.value(),
			      fCompressionLevel.value());
    if (muon_block) {
      StntupleGetProcessName(fMuonCollName.value().data(),proc,desc,collOrView);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      muon_block->SetCollName(proc,desc,collOrView);
      muon_block->SetResolveLinksMethod(StntupleMuonBlockLinks);
    }
  }

//--------------------------------
//  TopT Muons
//--------------------------------
  if (fMakeTopTMuons.value()) {
    TStnDataBlock* muon_block;
    muon_block = (TStnMuonBlock*) AddDataBlock("TopTMuonBlock","TStnMuonBlock",
			      StntupleInitMuonBlock,
			      fBufferSize.value(),
			      fSplitMode.value(),
			      fCompressionLevel.value());
    if (muon_block) {
      StntupleGetProcessName(fTopTMuonCollName.value().data(),proc,desc,collOrView);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      muon_block->SetCollName(proc,desc,collOrView);
      muon_block->SetResolveLinksMethod(StntupleMuonBlockLinks);
    }
  }

//--------------------------------
//  TopL Muons
//--------------------------------
  if (fMakeTopLMuons.value()) {
    TStnDataBlock* muon_block;
    muon_block = (TStnMuonBlock*) AddDataBlock("TopLMuonBlock","TStnMuonBlock",
			      StntupleInitMuonBlock,
			      fBufferSize.value(),
			      fSplitMode.value(),
			      fCompressionLevel.value());
    if (muon_block) {
      StntupleGetProcessName(fTopLMuonCollName.value().data(),proc,desc,collOrView);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      muon_block->SetCollName(proc,desc,collOrView);
      muon_block->SetResolveLinksMethod(StntupleMuonBlockLinks);
    }
  }

//------------------------------------------------------------------------------
//  taus: for L3 efficiencies need also L3 tau's. DO not resolve links for
//  those for the same reason as for the L3 muons
//------------------------------------------------------------------------------
  if (fMakePi0s.value()) {
    TStnDataBlock* pi0_block = AddDataBlock("Pi0Block","TStnPi0Block",
					    StntupleInitPi0Block,
					    fBufferSize.value(),
					    fSplitMode.value(),
					    fCompressionLevel.value());

    pi0_block->SetCollName(fProcessName.value().data(),fPi0CollName.value().data());
    SetResolveLinksMethod("Pi0Block",StntuplePi0BlockLinks);
  }

  if (fMakeTaus.value()) {
    TStnDataBlock* tau_block = AddDataBlock("TauBlock","TStnTauBlock",
					    StntupleInitTauBlock,
					    fBufferSize.value(),
					    fSplitMode.value(),
					    fCompressionLevel.value());

    tau_block->SetCollName(fProcessName.value().data(),"CdfTauCollection");
    SetResolveLinksMethod("TauBlock",StntupleTauBlockLinks);
  }

  if (fMakeL3Taus.value()) {
    TStnDataBlock* tau_block = AddDataBlock("L3TauBlock","TStnTauBlock",
					    StntupleInitTauBlock,
					    fBufferSize.value(),
					    fSplitMode.value(),
					    fCompressionLevel.value());
    tau_block->SetCollName("L3","CdfTauCollection");
  }
//-----------------------------------------------------------------------------
//  Conversions
//-----------------------------------------------------------------------------
  if (fMakeConversions.value()) {
    TStnDataBlock* conv_block;
    conv_block = (TStnConversionBlock*) AddDataBlock("ConversionBlock",
						     "TStnConversionBlock",
						     StntupleInitConversionBlock,
						     fBufferSize.value(),
						     fSplitMode.value(),
						     fCompressionLevel.value());
    if (conv_block) {
      conv_block->SetCollName(fProcessName.value().data(),"Conversions");
      conv_block->SetResolveLinksMethod(StntupleConversionBlockLinks);
    }
  }
//-----------------------------------------------------------------------------
//  Cosmic
//-----------------------------------------------------------------------------
  if (fMakeCosmic.value()) {
    TStnDataBlock* cosmic_block;
    cosmic_block = (TStnCosmicBlock*) AddDataBlock("CosmicBlock","TStnCosmicBlock",
			      StntupleInitCosmicBlock,
			      fBufferSize.value(),
			      fSplitMode.value(),
			      fCompressionLevel.value());
    if (cosmic_block) {
      StntupleGetProcessName(fCosmicCollName.value().data(),proc,desc,collOrView);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      cosmic_block->SetCollName(proc,desc,collOrView);
      cosmic_block->SetResolveLinksMethod(StntupleCosmicBlockLinks);
    }
  }
//-----------------------------------------------------------------------------
// Met branches
//-----------------------------------------------------------------------------
  if (fMakeMet.value()) {
    TStnMetBlock* data;

    for (AbsParmList<string>::ConstIterator name = fMetCollName.begin();
         name != fMetCollName.end(); ++name) {

					// parse collection name

      StntupleGetProcessName(name->data(),proc,desc);

      if (proc[0] == 0) {
					// set default process name

	strcpy(proc,fProcessName.value().data());
      }
					// figure the block name - the default
					// collection goes to "MetBlock", 
					// the rest - "PROC@desc"

      if (name == fMetCollName.begin()) {
	strcpy(block_name,"MetBlock");
      }
      else {
	strcpy(block_name,proc);
	strcat(block_name,"@");
	strcat(block_name,desc);
      }

      data =  (TStnMetBlock*) AddDataBlock(block_name,
					   "TStnMetBlock",
					   StntupleInitMetBlock,
					   fBufferSize.value(),
					   fSplitMode.value(),
					   fCompressionLevel.value());
      if (data) {
	data->SetCollName(proc,desc);
	data->SetResolveLinksMethod(StntupleMetBlockLinks);
      }
    }
  }



//---------------------------------------------
//   Top MET block should be the last one
//---------------------------------------------
  if (fMakeTopMet.value()) {
    TStnDataBlock* topmet_block;
    topmet_block = (TStnMetBlock*) AddDataBlock("TopMetBlock",
						"TStnMetBlock",
						StntupleInitMetBlock,
						fBufferSize.value(),
						fSplitMode.value(),
						fCompressionLevel.value());
    if (topmet_block) {
      StntupleGetProcessName(fTopMetName.value().data(),proc,desc);
      if (proc[0] == 0) strcpy(proc,fProcessName.value().data());
      topmet_block->SetCollName(proc,desc);
    }
  }


//---------------------------------------------
//   Top Global Summary
//---------------------------------------------
  if (fMakeTopSummary.value()) {
    TStnTopSummaryBlock* Top_block;
    Top_block = (TStnTopSummaryBlock*)AddDataBlock("TopSummaryBlock",
						   "TStnTopSummaryBlock",
						   StntupleInitTopSummaryBlock,
						   fBufferSize.value(),
						   fSplitMode.value(),
						   fCompressionLevel.value());
    if (Top_block) {
      Top_block->SetCollName(fTopSummaryName.value().data());
    }
  }


  if (fMakeXft.value()) {
    TXftBlock* xft;
    xft = (TXftBlock*) AddDataBlock("XftBlock",
				    "TXftBlock",
				    StntupleInitXftBlock,
				    fBufferSize.value(),
				    fSplitMode.value(),
				    fCompressionLevel.value());

    xft->SetStoreHits  (fStoreXftHits.value());
    xft->SetStorePixels(fStoreXftPixels.value());
    xft->SetStoreTracks(fStoreXftTracks.value());
  }


  if (fMakeSvt.value()) {
    AddDataBlock("SvtDataBlock","TSvtDataBlock",
		 StntupleInitSvtDataBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
  } 


  if (fMakeSiGeantIsect.value()) {
    AddDataBlock("SiGeantIsectBlock","TSiGeantIsectBlock",
		 StntupleInitSiGeantIsectBlock,
		 fBufferSize.value(),
		 fSplitMode.value(),
		 fCompressionLevel.value());
    SetResolveLinksMethod("SiGeantIsectBlock",StntupleSiGeantIsectBlockLinks);
  }

  if (fMakeSiIsect.value()) {
    TStnDataBlock* isec_data = AddDataBlock("SiIsectBlock","TSiIsectBlock",
		 StntupleInitSiIsectBlock,
		 fBufferSize.value(),
		 -1,
		 fCompressionLevel.value());
    SetResolveLinksMethod("SiIsectBlock",StntupleSiIsectBlockLinks);

    if (isec_data) {
					// should refer to the 1st track
					// collection here
      GetDefTrackCollName(coll_name);
      isec_data->SetCollName(coll_name);
    }
  }

//---------------------------------------------------
//   SecVtx Block
//---------------------------------------------------
//
//  if (fMakeSecVtxTag.value()) {
//    TStnSecVtxTagBlock* secvtx_data;
//    secvtx_data = (TStnSecVtxTagBlock*) AddDataBlock("SecVtxTagBlock",
//						     "TStnSecVtxTagBlock",
//						     StntupleInitSecVtxTagBlock,
//						     fBufferSize.value(),
//						     fSplitMode.value(),
//						     fCompressionLevel.value());
//    if (secvtx_data) {
//      secvtx_data->SetCollName(fSecVtxCollName.value().data());
//      SetResolveLinksMethod("SecVtxTagBlock",StntupleSecVtxTagBlockLinks);
//    }
//
//  }
//
//---------------------------------------------------
//   SecVtx Block
//---------------------------------------------------
  if (fMakeSecVtxTag.value()) {
    TStnSecVtxTagBlock* secvtx_data;

    for (AbsParmList<string>::ConstIterator name = fSecVtxCollName.begin();
         name != fSecVtxCollName.end(); ++name) {

                                        // parse collection name

      StntupleGetProcessName(name->data(),proc,desc);
      if (proc[0] == 0) {
                                        // set default process name

        strcpy(proc,fProcessName.value().data());
      }
                                        // figure the block name - the default
                                        // collection goes to "SecVtxTagBlock",
                                        // the rest - "PROC@desc"

      if (name == fSecVtxCollName.begin()) {
        strcpy(block_name,"SecVtxTagBlock");
      }
      else {
        strcpy(block_name,proc);
        strcat(block_name,"@");
        strcat(block_name,desc);
      }


      secvtx_data = (TStnSecVtxTagBlock*)  AddDataBlock(block_name,
                                           "TStnSecVtxTagBlock",
                                           StntupleInitSecVtxTagBlock,
                                           fBufferSize.value(),
                                           fSplitMode.value(),
                                           fCompressionLevel.value());
      if (secvtx_data) {
        secvtx_data->SetCollName(proc,desc);
        SetResolveLinksMethod(block_name,StntupleSecVtxTagBlockLinks);
      }
    }
  }


//---------------------------------------------------
//   Jet Probability Block
//---------------------------------------------------

 if (fMakeJetProb.value()) {
   AddDataBlock("JetProbBlock",
		"TStnJetProbBlock",
		StntupleInitJetProbBlock,
		fBufferSize.value(),
		fSplitMode.value(),
		fCompressionLevel.value());
   SetResolveLinksMethod("JetProbBlock",StntupleJetProbBlockLinks);
 }

 // setup for Cpr clustering in photons
  pCprCollMaker->initJob(false); // false= do not use CPRQ

  return AppResult::OK;
}

//_____________________________________________________________________________
AppResult StntupleMakerModule::event(AbsEvent* event) {

  // when execution comes here al the registered data blocks are already
  // initialized with the event data. Left: variables in the data blocks
  // which depend on the variable defined in other blocks, like track number
  // for a muon or an electron - the idea is that these are defined during the
  // 2nd loop in FillStntupleModule, where ResolveLinks methods are called
  // for each data block

//-----------------------------------------------------------------------------
// connect to the error reporting facility
//-----------------------------------------------------------------------------
  TStnErrorLogger* logger = Event()->GetErrorLogger();
  logger->Connect("Report(Int_t, const char*)",
		  "StntupleModule",
		  this,
		  "LogError(const char*)");
//-----------------------------------------------------------------------------
//  define cluster numbers for each of the reconstructed photons
//-----------------------------------------------------------------------------
  if (fMakePhotons.value()) {
    TStnPhotonBlock*  pho_block;
    pho_block = (TStnPhotonBlock* ) Event()->GetDataBlock("PhotonBlock");

    // now fill in the CES-seeded CPR cluster
    pCprCollMaker->initCollection(event);
    pCprClusMaker->initCprClusterMaker();
    CprWirePar  wirePar(NULL);
    wirePar.setNumberWires(5);
    CprClustPar clustPar(NULL);
    clustPar.setNumberMaxWires(5);
    vector<CesCluster> wireclus;
    vector<CesCluster> strpclus;
    vector<CesCluster>::const_iterator is;
    vector<CesCluster>::const_iterator iw;
    CdfTrack_clnk emptyTrackLink;

    double sumEtNoJets = PhotonVariables::phoSumetNoJets();
    
    for (int i=0; i<pho_block->NPhotons(); i++) {
      TStnPhoton* pho = pho_block->Photon(i);
      pho->fCescprx = -99.0;
      pho->fCescprq = -99.0;
      pho->fCprwht = -1.0e6;
      if (pho->GetCesWireCluster() && pho->GetCesStrpCluster() ) {
	wireclus.clear();   wireclus.push_back(*pho->GetCesWireCluster());
	strpclus.clear();   strpclus.push_back(*pho->GetCesStrpCluster());
	is=strpclus.begin();
	iw=wireclus.begin();
	float zv = (pho->fZv>-900.0 ? pho->fZv : 0.0);
	HepPoint3D primvtx(0,0,zv);
	const vector<CprWire> cluWires = 
            pCprCollMaker->get_ces_based_wires(&wirePar, is, iw, primvtx);
	if (cluWires.size()>0) {
	  pCprClusMaker->setSeedWire(pCprCollMaker->get_SeedWireNo());

	  CprCluster myCluster = pCprClusMaker->do_cluster_wires( 
				    &cluWires, &clustPar, emptyTrackLink);
	  if (pCprClusMaker->is_valid()) {
	    pho->fCescprx = myCluster.localCoord();
	    pho->fCescprq = myCluster.energy();
	    if(pho->fCescprq>500.0) pho->fWrd |= (1<<19);
	  } // cluster found
	}// if Cpr wires found

	double phoeff, baceffs, nphobac;
	double cprsys1, cprsys2, cprsys3, cprsys4;
	pho->fCprwht  = 
	  PhotonBackgroundComputer::getCprWeight(
                  pho->CesCprQ(),pho->Etc(),pho->SinTheta(),
		  phoeff, baceffs, nphobac,
		  cprsys1, cprsys2, cprsys3, cprsys4, -1.0, -1, sumEtNoJets);
	pho->fCprpg = phoeff;
	pho->fCprpb = baceffs;


      } // endif photon has CES clusters
    } // end of loop over photons for CES-seeded Cpr clusters 


  } // if make photons

//-----------------------------------------------------------------------------
// disconnect from the error reporting signal and return back to AC++
//-----------------------------------------------------------------------------
  logger->Disconnect("Report(Int_t,const char*)",
		     this,"LogError(Int_t,const char*)");

  return AppResult::OK;
}


//------------------------------------------------------------------------------
void StntupleMakerModule::GetDefTrackCollName(char* Name) {
  // put in a working kludge first

  strcpy(Name,"default");
}



//_____________________________________________________________________________
StntupleMakerModule::Command::Command() {
}

//_____________________________________________________________________________
StntupleMakerModule::Command::~Command() {
}


//_____________________________________________________________________________
StntupleMakerModule::Command::Command(const char* const name, 
				      StntupleMakerModule* module) : 
    APPCommand(name,module)
{
}


//_____________________________________________________________________________
int StntupleMakerModule::Command::handle(int argc, char* argv[]) {
  //
  int rc        = 0;
  return rc;
}


//_____________________________________________________________________________
void StntupleMakerModule::Command::show() const {
  if(strncmp(command(),"DETECTORS",9)==0) {
  }
}

//_____________________________________________________________________________
bool StntupleMakerModule::Command::isShowable() const {
  return true;
}

//_____________________________________________________________________________
string StntupleMakerModule::Command::description() const {
  string retval = "description is missing";
  if (strcmp(command(),"useEleMaker") == 0) {
    retval = "Use Electron Maker and read electron cuts menu";
  }
  return retval;
}

//_____________________________________________________________________________
int StntupleMakerModule::InitCalDataBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitCalDataBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitElectronBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitElectronBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitElectronBlockLinks(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleElectronBlockLinks(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitGenpBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitGenpBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitHeaderBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitHeaderBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitJetBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitJetBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitMetBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitMetBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitMuonBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitMuonBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitObspBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitObspBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitTauBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitTauBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitTofDataBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitTofDataBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitTrackBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitTrackBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitTriggerBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitTriggerBlock(Block,event,mode);
}

//_____________________________________________________________________________
int StntupleMakerModule::InitTrigSimBlock(TStnDataBlock* Block) {
  int mode = 0;
  AbsEvent* event = AbsEnv::instance()->theEvent();
  return StntupleInitTrigSimBlock(Block,event,mode);
}