ROOT logo
//*-- Author : Jochen Markert 18.07.2007

#ifndef  __HLOOP_H__
#define  __HLOOP_H__

#include "TFile.h"
#include "TTree.h"
#include "TChain.h"
#include "TArrayI.h"
#include "TSystem.h"
#include "TString.h"
#include "TObject.h"

#include "htree.h"
#include "heventheader.h"
#include "hrecevent.h"
#include "hpartialevent.h"
#include "hgeantheader.h"
#include "hgeantmedia.h"
#include "hcategory.h"

#include <map>
#include <fstream>
#include <iomanip>
using namespace std;




class HSectorSelector : public TObject {

private:
    map<TString,TArrayI> goodSectors;

    Int_t defaultVal;
public:
    HSectorSelector(Bool_t val=kFALSE) {
        defaultVal=val;
    };
    ~HSectorSelector() { goodSectors.clear();};

    void setDefaultVal(Bool_t val) { defaultVal = val;}


    Bool_t readInput(TString infile="",Bool_t print=kFALSE)
    {
	// format: file  1 1 1 1 1 1  (2char+11digit ,hld name without eventbuilder +  6 digits (0 or 1) per line)
        goodSectors.clear();

	if(gSystem->AccessPathName(infile.Data())==1){
	    Error("readInput()","Inputfile %s could not be read!",infile.Data());
            return kFALSE;
	}

	TArrayI sectors(6);
	sectors.Reset(0);

        TString file;
        Char_t line[4000];
        Char_t fname[4000];

	ifstream input;
	input.open(infile.Data());
	while (!input.eof()&&input.good()) {
	    input.getline(line,4000);
            file=line;
	    if(file.BeginsWith('#')) { continue; } // skip comment line
            Int_t n = sscanf(line,"%s %d %d %d %d %d %d",fname,&sectors[0],&sectors[1],&sectors[2],&sectors[3],&sectors[4],&sectors[5]);
            file=fname;
	    if (input.good() && n == 7) {
		if(print)cout<<file<<":  "<<sectors[0]<<" "<<sectors[1]<<" "<<sectors[2]<<" "<<sectors[3]<<" "<<sectors[4]<<" "<<sectors[5]<<endl;
		goodSectors[file] = sectors;
	    }
	}
	input.close();

        return kTRUE;
    }

    Int_t  getNFiles() {return goodSectors.size();}
    Bool_t getSectors(Int_t* sectors,TString filename)
    {
	map<TString,TArrayI>::iterator iter = goodSectors.find(filename);
	if (iter == goodSectors.end()) {
	    // file not in list
	    for(Int_t s=0;s<6;s++){
		sectors[s] = defaultVal;
	    }
	    return kFALSE;

	} else {
	    for(Int_t s=0;s<6;s++){
		sectors[s]=iter->second.At(s);
	    }
	}
	return kTRUE;
    }

    void printFile(TString filename) {
	map<TString,TArrayI>::iterator iter = goodSectors.find(filename);
	if (iter == goodSectors.end()) {
	    // file not in list
	    ::Error("printFile()","File %s not found in map!",filename.Data());
	} else {
	    cout<<setw(30)<<filename
		<<" "<<iter->second.At(0)
		<<" "<<iter->second.At(1)
		<<" "<<iter->second.At(2)
		<<" "<<iter->second.At(3)
		<<" "<<iter->second.At(4)
		<<" "<<iter->second.At(5)
		<<endl;
	}
    }

    void print(){
        Int_t ct=0;
	for(map< TString, TArrayI>::iterator iter = goodSectors.begin(); iter != goodSectors.end(); ++iter ) {
	    ct++;
	    cout<<setw(5)<<ct
		<<" "<<setw(30)<<iter->first
		<<" "<<iter->second.At(0)
		<<" "<<iter->second.At(1)
		<<" "<<iter->second.At(2)
		<<" "<<iter->second.At(3)
		<<" "<<iter->second.At(4)
		<<" "<<iter->second.At(5)
		<<endl;
	}
    }
    ClassDef(HSectorSelector,0) // simple file to valide sector map
};

class HLoop;

R__EXTERN HLoop *gLoop;

class HLoop : public TObject {

private:

