void KVDP2toCsIGridConvertor::ReadGammaFile(const Char_t* gammafile)
{
   ifstream gamfile;
   gamfile.open(gammafile);

   if (!gamfile.good()) {
      Error(KV__ERROR(ReadGammaFile),
            "Problem reading file %s", gammafile);
      return;
   }
   KVString s;

   s.ReadLine(gamfile);

   while (gamfile.good()) {

      if (s == "") {
         s.ReadLine(gamfile);
         continue;
      }

      if (!s.BeginsWith('#')) { //'#' sign signals comments
         int ring, modu, frun, lrun;
         if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) !=
               4) {
            Error(KV__ERROR(ReadGammaFile), "Problem reading file %s\nLast line read: %s",
                  gammafile, s.Data());
            return;
         };
         //get grid for this ring,mod
         TString name;
         name.
         Form
         ("CsI R-L Grid First run=%d Last run=%d Ring min=%d Ring max=%d Mod min=%d Mod max=%d",
          frun, lrun, ring, ring, modu, modu);
         KVIDGrid* grid = (KVIDGrid*)fGrids->FindObject(name.Data());
         if (!grid) {
            Error(KV__ERROR(ReadGammaFile), "Can't find grid %s", name.Data());
         }
         int npoints;
         gamfile >> npoints;
         //found gamma line
         KVIDLine* line = 0;
         if (grid) {
            line = grid->NewLine("ok");
            line->SetName("gamma_line");
            line->Set(npoints);
            grid->Add("ok", line);
         }
         //read in points
         for (int i = 0; i < npoints; i++) {
            Double_t x, y;
            gamfile >> x >> y;
            if (grid)
               line->SetPoint(i, x, y);
         }
      }
      s.ReadLine(gamfile);
   }
