#ifndef __HSelectedEvents__ #define __HSelectedEvents__ #include "hades.h" #include "htime.h" #include "hreconstructor.h" #include "hdatasource.h" #include "TString.h" #include #include //_HADES_CLASS_DESCRIPTION /////////////////////////////////////////////////////////////// // HSelectedEvents // // Helper class to read just selected events form hld files. // Needs a list of squence numbers from hld file as ascii input. // Format : hldfilename eventsequencenumber per line // ( example : be1210817112103 27 ) // All events not contained in the list will be skipped. // If no input file is set all events will be taken. // Add this task first in the task list. The task will analyze // the eventhader only, no complicated event reconstruction is // needed. // //------------------------------------------------------------- // CREATE a list of sequence numbers using HLoop: // { // HLoop loop(kTRUE); // // Bool_t ret = loop.addMultFiles(infileList); // if(ret == 0) { // cout<<"READBACK: ERROR : cannot find inputfiles : "<getEventSeqNumber()<getEventSeqNumber()<setInputFile("seqNumber.txt"); // comment this line for no selection // // HTaskSet *masterTaskSet = gHades->getTaskSet("all"); // masterTaskSet->add(selection); // put it first in tasklist to skip discarded events from the beginning // /////////////////////////////////////////////////////////////// using namespace std; class HSelectedEvents : public HReconstructor { protected: // put all vars here which are not // local to a function ifstream input; TString fname; TString bename; Int_t seqNum; public: HSelectedEvents(const Text_t *name = "",const Text_t *title ="") : HReconstructor(name,title) { // init your vars fname = ""; } virtual ~HSelectedEvents() { // clean up all dynamically created objects } Bool_t init() { // this function is called once in the beginning // create histograms or get pointer to param containers // or data containers here. Tip: Create first your // output file and and after that your histograms/ ntuples. // In this way you make shure the object will end up in your // root file and not any other one. if(fname.CompareTo("")!=0) input.open(fname); else { Warning("init()","Inputfile not set!"); return kTRUE; } if(input.good() ) input >> bename >> seqNum; return kTRUE; } Bool_t reinit() { // this function is called for each file // after init() // use this place if you need already initialized // containers return kTRUE; } Int_t execute() { // this function is called once per event. // if the function returns kSkipEvent the event // will be skipped a. for all following tasks // and b. not appear in output (hades eventLoop()) Bool_t print =kTRUE; if(input.good()){ Int_t num = gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(); TString currentfile; HDataSource* source = gHades->getDataSource(); if(source) { currentfile = source->getCurrentFileName(); currentfile = HTime::stripFileName(currentfile); } if(currentfile.CompareTo(bename.Data()) != 0){ if(print) cout<<"wind forward to find correct file name : current "<> bename >> seqNum; if(print)cout<<"file name : current "<= current "<> bename >> seqNum; return 0; } if(num > seqNum) { // wind forward seqnumber from file if(print)cout<<"file name : current "<> bename >> seqNum; if(print)cout<<"file name : current "<= current "<