ROOT logo
//____________________________________________________________________
//
// $Id$
//
// Script to make a class derived from AliFMDMap. 
//
#ifndef __CINT__
#include <fstream>
#include <TString.h>
#include <TDatime.h>
#include <TSystem.h>
#include <iostream>
using namespace std;
#endif

void MakeMap(const Char_t* type="Int_t", const Char_t* name=0) 
{
  TString base;
  TString ttype(type);
  if (ttype.EndsWith("_t")) {
    Ssiz_t undert = ttype.Index("_t");
    ttype.Remove(undert);
  }
  if (!name) 
    base = Form("AliFMD%sMap", ttype.Data());
  else
    base = name;

  cout << "Base name is " << base << endl;
  
  TString decl_name(Form("%s.h", base.Data()));
  TString impl_name(Form("%s.cxx", base.Data()));
  ofstream decl(decl_name.Data());
  ofstream impl(impl_name.Data());

  if (!decl) {
    cerr << "Cannot open declaration file " << decl_name << endl;
    return;
  }
  if (!impl) {
    cerr << "Cannot open implementation file " << impl_name << endl;
    return;
  }
  
  TDatime now;
  cout << "The time is now " << now.AsString() << endl;
  UserGroup_t* uinfo = gSystem->GetUserInfo();
  TString     uname(uinfo->fRealName);
  Ssiz_t      comma = uname.Index(",");
  if (comma != kNPOS) uname.Remove(comma);
  cout << "User's name is " << uname << endl;
  TString guard(base);
  guard.Append("_h");
  guard.ToUpper();

  cout << "Writing declaration file " << decl_name << " ... " 
       << flush;
  decl << "#ifndef " << guard << "\n";
  decl << "#define " << guard << "\n";
  decl << "/* Copyright (c) " << now.GetYear() ;
  decl << ", ALICE Experiment @ CERN.\n" ;
  decl << " * All rights reserved\n";
  decl << " * See " << impl_name << " for full copyright notice\n";
  decl << " * \n" ;
  decl << " * Created " << now.AsString() << " by " << uname << "\n";
  decl << " */\n";
  decl << "/* $Id$ */\n";
  decl << "//__________________________________________________________\n";
  decl << "// \n";
  decl << "// Map of " << type << " for each FMD strip\n" ;
  decl << "// \n";
  decl << "#ifndef ALIFMDMAP_H\n";
  decl << "# include <AliFMDMap.h>\n";
  decl << "#endif\n\n";
  decl << "class " << base << " : public AliFMDMap\n";
  decl << "{\n";
  decl << "public:\n";
  decl << "  " << base << "(const " << base << "& other);\n";
  decl << "  " << base << "(size_t maxDet  = kMaxDetectors,\n";
  decl << "                 size_t maxRing = kMaxRings,\n";
  decl << "                 size_t maxSec  = kMaxSectors,\n";
  decl << "                 size_t maxStr  = kMaxStrips);\n";
  decl << "  virtual ~" << base << "() { delete [] fData; }\n";
  decl << "  " << base << "& operator=(const " << base << "& other);\n";
  decl << "  virtual void Clear(const " << type << "& v=" << type << "());\n";
  decl << "  virtual " << type << "& operator()(UShort_t det,\n";
  decl << "                                     Char_t   ring,\n";
  decl << "                                     UShort_t sec,\n";
  decl << "                                     UShort_t str);\n";
  decl << "  virtual const " << type << "& operator()(UShort_t det,\n";
  decl << "                                           Char_t   ring,\n";
  decl << "                                           UShort_t sec,\n";
  decl << "                                           UShort_t str) const;\n";
  decl << "protected:\n";
  decl << "  " << type << "* fData; // The Data\n";
  decl << "  ClassDef(" << base << ",1) // Map of " << type ;
  decl << " data per strip\n" ;
  decl << "};\n\n";
  decl << "#endif\n";
  decl << "//__________________________________________________________\n";
  decl << "// \n";
  decl << "// Local Variables:\n";
  decl << "//   mode: C++\n";
  decl << "// End:\n";
  decl << "//" << endl;;
  decl.close();
  cout << "done" << endl;

  cout << "Writing implementation file " << impl_name << " ... " 
       << flush;
  impl << "/**************************************************************\n";
  impl << " * Copyright(c) 1998-1999, ALICE Experiment at CERN.          *\n";
  impl << " * All rights reserved.                                       *\n";
  impl << " *                                                            *\n";
  impl << " * Author: The ALICE Off-line Project.                        *\n";
  impl << " * Contributors are mentioned in the code where appropriate.  *\n";
  impl << " *                                                            *\n";
  impl << " * Permission to use, copy, modify and distribute this        *\n";
  impl << " * software and its documentation strictly for non-commercial *\n";
  impl << " * purposes is hereby granted without fee, provided that the  *\n";
  impl << " * above copyright notice appears in all copies and that both *\n";
  impl << " * the copyright notice and this permission notice appear in  *\n";
  impl << " * the supporting documentation. The authors make no claims   *\n";
  impl << " * about the suitability of this software for any purpose. It *\n";
  impl << " * is provided \"as is\" without express or implied warranty.   *\n";
  impl << " **************************************************************/\n";
  impl << "/* $Id$ */\n";
  impl << "//__________________________________________________________\n";
  impl << "// \n";
  impl << "// Map of per strip " << type << " information\n";
  impl << "// \n";
  impl << "// Created " << now.AsString() << " by " << uname << "\n";
  impl << "// \n";
  impl << "#include \"" << decl_name << "\"\t//" << guard << "\n";
  impl << "//__________________________________________________________\n";
  impl << "ClassImp(" << base << ");\n";
  impl << "//__________________________________________________________\n";
  impl << base << "::" << base << "(const " << base << "& other)\n";
  impl << "  : AliFMDMap(other.fMaxDetectors,\n";
  impl << "              other.fMaxRings,\n";
  impl << "              other.fMaxSectors,\n";
  impl << "              other.fMaxStrips),\n";
  impl << "    fData(0)\n";
  impl << "{\n";
  impl << "  // Copy constructor\n";
  impl << "  fData = new " << type << "[fMaxDetectors * fMaxRings ";
  impl << "* fMaxSectors * fMaxStrips];\n" ;
  impl << "  for (size_t i = 0; i < fMaxDetectors * fMaxRings ";
  impl << "* fMaxSectors * fMaxStrips; i++)\n";
  impl << "    fData[i] = other.fData[i];\n";
  impl << "}\n\n";
  impl << "//__________________________________________________________\n";
  impl << base << "::" << base << "(size_t maxDet,\n";
  impl << "                         size_t maxRing,\n";
  impl << "                         size_t maxSec,\n";
  impl << "                         size_t maxStr)\n";
  impl << "  : AliFMDMap(maxDet, maxRing, maxSec, maxStr),\n";
  impl << "    fData(0)\n";
  impl << "{\n";
  impl << "  // Constructor.\n";
  impl << "  // Parameters:\n";
  impl << "  //\tmaxDet\tMaximum number of detectors\n";
  impl << "  //\tmaxRing\tMaximum number of rings per detector\n";
  impl << "  //\tmaxSec\tMaximum number of sectors per ring\n";
  impl << "  //\tmaxStr\tMaximum number of strips per sector\n";
  impl << "  fData = new " << type << "[fMaxDetectors * fMaxRings ";
  impl << "* fMaxSectors * fMaxStrips];\n" ;
  impl << "  Clear();\n";
  impl << "}\n\n";
  impl << "//__________________________________________________________\n";
  impl << base << "&\n";
  impl << base << "::operator=(const " << base << "& other)\n";
  impl << "{\n";
  impl << "  // Assignment operator \n";
  impl << "  fMaxDetectors = other.fMaxDetectors;\n";
  impl << "  fMaxRings     = other.fMaxRings;\n";
  impl << "  fMaxSectors   = other.fMaxSectors;\n";
  impl << "  fMaxStrips    = other.fMaxStrips;\n";
  impl << "  if (fData) delete [] fData;\n";
  impl << "  fData = new " << type << "[fMaxDetectors * fMaxRings ";
  impl << "* fMaxSectors * fMaxStrips];\n" ;
  impl << "  for (size_t i = 0; i < fMaxDetectors * fMaxRings ";
  impl << "* fMaxSectors * fMaxStrips; i++)\n";
  impl << "    fData[i] = other.fData[i];\n";
  impl << "}\n\n"    ;
  impl << "//__________________________________________________________\n";
  impl << "void\n";
  impl << base << "::Clear(const " << type << "& val)\n";
  impl << "{\n";
  impl << "  // Reset map to val\n";
  impl << "  for (size_t i = 0; i < fMaxDetectors * fMaxRings ";
  impl << "* fMaxSectors * fMaxStrips; i++)\n";
  impl << "    fData[i] = val;\n";
  impl << "}\n\n"    ;
  impl << "//__________________________________________________________\n";
  impl << type << "&\n";
  impl << base << "::operator()(UShort_t det, Char_t ring, UShort_t sec, " ;
  impl << "UShort_t str)\n" ;
  impl << "{\n" ;
  impl << "  // Get data\n";
  impl << "  // Parameters:\n";
  impl << "  //\tdet\tDetector #\n";
  impl << "  //\tring\tRing ID\n";
  impl << "  //\tsec\tSector #\n";
  impl << "  //\tstr\tStrip #\n" ;
  impl << "  // Returns appropriate data\n";
  impl << "  return fData[CalcIndex(det, ring, sec, str)];\n";
  impl << "}\n\n";
  impl << "//__________________________________________________________\n";
  impl << "const " << type << "&\n";
  impl << base << "::operator()(UShort_t det, Char_t ring, UShort_t sec, " ;
  impl << "UShort_t str) const\n" ;
  impl << "{\n" ;
  impl << "  // Get data\n";
  impl << "  // Parameters:\n";
  impl << "  //\tdet\tDetector #\n";
  impl << "  //\tring\tRing ID\n";
  impl << "  //\tsec\tSector #\n";
  impl << "  //\tstr\tStrip #\n" ;
  impl << "  // Returns appropriate data\n";
  impl << "  return fData[CalcIndex(det, ring, sec, str)];\n";
  impl << "}\n\n";
  impl << "//__________________________________________________________\n";
  impl << "// \n";
  impl << "// EOF\n";
  impl << "// \n";
  impl << endl;
  impl.close();
  cout << "done" << endl;
}

  


