//this file looks like plain C, but it's actually -*- c++ -*-
#ifndef __TQSample__
#define __TQSample__

#include "TTree.h"

class TQSampleVisitor;
class TQCounter;
class TQToken;

#include "QFramework/TQSampleFolder.h"

#ifdef HAS_XAOD
namespace xAOD { //EXCLUDE
  class TEvent;
}
#endif

class TQSample : public TQSampleFolder { 
  protected:
  TString fTreeLocation = "";
  double fNormalisation = 1.;

  
  TTree * fTree = 0; //!
#ifdef HAS_XAOD
  xAOD::TEvent* fEvent = 0; //!
#endif
  bool fTreeIsTransient = false; //!
  bool fTokensAreShared = false; //!
  
  TFile * fFile = 0; //!
  TList * fTokens = 0; //!
  
  TQSample* fProxySample = nullptr; //!
  
  void setTree(TFile* file, const TString& treename);
  bool getTree();
  void promoteTreeToFriends();
  void retractTreeFromFriends();

  void clearTree();

  friend TQSampleFolder;

  virtual void findFriendsInternal(TQSampleFolder* otherSF, bool forceUpdateSubsamples = false, std::shared_ptr<TList> otherSFContents = nullptr) override;
  bool createFriendLinksForSamplesWithTreeLocation(TQSampleFolder* otherSF, std::shared_ptr<TList> otherSFContents = nullptr);

public:

  static bool gUseTransientTree;
  static bool gUseAthenaAccessMode; //use kAthenaAccess mode for xAODs (default is to use kClassAccess mode which is faster but does not work in all cases)

  static TList * splitTreeLocations(TString treeLocations);
  static TString extractFilename(const TString& treeLocation);
  static TString extractTreename(const TString& treeLocation);
  
  TQSample();
  TQSample(const TString& name);

  virtual TQFolder * newInstance(const TString& name) override;
 
  void setNormalisation(double normalisation_);
  double getNormalisation();

  bool setTreeLocation(TString treeLocation_);
  TString getTreeLocation();
  const TString& getTreeLocationRef();
  
  bool updateTreeLocation();

  TString getFilename();
  TString getTreename();
  TFile* getFile();

  TQSample * getBaseSample();

  bool addSubSample(TQSample * subSample);
  TQSample * addSelfAsSubSample(const TString& name);
  TQSample * getSubSample(const TString& path);
  bool isSubSample();
  bool hasSubSamples();

  TQToken * getTreeToken();
  TQToken * getFileToken();
  TQToken * getEventToken();
  bool returnTreeToken(TQToken * &token_);
  bool returnToken(TQToken * &token_);
  int getNTreeTokens();
  void printTreeTokens();

  bool checkTreeAccessibility();
  virtual int getOwnSize() const override;

  void setProxySample(TQSample* proxy) {fProxySample = proxy;}
  TQSample* getProxySample() {return fProxySample;}
    
  virtual ~TQSample();
 
  ClassDefOverride(TQSample, 3); // container class to hold a specific data or monte carlo sample

};

#endif
 TQSample.h:1
 TQSample.h:2
 TQSample.h:3
 TQSample.h:4
 TQSample.h:5
 TQSample.h:6
 TQSample.h:7
 TQSample.h:8
 TQSample.h:9
 TQSample.h:10
 TQSample.h:11
 TQSample.h:12
 TQSample.h:13
 TQSample.h:14
 TQSample.h:15
 TQSample.h:16
 TQSample.h:17
 TQSample.h:18
 TQSample.h:19
 TQSample.h:20
 TQSample.h:21
 TQSample.h:22
 TQSample.h:23
 TQSample.h:24
 TQSample.h:25
 TQSample.h:26
 TQSample.h:27
 TQSample.h:28
 TQSample.h:29
 TQSample.h:30
 TQSample.h:31
 TQSample.h:32
 TQSample.h:33
 TQSample.h:34
 TQSample.h:35
 TQSample.h:36
 TQSample.h:37
 TQSample.h:38
 TQSample.h:39
 TQSample.h:40
 TQSample.h:41
 TQSample.h:42
 TQSample.h:43
 TQSample.h:44
 TQSample.h:45
 TQSample.h:46
 TQSample.h:47
 TQSample.h:48
 TQSample.h:49
 TQSample.h:50
 TQSample.h:51
 TQSample.h:52
 TQSample.h:53
 TQSample.h:54
 TQSample.h:55
 TQSample.h:56
 TQSample.h:57
 TQSample.h:58
 TQSample.h:59
 TQSample.h:60
 TQSample.h:61
 TQSample.h:62
 TQSample.h:63
 TQSample.h:64
 TQSample.h:65
 TQSample.h:66
 TQSample.h:67
 TQSample.h:68
 TQSample.h:69
 TQSample.h:70
 TQSample.h:71
 TQSample.h:72
 TQSample.h:73
 TQSample.h:74
 TQSample.h:75
 TQSample.h:76
 TQSample.h:77
 TQSample.h:78
 TQSample.h:79
 TQSample.h:80
 TQSample.h:81
 TQSample.h:82
 TQSample.h:83
 TQSample.h:84
 TQSample.h:85
 TQSample.h:86
 TQSample.h:87
 TQSample.h:88
 TQSample.h:89
 TQSample.h:90
 TQSample.h:91
 TQSample.h:92
 TQSample.h:93
 TQSample.h:94
 TQSample.h:95
 TQSample.h:96
 TQSample.h:97
 TQSample.h:98
 TQSample.h:99
 TQSample.h:100
 TQSample.h:101
 TQSample.h:102
 TQSample.h:103
 TQSample.h:104