001
002
003
004
005
006
007
008
009
010
011
012
013
014 #include <string>
015 using std::string;
016 #include <string.h>
017
018
019
020
021 #include "Hepevt2HepgModule.hh"
022
023
024
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
039
040 #include "AbsEnv/AbsEnv.hh"
041
042 #include "stdhep_i/CdfHepevt.hh"
043
044
045
046
047
048
049 extern "C" {
050 int hepfil_(const char*,
051 int*,int*,int*,
052 int);
053 int hepred_(int*,int*);
054 int hepcls_(int*);
055 }
056
057
058
059
060
061 const char* Hepevt2HepgModule::genId="StdhepInput";
062
063
064
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
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
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
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
158 _events++;
159
160
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
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
188 }
189
190 _cdfhepevt->clear();
191
192
193 return 0;
194 }
195
196 void Hepevt2HepgModule::fillHepevt() {
197
198
199
200
201
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 }
Send problems or questions to cdfcode@fnal.gov