Пример #1
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;   
}
Пример #2
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);
}