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:
//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.
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.
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