//<<<<<< INCLUDES                                                       >>>>>>

#include "Utilities/Configuration/interface/Architecture.h"
#include "Visualisation/CustomTracker/interface/VisCuTkEventDataProxy.h"
#include "Visualisation/CustomTracker/interface/VisCuTkTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTrackerSelectionTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkSlThetaPhiTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkSlRecTracksTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkSlSimTracksTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkEvTrackerTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkEvRecHitsTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkEvRecTracksTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkEvSimHitsTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkEvSimTracksTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkMapTrackerTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkMapRecHitsTwig.h"
#include "Visualisation/CustomTracker/interface/VisCuTkMapSimHitsTwig.h"
#include "Visualisation/CobraVisBase/interface/VisPackageInitializer.h"
#include "Ig_Modules/IgStudio/interface/IgDocumentData.h"
#include "Ig_Framework/IgObjectBrowser/interface/IgRepSet.h"
#include <classlib/callback.h>
#include <qapplication.h>

//<<<<<< PRIVATE DEFINES                                                >>>>>>
//<<<<<< PRIVATE CONSTANTS                                              >>>>>>
//<<<<<< PRIVATE TYPES                                                  >>>>>>
//<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
//<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
//<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>

IG_DEFINE_STATE_ELEMENT (VisCuTkEventDataProxy, "Data/COBRA/Event/CustomTracker");

//<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
//<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
//<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>

/** Initialise Tracker event data proxy. */
VisCuTkEventDataProxy::VisCuTkEventDataProxy (IgState *state)
    : VisDataProxy (state, s_key, EVENT_THREAD,
		    create_callback (this, &VisCuTkEventDataProxy::init))
{
}

/** Actual (in-event-thread) initialisation: add the Tracker event twig
    and all other Tracker-related twigs to the document data tree.  */
void
VisCuTkEventDataProxy::init (void) 
{
    qApp->lock ();
    
    // FIXME: Do something here if Event is not found: create
    // a parent Twig?
    IgTwig *eventTwig = IgDocumentData::get (state ())->find ("Event");
    IgTwig *customtrackerTwig = new VisCuTkTwig (state (), eventTwig);
    IgTwig *tkselection = new IgSimpleTwig (customtrackerTwig, "TkSelection", true, false, true );
    IgTwig *tkevent = new IgSimpleTwig (customtrackerTwig, "TkEvent", true, false, true );
    IgTwig *tk2dmap = new IgSimpleTwig (customtrackerTwig, "Tk2DMap", true, false, true );

    new VisCuTrackerSelectionTwig (state (), tkselection);
    new VisCuTkSlThetaPhiTwig (state (), tkselection);
    new VisCuTkSlRecTracksTwig (state (), tkselection);
    new VisCuTkSlSimTracksTwig (state (), tkselection);

    new VisCuTkEvTrackerTwig (state (), tkevent);
    new VisCuTkEvRecHitsTwig (state (), tkevent);
    new VisCuTkEvRecTracksTwig (state (), tkevent);
    new VisCuTkEvSimHitsTwig (state (), tkevent);
    new VisCuTkEvSimTracksTwig (state (), tkevent);

    new VisCuTkMapTrackerTwig (state (), tk2dmap);
    new VisCuTkMapRecHitsTwig (state (), tk2dmap);
    new VisCuTkMapSimHitsTwig (state (), tk2dmap);

    IgRepSet::update (eventTwig, IgTwig::STRUCTURE_MASK);

    qApp->unlock (false);
}