Пример #2
0
void KVINDRA::SetPinLasersForCsI()
{
   // Sets the KVCsI::fPinLaser member of each CsI detector with the number of the
   // pin laser associated for the stability control of these detectors.
   //
   // We look for a file with the following format:
   //
   // CSI_0101     1
   // CSI_0102     1
   // CSI_0103     1
   // CSI_0104     1
   // etc.
   //
   // i.e. 'name of CsI detector'   'number of pin laser (1-8)'
   // Comment lines must begin with '#'
   //
   // The default name of this file is defined in .kvrootrc by
   //
   // INDRADB.CsIPinCorr:          CsI_PILA.dat
   //
   // Dataset-specific version can be specified:
   //
   // INDRA_e999.INDRADB.CsIPinCorr:    CorrCsIPin_2054.dat
   //
   // This file should be in the directory corresponding to the current dataset,
   // i.e. in $KVROOT/KVFiles/name_of_dataset

   ifstream pila_file;
   if (gDataSet->OpenDataSetFile(gDataSet->GetDataSetEnv("INDRADB.CsIPinCorr", ""), pila_file)) {

      Info("SetPinLasersForCsI", "Setting correspondance CsI-PinLaser using file %s.",
           gDataSet->GetDataSetEnv("INDRADB.CsIPinCorr", ""));
      // read file, set correspondance
      KVString line;
      line.ReadLine(pila_file);
      while (pila_file.good()) {
         if (!line.BeginsWith("#")) {
            line.Begin(" ");
            KVString detname = line.Next(kTRUE);
            KVCsI* det = (KVCsI*)GetDetector(detname.Data());
            Int_t pila = line.Next(kTRUE).Atoi();
            if (det) {
               det->SetPinLaser(pila);
            }
         }
         line.ReadLine(pila_file);
      }
      pila_file.close();
   }
   else {
      Info("SetPinLasersForCsI", "File %s not found. Correspondance Csi-PinLaser is unknown.",
           gDataSet->GetDataSetEnv("CsIPinCorr", ""));
   }
}
Пример #3
0
void KVINDRAPulserDataTree::ReadFile(ifstream& fin)
{
	// Read data in one file

	KVString line;
	line.ReadLine(fin);
	while( fin.good() ){
		if( !line.BeginsWith("#") ){
			line.Begin(" ");
			KVString br_name = line.Next(kTRUE);
			Int_t index = GetIndex(br_name.Data());
			fVal[index] = line.Next(kTRUE).Atof();
		}
		line.ReadLine(fin);
	}
	fin.close();
}
Пример #4
0
void KVTGIDGrid::ReadFromAsciiFile(ifstream& gridfile)
{
   // Read grid and parameters of LTG fit used to generate grid in gridfile.
   KVIDGraph::ReadFromAsciiFile(gridfile);
   KVString line;
   if (fPar->GetIntValue("HasTGID")) {
      line.ReadLine(gridfile);
      if (line.BeginsWith("++KVTGID"))  fTGID = KVTGID::ReadFromAsciiFile(GetName(), gridfile);
   }
   FindAxisLimits();
}
void KVDP2toIDGridConvertor::ReadFile(const Char_t* filename)
{
   // Read grids in file and add to fGrids list

   if (!fGridClass) {
      Error(KV__ERROR(ReadFile),
            "Set class of ID grids to generate first!");
      return;
   }

   ifstream datfile;
   datfile.open(filename);

   if (!datfile.good()) {
      Error(KV__ERROR(ReadFile),
            "Problem reading file %s", filename);
      return;
   }
   KVString s;

   s.ReadLine(datfile);

   while (datfile.good()) {

      if (s == "") {
         s.ReadLine(datfile);
         continue;
      }

      if (!s.BeginsWith('#')) { //'#' sign signals comments
         int ring, modu, frun, lrun, totpoints;
         if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) !=
               4) {
            Error(KV__ERROR(ReadFile), "Problem reading file %s\nLast line read: %s",
                  filename, s.Data());
            return;
         };
         KVIDGrid* grid = (KVIDGrid*) fGridClass->New(); //create new grid

         //add to list of grids
         fGrids->Add(grid);

         grid->GetParameters()->SetValue("First run", frun);
         grid->GetParameters()->SetValue("Last run", lrun);
         grid->GetParameters()->SetValue("Ring min", ring);
         grid->GetParameters()->SetValue("Ring max", ring);
         grid->GetParameters()->SetValue("Mod min", modu);
         grid->GetParameters()->SetValue("Mod max", modu);
         int nlines;
         datfile >> nlines;
         totpoints = 0;
         //read Z,A and number of points in each line
         for (int i = 0; i < nlines; i++) {
            int z, a, npoints;
            datfile >> z >> a >> npoints;
            totpoints += 2 * npoints;
            if (z > 0) {
               //identification line
               KVIDLine* line = (KVIDLine*)grid->NewLine("id");
               line->SetZ(z);
               line->SetA(a);
               line->Set(npoints);
               grid->Add("id", line);
            }
            else {
               //"ok" line
               KVIDLine* line = (KVIDLine*)grid->NewLine("ok");
               line->Set(npoints);
               grid->Add("ok", line);
            }
         }
         ReadLineCoords(grid, datfile);
         //calculate line widths in grid
         grid->CalculateLineWidths();
      }
      s.ReadLine(datfile);
   }
