Example #1
0
Bool_t KVAvailableRunsFile::CheckAvailable(Int_t run)
{
   //Look for a given run number in the file
   //If run not found, returns kFALSE
   //If available runs file does not exist, Update() is called to create it.

   //does runlist exist ?
   if (!OpenAvailableRunsFile()) {
      Error("CheckAvailable", "Error opening available runs file");
      return kFALSE;
   }
   //loop over lines in runlist file
   //look for line beginning with 'run|'
   Bool_t found = kFALSE;
   TString line;
   line.ReadLine(fRunlist);
   while (fRunlist.good()) {
      if (line.BeginsWith(Form("%d|", run))) {
         CloseAvailableRunsFile();
         return kTRUE;
      }
      line.ReadLine(fRunlist);
   }
   CloseAvailableRunsFile();
   return found;
}
Example #2
0
  /** 
   * Get the job url. 
   * 
   * @param name  Production name  
   * @param mc    Should be true for MC 
   * @param url   On return, the job url 
   * 
   * @return true on success 
   */
  Bool_t GetJobUrl(const TString& name, Bool_t mc, TString& url)
  {
    url = "";
    TString index("raw.jsp");
    if (!Download((mc ? "job_details.jsp" : "production/raw.jsp"), index))
	return false;
    
    std::ifstream in(index.Data());
    TString line;
    TString tgt(Form("<td class=\"table_row\">%s</td>", name.Data()));
    do { 
      line.ReadLine(in);
      if (!line.Contains(tgt)) continue;
      line.ReadLine(in);
      Int_t first = line.Index("href=\"");
      Int_t last  = line.Index("\"", first+7);
      url = line(first+6,last-first-6);
      break;
      
    } while (!in.eof());
    in.close();
    
    if (url.IsNull()) { 
      Error("GetJobUrl", "Production %s not found", name.Data());
      return false;
    }

    return true;
  }
