Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AlephCardsReader.cpp

Go to the documentation of this file.
00001 
00002 // Implemenatation file for Class AlephCardsReader:
00003 // sets default values, reads cards file and holds the cards
00004 // to be updated whenever new card appears
00005 //
00006 // Author : G.Dissertori
00007 // 08.2001: modified by C.Delaere (new cards and rules)
00008 // 08.2002: FILO card
00009 //
00011 
00012 #include <iostream>
00013 
00014 #ifndef OS_NO_STD_NAMESPACE
00015   using namespace std;
00016 #endif
00017 #include <fstream>
00018 #include <vector>
00019 #include <stdlib.h>
00020 #include "AlephSession.h"
00021 #include "AlephCardsReader.h"
00022 #include "GetDefaultValue.h"
00023 
00024 extern int setenv(const char*, const char*, int);
00025 extern ofstream fout;
00026 
00027 // constructor : sets defaults and reads the cards
00028 AlephCardsReader::AlephCardsReader()
00029 {
00030   fout << endl;
00031   fout << " ======== AlephCardsReader constructor ======== " << endl;
00032   fout << endl;
00033   // the cards file is set by an environment variable
00034   char* CardsFile = getenv("ALPHAPP_CARDS");
00035   if (CardsFile == "") CardsFile = "cards.default";
00036   fout << " Cardsfile = " << CardsFile << endl << endl;
00037   // default setting;
00038   _Nevt.push_back(2000000000);
00039   string DefDbFile("defaultFile");
00040   string DefReadFile("mc94");
00041   vector<int> DefClass(1,-1);
00042   vector<string> readFiliFiles;
00043   vector<string> readDbFiles;
00044   vector<float> DefMuidCuts(5);
00045       DefMuidCuts[0] = 0.5;
00046       DefMuidCuts[1] = 1.;
00047       DefMuidCuts[2] = 4.;
00048       DefMuidCuts[3] = 0.95;
00049       DefMuidCuts[4] = 10.;
00050   vector<float> DefElidCuts(13);
00051       DefElidCuts[0] = 0.5;      DefElidCuts[7]  = -3.;
00052       DefElidCuts[1] = 1.;       DefElidCuts[8]  = -7.;
00053       DefElidCuts[2] = 4.;       DefElidCuts[9]  = -5.;
00054       DefElidCuts[3] = 0.95;     DefElidCuts[10] = 1000.;
00055       DefElidCuts[4] = 10.;      DefElidCuts[11] = 0.5;
00056       DefElidCuts[5] = 40.;      DefElidCuts[12] = 1000.;
00057       DefElidCuts[6] = 1000.;
00058   vector<float> DefTaidCuts(8);
00059       DefTaidCuts[0] = 0.01;     DefTaidCuts[4] = 2.;
00060       DefTaidCuts[1] = 1.;       DefTaidCuts[5] = 4.;
00061       DefTaidCuts[2] = 1.;       DefTaidCuts[6] = 0.95;
00062       DefTaidCuts[3] = 1.;       DefTaidCuts[7] = 10.;
00063   // read the cards  
00064   // database type
00065   string defDbType("epio");
00066   _DbType = GetDefaultValue(CardsFile,"DBTY",defDbType);
00067   fout << " DBTY " << _DbType << endl;
00068   // number of events
00069   _Nevt = GetDefaultValueVector(CardsFile,"NEVT",_Nevt);
00070   if(_Nevt.size()==2)
00071           fout << " NEVT " << _Nevt[0] << " - " << _Nevt[1] << endl;
00072   else if(_Nevt.size()==1)
00073         fout << " NEVT " << _Nevt[0] << endl;
00074   else cerr << " ERROR : AlephCardReader : no NEVT card. Should be a default value." << endl; 
00075   // Alpha FILI
00076   string defAlphaFili(" none ");
00077   _AlphaFili = GetFILIDefaultValues(CardsFile,"AFII ",defAlphaFili);
00078   for (vector<string>::iterator Ifile = _AlphaFili.begin(); 
00079                                 Ifile < _AlphaFili.end();   Ifile++ )
00080   {
00081         fout << " AFII '" << (*Ifile) << "'" << endl;
00082   }
00083   // Alpha SRUN
00084   vector<long> defAlphaSrun(0);
00085   int cnt = 0;
00086   _AlphaSrun = GetSRUNDefaultValues(CardsFile,"ASRU",defAlphaSrun);
00087   if (_AlphaSrun.size()!=0) fout << " ASRU ";
00088   for (vector<long>::iterator Iruns = _AlphaSrun.begin(); 
00089                               Iruns < _AlphaSrun.end();   Iruns++ )
00090   {
00091         cnt++;
00092         fout << (*Iruns) << " ";
00093         if((cnt%10)==0) fout << endl << "      ";
00094   }
00095   if(defAlphaSrun.size()) fout << endl;
00096   // Database files to analyze
00097   _DbFiles = GetManyDefaultValues(CardsFile,"FILI",DefDbFile);
00098   for (vector<string>::iterator Ifile = _DbFiles.begin(); 
00099                                 Ifile < _DbFiles.end();   Ifile++ )
00100   {
00101         fout << " FILI " << (*Ifile) << endl;
00102   }
00103   // Check if FILI files included via READ statement
00104   readFiliFiles = GetManyDefaultValues(CardsFile,"READ",DefReadFile);
00105   if (readFiliFiles.size() > 0)
00106     {
00107       // now loop over READ files and add in FILI statements
00108       for (vector<string>::iterator Irfile = readFiliFiles.begin(); 
00109            Irfile < readFiliFiles.end(); Irfile++ )
00110         {
00111           fout << " READ " << (*Irfile) << endl;
00112           readDbFiles = GetManyDefaultValues((*Irfile).c_str(),"FILI",DefDbFile);
00113           for (vector<string>::iterator IrFILI = readDbFiles.begin(); 
00114                IrFILI < readDbFiles.end(); IrFILI++ )
00115             {
00116               fout << " FILI " << (*IrFILI) << endl;
00117               _DbFiles.push_back(*IrFILI);
00118             }
00119         }
00120     }
00121   // class bits to use
00122   _Class = GetDefaultValueVector(CardsFile,"CLAS",DefClass);
00123   if(_Class.size()==1) if (_Class[0]==-1) _Class.resize(0);
00124   fout << " CLAS ";
00125   for (vector<int>::iterator Iclass = _Class.begin(); 
00126        Iclass < _Class.end(); Iclass++ )
00127     {
00128       fout << (*Iclass) << "  " ;
00129     }
00130   if(_Class.size()) fout << endl;
00131   // Random generator seed
00132   _Seed = GetDefaultValue(CardsFile,"SEED",_Seed);
00133   fout << " SEED " << _Seed << endl;
00134   // HIST
00135   string defHist("alpha++.hist");
00136   _Hist = GetDefaultValue(CardsFile,"HIST",defHist);
00137   fout << " HIST " << _Hist << endl;
00138   // transaction type
00139   string defTaType("read");
00140   _TaType = GetDefaultValue(CardsFile,"TATY",defTaType);
00141   fout << " TATY " << _TaType << endl;
00142   string defSeType("batch");
00143   _SeType = GetDefaultValue(CardsFile,"SETY",defSeType);
00144   fout << " SETY " << _SeType << endl;
00145   AlephSession::TheAlephSession()->setSessionType(_SeType);
00146   // alpha FILO
00147   string defAlphaFilo(" none ");
00148   _AlphaFilo = GetDefaultValue(CardsFile,"AFIO",defAlphaFilo);
00149   fout << " AFIO " << _AlphaFilo << endl;
00150   // alpha READ
00151   string defAlphaRead(" none ");
00152   _AlphaRead = GetManyDefaultValues(CardsFile,"AREA",defAlphaRead);
00153   for (vector<string>::iterator Ifile = _AlphaRead.begin(); 
00154        Ifile < _AlphaRead.end(); Ifile++ )
00155     {
00156       fout << " AREA " << (*Ifile) << endl;
00157     }
00158   // alpha cards file
00159   string defAlphaCard(" none ");
00160   _AlphaCard = GetDefaultValue(CardsFile,"ACAR",defAlphaCard);
00161   fout << " ACAR " << _AlphaCard << endl;
00162   // User defined cards
00163   _UserCards = GetUserDefaultValues(CardsFile,"USER",1.);
00164   fout << " USER ";
00165   for (vector<element>::const_iterator subcard = _UserCards.begin();
00166                                        subcard < _UserCards.end();
00167                                        subcard++)
00168    {
00169      fout << subcard->first << " : ";
00170      for(vector<double>::const_iterator value = subcard->second.begin();
00171                                         value < subcard->second.end();
00172                                         value ++)
00173         fout << (*value) << "  ";
00174      fout << endl << "      ";
00175    }
00176   fout << endl;
00177   // lepton id cuts to use
00178   _Muid = GetDefaultValueVector(CardsFile,"MUID",DefMuidCuts);
00179   fout << " MUID ";
00180   for (vector<float>::iterator Imuid = _Muid.begin(); 
00181        Imuid < _Muid.end(); Imuid++ )
00182     {
00183       fout << (*Imuid) << "  " ;
00184     }
00185   fout << endl;
00186   _Elid = GetDefaultValueVector(CardsFile,"ELID",DefElidCuts);
00187   fout << " ELID ";
00188   for (vector<float>::iterator Ielid = _Elid.begin(); 
00189        Ielid < _Elid.end(); Ielid++ )
00190     {
00191       fout << (*Ielid) << "  " ;
00192     }
00193   fout << endl;
00194   _Taid = GetDefaultValueVector(CardsFile,"TAID",DefTaidCuts);
00195   fout << " TAID ";
00196   for (vector<float>::iterator Itaid = _Taid.begin(); 
00197        Itaid < _Taid.end(); Itaid++ )
00198     {
00199       fout << (*Itaid) << "  " ;
00200     }
00201   fout << endl;
00202   // prepare the alpha cards if needed.
00203   if((_DbType=="epio")||(_DbType=="epio/root"))
00204       prepareAlphaCards();
00205   fout << endl;
00206   fout << " ======== End AlephCardsReader constructor ======== " << endl;
00207   fout << endl;
00208 }
00209 
00211 // methods : 
00213 
00214 // prepare the alpha cards
00215 void AlephCardsReader::prepareAlphaCards()
00216 {
00217   fout << " preparing alpha cards ... " << endl << endl;
00218   // if ACAR is present, uses it; otherwise uses empty file as basis 
00219   string alphaCardsFile("alpha_cards_tmp.cards");
00220   // create system rm command and remove existing file
00221   string rmcommand = "rm -f "+alphaCardsFile;
00222   system(rmcommand.c_str());
00223   if ((getDbType()    == "epio" || getDbType() == "epio/root" ) && 
00224       (getAlphaCard() != " none " ) )
00225     {
00226       string command = string("cp -f ")+getAlphaCard()+string(" ")+alphaCardsFile;
00227       system(command.c_str());
00228       fout << " using ACAR cards as basis for alpha_cards_tmp.cards... " << endl << endl;
00229     }
00230   // add other cards to the file
00231   ofstream Cout(alphaCardsFile.c_str(), ios::app);
00232   Cout << "*** temporary cards file : created by AlephCardsReader " << endl;
00233   Cout << endl;
00234   if(_Nevt.size()==2)
00235           Cout << "NEVT " << _Nevt[0] << " - " << _Nevt[1] << endl;
00236   else if(_Nevt.size()==1)
00237           Cout << "NEVT " << _Nevt[0] << endl << endl;
00238   else cerr << " ERROR : AlephCardReader : no NEVT card. Should be a default value." << endl;
00239   Cout << "CLAS ";
00240   for ( uint icl = 0; icl < getClass().size() ; icl++ )
00241   {
00242         Cout << getClass()[icl] << " ";
00243   }
00244   Cout << endl;
00245   if ((strrchr(getHist().c_str(),'.') == NULL)||(strcmp(strrchr(getHist().c_str(),'.'),".root")))
00246         Cout << "HIST '" << getHist() << "'" << endl << endl;
00247   if (((strrchr(getAlphaFilo().c_str(),'.') == NULL)||(strcmp(strrchr(getAlphaFilo().c_str(),'.'),".root")))&&(getAlphaFilo() != " none "))
00248         Cout << "FILO '" << getAlphaFilo() << "'" << endl << endl;
00249   Cout << "*** FILI ***" << endl;
00250   vector<string> filiVector = getAlphaFili();
00251   vector<string>::iterator fItr;
00252   for (fItr = filiVector.begin() ; fItr < filiVector.end(); fItr++ )
00253   {
00254         Cout << "FILI '" << (*fItr) << "'" << endl;
00255   }
00256   vector<string> readVector = getAlphaRead();
00257   vector<string>::iterator rItr;
00258   for (rItr = readVector.begin() ; rItr < readVector.end(); rItr++ )
00259   {
00260         Cout << "READ '" << (*rItr) << "'" << endl;
00261   }
00262   Cout << endl;
00263   vector<long> runsVector = getAlphaSrun();
00264   vector<long>::iterator runsItr;
00265   int cnt = 0;
00266   if (runsVector.size()!=0) Cout << "SRUN ";
00267   for (runsItr = runsVector.begin() ; runsItr < runsVector.end(); runsItr++ )
00268     {
00269             cnt++;
00270             Cout << (*runsItr) << " ";
00271             if ((cnt%10)==0) Cout << endl << "      ";
00272     }
00273   Cout << endl; 
00274   Cout << "*** Some default cards...." << endl;
00275   Cout << "EFLW" << endl;
00276   Cout << "BSIZ 0.0120 0.0007" << endl;
00277   Cout << "QFND" << endl;
00278   Cout << "DWIN 1 0.035" << endl;
00279   Cout << "NSEQ" << endl;
00280   Cout << "ENDQ" << endl;
00281   int set = setenv("ALPHACARDS",alphaCardsFile.c_str(),1);
00282 }
00283 
00284 // get the cards info
00285 
00286 vector<long>   AlephCardsReader::getNevt() const { return _Nevt; }
00287 vector<int>    AlephCardsReader::getClass() const { return _Class ; }
00288 vector<string> AlephCardsReader::getDbFiles() const { return _DbFiles; }
00289 string         AlephCardsReader::getDbType() const { return _DbType; }
00290 string         AlephCardsReader::getTaType() const { return _TaType; }
00291 string         AlephCardsReader::getSeType() const { return _SeType; }
00292 string         AlephCardsReader::getAlphaFilo() const { return _AlphaFilo; } 
00293 vector<string> AlephCardsReader::getAlphaFili() const { return _AlphaFili; }
00294 vector<string> AlephCardsReader::getAlphaRead() const { return _AlphaRead; }
00295 vector<long>   AlephCardsReader::getAlphaSrun() const { return _AlphaSrun; }
00296 string         AlephCardsReader::getAlphaCard() const { return _AlphaCard; } 
00297 string         AlephCardsReader::getHist() const { return _Hist; }
00298 unsigned long  AlephCardsReader::getSeed() const { return _Seed; }
00299 vector<element> AlephCardsReader::getUserCards() const { return _UserCards; }
00300 vector<float>  AlephCardsReader::MUIDcuts() const { return _Muid ; }
00301 vector<float>  AlephCardsReader::ELIDcuts() const { return _Elid ; }
00302 vector<float>  AlephCardsReader::TAIDcuts() const { return _Taid ; }
00303 

Generated at Wed Jun 18 17:19:09 2003 for ALPHA++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001