void KVNameValueList::SetValue(const KVNamedParameter& p)
{
   // add (or replace) a parameter with the same name, type & value as 'p'

   KVNamedParameter* par = FindParameter(p.GetName());
   par ? par->Set(p.GetName(), p) : fList.Add(new KVNamedParameter(p));

}
Exemple #2
0
void KVGeoImport::ImportGeometry(Double_t dTheta, Double_t dPhi,
                                  Double_t ThetaMin, Double_t PhiMin, Double_t ThetaMax, Double_t PhiMax)
{
    // Scan the geometry in order to find all detectors and detector alignments.
    // This is done by sending out "particles" from (0,0,0) in all directions between
    // (ThetaMin,ThetaMax) - with respect to Z-axis - and (PhiMin,PhiMax) - cylindrical
    // angle in the (X,Y)-plane, over a grid of step dTheta in Theta and dPhi in Phi.

    KVEvent* evt = new KVEvent();
    KVNucleus* nuc = evt->AddParticle();
    nuc->SetZAandE(1,1,1);
    Double_t theta,phi;
    Int_t count=0;

    // note that ImportGeometry can be called for a KVMultiDetArray
    // which already contains detectors, groups and id telescopes
    fGroupNumber=fArray->GetStructureTypeList("GROUP")->GetEntries();
    Int_t ndets0 = fArray->GetDetectors()->GetEntries();
    Int_t idtels0 = fArray->GetListOfIDTelescopes()->GetEntries();

    for(theta=ThetaMin; theta<=ThetaMax; theta+=dTheta){
        for(phi=PhiMin; phi<=PhiMax; phi+=dPhi){
                nuc->SetTheta(theta);
                nuc->SetPhi(phi);
                fCurrentGroup = 0;
                fLastDetector = 0;
                PropagateEvent(evt);
                count++;
        }
    }

    // make sure detector nodes are correct
    TIter next(fArray->GetDetectors());
    KVDetector*d;
    while( (d=(KVDetector*)next()) ) d->GetNode()->RehashLists();
    // set up all detector node trajectories
    //fArray->CalculateGeoNodeTrajectories();

    if(fCreateArray){
        fArray->SetGeometry(GetGeometry());
        KVGeoNavigator* nav = fArray->GetNavigator();
        nav->SetDetectorNameFormat(fDetNameFmt);
        for(register int i=0; i<fStrucNameFmt.GetEntries(); i++){
            KVNamedParameter* fmt = fStrucNameFmt.GetParameter(i);
            nav->SetStructureNameFormat(fmt->GetName(), fmt->GetString());
        }
        nav->SetNameCorrespondanceList(fDetStrucNameCorrespList);
        fArray->CalculateDetectorSegmentationIndex();
    }
    Info("ImportGeometry",
         "Tested %d directions - Theta=[%f,%f:%f] Phi=[%f,%f:%f]",count,ThetaMin,ThetaMax,dTheta,PhiMin,PhiMax,dPhi);
    Info("ImportGeometry",
         "Imported %d detectors into array", fArray->GetDetectors()->GetEntries()-ndets0);
    if(fCreateArray){
        fArray->CreateIDTelescopesInGroups();
        Info("ImportGeometry",
             "Created %d identification telescopes in array", fArray->GetListOfIDTelescopes()->GetEntries()-idtels0);
    }
}
void KVNameValueList::AddValue(const KVNamedParameter& p)
{
   // if a parameter with the same name & type as 'p' exists,
   // add numerical value of p to value of parameter in list,
   // or for strings we add to a comma-separated list of strings.
   // otherwise, add a copy of p to list

   KVNamedParameter* par = FindParameter(p.GetName());
   par ? par->Add(p) : fList.Add(new KVNamedParameter(p));
}
Exemple #4
0
void KVClassFactory::AddGetSetMethods(const KVNameValueList& nvl)
{
   // For each named parameter in the list, we add protected member variables and
   // public Get/Set methods with the name and type of the parameter.
   // Example: given a list containing NAME="some string" NUMBER=3 [integer]
   // PI=3.141592 [double], we generate the methods
   //   void SetNAME(const TString&);
   //   const TString& GetNAME() const;
   //   void SetNUMBER(Int_t);
   //   Int_t GetNUMBER() const;
   //   void SetPI(Double_t);
   //   Double_t GetPI() const;

   int npars = nvl.GetNpar();
   for(int i=0; i<npars; i++){
      KVNamedParameter* par = nvl.GetParameter(i);
      if(par->IsString()){
         KVClassMember* v = AddMember(par->GetName(),"TString","member automatically generated by KVClassFactory::AddGetSetMethods");
         KVClassMethod* m = AddMethod(Form("Set%s",par->GetName()), "void");
         m->AddArgument("const TString&");
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    %s=arg1;", v->GetName())
         );
         m = AddMethod(Form("Get%s",par->GetName()), "const TString&", "public", kFALSE, kTRUE);
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    return %s;", v->GetName())
                  );
         // make sure #include "TString.h" appears in header file
         if( ! fHeadInc.FindObject("TString.h") ) AddHeaderIncludeFile("TString.h");
      }
      else if(par->IsInt()){
         KVClassMember* v = AddMember(par->GetName(),"Int_t","member automatically generated by KVClassFactory::AddGetSetMethods");
         KVClassMethod* m = AddMethod(Form("Set%s",par->GetName()), "void");
         m->AddArgument("Int_t");
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    %s=arg1;", v->GetName())
         );
         m = AddMethod(Form("Get%s",par->GetName()), "Int_t", "public", kFALSE, kTRUE);
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    return %s;", v->GetName())
                  );
      }
      else if(par->IsDouble()){
         KVClassMember* v = AddMember(par->GetName(),"Double_t","member automatically generated by KVClassFactory::AddGetSetMethods");
         KVClassMethod* m = AddMethod(Form("Set%s",par->GetName()), "void");
         m->AddArgument("Double_t");
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    %s=arg1;", v->GetName())
         );
         m = AddMethod(Form("Get%s",par->GetName()), "Double_t", "public", kFALSE, kTRUE);
         m->SetMethodBody(
Form("    // Method automatically generated by KVClassFactory::AddGetSetMethods\n"
"\n"
"    return %s;", v->GetName())
                  );
      }
   }
}