#ifndef __CINT__
int main() 
{
  makemap();
  return 0;
}
#endif

//____________________________________________________________________
//
// EOF
//
 MakeMap.C:1
 MakeMap.C:2
 MakeMap.C:3
 MakeMap.C:4
 MakeMap.C:5
 MakeMap.C:6
 MakeMap.C:7
 MakeMap.C:8
 MakeMap.C:9
 MakeMap.C:10
 MakeMap.C:11
 MakeMap.C:12
 MakeMap.C:13
 MakeMap.C:14
 MakeMap.C:15
 MakeMap.C:16
 MakeMap.C:17
 MakeMap.C:18
 MakeMap.C:19
 MakeMap.C:20
 MakeMap.C:21
 MakeMap.C:22
 MakeMap.C:23
 MakeMap.C:24
 MakeMap.C:25
 MakeMap.C:26
 MakeMap.C:27
 MakeMap.C:28
 MakeMap.C:29
 MakeMap.C:30
 MakeMap.C:31
 MakeMap.C:32
 MakeMap.C:33
 MakeMap.C:34
 MakeMap.C:35
 MakeMap.C:36
 MakeMap.C:37
 MakeMap.C:38
 MakeMap.C:39
 MakeMap.C:40
 MakeMap.C:41
 MakeMap.C:42
 MakeMap.C:43
 MakeMap.C:44
 MakeMap.C:45
 MakeMap.C:46
 MakeMap.C:47
 MakeMap.C:48
 MakeMap.C:49
 MakeMap.C:50
 MakeMap.C:51
 MakeMap.C:52
 MakeMap.C:53
 MakeMap.C:54
 MakeMap.C:55
 MakeMap.C:56
 MakeMap.C:57
 MakeMap.C:58
 MakeMap.C:59
 MakeMap.C:60
 MakeMap.C:61
 MakeMap.C:62
 MakeMap.C:63
 MakeMap.C:64
 MakeMap.C:65
 MakeMap.C:66
 MakeMap.C:67
 MakeMap.C:68
 MakeMap.C:69
 MakeMap.C:70
 MakeMap.C:71
 MakeMap.C:72
 MakeMap.C:73
 MakeMap.C:74
 MakeMap.C:75
 MakeMap.C:76
 MakeMap.C:77
 MakeMap.C:78
 MakeMap.C:79
 MakeMap.C:80
 MakeMap.C:81
 MakeMap.C:82
 MakeMap.C:83
 MakeMap.C:84
 MakeMap.C:85
 MakeMap.C:86
 MakeMap.C:87
 MakeMap.C:88
 MakeMap.C:89
 MakeMap.C:90
 MakeMap.C:91
 MakeMap.C:92
 MakeMap.C:93
 MakeMap.C:94
 MakeMap.C:95
 MakeMap.C:96
 MakeMap.C:97
 MakeMap.C:98
 MakeMap.C:99
 MakeMap.C:100
 MakeMap.C:101
 MakeMap.C:102
 MakeMap.C:103
 MakeMap.C:104
 MakeMap.C:105
 MakeMap.C:106
 MakeMap.C:107
 MakeMap.C:108
 MakeMap.C:109
 MakeMap.C:110
 MakeMap.C:111
 MakeMap.C:112
 MakeMap.C:113
 MakeMap.C:114
 MakeMap.C:115
 MakeMap.C:116
 MakeMap.C:117
 MakeMap.C:118
 MakeMap.C:119
 MakeMap.C:120
 MakeMap.C:121
 MakeMap.C:122
 MakeMap.C:123
 MakeMap.C:124
 MakeMap.C:125
 MakeMap.C:126
 MakeMap.C:127
 MakeMap.C:128
 MakeMap.C:129
 MakeMap.C:130
 MakeMap.C:131
 MakeMap.C:132
 MakeMap.C:133
 MakeMap.C:134
 MakeMap.C:135
 MakeMap.C:136
 MakeMap.C:137
 MakeMap.C:138
 MakeMap.C:139
 MakeMap.C:140
 MakeMap.C:141
 MakeMap.C:142
 MakeMap.C:143
 MakeMap.C:144
 MakeMap.C:145
 MakeMap.C:146
 MakeMap.C:147
 MakeMap.C:148
 MakeMap.C:149
 MakeMap.C:150
 MakeMap.C:151
 MakeMap.C:152
 MakeMap.C:153
 MakeMap.C:154
 MakeMap.C:155
 MakeMap.C:156
 MakeMap.C:157
 MakeMap.C:158
 MakeMap.C:159
 MakeMap.C:160
 MakeMap.C:161
 MakeMap.C:162
 MakeMap.C:163
 MakeMap.C:164
 MakeMap.C:165
 MakeMap.C:166
 MakeMap.C:167
 MakeMap.C:168
 MakeMap.C:169
 MakeMap.C:170
 MakeMap.C:171
 MakeMap.C:172
 MakeMap.C:173
 MakeMap.C:174
 MakeMap.C:175
 MakeMap.C:176
 MakeMap.C:177
 MakeMap.C:178
 MakeMap.C:179
 MakeMap.C:180
 MakeMap.C:181
 MakeMap.C:182
 MakeMap.C:183
 MakeMap.C:184
 MakeMap.C:185
 MakeMap.C:186
 MakeMap.C:187
 MakeMap.C:188
 MakeMap.C:189
 MakeMap.C:190
 MakeMap.C:191
 MakeMap.C:192
 MakeMap.C:193
 MakeMap.C:194
 MakeMap.C:195
 MakeMap.C:196
 MakeMap.C:197
 MakeMap.C:198
 MakeMap.C:199
 MakeMap.C:200
 MakeMap.C:201
 MakeMap.C:202
 MakeMap.C:203
 MakeMap.C:204
 MakeMap.C:205
 MakeMap.C:206
 MakeMap.C:207
 MakeMap.C:208
 MakeMap.C:209
 MakeMap.C:210
 MakeMap.C:211
 MakeMap.C:212
 MakeMap.C:213
 MakeMap.C:214
 MakeMap.C:215
 MakeMap.C:216
 MakeMap.C:217
 MakeMap.C:218
 MakeMap.C:219
 MakeMap.C:220
 MakeMap.C:221
 MakeMap.C:222
 MakeMap.C:223
 MakeMap.C:224
 MakeMap.C:225
 MakeMap.C:226
 MakeMap.C:227
 MakeMap.C:228
 MakeMap.C:229
 MakeMap.C:230
 MakeMap.C:231
 MakeMap.C:232
 MakeMap.C:233
 MakeMap.C:234
 MakeMap.C:235
 MakeMap.C:236
 MakeMap.C:237
 MakeMap.C:238
 MakeMap.C:239
 MakeMap.C:240
 MakeMap.C:241
 MakeMap.C:242
 MakeMap.C:243
 MakeMap.C:244
 MakeMap.C:245
 MakeMap.C:246
 MakeMap.C:247