Пример #6
0
Bool_t KVRemoteDataSetManager::OpenAvailableDatasetsFile()
{
   //Transfers file $KVROOT/KVFiles/[repository name].available.datasets
   //from remote machine containing info on available datasets and
   //associated subdirectories in remote data repository.
   //Copies to local working directory and opens for reading, if all goes
   //well (returns kTRUE).
   //Returns kFALSE in case of problems.
   //
   //N.B. If 'curl' is used to transfer the file, we check for HTML code in the file
   //It can happen that 'curl' itself does not give an error when the web server
   //is down, but transfers a file which looks like this:
// <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
// <html><head>
// <title>403 Forbidden</title>
// </head><body>
// <h1>Forbidden</h1>
// <p>You don't have permission to access /KaliVedaDoc/ccali.available.datasets
// on this server.</p>
// <p>Additionally, a 403 Forbidden
// error was encountered while trying to use an ErrorDocument to handle the request.</p>
// <hr>
// <address>Apache/2.0.53 (Unix) mod_ssl/2.0.53 OpenSSL/0.9.7a DAV/2 PHP/5.1.6 mod_python/3.2.8 Python/2.4.2 mod_jk/1.2.15 mod_perl/2.0.2 Perl/v5.8.7 Server at indra.in2p3.fr Port 80</address>
// </body></html>
   

   TString http =
       gEnv->GetValue(Form("%s.DataRepository.RemoteAvailableRuns.url",
                           fRepository->GetName()), "");
   if (http == "") {
      Warning("OpenAvailableDatasetsFile()",
              "%s.DataRepository.RemoteAvailableRuns.url is not defined. See $KVROOT/KVFiles/.kvrootrc",
              fRepository->GetName());
      return kFALSE;
   }
   TString url;
   url.Form("%s/%s", http.Data(), fCacheFileName.Data());
   
   //Find executable 'curl' or programme indicated by
   //value of DataRepository.RemoteAvailableRuns.protocol
   fCurl = gEnv->GetValue(Form
                          ("%s.DataRepository.RemoteAvailableRuns.protocol",
                           fRepository->GetName()), "curl");
   if(!KVBase::FindExecutable(fCurl)){
      Error("OpenAvailableDatasetsFile",
            "Executable for file transfer \"%s\" not found. You cannot use remote data repository.",
            fCurl.Data());
      return kFALSE;
   }
   TString cmd;
   cmd.Form("%s -oremote.available.datasets %s", fCurl.Data(), url.Data());
   if (gSystem->Exec(cmd.Data()))
      return kFALSE;            // problem with curl
   fDatasets.open("remote.available.datasets");
   if( fCurl.Contains("curl") ){
      //check contents of file for HTML code
      KVString line; line.ReadLine( fDatasets );
      if( line.Contains("<") ){
         Error("OpenAvailableDatasetsFile",
               "Remote available datasets file transferred by curl contains HTML code :");
         //print contents of file
         cout << line.Data() << endl;
         line.ReadLine( fDatasets );
         while( fDatasets.good() ){
            cout << line.Data() << endl;
            line.ReadLine( fDatasets );
         }
         Error("OpenAvailableDatasetsFile",
               "You cannot use this remote data repository");
         return kFALSE;
      }
      else   // no HTML in file : OK
      {
         //reset stream to beginning of file
         fDatasets.clear();         // clear any error flags (EOF etc.)
         fDatasets.seekg(0, ios::beg);      // set file buffer pointer to beginning of file
      }
   }
   return kTRUE;
}
Пример #7
0
KVTGID* KVTGID::ReadFromAsciiFile(const Char_t* name, ifstream & gridfile)
{
    // Read parameters of LTG fit in file (which must have been written with
    // current version of KVTGID::WriteToAsciiFile)

    KVTGID* LTGfit=0;
    Int_t Ftyp, Flite, FZorA, Fmass;
    FZorA=Fmass=Ftyp=Flite=0;

    KVString line;
    line.ReadLine(gridfile);
    TString buff= GetValue(line,'=');
    Ftyp = buff.Atoi();
    line.ReadLine(gridfile);
    buff = GetValue(line,'=');
    Flite = buff.Atoi();
    line.ReadLine(gridfile);
    buff = GetValue(line,'=');
    FZorA =buff.Atoi();
    if (FZorA)
    {
        line.ReadLine(gridfile);
        buff = GetValue(line,'=');
        Fmass = buff.Atoi();
    }

    LTGfit = MakeTGID(name,Ftyp,Flite,FZorA,Fmass);

    line.ReadLine(gridfile); // skip "Functional=" line : name of functional not used
    line.ReadLine(gridfile);
    LTGfit->SetValidRuns( KVNumberList(GetValue(line, '=').Data()) );
    line.ReadLine(gridfile);
    LTGfit->SetStringTelescopes( GetValue(line,'=') );
    line.ReadLine(gridfile);
	line.Remove(0,6);
	line.Remove(KVString::kBoth,' ');
    LTGfit->SetVarX(line.Data());
    line.ReadLine(gridfile);
	line.Remove(0,6);
	line.Remove(KVString::kBoth,' ');
    LTGfit->SetVarY(line.Data());
    line.ReadLine(gridfile);
    Int_t zmin,zmax;
    sscanf(line.Data(), "ZMIN=%d ZMAX=%d", &zmin, &zmax);
    LTGfit->SetIDmin(zmin);
    LTGfit->SetIDmax(zmax);
    Bool_t type1 = (Ftyp==1);
    line.ReadLine(gridfile);
    buff = GetValue(line,'=');
    LTGfit->SetLambda( buff.Atof() );
    if (type1){
        line.ReadLine(gridfile);
        buff = GetValue(line,'=');
        LTGfit->SetAlpha( buff.Atof() );
        line.ReadLine(gridfile);
        buff = GetValue(line,'=');
        LTGfit->SetBeta( buff.Atof() );
    }
    line.ReadLine(gridfile);
    buff = GetValue(line,'=');
    LTGfit->SetMu( buff.Atof() );
    if (type1){
        line.ReadLine(gridfile);
        buff = GetValue(line,'=');
        LTGfit->SetNu( buff.Atof() );
        line.ReadLine(gridfile);
        buff = GetValue(line,'=');
        LTGfit->SetXi( buff.Atof() );
    }
    line.ReadLine(gridfile);
    buff = GetValue(line,'=');
    LTGfit->SetG( buff.Atof() );
    line.ReadLine(gridfile);
    buff = GetValue(line,'=');
    LTGfit->SetPdx( buff.Atof() );
    line.ReadLine(gridfile);
    buff = GetValue(line,'=');
    LTGfit->SetPdy( buff.Atof() );
    if (Flite==1){
        line.ReadLine(gridfile);
        buff = GetValue(line,'=');
        LTGfit->SetEta( buff.Atof() );
    }
    line.ReadLine(gridfile);
    return LTGfit;
}
Пример #8
0
void KVRangeYanez::ReadPredefinedMaterials(const Char_t* filename)
{
   // Read materials from file whose name is given

   TString DataFilePath = filename;

   ifstream filestream;
   if (!SearchAndOpenKVFile(DataFilePath, filestream, "data")) {
      Error("ReadPredefinedMaterials", "Cannot open %s for reading", DataFilePath.Data());
      return;
   }
   Info("ReadPredefinedMaterials", "Reading materials in file : %s", filename);

   Bool_t compound, mixture;
   compound = mixture = kFALSE;

   KVString line;
   while (filestream.good()) {
      line.ReadLine(filestream);
      if (filestream.good()) {
         if (line.BeginsWith("//")) continue;
         if (line.BeginsWith("COMPOUND")) {
            compound = kTRUE;
            mixture = kFALSE;
         } else if (line.BeginsWith("MIXTURE")) {
            compound = kFALSE;
            mixture = kTRUE;
         }
         if (compound || mixture) {
            // new compound or mixed material
            KVString name, symbol, state;
            Double_t density = -1;
            KVString element[10];
            Int_t natoms[10];
            Int_t z[10], a[10];
            Double_t proportion[10];
            Int_t nelem = 0;
            line.ReadLine(filestream);
            while (filestream.good() && !line.IsWhitespace() && line != "\n") {
               line.Begin("=");
               KVString next = line.Next();
               if (next == "name") name = line.Next();
               else if (next == "symbol") symbol = line.Next();
               else if (next == "state") state = line.Next();
               else if (next == "density") density = line.Next().Atof();
               else if (next == "nelem") {
                  nelem = line.Next().Atoi();
                  for (int i = 0; i < nelem; i++) {
                     line.ReadLine(filestream);
                     line.Begin(" ");
                     element[i] = line.Next();
                     a[i] = KVNucleus::IsMassGiven(element[i]);
                     KVNucleus n(element[i]);
                     z[i] = n.GetZ();
                     if (!a[i]) a[i] = TMath::Nint(n.GetNaturalA());
                     natoms[i] = line.Next().Atoi();
                     if (mixture) proportion[i] = line.Next().Atof();
                  }
               }
               line.ReadLine(filestream, kFALSE); //do not skip 'whitespace'
            }
            if (compound) AddCompoundMaterial(name, symbol, nelem, z, a, natoms, density);
            else if (mixture) AddMixedMaterial(name, symbol, nelem, z, a, natoms, proportion, density);
            compound = mixture = kFALSE;
         }
      }
   }
}