File indexing completed on 2025-02-22 10:33:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef INCLUDE_EICSMEAR_ERHIC_FILE_H_
0011 #define INCLUDE_EICSMEAR_ERHIC_FILE_H_
0012
0013 #include <iostream>
0014 #include <map>
0015 #include <string>
0016
0017 #include <TObject.h>
0018 #include <TObjString.h>
0019 #include <TString.h>
0020
0021 #include "eicsmear/erhic/EventBase.h"
0022 #include "eicsmear/erhic/EventHepMC.h"
0023 #include "eicsmear/erhic/EventMilou.h"
0024 #include "eicsmear/erhic/EventPythia.h"
0025 #include "eicsmear/erhic/EventFactory.h"
0026
0027 namespace erhic {
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 class LogReader : public TObject {
0038 public:
0039
0040
0041
0042 LogReader() { }
0043
0044
0045
0046
0047 virtual ~LogReader() { }
0048
0049
0050
0051
0052 virtual LogReader* Create() const = 0;
0053
0054
0055
0056
0057 virtual bool Extract(const std::string& file) = 0;
0058
0059
0060
0061
0062
0063
0064
0065 virtual Int_t Save() const = 0;
0066
0067 ClassDef(erhic::LogReader, 1)
0068 };
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 class LogReaderPythia : public LogReader {
0079 public:
0080
0081
0082
0083 LogReaderPythia();
0084
0085
0086
0087
0088 virtual ~LogReaderPythia();
0089
0090
0091
0092
0093 LogReaderPythia* Create() const;
0094
0095
0096
0097
0098 bool Extract(const std::string& file);
0099
0100
0101
0102
0103
0104
0105 Int_t Save() const;
0106
0107 protected:
0108 TObjString crossSection_;
0109 TObjString nEvents_;
0110 TObjString nTrials_;
0111
0112 ClassDef(erhic::LogReaderPythia, 2)
0113 };
0114
0115 inline LogReaderPythia* LogReaderPythia::Create() const {
0116 return new LogReaderPythia;
0117 }
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 class LogReaderPepsi : public LogReader {
0128 public:
0129
0130
0131
0132 LogReaderPepsi();
0133
0134
0135
0136
0137 virtual ~LogReaderPepsi();
0138
0139
0140
0141
0142 LogReaderPepsi* Create() const;
0143
0144
0145
0146
0147 bool Extract(const std::string& file);
0148
0149
0150
0151
0152
0153
0154 Int_t Save() const;
0155
0156 protected:
0157 TObjString crossSection_;
0158 TObjString nEvents_;
0159 TObjString nTrials_;
0160
0161 ClassDef(erhic::LogReaderPepsi, 2)
0162 };
0163
0164 inline LogReaderPepsi* LogReaderPepsi::Create() const {
0165 return new LogReaderPepsi;
0166 }
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 class LogReaderDjangoh : public LogReader {
0177 public:
0178
0179
0180
0181 LogReaderDjangoh();
0182
0183
0184
0185
0186 virtual ~LogReaderDjangoh();
0187
0188
0189
0190
0191 LogReaderDjangoh* Create() const;
0192
0193
0194
0195
0196 bool Extract(const std::string& file);
0197
0198
0199
0200
0201
0202
0203 Int_t Save() const;
0204
0205 protected:
0206 TObjString crossSection_;
0207 TObjString nEvents_;
0208 TObjString nTrials_;
0209
0210 ClassDef(erhic::LogReaderDjangoh, 2)
0211 };
0212
0213 inline LogReaderDjangoh* LogReaderDjangoh::Create() const {
0214 return new LogReaderDjangoh;
0215 }
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225 class LogReaderMilou : public LogReader {
0226 public:
0227
0228
0229
0230 LogReaderMilou() { }
0231
0232
0233
0234
0235 virtual ~LogReaderMilou() { }
0236
0237
0238
0239
0240 LogReaderMilou* Create() const;
0241
0242
0243
0244
0245 bool Extract(const std::string& file);
0246
0247
0248
0249
0250
0251
0252 Int_t Save() const;
0253
0254
0255
0256
0257
0258 Int_t GetNEvents() const;
0259
0260
0261
0262
0263
0264 Double_t GetCrossSection() const;
0265
0266
0267
0268
0269
0270 Double_t GetCrossSectionError() const;
0271
0272 protected:
0273 TObjString crossSection_;
0274 TObjString crossSectionError_;
0275 TObjString nEvents_;
0276
0277 ClassDef(erhic::LogReaderMilou, 1)
0278 };
0279
0280 inline LogReaderMilou* LogReaderMilou::Create() const {
0281 return new LogReaderMilou;
0282 }
0283
0284 inline Int_t LogReaderMilou::GetNEvents() const {
0285 return nEvents_.GetString().Atoi();
0286 }
0287
0288 inline Double_t LogReaderMilou::GetCrossSection() const {
0289 return crossSection_.GetString().Atof();
0290 }
0291
0292
0293
0294
0295
0296 inline Double_t LogReaderMilou::GetCrossSectionError() const {
0297 return crossSectionError_.GetString().Atof();
0298 }
0299
0300
0301
0302
0303
0304
0305
0306 class LogReaderGmcTrans : public LogReader {
0307 public:
0308
0309
0310
0311 LogReaderGmcTrans();
0312
0313
0314
0315
0316 virtual ~LogReaderGmcTrans();
0317
0318
0319
0320
0321 LogReaderGmcTrans* Create() const;
0322
0323
0324
0325
0326
0327
0328 bool Extract(const std::string& filename);
0329
0330
0331
0332
0333
0334
0335
0336 Int_t Save() const;
0337
0338
0339
0340
0341
0342 Int_t GetNEvents() const;
0343
0344
0345
0346
0347
0348 Double_t GetCrossSection() const;
0349
0350 protected:
0351 TObjString mNEvents;
0352 TObjString mCrossSection;
0353
0354 ClassDef(erhic::LogReaderGmcTrans, 1)
0355 };
0356
0357
0358
0359
0360
0361
0362
0363
0364 class LogReaderFactory {
0365 public:
0366
0367
0368
0369 static LogReaderFactory& GetInstance();
0370
0371
0372
0373
0374
0375
0376
0377 LogReader* CreateReader(const EventBase& event) const;
0378
0379
0380
0381
0382
0383
0384
0385 LogReader* CreateReader(const std::string& name) const;
0386
0387
0388
0389
0390
0391
0392
0393
0394 LogReader* CreateReader(std::istream&) const;
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404 std::string Locate(const std::string& mcFile) const;
0405
0406 protected:
0407
0408
0409
0410 LogReaderFactory();
0411
0412
0413
0414
0415 ~LogReaderFactory();
0416
0417 typedef std::map<std::string, LogReader*> Map;
0418 Map prototypes_;
0419
0420 ClassDef(erhic::LogReaderFactory, 1)
0421 };
0422
0423
0424
0425
0426
0427
0428 class FileType : public TObject {
0429 public:
0430
0431
0432
0433 virtual ~FileType() { }
0434
0435
0436
0437
0438 virtual FileType* Create() const = 0;
0439
0440
0441
0442
0443 virtual EventBase* AllocateEvent() const = 0;
0444
0445
0446
0447
0448
0449 virtual std::string GetGeneratorName() const;
0450
0451
0452
0453
0454
0455 virtual void SetGeneratorName(const std::string newname="");
0456
0457
0458
0459
0460 virtual LogReader* CreateLogReader() const = 0;
0461
0462
0463
0464
0465 virtual VirtualEventFactory* CreateEventFactory(std::istream&) const = 0;
0466
0467 protected:
0468 std::string generatorname;
0469
0470 ClassDef(erhic::FileType, 2)
0471 };
0472
0473
0474
0475
0476
0477 template<typename T>
0478 class File : public FileType {
0479 public:
0480
0481
0482
0483
0484
0485
0486 File();
0487
0488
0489
0490
0491 virtual ~File();
0492
0493
0494
0495
0496 virtual File<T>* Create() const;
0497
0498
0499
0500
0501 virtual T* AllocateEvent() const;
0502
0503
0504
0505
0506
0507
0508
0509 virtual LogReader* CreateLogReader() const;
0510
0511
0512
0513
0514 virtual EventFromAsciiFactory<T>*
0515 CreateEventFactory(std::istream& is) const {
0516 return new EventFromAsciiFactory<T>(is);
0517 }
0518
0519 protected:
0520 T* t_;
0521
0522
0523
0524 ClassDef(File, 2)
0525 };
0526
0527 template<>
0528 class File<erhic::EventHepMC> : public FileType {
0529 public:
0530
0531
0532
0533
0534
0535
0536
0537 File(){}
0538
0539
0540
0541
0542 virtual ~File(){}
0543
0544
0545
0546
0547 virtual File<erhic::EventHepMC>* Create() const {
0548 return new File<erhic::EventHepMC>();
0549 }
0550
0551
0552
0553
0554 virtual erhic::EventHepMC* AllocateEvent() const {
0555 return new erhic::EventHepMC();
0556 }
0557
0558
0559
0560
0561
0562
0563
0564 virtual LogReader* CreateLogReader() const {return nullptr;}
0565
0566 EventFromAsciiFactory<erhic::EventHepMC>* CreateEventFactory(std::istream& is) const {
0567 return new EventFromAsciiFactory<erhic::EventHepMC>(is);}
0568 protected:
0569 erhic::EventHepMC* t_;
0570
0571 ClassDef(File<erhic::EventHepMC>, 1)
0572 };
0573
0574 template<typename T>
0575 inline T* File<T>::AllocateEvent() const {
0576 return new T;
0577 }
0578
0579 template<typename T>
0580 inline File<T>* File<T>::Create() const {
0581 return new File<T>();
0582 }
0583
0584
0585
0586
0587
0588
0589 class FileFactory {
0590 public:
0591
0592
0593
0594 static FileFactory& GetInstance();
0595
0596
0597
0598
0599 const FileType* GetFile(const std::string& generatorName) const;
0600
0601
0602
0603
0604
0605 const FileType* GetFile(std::shared_ptr<std::istream>& isp, const std::string fileName="") const;
0606
0607 protected:
0608
0609
0610
0611 FileFactory();
0612
0613
0614
0615
0616 virtual ~FileFactory();
0617
0618 typedef std::map<std::string, FileType*> Map;
0619 Map prototypes_;
0620 };
0621
0622 }
0623
0624 #endif