00001 
00002 
00004 #ifndef __Ntuple__
00005 #define __Ntuple__
00006 
00007 #include "CUtils.h"
00008 #include "TMath.h"
00009 using namespace std;
00010 
00011 #define NETMAX 10
00012 
00019 class Tuple {
00020 
00021  public:
00022 
00032   Tuple(vector <int> aStreamIndex);
00033 
00037   virtual ~Tuple(void);
00048   inline bool IsStreamInside(const int aStreamIndex){
00049     for(int s=0; s<(int)StreamIndex.size(); s++) if(aStreamIndex==StreamIndex[s]) return true;
00050     return false;
00051   };
00052 
00057   inline string GetName(void){ return tname; };
00058 
00068   inline bool IsTheSame(Tuple *aTestTuple){
00069     if((int)StreamIndex.size()!=aTestTuple->GetNstreams()) return false;
00070     if((int)Event[0].size()!=aTestTuple->GetNevents()) return false;
00071     
00072     for(int s=0; s<(int)StreamIndex.size(); s++)
00073       for(int e=0; e<(int)Event[0].size(); e++)
00074     if(Event[s][e]!=aTestTuple->GetEvent(s,e)) return false;
00075     return false;
00076   };
00077 
00083   inline bool AddTuple(vector <int> aEvent){
00084     for(int s=0; s<(int)StreamIndex.size(); s++) Event[s].push_back(aEvent[s]);
00085     return true;
00086   };
00087 
00091   inline bool ResetEvents(void){
00092     for(int s=0; s<(int)StreamIndex.size(); s++) Event[s].clear();
00093     return true;
00094   };
00095 
00100   inline bool RemoveEvent(const int aPosition){
00101     for(int s=0; s<(int)StreamIndex.size(); s++) Event[s].erase (Event[s].begin()+aPosition);
00102     return true;
00103   };
00104 
00108   inline int GetNstreams(void){ return (int)StreamIndex.size(); };
00109 
00113   inline int GetNevents(void){ return (int)Event[0].size(); };
00114 
00120   inline int GetEvent(const int aStreamNumber, const int aPosition){
00121     return Event[aStreamNumber][aPosition];
00122   };
00123 
00129   inline int GetEventFromStream(const int aStreamIndex, const int aPosition){
00130     return Event[IndexFromStream[aStreamIndex]][aPosition];
00131   };
00132   
00137   inline vector <int> GetEvents(const int aStreamNumber){
00138     return Event[aStreamNumber];
00139   };
00140 
00145   inline vector <int> GetEventsFromStream(const int aStreamIndex){ 
00146     return Event[IndexFromStream[aStreamIndex]]; 
00147   };
00148 
00152   inline void PrintEvents(void){
00153     for(int e=0; e<(int)Event[0].size(); e++){
00154       for(int s=0; s<(int)StreamIndex.size(); s++) cout<<Event[s][e]<<" ";
00155       cout<<endl;
00156     }
00157     return;
00158   };
00159 
00160  private:
00161 
00162   string tname;                   
00163   vector <int> StreamIndex;       
00164   vector <int> IndexFromStream;   
00165   vector <int> Event[NETMAX];     
00166 
00167 };
00168 
00169 
00175 class Ntuple {
00176 
00177  public:
00178 
00188   Ntuple(const int aNstreams);
00189 
00193   virtual ~Ntuple(void);
00204   bool IsStreamInside(const int aStreamNumber, const int aTupleIndex);
00205  
00216   bool AddPair(const int aStreamNumber0, const int aStreamNumber1, const int aEventIndex0, const int aEventIndex1);
00217 
00226   bool MakeNtuple(const int aNmax, const bool aUniq=false);
00227 
00235   vector <int> GetEvents(const int aTupleIndex, const int aStreamIndex);
00236 
00241   inline bool ResetEvents(void){
00242     for(int n=0; n<ntuples; n++) if(!tuple[n]->ResetEvents()) return false;
00243     return true;
00244   };
00245 
00249   inline int GetNtuples(void){ return (int)pow(2.0,(double)Nstreams); };
00250 
00256   inline int GetTupleType(const int aTupleIndex){ return GetType(aTupleIndex); };
00257 
00263   inline int GetNevents(const int aTupleIndex){
00264     if(aTupleIndex<0||aTupleIndex>=ntuples){
00265       cerr<<"Ntuple::GetNevents: the tuple number "<<aTupleIndex<<" does not exist"<<endl;
00266       return -1;
00267     }
00268 
00269     return tuple[aTupleIndex]->GetNevents();
00270   };
00271 
00275   void PrintEvents(void);
00276   
00277  private:
00278 
00279   int Nstreams;            
00280   
00281   
00282   int Ncomb[NETMAX+1];     
00283   int ntuples;             
00284   Tuple **tuple;           
00285 
00286   
00287   bool MakeUniq(const int aNmax);
00288 
00289   
00290   inline int GetType(const int aTupleIndex){
00291     if(aTupleIndex<0) return -1;
00292     if(aTupleIndex>=ntuples) return -1;
00293     int count = 0;
00294     int n=aTupleIndex;
00295     while(n){
00296       n &= (n-1) ;
00297       count++;
00298     }
00299     return count;
00300   };
00301   
00302   
00303   inline bool NextPerm(const int aN, int *aComb, int *aNcombmax, int *aCombMin){
00304     aComb[aN-1]++;
00305     for(int i=aN-1; i>=0; i--){
00306       if(aComb[i]>=aNcombmax[i]){
00307     if(i==0) return false;
00308     aComb[i]=aCombMin[i];
00309     aComb[i-1]++;
00310       }
00311       if(aComb[i]<aCombMin[i]) aComb[i]=aCombMin[i];
00312     }
00313     return true;
00314   };
00315   
00316   ClassDef(Ntuple,0)  
00317 };
00318 
00319 #endif
00320 
00321