CDF II
CDF KITS
source navigation ]
diff markup ]
identifier search ]
freetext search ]
file search ]
 
Architecture: i386 ]
Version: 4.10.4 ] [ 4.10.5 ] [ 4.8.4 ] [ 4.8.4l3s ] [ 4.8.5 ] [ 4.9.0 ] [ 4.9.1 ] [ 4.9.1.hpt3 ] [ 4.9.1hpt3 ] [ 4.9.1top1 ] [ 5.0.0 ] [ 5.1.0 ] [ 5.1.0beamonly ] [ 5.1.1 ] [ 5.2.0 ] [ 5.3.0 ] [ 5.3.1 ] [ 5.3.1dsp ] [ 5.3.3 ] [ 5.3.3_nt ] [ 5.3.4 ] [ 6.1.1 ] [ 6.1.1b ] [ 6.1.2 ] [ 6.1.3 ] [ 6.1.4 ] [ 6.1.4int3 ] [ 6.1.4mc ] [ 6.1.4mc_a ] [ 6.1.6 ] [ development ]

001 //------------------------------------------------------------------------
002 // Description:
003 //      Class Hepevt2HepgModule
004 //
005 // this module fills /HEPEVT/ from binary/ascii file and
006 // and writes HEPG bank from /HEPEVT/ common block in an STDHEP file
007 //
008 //  Sebastian Carron (Duke),Elena Gershtein (CMU), Stan Thompson (Glascow)
009 //------------------------------------------------------------------------
010 
011 
012 // String Header First  --
013 //------------------------
014 #include <string>
015 using std::string;
016 #include <string.h>
017 
018 //-----------------------
019 // This Class's Header --
020 //-----------------------
021 #include "Hepevt2HepgModule.hh"
022 
023 //---------------
024 // C++ Headers -- MUST use defects !!!!
025 //---------------
026 #include <iostream>
027 #include <fstream>
028 #include <iomanip>
029 using std::cout;
030 using std::endl;
031 using std::setw;
032 #include "Edm/Handle.hh"
033 #include "Edm/ConstHandle.hh"
034 #include "Edm/EventRecord.hh"
035 #include "SimulationObjects/HEPG_StorableBank.hh"
036 
037 //-------------------------------
038 // Collaborating Class Headers --
039 //-------------------------------
040 #include "AbsEnv/AbsEnv.hh"
041 
042 #include "stdhep_i/CdfHepevt.hh"
043 
044 
045 
046 //------------------------------------------
047 // Fortran routines called from this code --
048 //--------------------------------------------
049 extern "C" {
050   int hepfil_(const char*,
051               int*,int*,int*,
052                int); // lengths of character strings (value, not reference)  
053   int hepred_(int*,int*);
054   int hepcls_(int*);
055 }
056 
057 //-----------------------------------------------------------------------
058 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
059 //-----------------------------------------------------------------------
060 
061 const char* Hepevt2HepgModule::genId="StdhepInput";
062 
063 //----------------
064 // Constructors --
065 //----------------
066 
067 Hepevt2HepgModule::Hepevt2HepgModule() : 
068   AbsGenModule( Hepevt2HepgModule::genId, 
069                 "AC++ Stdhep Input module"),
070   _stdhepFile("StdhepFile",this,""),
071 
072   _firstlistevent("Listfirst",    this, 1),
073   _lastlistevent ("Listlast",    this, 1),
074   _eventlistlevel("Evlistlevel",    this, 1),
075   _initlistlevel("Inlistlevel",    this, 11)
076 {
077   
078   _firstlistevent.addDescription(
079   "      \t\t\tFirst event to list");  
080   _lastlistevent.addDescription(
081   "      \t\t\tLast event to list");  
082   _eventlistlevel.addDescription(
083   "      \t\t\tEvent listing level");  
084   _initlistlevel.addDescription(
085   "      \t\t\tLevel of Particle information to be given at run start"); 
086   _stdhepFile.addDescription(
087   "      \t\t\tFile containing events consisting of dump of  HEPEVT common"); 
088   commands()->append(&_firstlistevent);
089   commands()->append(&_lastlistevent);
090   commands()->append(&_eventlistlevel);
091   commands()->append(&_initlistlevel);
092   commands()->append(&_stdhepFile); 
093 }
094 
095 //--------------
096 // Destructor --
097 //--------------
098 
099 Hepevt2HepgModule::~Hepevt2HepgModule()
100 {
101 }
102 
103 AppResult Hepevt2HepgModule::genBeginRun(AbsEvent* aRun) {
104   return AppResult::OK;
105 }
106 
107 AppResult Hepevt2HepgModule::genBeginJob() {
108 
109   // Get the Input file:
110   const string& fileName = _stdhepFile.value();
111   if (fileName.empty()) {
112       ERRLOG(ELfatal,"Hepevt2HepgModule: No file specified")
113         << "@SUB=genBeginJob:No filename given"
114         << endmsg;
115       return AppResult::ERROR;}
116    else {
117       _istr=11;
118       _events = _firstlistevent.value();
119       _endoffile=0;
120       if (hepfil_(fileName.c_str(),&_istr,&_events,&_endoffile,fileName.size())) 
121         {if(_endoffile==1)
122           {ofstream out("endfile", std::ios::out | std::ios::binary);
123            out.put((char) 1);
124            out.close();
125            ERRLOG(ELfatal,"Hepevt2Hepg error: STDHEP file has fewer events than your initial event number!!!. endfile file has been created.")
126            << "@SUB=genBeginJob" << endmsg;
127            return AppResult::ERROR;
128           }   
129          ERRLOG(ELfatal,"Hepevt2Hepg error reading file")
130           << "@SUB=genBeginJob" << endmsg;
131          return AppResult::ERROR;
132       }
133   }
134   return AppResult::OK;
135 }
136 
137 int Hepevt2HepgModule::callGenerator(AbsEvent* anEvent) {
138 
139 
140    CdfHepevt* _cdfhepevt = CdfHepevt::Instance();
141 
142   // Read the file
143    _endoffile=0;
144   if(hepred_(&_istr,&_endoffile)) {
145         ERRLOG(ELabort,":StdhepInput Module:******* Error reading file: Bad Event!!***************")
146           <<"@SUB=callGenerator"<< endmsg;
147       return 1;
148   }
149   if(_endoffile==1)
150     {ofstream out("endfile", std::ios::out | std::ios::binary);
151      out.put((char) 1);
152      out.close();
153      ERRLOG(ELabort,":StdhepInput Module: YOU HAVE REACHED THE END OF THE FILE, CORE DUMP WILL HAPPEN BUT YOUR OUTPUT WILL BE FINE - endfile file has been created")
154     <<"@SUB=callGenerator"<<endmsg;
155     return 1;
156    }
157   // Update our event counter 
158   _events++;
159   //_cdfhepevt->common2list();
160   // See if we are supposed to list this event  
161   int mevlist=_eventlistlevel.value();
162   if ( (_events >= _firstlistevent.value() && 
163        _events <= _lastlistevent.value()) || !(_events%100)) {
164     cout << " StdHep event no. " << _events << endl;   
165   }
166    for ( std::list<Hepevt*>::iterator i =_cdfhepevt->contentHepevt().begin();
167          i !=  _cdfhepevt->contentHepevt().end(); i++ ) {
168 
169      // make HEPG from hepevt;
170      HEPG_StorableBank* hepg = (*i)->makeHEPG(anEvent);
171      if (!hepg || hepg->is_invalid()) {
172        ERRLOG(ELsevere2,"[GEN_BAD_HEPG]")
173          << "Hepevt2HepgModule: can't create a valid "
174          << "HEPG_StorableBank"
175          << endmsg;
176          return AppResult::OK;
177      }
178      Handle<HEPG_StorableBank> h(hepg);
179      if ((anEvent->append(h)).is_null()) {
180        ERRLOG(ELsevere2,"[GEN_BAD_HEPG]")
181          << "Hepevt2HepgModule: can't add"
182          << "HEPG_StorableBank to the event."
183          << endmsg;
184        return AppResult::OK;
185      }
186 
187      //_cdfhepevt->clearCommon(); // overkill...
188    }
189 
190    _cdfhepevt->clear();
191    //_cdfhepevt->clearCommon();
192 
193   return 0;
194 }
195 
196 void Hepevt2HepgModule::fillHepevt() {
197   //  doesn't do much HEPEVT is already filled
198   //CdfHepevt* cdfhepevt = CdfHepevt::Instance();
199   //Hepevt_t* hepevt = cdfhepevt->hepevtprt();
200   //hepevt->NEVHEP = _events; // manually set event counter
201   //cdfhepevt->common2list(); 
202   _hepevt.nevhep()=_events;  
203 }
204 
205 AppResult Hepevt2HepgModule::genEndRun(AbsEvent* aRun) {
206 
207   hepcls_(&_istr);
208 
209   return AppResult::OK;
210 }
211 
212 AppResult Hepevt2HepgModule::genEndJob() {
213 
214   hepcls_(&_istr);
215 
216   return AppResult::OK;
217 }

source navigation ] diff markup ] identifier search ] freetext search ] file search ]

This page was automatically generated by the LXR engine.
The LXR team
Valid HTML 4.01!

Send problems or questions to cdfcode@fnal.gov