CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DataFormats/FEDRawData/interface/DaqData.h

Go to the documentation of this file.
00001 #ifndef FEDRawData_DaqData_h
00002 #define FEDRawData_DaqData_h
00003 
00049 #include <typeinfo>  
00050 #include <vector>  
00051 #include <map>
00052 #include <string>
00053 #include <cmath>
00054    
00055 template <class Format>
00056 class DaqData {
00057 
00058  public:
00059 
00060   DaqData(std::vector<unsigned int> & v) : size_(0), buffer_(0), nobjects_(0) {
00061 
00062     try {
00063 
00064       if (v.size() == 0)  throw string("DaqData: empty input data vector provided: ");     
00065 
00066       int Nfields = Format::getNumberOfFields();
00067       if (v.size()%Nfields != 0)  throw string("DaqData: ERROR. You must provide a number of input values compatibles with the requested format: ");
00068 
00069 
00070       int ObjSize = Format::getFieldLastBit(Nfields-1)+1;
00071       nobjects_ = v.size()/Nfields;
00072       //      cout<<"Going to create "<<nobjects_<< " objects of type "<<typeid(Format).name()<<endl;
00073 
00074       
00075       size_ = (int) ceil(((double)(ObjSize*nobjects_))/8);
00076       buffer_= new  char[size_];      
00077       //   cout<<"The buffer will be "<<size_ <<" bytes long"<<endl; 
00078 
00079       std::vector<unsigned int>::iterator vit = v.begin();
00080       char * p = buffer_;
00081       int bitsalreadyfilled = 0;
00082 
00083       int Totbytes=1;
00084 
00085       for(int i=0; i<nobjects_; i++) {
00086 
00087         //additional bytes necessary to accomodate the current object
00088         int Nbytes = (int) ceil((double)(Format::getFieldLastBit(Nfields-1)+1-8+bitsalreadyfilled)/8); 
00089 
00090         if ((Totbytes+=Nbytes)  > size_) throw string("Exceeded allocated buffer size");
00091         
00092         compressObject(p, vit, bitsalreadyfilled);
00093 
00094         // cout<<"Successfully compressed object "<< i <<endl; 
00095           
00096         data_.insert(std::pair< int, std::vector<unsigned int> >(i,std::vector<unsigned int>(vit-Nfields,vit) ));
00097 
00098         //the second term is necessary in the case the last byte has been fully used 
00099         p+=(Nbytes+(8-bitsalreadyfilled)/8) ;
00100         Totbytes+=(8-bitsalreadyfilled)/8 ;
00101       }
00102       if(bitsalreadyfilled==0) Totbytes--;
00103 
00104       /*
00105        cout << "Compression successful. "<< Totbytes<<" bytes compressed in total"<< endl;
00106        cout<< "Buffer pointer: "<<hex<< buffer_<< dec << "Size of buffer= "<< size_<<endl;
00107       for(int i=0; i<nobjects_; i++) {
00108         cout << "Object # "<< i << " fields: " <<endl;
00109         for(int j=0; j<Format::getNumberOfFields(); j++) cout << getValue(j,i) <<endl;
00110       }
00111       */
00112 
00113     }
00114 
00115     catch (std::string s){
00116 
00117       cout<<"DaqData - Exception caught: " << s <<endl;
00118       cout<<"Object compression failed! No data has been constructed for format: "<< string(typeid(Format).name())<<endl; 
00119       
00120     }
00121 
00122   }
00123 
00124 
00125   DaqData(const unsigned char * ptr, 
00126           int sizeinbytes) : size_(0), buffer_(0), nobjects_(0) {
00127 
00128 
00129     try {
00130 
00131       if (sizeinbytes==0) throw std::string("Buffer size is zero");
00132 
00133       int Nfields = Format::getNumberOfFields();
00134       int ObjSize = Format::getFieldLastBit(Nfields-1)+1;
00135       nobjects_ = (sizeinbytes*8)/ObjSize;
00136 
00137       // cout<<"Going to create "<<nobjects_<< " objects of type "<<typeid(Format).name()<<endl;
00138       // cout<<"The buffer will be "<<size_ <<" bytes long"<<endl;      
00139 
00140       if ((sizeinbytes*8)%ObjSize != 0) {
00141         cout<<"DaqData: there will be  " << (sizeinbytes*8)%ObjSize <<" meaningless bits at the end of the buffer"<<endl;
00142       }
00143 
00144       //     buffer_ = new char[sizeinbytes];
00145       //     memmove(buffer_,ptr,sizeinbytes);
00146 
00147       //      char * p = buffer_;
00148 
00149       const unsigned char * p = ptr;
00150       int bitsalreadyfilled = 0;
00151       
00152       int Totbytes=1;
00153 
00154       for(int i=0; i<nobjects_; i++) {
00155 
00156         std::vector<unsigned int> objdata;
00157         objdata.reserve(Nfields);
00158 
00159         //additional bytes necessary to accomodate the current object
00160         int Nbytes = (int) ceil((double)(Format::getFieldLastBit(Nfields-1)+1-8+bitsalreadyfilled)/8); 
00161 
00162 
00163         if ((Totbytes+=Nbytes) > sizeinbytes) throw std::string("Exceeded allocated buffer size");
00164 
00165         
00166         uncompressObject(p, objdata, bitsalreadyfilled);
00167      
00168         //      cout<<"Successfully uncompressed object "<< i <<endl; 
00169         data_.insert(std::pair< int, std::vector<unsigned int> >(i,objdata) );
00170 
00171         //the second term is necessary in the case the last byte has been fully used 
00172         p+= (Nbytes + (8-bitsalreadyfilled)/8);
00173         Totbytes+= (8-bitsalreadyfilled)/8;
00174 
00175       }
00176 
00177       if(bitsalreadyfilled==0) Totbytes--;
00178 
00179       /*
00180       cout << "Uncompression succeeded. "<< Totbytes<<" bytes uncompressed in total"<< endl;
00181       cout<< "Buffer pointer: "<<hex<< buffer_<< dec<< "Size of buffer= "<< size_<<endl;
00182 
00183       for(int i=0; i<nobjects_; i++) {
00184         cout << "Object # "<< i << " fields: " <<endl;
00185         for(int j=0; j<Format::getNumberOfFields(); j++) cout << getValue(j,i) <<endl;
00186       }
00187       */
00188 
00189     }
00190     catch (std::string s){
00191 
00192       std::cout<<"DaqData - Exception caught: " << s <<std::endl;
00193       std::cout<<"Object uncompression failed! No data has been constructed for format: "<<std::string(typeid(Format).name())<<endl; 
00194       
00195     }
00196 
00197   }
00198 
00199 
00200   DaqData(const DaqData & a) {
00201 
00202     size_ = a.Size();
00203     buffer_ = new char[size_];
00204     memmove(buffer_,a.Buffer(),size_);    
00205     nobjects_ = a.Nobjects();
00206 
00207     for(int i=0; i<nobjects_; i++) {
00208       std::vector<unsigned int> vec;
00209       for(int j=0; j<Format::getNumberOfFields(); j++) vec.push_back(a.getValue(j,i)); 
00210       data_.insert(std::pair< int, std::vector<unsigned int> >(i, vec));
00211     }
00212 
00213   }
00214 
00215 
00216   ~DaqData(){
00217 
00218     // cout<<"Deleting DaqData of type "<<typeid(Format).name()<<endl;
00219     if (buffer_!=0) delete [] buffer_;
00220 
00221   };
00222 
00223 
00224   char * Buffer() const {return buffer_;}
00225 
00226   int Size() const {return size_;}
00227 
00228   int Nobjects() const {
00229     return nobjects_;
00230     /*    cout<<"Nobjects()"<<endl;
00231     int Nfields = Format::getNumberOfFields();
00232     return size_/(Format::getFieldLastBit(Nfields-1)+1);
00233     */
00234   }
00235 
00236   unsigned int getValue(int indfield, int indobj=0) const {
00237     
00238     if (indobj<nobjects_ && indfield < Format::getNumberOfFields()) {
00239       std::map < int, std::vector<unsigned int> >::const_iterator it = data_.find(indobj);
00240       if (it != data_.end()) return ((*it).second)[indfield];
00241       else {
00242         cout<<"DaqData - Strange: object should exist but was not found "<<endl;
00243         return 0;
00244       }
00245     }
00246     else  cout<<"DaqData - Non existent field or object"<<endl;
00247     return 0;
00248 
00249   }
00250 
00251  private:
00252 
00253   void uncompressObject(const  unsigned char * ptr, 
00254                         std::vector<unsigned int> & objdata, 
00255                         int & bitsalreadyfilled) {
00256 
00257     int Nfields = Format::getNumberOfFields();
00258 
00259     int bitstoaccomodate=Format::getFieldLastBit(0)+1; // of current field
00260 
00261     int ifield = 0;
00262     unsigned int value = 0; 
00263 
00264     while (ifield < Nfields) {
00265 
00266       if(bitstoaccomodate > 8 - bitsalreadyfilled ) {
00267 
00268         // cout<<"can't complete value from current byte"<<endl;
00269         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00270 
00271         //1)The syntax below could be faster. 
00272         //  To be checked as soon as time available(check started with prog test4.C) .
00273         //2)check if all cast to unsigned int are really necessary(done, they are not).
00274         //3)Instead of using pow(2,1;2;3;4;5..), a faster enum could be used
00275         //Lower all bits but those not yet read
00276         //value += ( (*ptr & ((unsigned int)pow(2.,8-bitsalreadyfilled)-1)) << bitstoaccomodate + bitsalreadyfilled - 8 ) ;
00277         //              if(bitstoaccomodate > 8) value += ( ((((unsigned int)(*ptr)) << bitsalreadyfilled) & 0xff) << (bitstoaccomodate - 8) );
00278         //      else value += ( ((((unsigned int)(*ptr)) << bitsalreadyfilled) & 0xff) >> (8 - bitstoaccomodate) );
00279 
00280 
00281         if(bitstoaccomodate > 8) value += ( ( (*ptr << bitsalreadyfilled) & 0xff ) << (bitstoaccomodate - 8) );
00282         else value += ( ( (*ptr << bitsalreadyfilled) & 0xff) >> (8 - bitstoaccomodate) );
00283         
00284 
00285         // cout<< "value: "<< hex << value << " - " << dec <<  value<< endl;
00286         // cout<< "byte: "<< hex << (unsigned int)(*ptr) << " - " << dec << (unsigned int)(*ptr) << endl;
00287 
00288 
00289         ptr++;
00290         bitstoaccomodate -= (8-bitsalreadyfilled);
00291         bitsalreadyfilled = 0;
00292 
00293         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00294         
00295       } 
00296 
00297       else if(bitstoaccomodate < (8 - bitsalreadyfilled) && bitstoaccomodate >0){
00298         // cout<<"value can be completed from current byte, which still contain info"<<endl;
00299 
00300         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00301 
00302         //1)The syntax below could be faster. 
00303         //  To be checked as soon as time available.
00304         //2)check if all cast to unsigned int are really necessary.
00305         //3)Instead of using pow(2,1;2;3;4;5..), a faster enum could be used
00306         //Lower all bits but those not yet read
00307         //value += (*ptr & ((unsigned int)pow(2.,8-bitsalreadyfilled)-1)) >> (8 - bitstoaccomodate - bitsalreadyfilled);
00308 
00309         value += ( ( (*ptr << bitsalreadyfilled) & 0xff ) >> (8 - bitstoaccomodate) ) ;
00310 
00311         // cout<< "value: "<< hex << value << " - " << dec <<  value<< endl;
00312         // cout<< "byte: "<< hex << (unsigned int)(*ptr) << " - " << dec << (unsigned int)(*ptr) << endl;
00313 
00314 
00315         objdata.push_back(value);
00316         value = 0;
00317         bitsalreadyfilled+=bitstoaccomodate;
00318 
00319         // cout<<"Field completed"<<endl;
00320 
00321         if(ifield==Nfields-1) return;
00322        
00323         // cout<<"Uncompressing new Field"<<endl;
00324 
00325         ifield++;
00326         bitstoaccomodate=Format::getFieldLastBit(ifield)-Format::getFieldLastBit(ifield-1); 
00327         
00328         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00329 
00330       }
00331 
00332       else if(bitstoaccomodate == (8 - bitsalreadyfilled) && bitstoaccomodate >0){
00333         // cout<<"value can be completed from what left in current byte"<<endl; 
00334         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00335 
00336         //1)The syntax below could be faster. 
00337         //  To be checked as soon as time available.
00338         //2)check if all cast to unsigned int are really necessary.
00339         //3)Instead of using pow(2,1;2;3;4;5..), a faster enum could be used
00340         //Lower all bits but those not yet read
00341         //      value += *ptr & ((unsigned int)pow(2.,8-bitsalreadyfilled)-1);
00342 
00343         value += ( ( (*ptr << bitsalreadyfilled) & 0xff ) >> (8 - bitstoaccomodate) ) ;
00344 
00345         // cout<< "value: "<< hex << value << " - " << dec <<  value<< endl;
00346         // cout<< "byte: "<< hex << (unsigned int)(*ptr) << " - " << dec << (unsigned int)(*ptr) << endl;
00347 
00348 
00349         objdata.push_back(value);
00350         value = 0;
00351         bitsalreadyfilled=0;
00352 
00353         // cout<<"Field completed"<<endl;
00354 
00355         if(ifield==Nfields-1) return;
00356 
00357         // cout<<"Uncompressing new Field"<<endl;
00358 
00359         ptr++;
00360         ifield++;
00361         bitstoaccomodate=Format::getFieldLastBit(ifield)-Format::getFieldLastBit(ifield-1);     
00362 
00363         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00364 
00365       }
00366       else throw std::string(" unexpected situation during uncompression");
00367 
00368     } //end of cycle over fields
00369     
00370   }
00371 
00372 
00373 
00374 
00375   void compressObject(const unsigned char * ptr, std::vector<unsigned int>::iterator & vit, int & bitsalreadyfilled) {
00376 
00377     int Nfields = Format::getNumberOfFields();
00378 
00379     int bitstoaccomodate=Format::getFieldLastBit(0)+1; // of current field
00380     
00381     if (*vit > pow(2.,bitstoaccomodate)-1) throw string("The value is too large to fit in the field ");
00382  
00383     int ifield = 0;
00384 
00385     //Lower all bits but those already filled
00386     *ptr &= 0xff + 1 - (unsigned int)pow(2.,8-bitsalreadyfilled);
00387 
00388     while (ifield < Nfields) {
00389 
00390 
00391       if(bitstoaccomodate > 8 - bitsalreadyfilled ) {
00392 
00393         // cout<<"Field cannot be compressed from what left in current byte"<<endl;
00394         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00395 
00396         *ptr += (((*vit) >> (bitstoaccomodate - (8 - bitsalreadyfilled))) & 0xff);
00397         // cout<< "value: "<< hex << *vit <<" - " << dec <<  *vit<< endl;
00398         // cout<< "byte: "<< hex << (unsigned int)(*ptr) <<" - "<< dec << (unsigned int)(*ptr) << endl;
00399 
00400 
00401         bitstoaccomodate -= (8-bitsalreadyfilled);
00402         bitsalreadyfilled = 0;
00403         ptr++;
00404         *ptr &= 0xff + 1 - (unsigned int)pow(2.,8-bitsalreadyfilled);
00405 
00406         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00407 
00408       } 
00409 
00410       else if(bitstoaccomodate < (8 - bitsalreadyfilled) && bitstoaccomodate >0){
00411 
00412         // cout<<"Field can be compressed in the current byte, which will not be completely filled"<<endl;
00413 
00414         *ptr += ( (((*vit) << 8-bitstoaccomodate) & 0xff) >> (bitsalreadyfilled) );
00415 
00416         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00417         // cout<< "value: "<< hex << *vit <<" - " << dec <<  *vit<< endl;
00418         // cout<< "byte: "<< hex << (unsigned int)(*ptr) <<" - "<< dec << (unsigned int)(*ptr) << endl;
00419 
00420         vit++;
00421         bitsalreadyfilled+=bitstoaccomodate;
00422 
00423         // cout<<"Field completed"<<endl;
00424 
00425         if(ifield==Nfields-1) return;
00426 
00427         // cout<<"Compressing new Field"<<endl;
00428        
00429         ifield++;
00430         bitstoaccomodate=Format::getFieldLastBit(ifield)-Format::getFieldLastBit(ifield-1); 
00431         if (*vit > pow(2.,bitstoaccomodate)-1) throw string("The value is too large to fit in the field ");
00432 
00433         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00434 
00435       }
00436 
00437       else if(bitstoaccomodate == (8 - bitsalreadyfilled) && bitstoaccomodate >0){
00438 
00439         // cout<<"Field can be compressed in the current byte, which will be completely filled"<<endl;
00440 
00441 
00442         *ptr += ( (((*vit) << 8-bitstoaccomodate) & 0xff) >> (bitsalreadyfilled) );
00443 
00444         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00445         // cout<< "value: "<< hex << *vit <<" - " << dec <<  *vit<< endl;
00446         // cout<< "byte: "<< hex << (unsigned int)(*ptr) <<" - "<< dec << (unsigned int)(*ptr) << endl;
00447 
00448         vit++;
00449         bitsalreadyfilled=0;
00450 
00451         // cout<<"Field completed"<<endl;
00452 
00453         if(ifield==Nfields-1) return;
00454 
00455         // cout<<"Compressing new Field"<<endl;
00456 
00457         ptr++;
00458         *ptr &= 0xff + 1 - (unsigned int)pow(2.,8-bitsalreadyfilled);
00459 
00460         ifield++;
00461         bitstoaccomodate=Format::getFieldLastBit(ifield)-Format::getFieldLastBit(ifield-1);     
00462 
00463         if (*vit > pow(2.,bitstoaccomodate)-1) throw string("The value is too large to fit in the field ");
00464 
00465         // cout <<"bitstoaccomodate= "<<bitstoaccomodate<<" bitsalreadyfilled= "<<bitsalreadyfilled<<" ifield="<< ifield<<" Nfields="<<Nfields<<endl;
00466 
00467       }
00468       else throw string(" unexpected situation during compression");
00469 
00470     } //end of cycle over fields
00471     
00472   }
00473 
00474 
00475  private:
00476 
00477   std::map < int, std::vector<unsigned int> > data_;
00478 
00479   int size_;
00480   unsigned char * buffer_;
00481   int nobjects_;
00482 
00483   /* Old implementation of compress
00484  
00485   //assumes a correct number of objects has been sent. Alignment to the byte
00486   int compressObject(unsigned char * p, vector<unsigned int>::iterator & vit, int & bitsalreadyfilled){
00487  
00488     int Nfields = Format::getNumberOfFields();
00489     int Nbytes = (int) (ceil((double)(Format::getFieldLastBit(Nfields-1)+1)/8));
00490  
00491     unsigned int indfield=0; // index of current field
00492     unsigned int bitstoaccomodate=Format::getFieldLastBit(indfield)+1; // of current field
00493 
00494     //Here there should be a check on the size of the first value against the available bits
00495 
00496     for (int ibyte = 0; ibyte < Nbytes ; ibyte++){
00497 
00498       //      int bitsalreadyfilled = 0; // of current byte
00499 
00500       if(bitstoaccomodate>8-bitsalreadyfilled) {
00501         cout<<"More than available bits to accomodate"<<endl;
00502 
00503         *p = ( (*vit) >> (bitstoaccomodate - 8) ) & 0xff;
00504         cout<< "value: "<< hex << *vit << dec <<  *vit<< endl;
00505         cout<< "byte: "<< hex << *p << dec << *p << endl;
00506 
00507         bitstoaccomodate -= 8;
00508         p++;
00509         bitsalreadyfilled = 0;     
00510       } 
00511 
00512       else if(bitstoaccomodate<=8-bitsalreadyfilled && bitstoaccomodate>0){
00513 
00514         cout<<"bits to accomodate less than available"<<endl;
00515 
00516         unsigned int bytevalue=0;
00517 
00518         // First, put the bits of the current object in the current byte
00519         
00520         bytevalue += ( (*vit) << ( 8 - bitstoaccomodate ) ) & 0xff;
00521         cout<< "value: "<< hex << *vit << dec <<  *vit<< endl;
00522         cout<< "byte: "<< hex << bytevalue << dec << bytevalue << endl;
00523 
00524 
00525         bitsalreadyfilled = bitstoaccomodate;
00526         indfield++;
00527 
00528         if (indfield>=Nfields)  return 0;
00529        
00530         vit++;
00531 
00532         //Here there should be a check on the size of the current value against the left available bits
00533 
00534         if(bitsalreadyfilled==8) {
00535           bitstoaccomodate=Format::getFieldLastBit(indfield)-Format::getFieldLastBit(indfield-1);
00536           p++;
00537           continue;
00538         }
00539 
00540         //This is the case of remaining fields and space left in the byte
00541       
00542         //Compute the last field that can be treated for this byte
00543         int lastfield=indfield;
00544         int ntotbits=bitsalreadyfilled+Format::getFieldLastBit(indfield)-Format::getFieldLastBit(indfield-1);
00545         while(ntotbits < 8 && lastfield<Nfields )  {
00546           lastfield++;
00547           ntotbits+=Format::getFieldLastBit(lastfield)-Format::getFieldLastBit(lastfield-1);
00548         }
00549 
00550         // First, fit fields, if there are, that for sure fully fit into the current byte leaving at least one free bit
00551         for(; indfield < lastfield  ; indfield++) {
00552           bitsalreadyfilled += Format::getFieldLastBit(indfield)-Format::getFieldLastBit(indfield-1);
00553           
00554           bytevalue += ((*vit)<<(8-bitsalreadyfilled)) ;
00555           cout<< "value: "<< hex << *vit << dec <<  *vit<< endl;
00556           cout<< "byte: "<< hex << bytevalue << dec << bytevalue << endl;
00557           
00558           if(indfield<Nfields-1) {
00559             vit++;
00560             //Here there should be a check on the size of the current value against the left available bits.
00561           }
00562           else return 0;
00563         }
00564 
00565         //Special treatment of last field having at least some space in the byte. At this point it should always be indfield==lastfield 
00566         
00567         int lastfieldbits=Format::getFieldLastBit(indfield)-Format::getFieldLastBit(indfield-1);
00568         bitstoaccomodate = lastfieldbits - (8-bitsalreadyfilled);
00569         
00570         bytevalue += ((*vit) >> (lastfieldbits - (8-bitsalreadyfilled))) ; 
00571         cout<< "value: "<< hex << *vit << dec <<  *vit<< endl;
00572         cout<< "byte: "<< hex << bytevalue << dec << bytevalue << endl;
00573         
00574         *p=bytevalue;
00575         
00576         //Treatment of the case in which the last field fits too in the current byte
00577         if (bitstoaccomodate==0) {
00578 
00579           if (indfield < Nfields-1) {
00580 
00581             indfield++;
00582             vit++;
00583 
00584             //Here there should be a check on the size of the current value against the left available bits.
00585             
00586             bitstoaccomodate=Format::getFieldLastBit(indfield)-Format::getFieldLastBit(indfield-1);
00587           }
00588           else return 0;
00589         }
00590         p++;
00591       }
00592       else{
00593         cout<<"DaqData - ERROR: unexpected situation"<<endl;
00594       }
00595     } //end of cycle over bytes
00596   
00597     return 0;
00598 
00599   }
00600 
00601 */
00602 
00603 
00604 
00605 };
00606 
00607 
00608 #endif