Fork me on GitHub

source: svn/trunk/Utilities/FROG/Includes/FROG/FROG_Element_Event.h@ 238

Last change on this file since 238 was 95, checked in by severine ovyn, 16 years ago

first commit frog

File size: 3.4 KB
Line 
1// FROG_Events.h: interface for the FROG_Events class.
2//
3//////////////////////////////////////////////////////////////////////
4
5#ifndef _FROG_ELEMENT_EVENTS_H__
6#define _FROG_ELEMENT_EVENTS_H__
7
8#include <algorithm>
9#include <iostream>
10#include <vector>
11#include <map>
12#include <time.h>
13
14#include "FROG_Chunk.h"
15#include "FROG_Element_Base_With_DetId.h"
16
17class FROG_Element_Event : public FROG_Element_Base {
18private :
19 long int EventPosInFile_;
20 unsigned int EventNBytesToRead_;
21
22public :
23 unsigned int NRun_;
24 unsigned int NEvent_;
25 unsigned long long TimeStamp_;
26 char EventDate_[40];
27
28 typedef std::map<unsigned int,FROG_Element_Base*,std::less<unsigned int> > Frog_map;
29 typedef std::map<unsigned int,FROG_Element_Base*,std::less<unsigned int> >::iterator Frog_map_it;
30
31 virtual bool isCompactible(){ return false; }
32 static unsigned int sizeOf(){ return FROG_Element_Base::sizeOf() + 2*sizeof(unsigned int) + sizeof(unsigned long long); }
33
34 FROG_Element_Event() : FROG_Element_Base(C_EVENTRT){NRun_=0;NEvent_=0;TimeStamp_=0;size_ = sizeOf();SetUpDate();}
35 FROG_Element_Event(unsigned int Run, unsigned int Event, unsigned long long TimeStamp = 0) : FROG_Element_Base(C_EVENTRT){
36 NRun_ = Run;
37 NEvent_ = Event;
38 TimeStamp_= TimeStamp;
39 size_ = sizeOf();
40 SetUpDate();
41 }
42
43
44 FROG_Element_Event(FILE* pFile, unsigned int ChunkId) : FROG_Element_Base(ChunkId){
45 size_ = sizeOf();
46 fread(&NRun_ ,sizeof(NRun_) ,1,pFile);
47 fread(&NEvent_ ,sizeof(NEvent_) ,1,pFile);
48 if(ChunkId==C_EVENTRT){
49 fread(&TimeStamp_ ,sizeof(TimeStamp_) ,1,pFile);
50 }else{
51 TimeStamp_ = 0;
52 }
53 SetUpDate();
54 }
55
56 unsigned int PostPonedEventReading(FILE* pFile, unsigned int EventNBytesToRead){
57 EventPosInFile_ = ftell (pFile);
58 EventNBytesToRead_ = EventNBytesToRead;
59
60 fseek (pFile,EventNBytesToRead,SEEK_CUR);
61 return EventNBytesToRead;
62 }
63
64
65 virtual void write(){
66 std::vector< std::pair<unsigned int, unsigned int > >* blockOfDaughters = write_init();
67 if(blockOfDaughters==NULL)return;
68 data_ = FillBuffer(data_, &NRun_ , sizeof(NRun_));
69 data_ = FillBuffer(data_, &NEvent_ , sizeof(NEvent_));
70 data_ = FillBuffer(data_, &TimeStamp_, sizeof(TimeStamp_));
71 write_daughters(blockOfDaughters);
72 }
73
74 long int EventPosInFile(){return EventPosInFile_;}
75 unsigned int EventNBytesToRead(){return EventNBytesToRead_;}
76
77 void SetUpDate(){
78 if(TimeStamp_==0){
79 sprintf(EventDate_,"No TimeStamp");
80 return;
81 }
82
83 unsigned int Temp = TimeStamp_>>32;
84 if(Temp == 0){
85 sprintf(EventDate_,"Simulated Data");
86 return;
87 }else{
88 time_t rawtime(TimeStamp_>>32);
89 tm* timeinfo = localtime ( &rawtime );
90 strftime(EventDate_,40,"%a %b %d %H:%M:%S %Y",timeinfo);
91 }
92 }
93
94 void FillMap(FROG_Element_Base* mother=NULL) {
95 if(mother==NULL){
96 if(name_map .size() > 0) name_map .clear();
97 if(event_map.size() > 0) event_map.clear();
98 mother = this;
99 }
100
101 const std::vector<FROG_Element_Base*>& dau = mother->daughters();
102 for( unsigned int i=0; i<dau.size(); ++i) {
103 if(FROG_Element_Base_With_DetId* mod = dynamic_cast<FROG_Element_Base_With_DetId*>(dau[i])){
104 event_map[ mod->DetId() ] = dau[i];
105 FillMap(dau[i]);
106 }
107 }
108 }
109
110 FROG_Element_Base* FindByDetId (unsigned int DetId) {
111 if(DetId==0)return NULL;
112 Frog_map_it it = event_map.find(DetId);
113 if(it==event_map.end())return NULL;
114 return it->second;
115 }
116
117public :
118 Frog_map event_map;
119 std::vector<FROG_Element_Base*> name_map;
120};
121
122#endif
Note: See TracBrowser for help on using the repository browser.