Example #3
0
RDKConfig::RDKConfig(TString path){
	if(!config_map.empty()){
		config_map.clear();
	}
	ifstream in(path);
	if(in.is_open()){
		TString line;
		line.ReadLine(in);
		while(!in.eof()){
			line.ReadLine(in);
			TStringToken token(line,",",kTRUE);
			token.NextToken();
			UInt_t series=token.Atoi();
			token.NextToken();
			token.NextToken();
			token.NextToken();
			token.NextToken();
			token.NextToken();
			TString temp(token);
			if(temp.BeginsWith("0x")){
				temp.Remove(0,2);
				temp=TString::BaseConvert(temp,16,10);
			}
			UInt_t config=temp.Atoi();
			config_map[series]=config;
		}
	}else{
		cerr<<"No configuration file found"<<endl;
	}
}
Example #4
0
void KVAvailableRunsFile::GetRunInfos(Int_t run, KVList * dates,
                                      KVList * files)
{
   //Look for a given run number in the file, and read the file's modification date/time and filename
   //These informations are stored in the two TList as TObjString objects (these objects belong to the
   //lists and will be deleted by them).
   //We do not stop at the first run found, but continue until the end of the file, adding
   //informations for every occurence of the run in the file.
   //If available runs file does not exist, Update() is called to create it.

   //does runlist exist ?
   if (!OpenAvailableRunsFile()) {
      Error("GetRunInfos", "Error opening available runs file");
      return;
   }
   //clear lists - delete objects
   dates->Delete();
   files->Delete();

   //loop over lines in fRunlist file
   //look for line beginning with 'run|'
   TString line;
   line.ReadLine(fRunlist);
   while (fRunlist.good()) {
      if (line.BeginsWith(Form("%d|", run))) {

         //found it
         TObjArray *toks = line.Tokenize('|');  // split into fields
         // check date is not identical to a previous entry
         // i.e. there are spurious duplicate entries
         TObjString* rundate = (TObjString*)toks->At(1)->Clone();
         if(dates->FindObject(rundate->GetName())){
             delete toks;
             delete rundate;
             line.ReadLine(fRunlist);
             continue;
         }
         //add date string
         dates->Add(toks->At(1)->Clone());

         //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)
         if (toks->GetEntries() > 2) {
            files->Add(toks->At(2)->Clone());
         } else {
            files->
                Add(new
                    TObjString(fDataSet->
                               GetBaseFileName(GetDataType(), run)));
         }
         delete toks;

      }
      line.ReadLine(fRunlist);
   }
   CloseAvailableRunsFile();
}
Example #5
0
void KVAvailableRunsFile::Add(Int_t run, const Char_t * filename)
{
   //Add to the file an entry corresponding to this run, assumed to be present in the repository
   //with the given filename.
   //write in temporary runlist file '[run number]|[date of modification]|[name of file]|KaliVeda version|username

   //does runlist exist ?
   if (!OpenAvailableRunsFile()) {
      Error("Add", "Error opening available runs file");
      return;
   }
   //open temporary file
   TString tmp_file_path(GetFileName());
   ofstream tmp_file;
   KVBase::OpenTempFile(tmp_file_path, tmp_file);

   //copy all lines in runlist file
   TString line;
   line.ReadLine(fRunlist);
   while (fRunlist.good()) {
      tmp_file << line.Data() << endl;
      line.ReadLine(fRunlist);
   }

   CloseAvailableRunsFile();
   TString runlist_path;
   AssignAndDelete(runlist_path,
                   gSystem->ConcatFileName(fDataSet->GetDataSetDir(),
                                           GetFileName()));
   // keep lock on runsfile
   if( !runlist_lock.Lock( runlist_path.Data() ) ) return;

   //add entry for run
   FileStat_t fs;
   //get file modification date
   if (fDataSet->GetRepository()->
       GetFileInfo(fDataSet, GetDataType(), filename,
                   fs)) {
      //runfile exists in repository
      //write in temporary runlist file '[run number]|[date of modification]|[name of file]|KaliVeda version|username
      TDatime modt(fs.fMtime);
      UserGroup_t *userinfo = gSystem->GetUserInfo();
      tmp_file << run << '|' << modt.
          AsSQLString() << '|' << filename << '|' << GetKVVersion() << '|' << userinfo->fUser << endl;
      delete userinfo;
   }
   //close temp file
   tmp_file.close();

   //copy temporary file to KVFiles directory, overwrite previous
   gSystem->CopyFile(tmp_file_path, runlist_path, kTRUE);
   //set access permissions to 664
   gSystem->Chmod(runlist_path.Data(), CHMODE(6,6,4));
   //delete temp file
   gSystem->Unlink(tmp_file_path);
   //unlock runsfile
   runlist_lock.Release();
}
Example #6
0
void KVAvailableRunsFile::RemoveDuplicateLines(KVNumberList lines_to_be_removed)
{
   // Remove from available runs file all lines whose numbers are in the list

   //does runlist exist ?
   if (!OpenAvailableRunsFile()) {
      Error("Remove", "Error opening available runs file");
      return;
   }
   //open temporary file
   TString tmp_file_path(GetFileName());
   ofstream tmp_file;
   KVBase::OpenTempFile(tmp_file_path, tmp_file);

   //loop over lines in fRunlist file
   //all lines which are not in list are directly copied to temp file
   TString line;
   Int_t line_number=1;
   line.ReadLine(fRunlist);

   lines_to_be_removed.Begin();
   Int_t next_line_to_remove = 0;
   if(!lines_to_be_removed.End()) next_line_to_remove = lines_to_be_removed.Next();

   while (fRunlist.good()) {

       if(line_number!=next_line_to_remove)
           tmp_file << line.Data() << endl;
       else {
           if(!lines_to_be_removed.End()) next_line_to_remove = lines_to_be_removed.Next();
       }
       line_number++;
       line.ReadLine(fRunlist);

   }

   CloseAvailableRunsFile();
   TString fRunlist_path;
   AssignAndDelete(fRunlist_path,
                   gSystem->ConcatFileName(GetFilePath(),
                                           GetFileName()));
   //keep lock on runsfile
   if( !runlist_lock.Lock( fRunlist_path.Data() ) ) return;

   //close temp file
   tmp_file.close();

   //copy temporary file to KVFiles directory, overwrite previous
   gSystem->CopyFile(tmp_file_path, fRunlist_path, kTRUE);
   //set access permissions to 664
   gSystem->Chmod(fRunlist_path.Data(), CHMODE(6,6,4));
   //delete temp file
   gSystem->Unlink(tmp_file_path);
   //unlock runsfile
   runlist_lock.Release();
}
Example #7
0
KVNumberList KVAvailableRunsFile::GetRunList(const KVDBSystem * sys)
{
   //Returns list of available run numbers for this data type.
   //If 'sys' gives the address of a valid database reaction system, only runs
   //corresponding to the system will be included.

   KVNumberList runs;

   //does runlist exist ?
   if (!OpenAvailableRunsFile()) {
      Error("GetRunList", "Cannot open available runs file");
      return runs;
   }

   TString fLine;
   fLine.ReadLine(fRunlist);

   Int_t fRunNumber;
   KVDBTable *runs_table = 0;
   KVDataBase* db = fDataSet->GetDataBase();
   if (!db){
   	db = new KVDataBase();
   	db->AddTable("Runs","List of Runs");
   }
   runs_table = db->GetTable("Runs");
   
   //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;

      if (sys) {
         // check run is from right system
         KVDBRun *a_run = (KVDBRun *) runs_table->GetRecord(fRunNumber);
         if (a_run) {
            if (a_run->GetSystem() == sys)
               runs.Add(fRunNumber);
         }
      } else {
         // add all runs to list
         runs.Add(fRunNumber);
      }

      fLine.ReadLine(fRunlist);
   }

   CloseAvailableRunsFile();
   return runs;
}
Example #8
0
void KVINDRA::SetGGtoPGConversionFactors()
{
   // Sets the parameters for linear conversion of silicon & ChIo coder values
   // between GG and PG, using the following formula:
   //
   //   PG  = alpha + beta*(GG - GG_0) + PG_0
   //
   // where GG_0 and PG_0 are respectively GG and PG pedestals
   //
   // We look for the file whose name is given by the .kvrootrc variable
   //    [dataset].INDRADB.GGtoPGFactors:
   // or by default
   //    INDRADB.GGtoPGFactors:
   // and expect to find in it a line for each detector of the form:
   //    Det_Name   alpha   beta
   // Comments in the file can be written on lines beginning with the character '#'

   ifstream datfile;
   if (!gDataSet->OpenDataSetFile(gDataSet->GetDataSetEnv("INDRADB.GGtoPGFactors", ""), datfile)) {

      Info("SetGGtoPGConversionFactors", "Cannot open file with parameters for conversion (%s).",
           gDataSet->GetDataSetEnv("INDRADB.GGtoPGFactors", ""));
      return;
   }
   else {
      Info("SetGGtoPGConversionFactors", "Reading parameters from file %s",
           gDataSet->GetDataSetEnv("INDRADB.GGtoPGFactors", ""));

      Char_t detname[30];
      Double_t a, b;
      TString aline;
      aline.ReadLine(datfile);
      while (datfile.good()) {

         if (aline[0] != '#') {   //skip comments

            sscanf(aline.Data(), "%s %lf %lf", detname, &a, &b);
            KVINDRADetector* det = (KVINDRADetector*)GetDetector(detname);
            if (!det) {
               //no detector found with cou, mod and type
               Error("SetGGtoPGConversionFactors", "Unknown detector : %s", detname);
            }
            else {
               det->SetGGtoPGConversionFactors(a, b);
               //Info("SetGGtoPGConversionFactors", "%s : PG = %f + %f * GG", detname, a, b);
            }
         }
         aline.ReadLine(datfile);
      }                            //while( datfile.good()
      datfile.close();
   }
}
Example #9
0
void readAbbyTimeFile()
{
  ifstream CsvFile("/home/rjn/saltStuff/abbyTimeWindows.csv");
  
  int numLines=0;
  TString line;
  
  line.ReadLine(CsvFile); // Get rid of inital headings
  Int_t depthIndex[3]={-1,-1,-1};
  Int_t lastDepth[3]={0,0,0};

  while(line.ReadLine(CsvFile)) {

    //    cout << line.Data() << endl;
    TObjArray *vals = (TObjArray*) line.Tokenize(",");
    //    vals->Dump();
    TObjString *firstField=vals->At(0);
    //    exit(0);
    TObjString *antenna=vals->At(1);
    TObjString *disk=vals->At(2);
    TObjString *file=vals->At(3);
    TObjString *hole=vals->At(6);
    TObjString *peakTimeStr=vals->At(7);
    TObjString *minTimeStr=vals->At(8);
    TObjString *maxTimeStr=vals->At(9);
    //    cout << vals[0].Data() << "\t" << vals[1].Data() << endl;
    //    cout << x->GetString()->Data() << "\t" << y->GetString()->Data() << endl;
    Int_t antIndex=antenna->GetString().Atoi()-1;
    Int_t holeIndex=hole->GetString().Atoi()-2;
    Int_t depth=firstField->GetString().Atoi();
    if(lastDepth[antIndex]!=depth) {
      depthIndex[antIndex]++;
      depths[antIndex][depthIndex[antIndex]]=depth;
      lastDepth[antIndex]=depth;
    }
    //    cout << antIndex << "\t" << depthIndex[antIndex] << "\t" << holeIndex << "\t" << depth << endl;
    //    cout << numLines << "\t" << index <<  "\t" << depths[depthIndex[antIndex]] << endl;
    disks[antIndex][depthIndex[antIndex]][holeIndex]=disk->GetString().Atoi()+1;
    files[antIndex][depthIndex[antIndex]][holeIndex]=file->GetString().Atoi();
    peakTime[antIndex][depthIndex[antIndex]][holeIndex]=peakTimeStr->GetString().Atof();
    minTime[antIndex][depthIndex[antIndex]][holeIndex]=minTimeStr->GetString().Atof();
    maxTime[antIndex][depthIndex[antIndex]][holeIndex]=maxTimeStr->GetString().Atof();

    numLines++;
    
  }

}
Example #10
0
File: run.C Project: ktf/AliPhysics
TChain * GetAnalysisChain(const char * incollection){
  // Builds a chain of esd files
  // incollection can be
  // - a single root file
  // - an xml collection of files on alien
  // - a ASCII containing a list of local root files
  TChain* analysisChain = 0;
  // chain
  analysisChain = new TChain("esdTree");
  if (TString(incollection).Contains(".root")){
    analysisChain->Add(incollection);
  }
  else if (TString(incollection).Contains("xml")){
    TGrid::Connect("alien://");
    TAlienCollection * coll = TAlienCollection::Open (incollection);
    while(coll->Next()){
      analysisChain->Add(TString("alien://")+coll->GetLFN());
    }
  } else {
    ifstream file_collect(incollection);
    TString line;
    while (line.ReadLine(file_collect) ) {
      analysisChain->Add(line.Data());
    }
  }
  analysisChain->GetListOfFiles()->Print();

  return analysisChain;
}
Example #11
0
void TREEendlog(TString filename)
{	gROOT->Reset(); // reset ROOT
	
	ifstream edfile; // new stream 'edfile' to the data file

	edfile.open(filename, ios_base::in); // read and write access to the data file	
	if (edfile.good()){
		TString treename = filename + ".root";
		cout << "Creating tree " << treename << endl;
		TFile* file=TFile::Open(treename.Data(), "RECREATE"); // recreating a new file wherein the tree will be saved.
		//++++++++ options: "CREATE" ~ create and open a new file if it does not already exist ++++++++++++++++++++++++++++++
		//+++++++++++++++++ "RECREATE" ~ create and overwrite if existing +++++++++++++++++++++++++++++++++++++++++++++++++++

		cout << "Reading data from " << filename << endl;
		TString bdescriptor; // branch descriptor 'bdescriptor' as a empty string
		bdescriptor.ReadLine(edfile); // read branch descriptor from file
		bdescriptor.ReplaceAll(" ",":"); // format branch descriptor for root ("x y z" -> "x:y:z")

		TNtupleD* tree=new TNtupleD("mytree", "mytree", bdescriptor.Data()); // creating a new TTree([treename],[treetitle])	
		Int_t n = tree->GetNvar();
		while (1){
			for (int i = 0; i < n; i++) edfile >> tree->GetArgs()[i]; // read values into Arg-array of tree
			if (!edfile.good()) break;
			tree->Fill(tree->GetArgs()); // fill Args into tree
		}
		
		edfile.close(); // closing the stream 'edfile'
		file->Write();
		tree->Print(); // output of the tree overview
		delete tree;
		delete file;
	}
Example #12
0
//------------------------------
void KVINDRADB_e475s::ReadCalibrations()
//------------------------------
{

   ifstream finput;
   if (!OpenCalibFile("CalibFile", finput)) {
      Error("ReadCalibrations()", "Could not open file %s",
            GetCalibFileName("CalibFile"));
      return;
   }
   
	Info("ReadCalibrations()",
        "Reading calibration parameters...");
	
	TString sline;
   TString stit;
	TString calib_det,calib_gain,calib_file;
	TObjArray *toks=NULL;
	while (finput.good()) {
		sline.ReadLine(finput);
		if (!sline.IsNull()){
			cout << sline << endl;
			toks = sline.Tokenize(" ");
			calib_det = ((TObjString*)(*toks)[0])->GetString();
			calib_gain = ((TObjString*)(*toks)[1])->GetString();
			calib_file = ((TObjString*)(*toks)[2])->GetString();
			stit.Form("%s/%s",gDataSet->GetDataSetDir(),calib_file.Data());
			ifstream fin(stit.Data());
			ReadCalibFile(fin,calib_det,calib_gain);
			fin.close();
   	}
	}
	finput.close();

}
Example #13
0
//________________________________________________________________________________________
int main(int argc, char* argv[]) {
// Default options
	bool isList = false;
	TString outputdir = "TempOutput/";
	int verbose = 0;

// Parse options
	char ch;
	while ((ch = getopt(argc, argv, "d:v:lh?")) != -1 ) {
		switch (ch) {
			case 'd': outputdir = TString(optarg); break;
			case 'v': verbose = atoi(optarg); break;
			case 'l': isList = true; break;
			case '?':
			case 'h': usage(0); break;
			default:
			cerr << "*** Error: unknown option " << optarg << std::endl;
			usage(-1);
		}
	}

	argc -= optind;
	argv += optind;

        // Check arguments
	if( argc<1 ) {
		usage(-1);
	}

	TChain *theChain = new TChain("analyze/Analysis");
	for(int i = 0; i < argc; i++){
		if( !isList ){
			theChain->Add(argv[i]);
			printf(" Adding file: %s\n",argv[i]);
		} else {
			TString rootFile;
			ifstream is(argv[i]);
			while(rootFile.ReadLine(is) && (!rootFile.IsNull())){
				if(rootFile[0] == '#') continue;
				theChain->Add(rootFile);
				printf(" Adding file: %s\n", rootFile.Data());
			}
		}
	}

	cout << "--------------" << endl;
	cout << "OutputDir is:     " << outputdir << endl;
	cout << "Verbose level is: " << verbose << endl;
	cout << "Number of events: " << theChain->GetEntries() << endl;
	cout << "--------------" << endl;

	UserAnalyzer *tA = new UserAnalyzer(theChain);
	tA->SetOutputDir(outputdir);
	tA->SetVerbose(verbose);
	tA->BeginJob();
	tA->Loop();
	tA->EndJob();
	delete tA;
	return 0;
}
Example #14
0
TGraph *getScopePeriodiogram(char *fileName)
{
  ifstream CsvFile(fileName);
  
  int numLines=0;
  int numLines2=0;
  TString line;
  Double_t xVals[100000];
  Double_t yVals[100000];
  while(line.ReadLine(CsvFile)) {

    //    cout << line.Data() << endl;
    TObjArray *vals = (TObjArray*) line.Tokenize(",");
    //    vals.Dump();
    TObjString *x=vals->At(0);
    TObjString *y=vals->At(1);
    //    cout << vals[0].Data() << "\t" << vals[1].Data() << endl;
    //    cout << x->GetString()->Data() << "\t" << y->GetString()->Data() << endl;
    xVals[numLines]=x->GetString().Atof();
    yVals[numLines]=y->GetString().Atof();
    numLines++;
    
  }
  Double_t N=numLines*2;
  Double_t deltaF=(xVals[1]-xVals[0]);
  Double_t deltaT=1./(N*deltaF);
  //  cout << deltaT << endl;
  for(int i=0;i<numLines;i++) {
     xVals[i]=i*deltaF;
  }
  //  cout << xVals[0] << "\t" << xVals[numLines-1] << "\t" << xVals[1]-xVals[0] << "\n";

  TGraph *grWave = new TGraph(numLines,xVals,yVals);
  return grWave;
}
Example #15
0
TGraph *getWaveFromTxt(char *fileName)
{
  ifstream TxtFile(fileName);  
  int numLines=0;
  int numLines2=0;
  TString line;
  Double_t xVals[100000];
  Double_t yVals[100000];
  Double_t xVals2[100000];
  Double_t yVals2[100000];
  while(line.ReadLine(TxtFile)) {

    //    cout << line.Data() << endl;
    TObjArray *vals = (TObjArray*) line.Tokenize(" ");
    //    vals.Dump();
    TObjString *x=vals->At(0);
    TObjString *y=vals->At(1);
    //    cout << vals[0].Data() << "\t" << vals[1].Data() << endl;
    //    cout << x->GetString()->Data() << "\t" << y->GetString()->Data() << endl;
    xVals[numLines]=x->GetString().Atof();
    yVals[numLines]=y->GetString().Atof();
    //    yVals[numLines]=TMath::Sin(TMath::TwoPi()*500e6*xVals[numLines]);
    if(numLines%2==0) {
      xVals2[numLines2]=xVals[numLines];
      yVals2[numLines2]=yVals[numLines];
      numLines2++;
    }
    numLines++;
    
  }
  TGraph *grWave = new TGraph(numLines,xVals,yVals);
  return grWave;
}
IonisationChamberv::IonisationChamberv(LogFile* Log)
{
#ifdef DEBUG
   cout << "IonisationChamberv::Constructor" << endl;
#endif
   Ready = kFALSE;

   L = Log;

   NbChio = gEnv->GetValue("VAMOS.NbIC", -1);
   if (NbChio < 0) {
      cout << "Not Reading VAMOS.NbIC in IonisationChamberv Class" << endl;
   }
   //energy Raw
   E_Raw = new UShort_t[NbChio];
   E_Raw_Nr = new UShort_t[NbChio];
   IcRaw = new Int_t[NbChio];

   DetChio = new Int_t [NbChio];

   //Calibration coeff
   a = new Float_t[NbChio];
   b = new Float_t[NbChio];
   Vnorm = new Float_t[NbChio];

   //energy Calibrated
   E = new Float_t[NbChio];

   InitSavedQuantities();
   Init();

   Rnd = new Random;

   ifstream inf;
   Int_t num = 0;
   Float_t dummy1, dummy2, dummy3;
   TString sline;

   if (!gDataSet->OpenDataSetFile("IonisationChamber.cal", inf)) {
      cout << "Could not open the calibration file IonisationChamber.cal !" << endl;
      return;
   } else {
      cout << "Reading IonisationChamber.cal" << endl;
      while (!inf.eof()) {
         sline.ReadLine(inf);
         if (!inf.eof()) {
            if (!sline.BeginsWith("#")) {
               sscanf(sline.Data(), "%d %f %f %f", &num, &dummy1, &dummy2, &dummy3);
               a[num] = dummy1;
               b[num] = dummy2;
               Vnorm[num] = dummy3;
            }
         }
      }
   }
   inf.close();
   Ready = kTRUE;

}
Example #17
0
void KVINDRAUpDater::SetCsIPedestals(KVDBRun* kvrun)
{
   if (!kvrun->GetKey("Pedestals"))
      return;
   if (!kvrun->GetKey("Pedestals")->GetLinks())
      return;
   if (!kvrun->GetKey("Pedestals")->GetLinks()->At(1))
      return;

   //read CsI pedestals
   ifstream file_pied_csi;
   if (!KVBase::
         SearchAndOpenKVFile(kvrun->GetKey("Pedestals")->GetLinks()->At(1)->
                             GetName(), file_pied_csi, fDataSet.Data())) {
      Error("SetPedestals", "Problem opening file %s",
            kvrun->GetKey("Pedestals")->GetLinks()->At(1)->GetName());
      return;
   }
   cout << "--> Setting Pedestals" << endl;
   cout << "    CsI            : " << kvrun->GetKey("Pedestals")->
        GetLinks()->At(1)->GetName() << endl;

   int cou, mod, type, n_phys, n_gene;
   float ave_phys, sig_phys, ave_gene, sig_gene;
   TString line;

   //skip first 5 lines - header
   for (int i = 5; i; i--) {
      line.ReadLine(file_pied_csi);
   }

   while (file_pied_csi.good()) {

      file_pied_csi >> cou >> mod >> type >> n_phys >> ave_phys >> sig_phys
                    >> n_gene >> ave_gene >> sig_gene;

      KVDetector* det = GetINDRA()->GetDetectorByType(cou, mod, type);
      if (det) {
         switch (type) {

            case CsI_R:

               det->SetPedestal("R", ave_gene);
               break;

            case CsI_L:

               det->SetPedestal("L", ave_gene);
               break;

            default:

               break;
         }
      }
   }
   file_pied_csi.close();
}
Example #18
0
  /** 
   * Get the size of a given run 
   * 
   * @param in       Input stream 
   * @param runNo    Run number to search for 
   * @param mc       True for simulations 
   * @param minSize  Least size 
   * 
   * @return true on success 
   */
  Bool_t GetSize(std::istream& in, ULong_t runNo, 
		 Bool_t mc, ULong_t minSize=100000)
  {
    TString line;
    TString tgt2(mc ? "table_row_right" : "ESDs size");
    Int_t   cnt = 0;
    do {
      line.ReadLine(in);
      if (!line.Contains(tgt2)) continue;
      cnt++;
      if (mc && cnt < 3) continue;
      if (!mc) line.ReadLine(in);
      if (fDebug) Info("", line);

      TString ssiz;
      if (mc) { 
	Int_t first       = line.Index(">");
	Int_t last        = line.Index("<",first+1);
	if (first == kNPOS || last == kNPOS) { 
	  Error("GetDir", "Failed to get directory from %s", line.Data());
	  return false;
	}
	ssiz = line(first+1, last-first-1);
      }
      else {
	for (Int_t i = 0; i < line.Length(); i++) { 
	  if (line[i] == '<') break;
	  if (line[i] == ' ' || line[i] == '\t' || line[i] == ',') continue;
	  ssiz.Append(line[i]);
	}
      }
      Long_t size = ssiz.Atoll();
      if (fDebug) Info("", "Got run %lu %lu" , runNo, size);
      if (size < 0) {
	Error("GetSize", "Failed to extract size for run %lu", runNo);
	return false;
      }
      if (ULong_t(size) < minSize) {
	Warning("GetSize","Run %lu does not have enough events %lu",runNo,size);
	return false;
      }
      break;
    } while (!in.eof());
    return true;
  }
Example #19
0
void KVLogReader::ReadFile(const Char_t* fname)
{
   //Open file 'fname' and read contents

   Reset();                     //clear last read infos

   ifstream filestream(fname);
   if (!filestream.good()) {
      cout << "Error in KVLogReader::ReadFile - cannot open file " << fname
           << endl;
      return;
   }
   TString line;
   line.ReadLine(filestream);
   Bool_t ok = kTRUE;
   while (filestream.good() && ok) {
      ReadLine(line, ok);       //perform action based on content of line
      line.ReadLine(filestream);
   }
   filestream.close();
}
Example #20
0
//________________________________________________________________________________
TChain* CreateChainTXT(const char* inpData)
{
  const char* chName="esdTree";
  TChain* chain = new TChain(chName);
  //
  TString inpDtStr = inpData;
  if (inpDtStr.EndsWith(".root")) {
    chain->AddFile(inpData);
  }
  else {
    //
    ifstream inpf(inpData);
    if (!inpf.good()) {
      printf("Failed on input filename %s\n",inpData);
      return kFALSE;
    }
    //
    TString flName;
    flName.ReadLine(inpf);
    while ( !flName.IsNull() ) {
      flName = flName.Strip(TString::kBoth,' ');
      if (flName.BeginsWith("//") || flName.BeginsWith("#")) {flName.ReadLine(inpf); continue;}
      flName = flName.Strip(TString::kBoth,',');
      flName = flName.Strip(TString::kBoth,'"');
      if (flName.EndsWith("Barrel.root")) barrelFlag = kTRUE;
      printf("Adding %s\n",flName.Data());
      chain->AddFile(flName.Data());
      flName.ReadLine(inpf);
    }
  }
  //
  int n = chain->GetEntries();
  if (n<1) {
    printf("Obtained chain is empty\n");
    return kFALSE;
  }
  printf("Created chain with %d entries in %d trees from %s\n",chain->GetEntries(),chain->GetNtrees(),inpData);
  return chain;
}
Example #21
0
/**
 * Merge all files in folder path with names matching the regular expression filematch into trees in a ROOT file.
 *
 * @param filematch Merge files whose names match this regular expression (default: read all)
 * @param path Merge files in this folder (default: current folder)
 */
void merge_all(const char *filematch = "[0-9]+[a-z]+.out", const char *path = ".")
{
	TFile *outfile = new TFile("out.root","RECREATE"); // create ROOT file
	ifstream infile;
	TSystemDirectory dir(path,path); // open given folder
	TList *files = dir.GetListOfFiles(); // get all files in that folder
	TRegexp re(filematch); // create regular expression from given parameter

	outfile->cd(); // switch current directory to ROOT file
	
	Int_t n = 0;
	for (Int_t i = 0; ; i++){ // for loop incrementing index i
		TObject *f = files->At(i); // get file from folder with index i
		if (f){ // if next file was found
			TString filename = f->GetName(); // get filename
			TString fn = filename;
			fn.Resize(filename.Length() - 4); // shorten filename by extension ".out"
			
			ULong64_t jobnumber;
			char logtype[64];
			double data[1024];
			
			if ((re.Index(filename, &n) == 0) && (sscanf(fn.Data(), "%Ld%s", &jobnumber, logtype) == 2)){ // if filename matches regular expression and contains jobnumber
				infile.open(filename.Data()); // open file
				TNtupleD *tree = (TNtupleD*)outfile->Get(logtype); // get corresponding tree from file
				
				if (!tree) { // if tree does not yet exist
					TString bdescriptor;
					bdescriptor.ReadLine(infile); // read branch descriptor from file header
					bdescriptor.ReplaceAll(" ",":"); // format branch descriptor for root ("x y z" -> "x:y:z")

					tree = new TNtupleD(logtype, logtype, bdescriptor.Data()); // create new tree with name logtype from filename 
					printf("%ss have %i columns\n", logtype, tree->GetNvar());
				}
				else
					infile.ignore(9999, '\n'); // if tree already exists skip file header

				n = tree->GetNvar(); // get number of file columns
				cout << "Adding " << filename << '\n';
				while (1){
					for (int j = 0; j < n; j++) infile >> data[j]; // read values into data array
					if (!infile) break; // if something happened during reading: stop
					tree->Fill(data); // fill data into tree
				}
				infile.close(); // close file
				cout << "Entries: " << tree->GetEntries() << '\n';
			}
		}
		else break;
Example #22
0
void ChannelConfig::read(ifstream &file)
{
    bool success =true;
    while (!file.eof())
    {
	TString lineIn;
        lineIn.ReadLine(file);
	if(lineIn[0] == '#')
	{
	    if(lineIn[1] == '#') //Reached end of channel
	        return;
	    continue;
	}

	//Have line with data to read in so get id
	TString id, result;
	Ssiz_t from = 0;
	lineIn.Tokenize(id, from, " +");
	lineIn.Tokenize(result, from, " +");

	if(id == "ENABLE_INPUT")
	{
	    if(result == "YES") enabled = true;
	    else if( result == "NO" ) enabled = false;
	    else success &= false;
	}

	if( id == "DC_OFFSET")
	{
	    DCOffset = result.Atof();
	}

	if( id == "TRIGGER_THRESHOLD" )
	{
	    triggerThreshold = result.Atoi();
	}

	if(id == "CHANNEL_TRIGGER" )
	{
	    if(result == "DISABLED") triggerSetting = DSBLD;
	    else if ( result == "ACQUISITION_ONLY" ) triggerSetting = ACQ;
	    else if ( result == "ACQUISITION_AND_TRGOUT" ) triggerSetting = ACQ_TRGOUT;
	    else success &= false;
	}

	if(!success)
	    throw std::runtime_error("file formatted incorrectly");
    }
}
Example #23
0
int main(int argc, char** argv) {

  gSystem->Exec("rm -rf baby.root");

  TString reader;
  ifstream fileList(argv[1]);
  
  TChain* ch = new TChain("Events");
  while (!fileList.eof()) {
    reader.ReadLine(fileList);
    ch->Add(reader);
  }
  ScanChain(ch, -1, argv[2]);
  return 0;
}
Example #24
0
//______________________________________________________________________________
TChain* CreateChainFromESDList(const char *esdList)
{
  // Create a chain using tags from the run list.
  TChain* chain = new TChain("esdTree");
  ifstream inFile(esdList);
  TString inFileName;
  if (inFile.is_open()) {
    while (! inFile.eof() ) {
      inFileName.ReadLine(inFile,kFALSE);
      if(!inFileName.EndsWith(".root")) continue;
      chain->Add(inFileName.Data());
    }
  }
  inFile.close();
  if (!chain->GetNtrees()) return NULL;
  chain->ls();
  return chain;
}
Example #25
0
  /** 
   * Get list of runs associated with production
   *  
   * @param url     The production URL 
   * @param mc      True of MC
   * @param minSize Least size of runs to use 
   * 
   * @return true on success
   */
  Bool_t GetRuns(const TString& url, Bool_t mc, ULong_t minSize)
  {
    TString index("job");
    if (!Download(Form("%s%s", (mc ? "" : "raw/"), url.Data()), index)) 
      return false;

    std::ifstream in(index.Data());
    TString tgt1(mc ? "window.open" : "runDetails");
    TString line  = "";
    do { 
      line.ReadLine(in);
      if (!line.Contains(tgt1)) continue;
      Int_t   first = -1;
      Int_t   last  = -1;
      if (!mc) { 
	first = line.Index(tgt1);
	last  = line.Index(")", first+tgt1.Length()+1);
      }
      else { 
	Int_t tmp = line.Index(">");
	first = line.Index(">", tmp+1);
	last  = line.Index("<", first);
      }
      if (first == kNPOS || last == kNPOS) { 
	Error("GetDir", "Failed to get directory from %s", line.Data());
	return false;
      }
      first += (mc ? 1 : tgt1.Length()+1);
      last  -= first;
      TString srun  = line(first, last);
      ULong_t runNo = srun.Atoll();
      if (fDebug) Info("", "Got run %lu (%s)", runNo, srun.Data());

      if (!GetSize(in, runNo, mc, minSize)) continue;
      if (!GetDir(in, runNo, mc))           continue;

      if (!fRuns.IsNull()) fRuns.Append(",");
      fRuns.Append(Form("%lu", runNo));
    } while (!in.eof());
    in.close();
    if (fRuns.IsNull()) return false;

    return true;
  }
Example #26
0
//------------------------------
void KVINDRADB_e475s::ReadPedestalList()
//------------------------------
{

   ifstream finput;
   if (!OpenCalibFile("Pedestals", finput)) {
      Error("ReadPedestalList()", "Could not open file %s",
            GetCalibFileName("Pedestals"));
      return;
   }
   
	Info("ReadPedestalList()",
        "Reading calibration parameters...");
	
	TString sline;
   TString stit;
	TObjArray *toks=NULL;
	while (finput.good()) {
		TString calib_det="",calib_acq="",calib_file="";
		sline.ReadLine(finput);
		if (!sline.IsNull()){
			cout << sline << endl;
			toks = sline.Tokenize(" ");
			if  (toks->GetEntries()>=1) {
				calib_file = ((TObjString*)(*toks)[0])->GetString();
				if (toks->GetEntries()>=2) {
					calib_det = ((TObjString*)(*toks)[1])->GetString();
					if (toks->GetEntries()>=3) {
						calib_acq = ((TObjString*)(*toks)[2])->GetString();
					}
				}
			}
			
			stit.Form("%s/%s",gDataSet->GetDataSetDir(),calib_file.Data());
			ifstream fin(stit.Data());
			ReadPedestalFile(fin,calib_det,calib_acq);
			fin.close();
   	}
	}
	finput.close();


}
Example #27
0
  /** 
   * Get a directory 
   * 
   * @param in    Input stream
   * @param runNo The run number 
   * @param mc    True for MC 
   * 
   * @return true on success 
   */
  Bool_t GetDir(std::istream& in, ULong_t runNo, Bool_t mc)
  {
    TString line;
    TString tgt3("/catalogue/index.jsp");
    do { 
      line.ReadLine(in);
      // Info("", "line=%s", line.Data());
      if (!line.Contains(tgt3)) continue;
      if (fDebug) Info("", line);
      Int_t tmp         = mc ? line.Index(">")+1 : 0;
      Int_t first       = line.Index(">", tmp);
      Int_t last        = line.Index("<",first+1);
      if (first == kNPOS || last == kNPOS) { 
	Error("GetDir", "Failed to get directory from %s", line.Data());
	return false;
      }
      
      TString dir = line(first+1,last-first-1);
	
      if (fDebug) Info("", "Got run %lu %s", runNo, dir.Data());
      TString path, pass;
      if (!GetPathPass(dir, runNo, path, pass)) return false;
      
      if (fDebug) Info("", "Got run %lu %s %s", runNo,path.Data(),pass.Data());

      if      (fPath.IsNull()) fPath = path;
      else if (!fPath.EqualTo(path)) { 
	Warning("GetDir", "Run %lu location %s not %s", 
	      runNo, path.Data(), fPath.Data());
	return false;
      }

      if      (fPass.IsNull()) fPass = pass;
      else if (!fPass.EqualTo(pass)) { 
	Warning("GetDir", "Run %lu pass %s not %s", 
	      runNo, pass.Data(), fPass.Data());
	return false;
      }
      break;
    } while (!in.eof());
    return true;
  }
//_____________________________________________________________________________
TChain *CreateAODFriendChain(TString sDataset)
{ 
  if (!sDataset.EndsWith(".txt")) return 0;

  TChain *chain = new TChain("aodTree");
  TChain *cFrid = new TChain("aodTree");

  TString dataFile;
  ifstream dataList(sDataset.Data(), ios::in); 
  while (!dataList.eof()) {
    dataFile.ReadLine(dataList,kFALSE);
    if (!dataFile.EndsWith("AliAOD.root")) continue;
    if (!gSystem->AccessPathName(dataFile.Data())) chain->Add(dataFile.Data());

    dataFile.ReplaceAll("AliAOD.root","AliAOD.VertexingHF.root");
    if (!gSystem->AccessPathName(dataFile.Data())) cFrid->Add(dataFile.Data());
  } dataList.close();

  chain->AddFriend(cFrid);
  return chain;
}
Example #29
0
/*inline TString gGet_InputFile_Var(const TString& aFile_Name,const Int_t& aLine){{{*/
inline TString gGet_InputFile_Var(const TString& aFile_Name,const Int_t& aLine)
{
	ifstream file(aFile_Name.Data());
	TString content;
	Int_t i=0;
	TString outstring;
	while ( content.ReadLine(file) )
	{
		if ( i==aLine )
		{
			outstring=content;
			break;
		}
		i++;
		if ( !file.good() )
			break;
	}
	file.close();
	if ( outstring=="\"\"" )
		outstring="";
	return outstring;
}
Example #30
0
//_____________________________________________________________________________
TChain *CreateChain(TString sData)
{
  TChain *chain = new TChain("nt");
//=============================================================================

  if (gSystem->AccessPathName(sData.Data())) {
    ::Error("RunAnalysis.C::CreateChain","Dataset %s does not exist!",sData.Data());
    return NULL;
  }
//=============================================================================

  TString sFile;
  ifstream dataList(sData.Data(), ios::in);
  while (!dataList.eof()) {
    sFile.ReadLine(dataList,kFALSE);
    if (!sFile.EndsWith(".root")) continue;
    if (!gSystem->AccessPathName(sFile.Data())) chain->Add(sFile.Data());
  } dataList.close();
//=============================================================================

  return chain;
}