    TChain*                        fChain; // chain
    HEventHeader*                   fHead; // pointer to HADES event header
    HGeantMedia*              fGeantMedia; // pointer to HGEANT MEDIA (NULL if not avvailable!)
    map <TString,HCategory*>       fEvent; // map category name -> HCategory pointer
    map <TString,HPartialEvent*> fPartial; // map partial event name -> HPartialEvent pointer
    map <TString,Int_t>           fStatus; // map category name -> status
    map <TString,TString>       fPartialN; // map category name -> partial event name
    map <TString,Short_t>      fNameToCat; // map category name -> category number
    Long64_t                  fMaxEntries; // total number of entries in the chain
    Long64_t                fCurrentEntry; // current entry in chain
    TString                  fCurrentName; // current file name
    TFile*                   fFileCurrent; // current file pointer
    TTree*                          fTree; // current Tree of the chain
    HRecEvent*                  fRecEvent; // HADES event under reconstruction

    HSectorSelector       fSectorSelector; // selection of sectors from filelist
    Int_t                     fsectors[6]; // array of sector status form filelist


    Int_t                          fRefID; // reference ID for init of params
    Bool_t                    fFirstEvent; // true if first event called
    Bool_t               fHasCreatedHades; // remember if this class has created HADES
    Bool_t                     fIsNewFile; // == kTRUE for first entry after a new file is opened
    Bool_t                     fIsSkipped; // == kTRUE event was skipped by tasklist
    Bool_t                    fUseTaskSet; // == kTRUE if hades tasksets should be executed
    Long64_t               fTreeCacheSize; //
    Long64_t        fTreeCacheDefaultSize; // default 8MB
    Bool_t                    fIsCacheSet; // kTRUE if user has set the the cache.
    Bool_t        setStatus(TString catname, Int_t stat );
    Bool_t        addCatName(TString catname,Short_t catNum);

public:

    HLoop(Bool_t createHades=kFALSE);

    ~HLoop();
    void           setCurrentLoop() { gLoop=this;}

    Bool_t         addFile     (TString infile);
    Bool_t         addFiles    (TString expression);
    Bool_t         addFilesList(TString filelist);
    Bool_t         addMultFiles(TString commaSeparatedList);

    Bool_t           readSectorFileList(TString filename,Bool_t defaultVal=kFALSE,Bool_t print=kFALSE)  { fSectorSelector.setDefaultVal(defaultVal); return fSectorSelector.readInput(filename,print); }
    HSectorSelector& getSectorSelector()                                       { return fSectorSelector;}
    void             getSectors(Int_t* sectors)                                { for(Int_t s=0;s<6;s++) sectors[s]=fsectors[s];}
    Bool_t           goodSector(Int_t sector)                                  { return ( (sector < 6 && sector >=0 ) ? (fsectors[sector]==1) : kFALSE );}
    HEventHeader*  getEventHeader()            { return fHead; }
    HGeantMedia*   getGeantMedia ()            { return fGeantMedia; }
    TChain*        getChain      ()            { return fChain; }
    TTree*         getTree       ()            { return fTree; }
    Long64_t       getEntries    ()            { return fMaxEntries; }
    HCategory*     getCategory      (TString catname,Bool_t silent = kFALSE);
    Bool_t         getCategoryStatus(TString catname,Bool_t silent = kFALSE);
    HPartialEvent* getPartialEvent  (TString catname,Bool_t silent = kFALSE);
    HGeantHeader*  getGeantHeader   (Bool_t silent=kFALSE);
    TObject*       getFromInputFile(TString name="");
    Bool_t         isSkippedEvent()            { return fIsSkipped; }
    Bool_t         isNewFile(TString& name);
    Bool_t         setInput(TString readCategories = "");
    void           clearCategories();
    Int_t          nextEvent(Int_t iev);
    void           setRefID(Int_t id)          { fRefID = id;}
    void           setTreeCacheSize(Long64_t cs = 8000000);
    void           printCategories();
    void           printChain();
    void           printBranchStatus();

    ClassDef(HLoop,0) // simple class to fastly loop dst's
};

