00001
00002
00003
00004
00005
00006
00007 #include "event/ChannelHit.hh"
00008 #include "event/Event.hh"
00009 #include "event/Run.hh"
00010 #include "geometry/Chip.hh"
00011 #include "geometry/Dif.hh"
00012 #include "geometry/Board.hh"
00013 #include "geometry/Chamber.hh"
00014 #include "geometry/Detector.hh"
00015 #include "geometry/Channel.hh"
00016
00017 #include "tools/MicroException.hh"
00018 #include "tools/Log.hh"
00019 #include "slowControl/SlowControlEntry.hh"
00020 #include "slowControl/ChamberSlowControl.hh"
00021
00022
00023 #include <string>
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 using namespace std;
00071
00072
00073 std::ostream& operator <<(std::ostream &out, const Event &x) {
00074 return(x.operator <<(out));
00075 }
00076
00077
00078 Event::Event(Run& aRun):run(aRun), slowControlEntry(NULL)
00079 {
00080
00081
00082 timestamp = 0;
00083 difSynchro = 0;
00084 id = 0;
00085 slowControlEntry = NULL;
00086 crcIsCorrect = true;
00087 valid = VALID;
00088 }
00089
00090 Event::Event(Run& aRun, i64 aTimestamp, i32 aId):run(aRun), timestamp(aTimestamp), id(aId), slowControlEntry(NULL)
00091 {
00092 timestamp = 0;
00093 difSynchro = 0;
00094 id = 0;
00095 slowControlEntry = NULL;
00096 crcIsCorrect = true;
00097 valid = VALID;
00098
00099 }
00100
00101 Event::~Event()
00102 {
00103
00104
00105 map<ui16, multiset<ChannelHit*,sorter>* >::iterator iter;
00106
00107 for (iter=channelHits.begin(); iter!=channelHits.end(); iter++)
00108 {
00109 multiset<ChannelHit*,sorter>* list = (*iter).second;
00110 for (multiset<ChannelHit*,sorter>::iterator iterList = list->begin(); iterList!=list->end(); iterList++ )
00111 {
00112 delete (*iterList);
00113 }
00114 delete list;
00115 }
00116
00117 }
00118
00119
00120 ostream& Event::operator <<(ostream &out) const {
00121 return(out << "-Event id["<< id << "]" << endl
00122 << "-Event timestamp[" << timestamp << "]" << endl);
00123 }
00124
00125
00126 void Event::initChannelHitVector()
00127 {
00128 ChamberMap_t chambers = this->run.getDetector().getChambers();
00129
00130 for (ChamberMap_t::iterator iter = chambers.begin() ; iter != chambers.end() ; iter++)
00131 {
00132 i32 chamberId = (*iter).first;
00133 multiset<ChannelHit*, sorter> *list = new multiset<ChannelHit*, sorter>();
00134 FILE_LOG(logINFO) << "INIT map size BEFORE INSERT:[" << channelHits.size() << "]" << endl;
00135 channelHits[chamberId] = list;
00136 FILE_LOG(logINFO) << "INIT map size AFTER INSERT:[" << channelHits.size() << "]" << endl;
00137 }
00138 }
00139
00140 const multiset<ChannelHit*,sorter>& Event::getChannelHitVector(const Chamber& aChamber) const
00141 {
00142
00143 map<ui16, multiset<ChannelHit*,sorter>* >::const_iterator iter = channelHits.find(aChamber.getId());
00144 if( iter != channelHits.end() ) {
00145 return (*iter->second);
00146 }
00147
00148 throw ( MicroException("No channelHit vector for this chamber"));
00149
00150 }
00151
00152 void Event::insertHit(Chamber& aChamber, ChannelHit *aChannelHit)
00153 {
00154 ui16 chamberId = aChamber.getId();
00155
00156 multiset<ChannelHit*,sorter>* hits = NULL;
00157
00158 map<ui16, multiset<ChannelHit*,sorter> *>::iterator iter = channelHits.find(chamberId);
00159
00160 if( iter == channelHits.end() ) {
00161 hits = new multiset<ChannelHit*, sorter>();
00162 channelHits.insert(pair<i32, multiset<ChannelHit*,sorter>* > (chamberId,hits));
00163 }
00164
00165 else
00166 {
00167 hits = iter->second;
00168 }
00169
00170 hits->insert(aChannelHit);
00171
00172
00173 }
00174
00175
00176 const ChannelHit& Event::getChannelHitByOrder( ui64 order ,const Chamber& aChamber, i16 aThreshold)
00177 {
00178 if ( getChannelHitByOrder(order+1,aChamber).getAnalogValue() <= aThreshold )
00179 {
00180 return getChannelHitByOrder(order,aChamber);
00181 }
00182 else
00183 {
00184 throw MicroException("No Channel respond for this event, this order, this threshold and this chamber ");
00185 }
00186 }
00187
00188
00189 const ChannelHit& Event::getChannelHitByOrder(ui64 order ,const Chamber& aChamber)
00190 {
00191 multiset<ChannelHit*,sorter>* chamberChannelHit = this->channelHits.find(aChamber.getId())->second;
00192 ui64 items=0;
00193
00194 for (multiset<ChannelHit*,sorter>::const_iterator iter=chamberChannelHit->begin(); iter!=chamberChannelHit->end(); iter++)
00195 {
00196 if ( (*iter)->getChannel().getChamber().getId() == aChamber.getId() )
00197 {
00198 if ( order == items)
00199 {
00200 return *(*iter);
00201 }
00202
00203 items++;
00204 }
00205
00206 }
00207 throw MicroException("No Channel respond or this event, this order and this chamber ");
00208
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 void Event::setSlowControlParam(const SlowControlEntry* params)
00237 {
00238 slowControlEntry = params;
00239 FILE_LOG(logDEBUG1) << "Event temperature["<< slowControlEntry->getTemperature() << "]" << endl;
00240 FILE_LOG(logDEBUG1) << "Event overPressure["<< slowControlEntry->getOverPressure() << "]" << endl;
00241 FILE_LOG(logDEBUG1) << "Event Pressure["<< slowControlEntry->getPressure() << "]" << endl;
00242 }
00243
00244
00245
00246 void Event::print(void) const
00247 {
00248 FILE_LOG(logINFO) << "-Event id["<< id << "]" << endl;
00249 FILE_LOG(logINFO) << "-Event timestamp[" << timestamp << "]" << endl ;
00250 }
00251
00252
00253 const float Event::getPressure() const
00254 {
00255 if ( slowControlEntry != NULL)
00256 {
00257 return slowControlEntry->getPressure();
00258 }
00259 else
00260 {
00261 return 0;
00262 }
00263
00264 }
00265
00266 const float Event::getTemperature() const
00267 {
00268 if ( slowControlEntry != NULL)
00269 {
00270 return slowControlEntry->getTemperature();
00271 }
00272 else
00273 {
00274 return 0;
00275 }
00276
00277 }
00278
00279 const BoardSlowControl& Event::getBoardSlowControl(const ui32 chamberId,const ui32 difId, const ui32 boardId) const
00280 {
00281 if ( slowControlEntry != NULL)
00282 {
00283 try
00284 {
00285 return slowControlEntry->getBoard(chamberId,difId,boardId);
00286 }
00287 catch ( MicroException e) {}
00288 }
00289
00290 throw MicroException("Event::getBoardSlowControl: board not found");
00291 }
00292
00293 const float Event::getBoardDriftVolt(const ui32 chamberId,const ui32 difId, const ui32 boardId) const
00294 {
00295 if ( slowControlEntry != NULL)
00296 {
00297 try
00298 {
00299 return slowControlEntry->getBoard(chamberId,difId,boardId).getDrift().voltage;
00300 }
00301 catch ( MicroException e) {}
00302 }
00303 throw MicroException("Event::getBoardSlowControl: board not found");
00304
00305 }
00306
00307 const float Event::getBoardMeshVolt(const ui32 chamberId,const ui32 difId, const ui32 boardId) const
00308 {
00309 if ( slowControlEntry != NULL)
00310 {
00311 try
00312 {
00313 return slowControlEntry->getBoard(chamberId,difId,boardId).getMesh().voltage;
00314 }
00315 catch ( MicroException e) {}
00316 }
00317
00318 return -1;
00319
00320 }
00321
00322 ui64 Event::getChannelHitSize() const
00323 {
00324 ui64 size = 0;
00325 for ( std::map<ui16, std::multiset<ChannelHit*,sorter>* >::const_iterator it=channelHits.begin(); it != channelHits.end() ; it++)
00326 {
00327 size +=it->second->size();
00328 }
00329 return size;
00330 }
00331
00332
00333 void Event::setTemperature(ui16 difId, float asu1, float asu2, float dif)
00334 {
00335
00336 if ( temperatureAsu1.find(difId) != temperatureAsu1.end())
00337 {
00338 temperatureAsu1[difId] = asu1;
00339 }
00340 else
00341 {
00342 temperatureAsu1.insert(make_pair(difId,asu1));
00343 }
00344
00345 if ( temperatureAsu2.find(difId) != temperatureAsu2.end())
00346 {
00347 temperatureAsu2[difId] = asu2;
00348 }
00349 else
00350 {
00351 temperatureAsu2.insert(make_pair(difId,asu2));
00352 }
00353
00354 if ( temperatureDif.find(difId) != temperatureDif.end())
00355 {
00356 temperatureDif[difId] = dif;
00357 }
00358 else
00359 {
00360 temperatureDif.insert(make_pair(difId,dif));
00361 }
00362
00363 }
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 bool Event::isValid(void)
00492 {
00493 if ( valid == VALID ) return true;
00494 return false;
00495 }