Fork me on GitHub

source: svn/trunk/Utilities/FROG/Includes/FROG/FROG_Element_Base_With_DetId_And_Name.h@ 218

Last change on this file since 218 was 218, checked in by Xavier Rouby, 16 years ago

memory leak corrected in destructor

File size: 2.2 KB
Line 
1// FROG_Element_Base_With_DetId.h: base class for all modules (which contains a method DetId()
2
3// WARNING : Class heriting from FROG_Element_Base_With_DetId are responsible for saving/loading detId_
4// Loading and writting function of FROG_Element_Base_With_DetId are usefull only to make
5// a group of daughters (branchs) with a detId.
6
7
8//////////////////////////////////////////////////////////////////////
9
10#ifndef _FROG_ELEMENT_BASE_WITH_DETID_AND_NAME_H__
11#define _FROG_ELEMENT_BASE_WITH_DETID_AND_NAME__H__
12
13#include "FROG_Element_Base_With_DetId.h"
14
15class FROG_Element_Base_With_DetId_And_Name : public FROG_Element_Base_With_DetId {
16protected :
17 unsigned short NameLength_;
18public :
19 char* Name_;
20
21public :
22 virtual bool isCompactible(){ return false; }
23 static unsigned int sizeOf() { return 6 + sizeof(unsigned int) + sizeof(unsigned short);}
24
25 ~FROG_Element_Base_With_DetId_And_Name() {delete [] Name_;}
26 FROG_Element_Base_With_DetId_And_Name(unsigned int detId, const char* name, ...) :
27 FROG_Element_Base_With_DetId(C_FEB_DETID_NAME,detId){
28 char FullName[512];
29 va_list args;
30 va_start(args,name);
31 vsprintf(FullName,name,args);
32 va_end(args);
33
34 size_ = sizeOf();
35 NameLength_ = strlen(FullName);
36 Name_ = new char[NameLength_+1];
37 strcpy(Name_,FullName);
38 Name_[NameLength_]='\0';
39 size_ += NameLength_ * sizeof(char);
40 }
41
42 FROG_Element_Base_With_DetId_And_Name(FILE* pFile) : FROG_Element_Base_With_DetId(C_FEB_DETID_NAME){
43 size_ = sizeOf();
44 fread(&detId_ ,sizeof(detId_) ,1,pFile);
45 fread(&NameLength_ ,sizeof(NameLength_) ,1,pFile);
46 Name_ = new char[NameLength_+1];
47 fread(Name_,NameLength_*sizeof(char),1,pFile);
48
49 Name_[NameLength_]='\0';
50 size_ += NameLength_ * sizeof(char);
51 }
52
53 // Fill data_ and size_ with data
54 virtual void write(){
55 std::vector< std::pair<unsigned int, unsigned int > >* blockOfDaughters = write_init();
56
57 data_ = FillBuffer(data_, &detId_, sizeof(detId_)); // write the type
58 data_ = FillBuffer(data_, &NameLength_, sizeof(NameLength_));
59 data_ = FillBuffer(data_, Name_, NameLength_*sizeof(char));
60
61 write_daughters(blockOfDaughters);
62 }
63
64 const char* Name(){return Name_;}
65
66};
67#endif
68
Note: See TracBrowser for help on using the repository browser.