Example #1
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", "");
}
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;
}
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::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();
   }
}
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);
}
Example #6
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);
   }

}