TGeoMaterial* KVIonRangeTableMaterial::GetTGeoMaterial() const
{
   // Create and return pointer to a TGeoMaterial or TGeoMixture (for compound materials)
   // with the properties of this material.
   // gGeoManager must exist.

   TGeoMaterial* gmat = 0x0;
   if (!gGeoManager) return gmat;
   if (IsCompound()) {
      gmat = new TGeoMixture(GetTitle(), GetComposition()->GetEntries(), GetDensity());
      TIter next(GetComposition());
      KVNameValueList* nvl;
      while ((nvl = (KVNameValueList*)next())) {
         KVNucleus n(nvl->GetIntValue("Z"), nvl->GetIntValue("A"));
         TGeoElement* gel = gGeoManager->GetElementTable()->FindElement(n.GetSymbol("EL"));
         float poids = nvl->GetDoubleValue("NormWeight");
         ((TGeoMixture*)gmat)->AddElement(gel, poids);
      }
   }
   else {
      gmat = new TGeoMaterial(GetTitle(), GetMass(), GetZ(), GetDensity());
   }
   // set state of material
   if (IsGas()) gmat->SetState(TGeoMaterial::kMatStateGas);
   else gmat->SetState(TGeoMaterial::kMatStateSolid);
   return gmat;
}
Esempio n. 2
0
Int_t KVAvailableRunsFile::Count(Int_t run)
{
   //Count the number of times a given run number appears in the file
   //If available runs file does not exist, Update() is called to create it.

//    //does runlist exist ?
//    if (!OpenAvailableRunsFile()) {
//       Error("Count", "Error opening available runs file");
//       return 0;
//    }
//    //loop over lines in runlist file
//    //look for line beginning with 'run|'
//    TString line;
//    Int_t occurs = 0;
//    line.ReadLine(fRunlist);
//    while (fRunlist.good()) {
//       if (line.BeginsWith(Form("%d|", run))) {
//          occurs++;
//       }
//       line.ReadLine(fRunlist);
//    }
//    CloseAvailableRunsFile();
//    return occurs;
   ReadFile();
   KVNameValueList* nvlrun = (KVNameValueList*)fAvailableRuns->FindObject(Form("%d",run));
   if(nvlrun) return nvlrun->GetIntValue("Occurs");
   return 0;
}
Esempio n. 3
0
void KV_CCIN2P3_GE::GetBatchSystemParameterList(KVNameValueList& nl)
{
   // Fill the list with all relevant parameters for batch system,
   // set to their default values.
   //
   // Parameters defined here are:
   //   JobTime        [string]
   //   JobMemory      [string]
   //   JobDisk        [string]
   //   MultiJobsMode  [bool]
   //   RunsPerJob     [int]
   //   EMailOnStart   [bool]
   //   EMailOnEnd     [bool]
   //   EMailAddress   [string]

   KVBatchSystem::GetBatchSystemParameterList(nl);
   nl.SetValue("JobTime", fDefJobTime);
   nl.SetValue("JobMemory", fDefJobMem);
   nl.SetValue("JobDisk", fDefJobDisk);
   nl.SetValue("MultiJobsMode", MultiJobsMode());
   nl.SetValue("RunsPerJob", fRunsPerJob);
   nl.SetValue("EMailOnStart", kFALSE);
   nl.SetValue("EMailOnEnd", kFALSE);
   TString email = gSystem->GetFromPipe("email");
   if (email.Index('=') > -1) {
      email.Remove(0, email.Index('=') + 2);
      nl.SetValue("EMailAddress", email);
   }
   else
      nl.SetValue("EMailAddress", "");
}
Esempio n. 4
0
void KVNameValueList::Merge(const KVNameValueList& other)
{
   // Merge other list into this one.
   // Any parameters in 'other' which do not exist in this one are added.
   // Any parameters which exist in both have their values summed.

   for (int i = 0; i < other.GetNpar(); ++i) {
      KVNamedParameter* np_other = other.GetParameter(i);
      AddValue(*np_other);
   }
}
Esempio n. 5
0
KVNumberList KVAvailableRunsFile::CheckMultiRunfiles()
{
   //Returns a list with all runs which occur more than once in the available runs file.

//    //does runlist exist ?
//    if (!OpenAvailableRunsFile()) {
//       Error("CheckMultiRunfiles", "Cannot open available runs file");
//       return 0;
//    }
// 
//    TString fLine;
//    TList *run_list = new TList;
//    fLine.ReadLine(fRunlist);
// 
//    KVNumberList multiruns;
// 
//    Int_t fRunNumber;
//    KVDBTable *runs_table = fDataSet->GetDataBase()->GetTable("Runs");
// 
//    while (fRunlist.good()) {
// 
//       TObjArray *toks = fLine.Tokenize('|');    // split into fields
//       KVString kvs(((TObjString *) toks->At(0))->GetString());
//       fRunNumber = kvs.Atoi();
//       delete toks;
// 
//       KVDBRun *a_run = (KVDBRun *) runs_table->GetRecord(fRunNumber);
// 
//       if (!run_list->Contains(a_run)) {
//          //first time that run appears
//          run_list->Add(a_run);
//       } else {
//          //run appears >1 times
//          multiruns.Add(fRunNumber);
//       }
// 
//       fLine.ReadLine(fRunlist);
//    }
//    delete run_list;
//    CloseAvailableRunsFile();
// 
//    return multiruns;
   ReadFile();
   KVNumberList multiruns;
   TIter next(fAvailableRuns);
   KVNameValueList* run;
   while( (run = (KVNameValueList*)next()) ){
      
      if(run->GetIntValue("Occurs")>1) multiruns.Add(run->GetName());
      
   }
   return multiruns;
}
Esempio n. 6
0
KVNameValueList KVNameValueList::operator += (const KVNameValueList& nvl)
{
   TIter it(nvl.GetList());
   KVNamedParameter* par = 0;
   while ((par = (KVNamedParameter*)it())) SetValue(*par);
   return *this;
}
Esempio n. 7
0
void KVExpSetUp::GetArrayMultiplicities(KVReconstructedEvent* e, KVNameValueList& m, Option_t* opt)
{
   // Calculate multiplicities of particles in each array of the setup.
   // They will appear in the KVNameValueList as parameters with the name of the array.
   // e.g.
   //
   //    "INDRA" = 21
   //    "FAZIA" = 3
   //
   // Any option given will be used to determine the type of event iterator used -
   // see KVEvent::GetNextParticleIterator(Option_t*).

   m.Clear();
   for (KVEvent::Iterator it = e->GetNextParticleIterator(opt); it != e->end(); ++it) {
      m.IncrementValue((*it).GetParameters()->GetStringValue("ARRAY"), 1);
   }
}
Esempio n. 8
0
//______________________________________________
Int_t KVNameValueList::Compare(const TObject* obj) const
{
   // Compare the contents of two KVNameValueList
   // Returns the number of same parameters (name and value)

   KVNameValueList* nvl = (KVNameValueList*)obj;
   Int_t neq = 0;
   Int_t np1 = GetNpar();
   Int_t np2 = nvl->GetNpar();
   for (Int_t ii = 0; ii < np1; ii += 1) {
      for (Int_t jj = 0; jj < np2; jj += 1) {

         if (*(GetParameter(ii)) == *(GetParameter(jj)))  neq += 1;
      }
   }
   return neq;

}
Esempio n. 9
0
KVNameValueList* KVAvailableRunsFile::RunHasFileWithDateAndName(Int_t run, const Char_t* filename, TDatime modtime, Int_t& OccNum)
{
   // look in previously read infos (see ReadFile) to see if, for a given run, there is a file with the
   // given name and modification date/time
   // if so, returns the address of the KVNameValueList for the run & sets OccNum to the index number of
   // the corresponding entry (in case of several files for the run)
   // if not, returns NULL
   
   if(!fAvailableRuns) return NULL;
   // is run already in list ?
   KVNameValueList* NVL = (KVNameValueList*)fAvailableRuns->FindObject(Form("%d",run));
   if(!NVL) return NULL;
   Int_t Occurs = NVL->GetIntValue("Occurs");
   for(OccNum=0; OccNum<Occurs; OccNum++){
      if( NVL->IsValue( Form("Filename[%d]",OccNum) , filename ) && NVL->IsValue( Form("Date[%d]",OccNum) , modtime.AsSQLString() ) ) return NVL;
   }
   return NULL;
}
void KVIonRangeTableMaterial::PrintComposition(ostream& output) const
{
   // Print to stream the composition of this material, in a format compatible with the VEDALOSS parameter file.
   if (IsCompound()) output << "COMPOUND";
   else if (IsMixture()) output << "MIXTURE";
   else output << "ELEMENT";
   output << endl;
   if (IsCompound() || IsMixture()) {
      output << fComposition->GetEntries() << endl;
      TIter next(fComposition);
      KVNameValueList* nvl;
      while ((nvl = (KVNameValueList*)next())) {
         KVNucleus n(nvl->GetIntValue("Z"), nvl->GetIntValue("A"));
         output << n.GetZ() << " " << n.GetA() << " " << nvl->GetIntValue("Natoms");
         if (IsMixture()) output << " " << nvl->GetDoubleValue("Proportion");
         output << endl;
      }
   }
}
Esempio n. 11
0
Bool_t KVAvailableRunsFile::InfosNeedUpdate(Int_t run, const Char_t * filename)
{
   // return kTRUE if the given file for this run is lacking some information
   // e.g. the KV version and username
   // N.B.: if no file is known for this run, we return kFALSE
   
   ReadFile();
   // is run already in list ?
   KVNameValueList* NVL = (KVNameValueList*)fAvailableRuns->FindObject(Form("%d",run));
   if(!NVL) return kFALSE;
   Int_t Occurs = NVL->GetIntValue("Occurs");
   for(Int_t OccNum=0; OccNum<Occurs; OccNum++){
      if( NVL->IsValue( Form("Filename[%d]",OccNum) , filename ) ){
         // infos need update if no KV version has been set
         return ( !NVL->HasParameter(Form("KVVersion[%d]",OccNum)) );
      }
   }
   return kFALSE;   
}
Esempio n. 12
0
void KV_CCIN2P3_GE::SetBatchSystemParameters(const KVNameValueList& nl)
{
   // Use the parameters in the list to set all relevant parameters for batch system.

   KVBatchSystem::SetBatchSystemParameters(nl);
   SetJobTime(nl.GetStringValue("JobTime"));
   SetJobMemory(nl.GetStringValue("JobMemory"));
   SetJobDisk(nl.GetStringValue("JobDisk"));
   SetMultiJobsMode(nl.GetBoolValue("MultiJobsMode"));
   SetRunsPerJob(nl.GetIntValue("RunsPerJob"));
   if (nl.GetTStringValue("EMailAddress") != "") {
      if (nl.GetBoolValue("EMailOnStart")) SetSendMailOnJobStart();
      if (nl.GetBoolValue("EMailOnEnd")) SetSendMailOnJobEnd();
      SetSendMailAddress(nl.GetStringValue("EMailAddress"));
   }
}
Esempio n. 13
0
Int_t KVRunListCreator::ScanDirectory()
{
   // Return number of runs found

   KVSystemDirectory sysdir("rundir", GetRunDir());
   TIter it(sysdir.GetListOfFiles());
   KVSystemFile* sysfile;
   int howmany = 0;
   while ((sysfile = (KVSystemFile*)it())) {
      int run_num;
      if ((run_num = KVAvailableRunsFile::IsRunFileName(GetFileFormat(), sysfile->GetName()))) {
         KVDatime when;
         if (KVAvailableRunsFile::ExtractDateFromFileName(GetFileFormat(), sysfile->GetName(), when)) {
            ++howmany;
            KVNameValueList* infos = new KVNameValueList;
            infos->SetName(Form("run%06d", run_num));
            infos->SetValue("Run", run_num);
            infos->SetValue("Start", when.AsSQLString());
            infos->SetValue("End", sysfile->GetDate());
            Int_t x = sysfile->GetSize();
            if (x == sysfile->GetSize())
               infos->SetValue("Size", x);
            else
               infos->SetValue64bit("Size", sysfile->GetSize());
            if (fDataType != "") {
               fReader.reset(KVRawDataReader::OpenFile(fDataType, Form("%s/%s", sysdir.GetTitle(), sysfile->GetName())));
               ULong64_t events = 0;
               while (fReader->GetNextEvent()) ++events;
               Int_t x = events;
               if (x == events)
                  infos->SetValue("Events", x);
               else
                  infos->SetValue64bit("Events", events);
            }
            infos->ls();
            fRunInfos.Add(infos);
         }
      }
   }
   return howmany;
}
Esempio n. 14
0
void KVRangeYanezMaterial::Initialize()
{
   KVIonRangeTableMaterial::Initialize();
   if(IsCompound()){
      fNelem=0;
      iabso=-1;
      TIter next(fComposition);
      KVNameValueList* nvl;
      while( (nvl = (KVNameValueList*)next()) ){
         fAbsorb[fNelem].z = nvl->GetIntValue("Z");
         fAbsorb[fNelem].a = nvl->GetIntValue("A");
         fAbsorb[fNelem].w = nvl->GetDoubleValue("Ar*Weight");
         fNelem++;
      }
   }
   else if(IsMixture()){
      fNelem=0;
      iabso=-1;
      TIter next(fComposition);
      KVNameValueList* nvl;
      while( (nvl = (KVNameValueList*)next()) ){
         fAbsorb[fNelem].z = nvl->GetIntValue("Z");
         fAbsorb[fNelem].a = nvl->GetIntValue("A");
         fAbsorb[fNelem].w = nvl->GetDoubleValue("Ar*Weight");
         fNelem++;
      }
   }
}
void KVIonRangeTableMaterial::Print(Option_t*) const
{
   printf("Material : %s (%s)   State : %s\n",
          GetName(), GetSymbol(), fState.Data());
   printf("\tEffective Z=%f, A=%f  ", fZmat, fAmat);
   if (IsGas()) printf(" Molar Weight = %f g.", fMoleWt);
   else printf(" Density = %f g/cm**3", fDens);
   printf("\n");
   if (IsCompound()) printf("\tCompound material:\n");
   else if (IsMixture())  printf("\tMixed material:\n");
   if (IsCompound() || IsMixture()) {
      TIter next(fComposition);
      KVNameValueList* nvl;
      while ((nvl = (KVNameValueList*)next())) {
         KVNucleus n(nvl->GetIntValue("Z"), nvl->GetIntValue("A"));
         printf("\t\tElement: %s   Ar=%f g.   Natoms=%d", n.GetSymbol(), n.GetAtomicMass(), nvl->GetIntValue("Natoms"));
         if (IsMixture()) printf("   Proportion=%f", nvl->GetDoubleValue("Proportion"));
         printf("\n");
      }
   }
   printf("\n\n");
}
void KVIonRangeTableMaterial::AddCompoundElement(Int_t Z, Int_t A, Int_t Natoms)
{
   // Add an element to a compound material
   // Example: to define C3F8 gas:
   //      toto.AddCompoundElement(6,12,3);
   //      toto.AddCompoundElement(9,19,8);

   fCompound = kTRUE;
   KVNucleus n(Z, A);
   Int_t nel = 0;
   if (!fComposition) {
      fComposition = new KVList;
   }
   else nel = fComposition->GetEntries();
   KVNameValueList* l = new KVNameValueList(Form("Compound element %d", nel + 1));
   l->SetValue("Z", Z);
   l->SetValue("A", A);
   l->SetValue("Ar", n.GetAtomicMass());
   l->SetValue("Natoms", Natoms);
   l->SetValue("Weight", Natoms);
   l->SetValue("Ar*Weight", n.GetAtomicMass()*Natoms);
   fComposition->Add(l);
}
void KVIonRangeTableMaterial::AddMixtureElement(Int_t Z, Int_t A, Int_t Natoms, Double_t Proportion)
{
   // Add an element to a mixed material
   // Example: to define air, assuming 78% nitrogen (N2) and 21% oxygen (O2) and 1% argon (Ar):
   //      toto.AddMixtureElement(7,14, 2, 0.78);
   //      toto.AddMixtureElement(8,16, 2, 0.21);
   //      toto.AddMixtureElement(18, 40, 2, 0.01);

   fMixture = kTRUE;
   KVNucleus n(Z, A);
   Int_t nel = 0;
   if (!fComposition) fComposition = new KVList;
   else nel = fComposition->GetEntries();
   KVNameValueList* l = new KVNameValueList(Form("Mixture element %d", nel + 1));
   l->SetValue("Z", Z);
   l->SetValue("A", A);
   l->SetValue("Ar", n.GetAtomicMass());
   l->SetValue("Natoms", Natoms);
   l->SetValue("Proportion", Proportion);
   l->SetValue("Weight", Proportion * Natoms);
   l->SetValue("Ar*Weight", n.GetAtomicMass()*Proportion * Natoms);
   fComposition->Add(l);
}
void KVIonRangeTableMaterial::Initialize()
{
   // Correctly initialize material ready for use
   // For compound or mixed materials, calculate normalised weights of components,
   // effective Z and A, and molar weight of substance

   fMoleWt = 0.;
   if (IsCompound() || IsMixture()) {
      // mixture or compound
      // calculate molar weight and effective Z & A
      fZmat = fAmat = 0;
      TIter next(fComposition);
      KVNameValueList* nvl;
      Double_t totW = 0;
      while ((nvl = (KVNameValueList*)next())) {
         Double_t arw = nvl->GetDoubleValue("Ar*Weight");
         Double_t poid = nvl->GetDoubleValue("Weight");
         fMoleWt += arw;
         totW += poid;
         fZmat += poid * nvl->GetIntValue("Z");
         fAmat += poid * nvl->GetIntValue("A");
      }
      fZmat /= totW;
      fAmat /= totW;
      next.Reset();
      while ((nvl = (KVNameValueList*)next())) {
         Double_t prop = nvl->GetDoubleValue("Weight");
         nvl->SetValue("NormWeight", prop / totW);
      }
   }
   else {
      // isotopically-pure elemental material
      // get mass of 1 mole of element
      KVNucleus n(fZmat, fAmat);
      fMoleWt = n.GetAtomicMass();
   }
}
Esempio n. 19
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())
                  );
      }
   }
}
Esempio n. 20
0
void KVAvailableRunsFile::Update(Bool_t no_existing_file)
{
   // Examine the contents of the repository directory corresponding to this datatype
   // for parent dataset fDataSet.
   // For each file found which was not already in the list of available runs and
   // which corresponds to a run in the database gDataBase,
   // we add an entry to the available runlist file:
   //      [run number]|[date of modification]|[name of file]
   // For "old" runs we keep the existing informations (including KV version & username)
   //
   // When no_existing_file=kTRUE we are making an available runs file
   // for the first time. There is no pre-existing file.


      TString runlist;
      AssignAndDelete(runlist,
                   gSystem->ConcatFileName(GetFilePath(),
                                           GetFileName()));
   if(!no_existing_file){
      // read all existing informations
      ReadFile();
      //use "lockfile" to make sure nobody else tries to modify available_runs file
      //while we are working on it
      if(!runlist_lock.Lock(runlist.Data())) return;
   }
   //open temporary file
   TString tmp_file_path(GetFileName());
   ofstream tmp_file;
   KVBase::OpenTempFile(tmp_file_path, tmp_file);

   KVDataRepository *repository = fDataSet->GetRepository();

   cout << endl << "Updating runlist : " << flush;
   //get directory listing from repository
   KVUniqueNameList *dir_list =
       repository->GetDirectoryListing(fDataSet, GetDataType());
   if (!dir_list)
      return;

   TIter next(dir_list);
   KVBase *objs;
   //progress bar
   Int_t ntot = dir_list->GetSize();
   Int_t n5pc = TMath::Max(ntot / 20, 1);
   Int_t ndone = 0;
   KVDBTable *run_table = 0;
   KVDataBase* db = fDataSet->GetDataBase();
   if (!db){
   	db = new KVDataBase();
   	db->AddTable("Runs","List of Runs");
   }
   run_table = db->GetTable("Runs");
   while ((objs = (KVBase *) next())) {     // loop over all entries in directory

      Int_t run_num;
      //is this the correct name of a run in the repository ?
      Info("Update","%s %d",objs->GetName(),IsRunFileName(objs->GetName()));
      if ((run_num = IsRunFileName(objs->GetName()))) {

         KVDBRun *run = (KVDBRun *) run_table->GetRecord(run_num);
         if (run) {
            FileStat_t fs;
            //get file modification date
            if (repository->
                GetFileInfo(fDataSet, GetDataType(),
                            objs->GetName(), fs)) {
               //runfile exists in repository
               TDatime modt(fs.fMtime);
               if(!no_existing_file){
                  // was there already an entry for exactly the same file in the previous file ?
                  Int_t occIdx=0;
                  KVNameValueList* prevEntry = RunHasFileWithDateAndName(run->GetNumber(), objs->GetName(), modt, occIdx);
                  if(prevEntry){
                     // copy infos of previous entry
                     tmp_file << run->GetNumber() << '|' << modt.AsSQLString() << '|' << objs->GetName();
                     if(prevEntry->HasParameter(Form("KVVersion[%d]",occIdx))){
                        tmp_file <<"|"<< prevEntry->GetStringValue(Form("KVVersion[%d]",occIdx)) <<"|"<<prevEntry->GetStringValue(Form("Username[%d]",occIdx));
                     }
                     tmp_file << endl;
                  }
                  else
                  {
                     // New Entry - write in temporary runlist file '[run number]|[date of modification]|[name of file]
                     tmp_file << run->GetNumber() << '|' << modt.AsSQLString() << '|' << objs->GetName() << endl;
                  }
               }
               else // no previous existing file
               {
                  // New Entry in a new file - write in temporary runlist file '[run number]|[date of modification]|[name of file]
                  tmp_file << run->GetNumber() << '|' << modt.AsSQLString() << '|' << objs->GetName() << endl;
               }
            }
         }
         else{
         	Info("Update","the current run [%s] is not in database",objs->GetName());
            FileStat_t fs;
            if (repository->GetFileInfo(fDataSet, GetDataType(),objs->GetName(), fs))
            {
               TDatime modt(fs.fMtime);
            	// New Entry in a new file - write in temporary runlist file '[run number]|[date of modification]|[name of file]
            	tmp_file << run_num  << '|' << modt.AsSQLString() << '|' << objs->GetName() << endl;
            }	
            else{
               Warning("Update","%s GetFileInfo return kFALSE",objs->GetName());
         	}
         }
      }

      ndone++;
      if (!(ndone % n5pc))
         cout << '>' << flush;
   }

   cout << " DONE" << endl;
   delete dir_list;
   //close temp file
   tmp_file.close();

   if(no_existing_file){
      //use "lockfile" to make sure nobody else tries to modify available_runs file
      //while we are working on it
      if(!runlist_lock.Lock(runlist.Data())) return;
   }
   
   //copy temporary file to KVFiles directory, overwrite previous   
   gSystem->CopyFile(tmp_file_path, runlist, kTRUE);
   //set access permissions to 664
   gSystem->Chmod(runlist.Data(), CHMODE(6,6,4));

      //remove lockfile
      runlist_lock.Release();

   //delete temp file
   gSystem->Unlink(tmp_file_path);
}
Esempio n. 21
0
void KVAvailableRunsFile::ReadFile()
{
   // Read all infos in available runs file and store as KVNameValueList objects in fAvailableRuns.
   // For each run in the file we add a KVNameValueList with the following fields:
   //
   // Name = run number
   // Occurs = number of times run appears in file
   // Filename[0] = name of first file for run
   // Filename[1] =
   //  ...
   // Filename[Occurs-1] = name of last file for run
   // Date[0] = date & time of generation of first file etc.
   // KVVersion[0] = name of KaliVeda version used to generate first file etc. (if known)
   // Username[0] = name of user who generated first file etc. (if known)
   
   //does runlist exist ?
   if (!OpenAvailableRunsFile()) {
      Error("ReadFile", "Cannot open available runs file");
      return;
   }

   if(fAvailableRuns) delete fAvailableRuns;
   fAvailableRuns = new KVHashList;
   fAvailableRuns->SetOwner(kTRUE);
   
   TString fLine;
   Int_t line_number=1;
   fLine.ReadLine(fRunlist);

   KVNumberList duplicate_lines;

   Int_t fRunNumber;

   while (fRunlist.good()) {

      TObjArray *toks = fLine.Tokenize('|');    // split into fields
      
      // number of fields can vary
      // nfields = 2: run number, date
      // nfields = 3: run number, date, filename
      // nfields = 5: run number, date, filename, KaliVeda version, username
      Int_t nfields = toks->GetEntries();
      KVString kvs(((TObjString *) toks->At(0))->GetString());
      fRunNumber = kvs.Atoi();
      if(nfields<2){
            Warning("ReadFile", "Less than 2 fields in entry for run %d (line:%d)???",fRunNumber,line_number);
			toks->ls();
			continue;
		}
      //get date string
      KVString datestring(((TObjString *) toks->At(1))->GetString());
      
      // is run already in list ?
      KVNameValueList* NVL = (KVNameValueList*)fAvailableRuns->FindObject(kvs);
      Int_t Occurs = (NVL ? NVL->GetIntValue("Occurs") : 0);
      if(!NVL) {
         NVL = new KVNameValueList(kvs);
         fAvailableRuns->Add(NVL);
      }
      else
      {
         // check date for run is different to any others
         Bool_t ok = kTRUE;
         for(Int_t ii=0;ii<Occurs;ii++){
            KVString olddate = NVL->GetStringValue(Form("Date[%d]",ii));
            if(olddate==datestring){               
               ok=kFALSE;
               duplicate_lines.Add(line_number);
               break;
            }
         }
         if(!ok){
            delete toks;
             line_number++;
            fLine.ReadLine(fRunlist);
            continue;
         }
      }
      Occurs++;
      NVL->SetValue("Occurs", Occurs);
      
      NVL->SetValue(Form("Date[%d]",Occurs-1), datestring.Data());

      //backwards compatibility
      //an old available_runs file will not have the filename field
      //in this case we assume that the name of the file is given by the
      //dataset's base file name (i.e. with no date/time suffix)
      KVString filename;
      if (nfields > 2) {
         filename = ((TObjString *) toks->At(2))->GetString();
      } else {
         filename = fDataSet->GetBaseFileName(GetDataType(), fRunNumber);
      }
      NVL->SetValue(Form("Filename[%d]",Occurs-1), filename.Data());
      KVString kvversion,username;
      if (nfields > 4) {
         kvversion = ((TObjString *) toks->At(3))->GetString();
         username = ((TObjString *) toks->At(4))->GetString();
         NVL->SetValue(Form("KVVersion[%d]",Occurs-1), kvversion.Data());
         NVL->SetValue(Form("Username[%d]",Occurs-1), username.Data());
      }
      delete toks;

      line_number++;
      fLine.ReadLine(fRunlist);
   }

   CloseAvailableRunsFile();

   if(duplicate_lines.GetNValues()){
       Info("ReadFile", "There were %d duplicate entries in available runs file, they will be removed", duplicate_lines.GetNValues());
       RemoveDuplicateLines(duplicate_lines);
   }

}
Esempio n. 22
0
//______________________________________________
KVNameValueList::KVNameValueList(const KVNameValueList& NVL) : TNamed()
{
   // Copy constructor
   NVL.Copy(*this);
   fList.SetOwner(kTRUE);
}
Esempio n. 23
0
void KVINDRA_VAMOS::DetectEvent(KVEvent* event, KVReconstructedEvent* rec_event, const Char_t* detection_frame)
{

   // the ROOT geometry can not be use for filtering
   SetROOTGeometry(kFALSE);

   // iterate through list of particles
   // and detect in VAMOS
   KVNucleus* part, *_part;
   KVNameValueList* nvl = NULL;
   Bool_t isVAMOSevent = kFALSE;
   static KVVAMOSReconEvent tmp_rec_vamos_event;
   tmp_rec_vamos_event.Clear();

   while ((part = event->GetNextParticle())) {  // loop over particles


#ifdef KV_DEBUG
      cout << "DetectEvent(): looking at particle in VAMOS---->" << endl;
      part->Print();
#endif
      _part = (KVNucleus*)part->GetFrame(detection_frame, kFALSE);

      if (_part->GetTheta() > 14) continue;

      _part->SetE0();
      Double_t eLostInTarget = 0;

      if (fTarget && (fFilterType != kFilterType_Geo)) {
         fTarget->SetOutgoing(kTRUE);
         //simulate passage through target material
         Double_t ebef = _part->GetKE();
         fTarget->DetectParticle(_part);
         eLostInTarget = ebef - _part->GetKE();
         if (_part->GetKE() < 1.e-3) {
            part->GetParameters()->SetValue("UNDETECTED", "STOPPED IN TARGET");

            part->AddGroup("UNDETECTED");
            part->AddGroup("STOPPED IN TARGET");
         }
         fTarget->SetOutgoing(kFALSE);

      }


      if ((_part->GetKE() > 1.e-3) && (nvl = GetVAMOS()->DetectParticle(_part)) && (nvl->GetNpar() > 0)) {

         _part->SetMomentum(*_part->GetPInitial());

         isVAMOSevent = kTRUE;
         KVVAMOSReconNuc* recon_nuc = (KVVAMOSReconNuc*)tmp_rec_vamos_event.AddParticle();

         // copy parameter list
         part->GetParameters()->Copy(*(recon_nuc->GetParameters()));


         recon_nuc->SetZandA(part->GetZ(), part->GetA());

         recon_nuc->SetMomentum(_part->GetMomentum());
         recon_nuc->SetQ(_part->GetParameters()->GetIntValue("Q"));
         recon_nuc->SetBrho(_part->GetParameters()->GetDoubleValue("Brho"));
         recon_nuc->GetParameters()->SetValue("Delta", _part->GetParameters()->GetDoubleValue("Delta"));
         recon_nuc->SetThetaVandPhiV(_part->GetParameters()->GetDoubleValue("ThetaV"),
                                     _part->GetParameters()->GetDoubleValue("PhiV"));

         recon_nuc->GetParameters()->SetValue("DETECTED", "OK");
         recon_nuc->SetTargetEnergyLoss(eLostInTarget);
         recon_nuc->SetIsIdentified();
         recon_nuc->SetIsCalibrated();
         recon_nuc->SetIsOK();
         recon_nuc->SetZMeasured();
         recon_nuc->SetQMeasured();
         recon_nuc->SetAMeasured();
         //recon_nuc->SetIsBasicQandAidentified();

         // Clear this nucleus detected in VAMOS in order to inhibit the
         // its detection in INDRA
         part->Clear();

      } else _part->SetMomentum(*_part->GetPInitial());

      SafeDelete(nvl);
   }     //fin de loop over particles

   // if a nucleus is detected in VAMOS then continue filtering the event in INDRA
   if (isVAMOSevent) {
      //       Info("DetectEvent","event %d is a VAMOS event",event->GetNumber());
      GetINDRA()->DetectEvent(event, rec_event, detection_frame);

      // Set the reconstructed nucleus detected in VAMOS in the VAMOS event
      KVVAMOSReconEvent* rec_vamos_event = ((KVIVReconEvent*)rec_event)->GetVAMOSEvent();
      tmp_rec_vamos_event.Copy(*rec_vamos_event);

      //    rec_event->Print();
   }
}