scripts/MakeMap.C

Go to the documentation of this file.
00001 //____________________________________________________________________
00002 //
00003 // $Id: MakeMap.C,v 1.3 2006/03/17 11:42:24 cholm Exp $
00004 //
00005 // Script to make a class derived from AliFMDMap. 
00006 //
00007 #ifndef __CINT__
00008 #include <fstream>
00009 #include <TString.h>
00010 #include <TDatime.h>
00011 #include <TSystem.h>
00012 #include <iostream>
00013 using namespace std;
00014 #endif
00015 
00016 void MakeMap(const Char_t* type="Int_t", const Char_t* name=0) 
00017 {
00018   TString base;
00019   TString ttype(type);
00020   if (ttype.EndsWith("_t")) {
00021     Ssiz_t undert = ttype.Index("_t");
00022     ttype.Remove(undert);
00023   }
00024   if (!name) 
00025     base = Form("AliFMD%sMap", ttype.Data());
00026   else
00027     base = name;
00028 
00029   cout << "Base name is " << base << endl;
00030   
00031   TString decl_name(Form("%s.h", base.Data()));
00032   TString impl_name(Form("%s.cxx", base.Data()));
00033   ofstream decl(decl_name.Data());
00034   ofstream impl(impl_name.Data());
00035 
00036   if (!decl) {
00037     cerr << "Cannot open declaration file " << decl_name << endl;
00038     return;
00039   }
00040   if (!impl) {
00041     cerr << "Cannot open implementation file " << impl_name << endl;
00042     return;
00043   }
00044   
00045   TDatime now;
00046   cout << "The time is now " << now.AsString() << endl;
00047   UserGroup_t* uinfo = gSystem->GetUserInfo();
00048   TString     uname(uinfo->fRealName);
00049   Ssiz_t      comma = uname.Index(",");
00050   if (comma != kNPOS) uname.Remove(comma);
00051   cout << "User's name is " << uname << endl;
00052   TString guard(base);
00053   guard.Append("_h");
00054   guard.ToUpper();
00055 
00056   cout << "Writing declaration file " << decl_name << " ... " 
00057        << flush;
00058   decl << "#ifndef " << guard << "\n";
00059   decl << "#define " << guard << "\n";
00060   decl << "/* Copyright (c) " << now.GetYear() ;
00061   decl << ", ALICE Experiment @ CERN.\n" ;
00062   decl << " * All rights reserved\n";
00063   decl << " * See " << impl_name << " for full copyright notice\n";
00064   decl << " * \n" ;
00065   decl << " * Created " << now.AsString() << " by " << uname << "\n";
00066   decl << " */\n";
00067   decl << "/* $Id: MakeMap.C,v 1.3 2006/03/17 11:42:24 cholm Exp $ */\n";
00068   decl << "//__________________________________________________________\n";
00069   decl << "// \n";
00070   decl << "// Map of " << type << " for each FMD strip\n" ;
00071   decl << "// \n";
00072   decl << "#ifndef ALIFMDMAP_H\n";
00073   decl << "# include <AliFMDMap.h>\n";
00074   decl << "#endif\n\n";
00075   decl << "class " << base << " : public AliFMDMap\n";
00076   decl << "{\n";
00077   decl << "public:\n";
00078   decl << "  " << base << "(const " << base << "& other);\n";
00079   decl << "  " << base << "(size_t maxDet  = kMaxDetectors,\n";
00080   decl << "                 size_t maxRing = kMaxRings,\n";
00081   decl << "                 size_t maxSec  = kMaxSectors,\n";
00082   decl << "                 size_t maxStr  = kMaxStrips);\n";
00083   decl << "  virtual ~" << base << "() { delete [] fData; }\n";
00084   decl << "  " << base << "& operator=(const " << base << "& other);\n";
00085   decl << "  virtual void Clear(const " << type << "& v=" << type << "());\n";
00086   decl << "  virtual " << type << "& operator()(UShort_t det,\n";
00087   decl << "                                     Char_t   ring,\n";
00088   decl << "                                     UShort_t sec,\n";
00089   decl << "                                     UShort_t str);\n";
00090   decl << "  virtual const " << type << "& operator()(UShort_t det,\n";
00091   decl << "                                           Char_t   ring,\n";
00092   decl << "                                           UShort_t sec,\n";
00093   decl << "                                           UShort_t str) const;\n";
00094   decl << "protected:\n";
00095   decl << "  " << type << "* fData; // The Data\n";
00096   decl << "  ClassDef(" << base << ",1) // Map of " << type ;
00097   decl << " data per strip\n" ;
00098   decl << "};\n\n";
00099   decl << "#endif\n";
00100   decl << "//__________________________________________________________\n";
00101   decl << "// \n";
00102   decl << "// Local Variables:\n";
00103   decl << "//   mode: C++\n";
00104   decl << "// End:\n";
00105   decl << "//" << endl;;
00106   decl.close();
00107   cout << "done" << endl;
00108 
00109   cout << "Writing implementation file " << impl_name << " ... " 
00110        << flush;
00111   impl << "/**************************************************************\n";
00112   impl << " * Copyright(c) 1998-1999, ALICE Experiment at CERN.          *\n";
00113   impl << " * All rights reserved.                                       *\n";
00114   impl << " *                                                            *\n";
00115   impl << " * Author: The ALICE Off-line Project.                        *\n";
00116   impl << " * Contributors are mentioned in the code where appropriate.  *\n";
00117   impl << " *                                                            *\n";
00118   impl << " * Permission to use, copy, modify and distribute this        *\n";
00119   impl << " * software and its documentation strictly for non-commercial *\n";
00120   impl << " * purposes is hereby granted without fee, provided that the  *\n";
00121   impl << " * above copyright notice appears in all copies and that both *\n";
00122   impl << " * the copyright notice and this permission notice appear in  *\n";
00123   impl << " * the supporting documentation. The authors make no claims   *\n";
00124   impl << " * about the suitability of this software for any purpose. It *\n";
00125   impl << " * is provided \"as is\" without express or implied warranty.   *\n";
00126   impl << " **************************************************************/\n";
00127   impl << "/* $Id: MakeMap.C,v 1.3 2006/03/17 11:42:24 cholm Exp $ */\n";
00128   impl << "//__________________________________________________________\n";
00129   impl << "// \n";
00130   impl << "// Map of per strip " << type << " information\n";
00131   impl << "// \n";
00132   impl << "// Created " << now.AsString() << " by " << uname << "\n";
00133   impl << "// \n";
00134   impl << "#include \"" << decl_name << "\"\t//" << guard << "\n";
00135   impl << "//__________________________________________________________\n";
00136   impl << "ClassImp(" << base << ");\n";
00137   impl << "//__________________________________________________________\n";
00138   impl << base << "::" << base << "(const " << base << "& other)\n";
00139   impl << "  : AliFMDMap(other.fMaxDetectors,\n";
00140   impl << "              other.fMaxRings,\n";
00141   impl << "              other.fMaxSectors,\n";
00142   impl << "              other.fMaxStrips),\n";
00143   impl << "    fData(0)\n";
00144   impl << "{\n";
00145   impl << "  // Copy constructor\n";
00146   impl << "  fData = new " << type << "[fMaxDetectors * fMaxRings ";
00147   impl << "* fMaxSectors * fMaxStrips];\n" ;
00148   impl << "  for (size_t i = 0; i < fMaxDetectors * fMaxRings ";
00149   impl << "* fMaxSectors * fMaxStrips; i++)\n";
00150   impl << "    fData[i] = other.fData[i];\n";
00151   impl << "}\n\n";
00152   impl << "//__________________________________________________________\n";
00153   impl << base << "::" << base << "(size_t maxDet,\n";
00154   impl << "                         size_t maxRing,\n";
00155   impl << "                         size_t maxSec,\n";
00156   impl << "                         size_t maxStr)\n";
00157   impl << "  : AliFMDMap(maxDet, maxRing, maxSec, maxStr),\n";
00158   impl << "    fData(0)\n";
00159   impl << "{\n";
00160   impl << "  // Constructor.\n";
00161   impl << "  // Parameters:\n";
00162   impl << "  //\tmaxDet\tMaximum number of detectors\n";
00163   impl << "  //\tmaxRing\tMaximum number of rings per detector\n";
00164   impl << "  //\tmaxSec\tMaximum number of sectors per ring\n";
00165   impl << "  //\tmaxStr\tMaximum number of strips per sector\n";
00166   impl << "  fData = new " << type << "[fMaxDetectors * fMaxRings ";
00167   impl << "* fMaxSectors * fMaxStrips];\n" ;
00168   impl << "  Clear();\n";
00169   impl << "}\n\n";
00170   impl << "//__________________________________________________________\n";
00171   impl << base << "&\n";
00172   impl << base << "::operator=(const " << base << "& other)\n";
00173   impl << "{\n";
00174   impl << "  // Assignment operator \n";
00175   impl << "  fMaxDetectors = other.fMaxDetectors;\n";
00176   impl << "  fMaxRings     = other.fMaxRings;\n";
00177   impl << "  fMaxSectors   = other.fMaxSectors;\n";
00178   impl << "  fMaxStrips    = other.fMaxStrips;\n";
00179   impl << "  if (fData) delete [] fData;\n";
00180   impl << "  fData = new " << type << "[fMaxDetectors * fMaxRings ";
00181   impl << "* fMaxSectors * fMaxStrips];\n" ;
00182   impl << "  for (size_t i = 0; i < fMaxDetectors * fMaxRings ";
00183   impl << "* fMaxSectors * fMaxStrips; i++)\n";
00184   impl << "    fData[i] = other.fData[i];\n";
00185   impl << "}\n\n"    ;
00186   impl << "//__________________________________________________________\n";
00187   impl << "void\n";
00188   impl << base << "::Clear(const " << type << "& val)\n";
00189   impl << "{\n";
00190   impl << "  // Reset map to val\n";
00191   impl << "  for (size_t i = 0; i < fMaxDetectors * fMaxRings ";
00192   impl << "* fMaxSectors * fMaxStrips; i++)\n";
00193   impl << "    fData[i] = val;\n";
00194   impl << "}\n\n"    ;
00195   impl << "//__________________________________________________________\n";
00196   impl << type << "&\n";
00197   impl << base << "::operator()(UShort_t det, Char_t ring, UShort_t sec, " ;
00198   impl << "UShort_t str)\n" ;
00199   impl << "{\n" ;
00200   impl << "  // Get data\n";
00201   impl << "  // Parameters:\n";
00202   impl << "  //\tdet\tDetector #\n";
00203   impl << "  //\tring\tRing ID\n";
00204   impl << "  //\tsec\tSector #\n";
00205   impl << "  //\tstr\tStrip #\n" ;
00206   impl << "  // Returns appropriate data\n";
00207   impl << "  return fData[CalcIndex(det, ring, sec, str)];\n";
00208   impl << "}\n\n";
00209   impl << "//__________________________________________________________\n";
00210   impl << "const " << type << "&\n";
00211   impl << base << "::operator()(UShort_t det, Char_t ring, UShort_t sec, " ;
00212   impl << "UShort_t str) const\n" ;
00213   impl << "{\n" ;
00214   impl << "  // Get data\n";
00215   impl << "  // Parameters:\n";
00216   impl << "  //\tdet\tDetector #\n";
00217   impl << "  //\tring\tRing ID\n";
00218   impl << "  //\tsec\tSector #\n";
00219   impl << "  //\tstr\tStrip #\n" ;
00220   impl << "  // Returns appropriate data\n";
00221   impl << "  return fData[CalcIndex(det, ring, sec, str)];\n";
00222   impl << "}\n\n";
00223   impl << "//__________________________________________________________\n";
00224   impl << "// \n";
00225   impl << "// EOF\n";
00226   impl << "// \n";
00227   impl << endl;
00228   impl.close();
00229   cout << "done" << endl;
00230 }
00231 
00232   
00233 
00234 
00235 #ifndef __CINT__
00236 int main() 
00237 {
00238   makemap();
00239   return 0;
00240 }
00241 #endif
00242 
00243 //____________________________________________________________________
00244 //
00245 // EOF
00246 //

Generated on Fri Mar 24 17:11:21 2006 for ALICE FMD Off-line by  doxygen 1.4.6