#endif /* !__HLOOP_H__ */







 hloop.h:1
 hloop.h:2
 hloop.h:3
 hloop.h:4
 hloop.h:5
 hloop.h:6
 hloop.h:7
 hloop.h:8
 hloop.h:9
 hloop.h:10
 hloop.h:11
 hloop.h:12
 hloop.h:13
 hloop.h:14
 hloop.h:15
 hloop.h:16
 hloop.h:17
 hloop.h:18
 hloop.h:19
 hloop.h:20
 hloop.h:21
 hloop.h:22
 hloop.h:23
 hloop.h:24
 hloop.h:25
 hloop.h:26
 hloop.h:27
 hloop.h:28
 hloop.h:29
 hloop.h:30
 hloop.h:31
 hloop.h:32
 hloop.h:33
 hloop.h:34
 hloop.h:35
 hloop.h:36
 hloop.h:37
 hloop.h:38
 hloop.h:39
 hloop.h:40
 hloop.h:41
 hloop.h:42
 hloop.h:43
 hloop.h:44
 hloop.h:45
 hloop.h:46
 hloop.h:47
 hloop.h:48
 hloop.h:49
 hloop.h:50
 hloop.h:51
 hloop.h:52
 hloop.h:53
 hloop.h:54
 hloop.h:55
 hloop.h:56
 hloop.h:57
 hloop.h:58
 hloop.h:59
 hloop.h:60
 hloop.h:61
 hloop.h:62
 hloop.h:63
 hloop.h:64
 hloop.h:65
 hloop.h:66
 hloop.h:67
 hloop.h:68
 hloop.h:69
 hloop.h:70
 hloop.h:71
 hloop.h:72
 hloop.h:73
 hloop.h:74
 hloop.h:75
 hloop.h:76
 hloop.h:77
 hloop.h:78
 hloop.h:79
 hloop.h:80
 hloop.h:81
 hloop.h:82
 hloop.h:83
 hloop.h:84
 hloop.h:85
 hloop.h:86
 hloop.h:87
 hloop.h:88
 hloop.h:89
 hloop.h:90
 hloop.h:91
 hloop.h:92
 hloop.h:93
 hloop.h:94
 hloop.h:95
 hloop.h:96
 hloop.h:97
 hloop.h:98
 hloop.h:99
 hloop.h:100
 hloop.h:101
 hloop.h:102
 hloop.h:103
 hloop.h:104
 hloop.h:105
 hloop.h:106
 hloop.h:107
 hloop.h:108
 hloop.h:109
 hloop.h:110
 hloop.h:111
 hloop.h:112
 hloop.h:113
 hloop.h:114
 hloop.h:115
 hloop.h:116
 hloop.h:117
 hloop.h:118
 hloop.h:119
 hloop.h:120
 hloop.h:121
 hloop.h:122
 hloop.h:123
 hloop.h:124
 hloop.h:125
 hloop.h:126
 hloop.h:127
 hloop.h:128
 hloop.h:129
 hloop.h:130
 hloop.h:131
 hloop.h:132
 hloop.h:133
 hloop.h:134
 hloop.h:135
 hloop.h:136
 hloop.h:137
 hloop.h:138
 hloop.h:139
 hloop.h:140
 hloop.h:141
 hloop.h:142
 hloop.h:143
 hloop.h:144
 hloop.h:145
 hloop.h:146
 hloop.h:147
 hloop.h:148
 hloop.h:149
 hloop.h:150
 hloop.h:151
 hloop.h:152
 hloop.h:153
 hloop.h:154
 hloop.h:155
 hloop.h:156
 hloop.h:157
 hloop.h:158
 hloop.h:159
 hloop.h:160
 hloop.h:161
 hloop.h:162
 hloop.h:163
 hloop.h:164
 hloop.h:165
 hloop.h:166
 hloop.h:167
 hloop.h:168
 hloop.h:169
 hloop.h:170
 hloop.h:171
 hloop.h:172
 hloop.h:173
 hloop.h:174
 hloop.h:175
 hloop.h:176
 hloop.h:177
 hloop.h:178
 hloop.h:179
 hloop.h:180
 hloop.h:181
 hloop.h:182
 hloop.h:183
 hloop.h:184
 hloop.h:185
 hloop.h:186
 hloop.h:187
 hloop.h:188
 hloop.h:189
 hloop.h:190
 hloop.h:191
 hloop.h:192
 hloop.h:193
 hloop.h:194
 hloop.h:195
 hloop.h:196
 hloop.h:197
 hloop.h:198
 hloop.h:199
 hloop.h:200
 hloop.h:201
 hloop.h:202
 hloop.h:203
 hloop.h:204
 hloop.h:205
 hloop.h:206
 hloop.h:207
 hloop.h:208
 hloop.h:209
 hloop.h:210
 hloop.h:211
 hloop.h:212
 hloop.h:213
 hloop.h:214
 hloop.h:215
 hloop.h:216
 hloop.h:217
 hloop.h:218
 hloop.h:219
 hloop.h:220