TClonesArray of unspecified type

Hi,

I defined different classes for different particles:

class PhJPhoton : public JBaseTrack {..} class JPizero : public JBaseTrack {..} class PhJCgl : public JBaseTrack {..}
I want to copy the list good particle TClonesArray into a mixing pool:

[code]void JEventPool::FillNewList(TClonesArray *inList, PartycleType type){

//copy inList===============
for(int i=0;i<inList->GetEntries();i++){
    switch (type) {
          case photon:
            PhJPhoton *EpPhoton = (PhJPhoton*)inList->At(i);
            new ((*List[cBin][lastAccepted[cBin]])[i]) PhJPhoton(*EpPhoton);
            break;
        case pizero:
            JPizero *EpPizero = (Jpizero*)inList->At(i);
            new ((*List[cBin][lastAccepted[cBin]])[i]) JPizero(*EpPizero);
            break;
        case hadron:
            PhCgl *EpHadron = (PhJCgl*)inList->At(i);
            new ((*List[cBin][lastAccepted[cBin]])[i]) PhJCgl(*EpHadron);
            break;
        default:
            cout<<"Unknown particle type in JEventPool::FillNewList"<<endl;
            exit(0);
    }   

[/code]
Is there any other way to do that without SWITCH? Something like template or typedef?
I tried to create TClonesArray of JBaseTrack but it stores only the virtual function defined
in JBaseTrack and not real one from derived classes.

Any idea here?

Thanks
Jan

By construction a TClonesArray (like vector) can only handle one type.
You should use a TObjArray instead

Rene

Dear Rene,

I apologize, I was not clear enough. I know that TClonesArray can handle only one type. I have different TClonesArray’s for different types (particles). When I do mixing
I don’t know which particle and TClonesArray will be later passed as an argument. That’s why I did this switch:

switch (type) { case photon: PhJPhoton *EpPhoton = (PhJPhoton*)inList->At(i); new ((*List[cBin][lastAccepted[cBin]])[i]) PhJPhoton(*EpPhoton); break; case pizero: JPizero *EpPizero = (Jpizero*)inList->At(i); new ((*List[cBin][lastAccepted[cBin]])[i]) JPizero(*EpPizero); break;

I was just asking if there is some more elegant way - eg. using some typeid() operator. If I tried to work with JBaseTrack classes they were not stored properly.

Thanks
Jan

Jan,

Sorry I missed your point. Do:

if (inList->At(i)->IsA()==PhJPhoton::Class()) new ((*List[cBin][lastAccepted[cBin]])[i]) PhJPhoton(*EpPhoton); else if(inList->At(i)->IsA()==EpPizero::Class()) new ((*List[cBin][lastAccepted[cBin]])[i]) JPizero(*EpPizero); endif

Rene

Hi,

You can also use the result of inlist->GetClass :

if (inlist->GetClass()==PhJPhoton::Class()) { for(int i=0;i<inList->GetEntries();i++){ PhJPhoton *EpPhoton = (PhJPhoton*)inList->At(i); new ((*List[cBin][lastAccepted[cBin]])[i]) PhJPhoton(*EpPhoton); } } else if (inlist->GetClass()==EpPizero::Class()) { for(int i=0;i<inList->GetEntries();i++){ JPizero *EpPizero = (Jpizero*)inList->At(i); new ((*List[cBin][lastAccepted[cBin]])[i]) JPizero(*EpPizero);\ } } else if .....

Cheers,
Philippe